Search in sources :

Example 11 with IAxisSet

use of org.eclipse.swtchart.IAxisSet in project swtchart by eclipse.

the class AbstractExtendedChart method adjustSecondaryYAxes.

@Override
public void adjustSecondaryYAxes() {
    IAxisSet axisSet = getAxisSet();
    IAxis yAxis = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    Range range = yAxis.getRange();
    for (int id : axisSet.getYAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_Y_AXIS) {
            IAxis axis = axisSet.getYAxis(id);
            IAxisSettings axisSettings = yAxisSettingsMap.get(id);
            if (axis != null && axisSettings instanceof ISecondaryAxisSettings) {
                IAxisScaleConverter axisScaleConverter = ((ISecondaryAxisSettings) axisSettings).getAxisScaleConverter();
                axisScaleConverter.setChartDataCoordinates(this);
                double start = axisScaleConverter.convertToSecondaryUnit(range.lower);
                double end = axisScaleConverter.convertToSecondaryUnit(range.upper);
                if (end > start) {
                    Range adjustedRange = new Range(start, end);
                    axis.setRange(adjustedRange);
                } else {
                    System.out.println("Can't set secondary y axes range: " + start + "\t" + end);
                }
            }
        }
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 12 with IAxisSet

use of org.eclipse.swtchart.IAxisSet in project tracecompass by tracecompass.

the class SwtScatterChart method refreshDisplayLabels.

@Override
protected void refreshDisplayLabels() {
    /**
     * TODO: support for the Y axis too
     */
    /* Only refresh if labels are visible */
    Chart chart = getChart();
    IAxisSet axisSet = chart.getAxisSet();
    IAxis xAxis = axisSet.getXAxis(0);
    if (!xAxis.getTick().isVisible()) {
        return;
    }
    /*
         * Shorten all the labels to 5 characters plus "…" when the longest
         * label length is more than 50% of the chart height.
         */
    Rectangle rect = chart.getClientArea();
    int lengthLimit = (int) (rect.height * 0.40);
    GC gc = new GC(getParent());
    gc.setFont(xAxis.getTick().getFont());
    // labels.
    if (!fXStringMap.isEmpty()) {
        /* Find the longest category string */
        String longestString = Collections.max(fXStringMap.keySet(), Comparator.comparingInt(String::length));
        /* Get the length and height of the longest label in pixels */
        Point pixels = gc.stringExtent(longestString);
        /* Completely arbitrary */
        int cutLen = 5;
        if (pixels.x > lengthLimit) {
            /* We have to cut down some strings */
            for (Entry<String, Integer> entry : fXStringMap.entrySet()) {
                String reference = checkNotNull(entry.getKey());
                if (reference.length() > cutLen) {
                    String key = reference.substring(0, cutLen) + ELLIPSIS;
                    fVisibleXMap.remove(reference);
                    fVisibleXMap.put(key, entry.getValue());
                } else {
                    fVisibleXMap.inverse().remove(entry.getValue());
                    fVisibleXMap.put(reference, entry.getValue());
                }
            }
        } else {
            /* All strings should fit */
            resetBiMap(fXStringMap, fVisibleXMap);
        }
        for (IAxis axis : axisSet.getXAxes()) {
            IAxisTick tick = axis.getTick();
            tick.setFormat(new LabelFormat(fVisibleXMap));
        }
    }
    /* Cleanup */
    gc.dispose();
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) LabelFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat) IAxisSet(org.eclipse.swtchart.IAxisSet) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Aggregations

IAxisSet (org.eclipse.swtchart.IAxisSet)12 IAxis (org.eclipse.swtchart.IAxis)11 Range (org.eclipse.swtchart.Range)5 Point (org.eclipse.swt.graphics.Point)4 Chart (org.eclipse.swtchart.Chart)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 MassifSnapshot (org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Control (org.eclipse.swt.widgets.Control)1 IAxisTick (org.eclipse.swtchart.IAxisTick)1 ILineSeries (org.eclipse.swtchart.ILineSeries)1 ITitle (org.eclipse.swtchart.ITitle)1