Search in sources :

Example 1 with IAxisTick

use of org.eclipse.swtchart.IAxisTick in project netxms by netxms.

the class LineChart method setTimeRange.

/**
 * Set time range
 *
 * @param from start time
 * @param to end time
 */
public void setTimeRange(final Date from, final Date to) {
    if (zoomedToSelectionX) {
        delayedRangeFrom = from;
        delayedRangeTo = to;
        return;
    }
    delayedRangeFrom = null;
    delayedRangeTo = null;
    timeFrom = from.getTime();
    timeTo = to.getTime();
    getAxisSet().getXAxis(0).setRange(new Range(timeFrom, timeTo));
    int seconds = (int) ((timeTo - timeFrom) / 1000);
    DateFormat format;
    int angle;
    if (seconds <= 600) {
        format = DateFormatFactory.getTimeFormat();
        angle = 0;
    } else if (seconds <= 86400) {
        format = DateFormatFactory.getShortTimeFormat();
        angle = 0;
    } else if (seconds <= 86400 * 7) {
        format = new SimpleDateFormat("E " + DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
        angle = 0;
    } else {
        format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
        angle = 45;
    }
    IAxisTick xTick = getAxisSet().getXAxis(0).getTick();
    xTick.setFormat(format);
    xTick.setTickLabelAngle(angle);
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Range(org.eclipse.swtchart.Range) SimpleDateFormat(java.text.SimpleDateFormat) DataPoint(org.netxms.nxmc.modules.charts.api.DataPoint) Point(org.eclipse.swt.graphics.Point)

Example 2 with IAxisTick

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

the class ScrollableChart method setAxisSettings.

private void setAxisSettings(IAxis axis, IAxisSettings axisSettings) {
    if (axis != null && axisSettings != null) {
        // 
        String axisText = axisSettings.getTitle();
        ITitle title = axis.getTitle();
        title.setText(axisText);
        title.setVisible(axisSettings.isVisible());
        // 
        IAxisTick axisTick = axis.getTick();
        axisTick.setFormat(axisSettings.getDecimalFormat());
        axisTick.setVisible(axisSettings.isVisible());
        // 
        IGrid grid = axis.getGrid();
        grid.setForeground(axisSettings.getGridColor());
        grid.setStyle(axisSettings.getGridLineStyle());
        // 
        axis.setPosition(axisSettings.getPosition());
        /*
			 * Set the color on demand.
			 */
        Color color = axisSettings.getColor();
        if (color != null) {
            title.setForeground(color);
            axisTick.setForeground(color);
        }
        /*
			 * Add a space between the scale and the label.
			 */
        Font font = title.getFont();
        int length = axisText.length() - 1;
        StyleRange styleRange = new StyleRange();
        styleRange.length = (length > 0) ? length : 0;
        styleRange.background = baseChart.getBackground();
        styleRange.foreground = (color != null) ? color : baseChart.getForeground();
        styleRange.font = font;
        styleRange.rise = getAxisExtraSpaceTitle(axis, axisSettings);
        title.setStyleRanges(new StyleRange[] { styleRange });
        // 
        axis.enableLogScale(axisSettings.isEnableLogScale());
        /*
			 * Apply primary axis specific settings.
			 */
        if (axisSettings instanceof IPrimaryAxisSettings) {
            IPrimaryAxisSettings primaryAxisSettings = (IPrimaryAxisSettings) axisSettings;
            axis.enableLogScale(primaryAxisSettings.isEnableLogScale());
            /*
				 * Category is only valid for the X-Axis.
				 */
            if (axis.getDirection() == Direction.X) {
                axis.enableCategory(primaryAxisSettings.isEnableCategory());
                axis.setCategorySeries(primaryAxisSettings.getCategorySeries());
            }
        }
    }
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) IGrid(org.eclipse.swtchart.IGrid) ITitle(org.eclipse.swtchart.ITitle) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 3 with IAxisTick

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

the class SwtBarChart method configureAxes.

@Override
protected void configureAxes() {
    /* Format X axes */
    Stream.of(getChart().getAxisSet().getXAxes()).forEach(a -> {
        a.enableCategory(true);
        a.setCategorySeries(fCategories);
    });
    /* Format Y axes */
    Stream.of(getChart().getAxisSet().getYAxes()).forEach(a -> {
        IAxisTick tick = a.getTick();
        tick.setFormat(getContinuousAxisFormatter(fYRanges, getYDescriptorsInfo()));
    });
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick)

Example 4 with IAxisTick

use of org.eclipse.swtchart.IAxisTick 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)

Example 5 with IAxisTick

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

the class SwtScatterChart method configureAxes.

@Override
protected void configureAxes() {
    /* Format X axes */
    Stream.of(getChart().getAxisSet().getXAxes()).forEach(a -> {
        IAxisTick tick = checkNotNull(a.getTick());
        Format format;
        /* Give a continuous formatter if the descriptors are numericals */
        if (getXDescriptorsInfo().areNumerical()) {
            format = getContinuousAxisFormatter(fXRanges, getXDescriptorsInfo());
        } else {
            fVisibleXMap = HashBiMap.create(fXStringMap);
            format = new LabelFormat(fVisibleXMap);
            updateTickMark(fVisibleXMap, tick, getChart().getPlotArea().getSize().x);
        }
        tick.setFormat(format);
    });
    /* Format Y axes */
    Stream.of(getChart().getAxisSet().getYAxes()).forEach(a -> {
        IAxisTick tick = checkNotNull(a.getTick());
        Format format;
        /* Give a continuous formatter if the descriptors are numericals. */
        if (getYDescriptorsInfo().areNumerical()) {
            format = getContinuousAxisFormatter(fYRanges, getYDescriptorsInfo());
        } else {
            fVisibleYMap = HashBiMap.create(fYStringMap);
            format = new LabelFormat(fVisibleYMap);
            updateTickMark(fVisibleYMap, tick, getChart().getPlotArea().getSize().y);
        }
        tick.setFormat(format);
    });
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) Format(java.text.Format) LabelFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat) LabelFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat)

Aggregations

IAxisTick (org.eclipse.swtchart.IAxisTick)5 Point (org.eclipse.swt.graphics.Point)3 LabelFormat (org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat)2 DateFormat (java.text.DateFormat)1 Format (java.text.Format)1 SimpleDateFormat (java.text.SimpleDateFormat)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Chart (org.eclipse.swtchart.Chart)1 IAxis (org.eclipse.swtchart.IAxis)1 IAxisSet (org.eclipse.swtchart.IAxisSet)1 IGrid (org.eclipse.swtchart.IGrid)1 ITitle (org.eclipse.swtchart.ITitle)1 Range (org.eclipse.swtchart.Range)1 DataPoint (org.netxms.nxmc.modules.charts.api.DataPoint)1