Search in sources :

Example 11 with ISeries

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

the class MouseMoveShiftEvent method handleEvent.

@Override
public void handleEvent(BaseChart baseChart, Event event) {
    if ((event.stateMask & shiftMask) == shiftMask) {
        /*
			 * Shift the selected series
			 */
        boolean supportDataShift = baseChart.getChartSettings().isSupportDataShift();
        Set<String> selectedSeriesIds = baseChart.getSelectedSeriesIds();
        if (supportDataShift && selectedSeriesIds.size() > 0) {
            /*
				 * Only shift if series have been selected.
				 */
            if (baseChart.getMoveStartTime() == 0) {
                /*
					 * Start
					 */
                baseChart.setCursor(baseChart.getDisplay().getSystemCursor(SWT.CURSOR_SIZENWSE));
                baseChart.setMoveStartTime(System.currentTimeMillis());
                baseChart.setXMoveStart(event.x);
                baseChart.setYMoveStart(event.y);
            } else {
                long deltaTime = System.currentTimeMillis() - baseChart.getMoveStartTime();
                if (deltaTime <= BaseChart.DELTA_MOVE_TIME) {
                    /*
						 * Shift
						 */
                    baseChart.setMoveStartTime(System.currentTimeMillis());
                    // 
                    double shiftX = baseChart.getShiftValue(baseChart.getXMoveStart(), event.x, IExtendedChart.X_AXIS);
                    double shiftY = baseChart.getShiftValue(baseChart.getYMoveStart(), event.y, IExtendedChart.Y_AXIS);
                    // 
                    for (String selectedSeriesId : selectedSeriesIds) {
                        ISeries dataSeries = baseChart.getSeriesSet().getSeries(selectedSeriesId);
                        if (dataSeries != null) {
                            baseChart.shiftSeries(selectedSeriesId, shiftX, shiftY);
                        }
                    }
                    baseChart.redraw();
                    // 
                    baseChart.setXMoveStart(event.x);
                    baseChart.setYMoveStart(event.y);
                } else {
                    /*
						 * Default
						 */
                    baseChart.setMoveStartTime(0);
                    baseChart.setXMoveStart(0);
                    baseChart.setYMoveStart(0);
                }
            }
        }
    }
}
Also used : ISeries(org.eclipse.swtchart.ISeries)

Example 12 with ISeries

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

the class LabelMarker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    BaseChart baseChart = getBaseChart();
    Rectangle rectangle = baseChart.getPlotArea().getClientArea();
    ISeries[] series = baseChart.getSeriesSet().getSeries();
    if (indexSeries >= 0 && indexSeries < series.length) {
        ISeries serie = series[indexSeries];
        int size = serie.getXSeries().length;
        for (int index : labels.keySet()) {
            if (index < size) {
                /*
					 * Draw the label if the index is within the
					 * range of the double array.
					 */
                String label = labels.get(index);
                Point point = serie.getPixelCoordinates(index);
                // 
                if (rectangle.contains(point)) {
                    /*
						 * Calculate x and y
						 */
                    int x;
                    int y;
                    Point labelSize = e.gc.textExtent(label);
                    GC gc = e.gc;
                    if (transform != null) {
                        gc.setTransform(transform);
                        x = -labelSize.x - (point.y - labelSize.x - 15);
                        y = point.x - (labelSize.y / 2);
                    } else {
                        x = point.x - labelSize.x / 2;
                        y = point.y - labelSize.y - 15;
                    }
                    gc.drawText(label, x, y, true);
                    gc.setTransform(null);
                }
            }
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 13 with ISeries

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

the class Axis method adjustRange.

/**
 * Adjusts the axis range to the series belonging to the axis.
 *
 * @param update
 *            true if updating chart layout
 */
public void adjustRange(boolean update) {
    if (isValidCategoryAxis()) {
        setRange(new Range(0, categorySeries.length - 1));
        return;
    }
    double minimum = Double.NaN;
    double maximum = Double.NaN;
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        int axisId = direction == Direction.X ? series.getXAxisId() : series.getYAxisId();
        if (!series.isVisible() || getId() != axisId) {
            continue;
        }
        // get axis length
        int length;
        if (isHorizontalAxis) {
            length = chart.getPlotArea().getSize().x;
        } else {
            length = chart.getPlotArea().getSize().y;
        }
        // get min and max value of series
        Range range = ((Series) series).getAdjustedRange(this, length);
        if (Double.isNaN(minimum) || range.lower < minimum) {
            minimum = range.lower;
        }
        if (Double.isNaN(maximum) || range.upper > maximum) {
            maximum = range.upper;
        }
    }
    // set adjusted range
    if (!Double.isNaN(minimum) && !Double.isNaN(maximum)) {
        if (minimum == maximum) {
            double margin = (minimum == 0) ? 1d : Math.abs(minimum / 2d);
            minimum -= margin;
            maximum += margin;
        }
        setRange(new Range(minimum, maximum), update);
    }
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries)

Example 14 with ISeries

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

the class AxisSet method deleteAxis.

/**
 * Deletes the axis with the axis id for given direction.
 *
 * @param id
 *            the axis id
 * @param direction
 *            the direction
 */
private void deleteAxis(int id, Direction direction) {
    if (id == 0) {
        SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
    }
    if (getAxisMap(direction).get(id) == null) {
        throw new IllegalArgumentException("Given axis id doesn't exist");
    }
    ((Axis) getAxis(id, direction)).dispose();
    getAxisMap(direction).remove(id);
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (direction == Direction.X) {
            if (series.getXAxisId() == id) {
                series.setXAxisId(0);
            }
        } else {
            if (series.getYAxisId() == id) {
                series.setYAxisId(0);
            }
        }
    }
    chart.updateLayout();
}
Also used : ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Example 15 with ISeries

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

the class Legend method sort.

/**
 * Sorts the given series array. For instance, if there are two stack series
 * in horizontal orientation, the top of stack series should appear at top
 * of legend.
 * <p>
 * If there are multiple x axes, the given series array will be sorted with
 * x axis first. And then, the series in each x axis will be sorted with
 * {@link Legend#sort(List, boolean, boolean)}.
 *
 * @param seriesArray
 *            the series array
 * @return the sorted series array
 */
private ISeries[] sort(ISeries[] seriesArray) {
    // create a map between axis id and series list
    Map<Integer, List<ISeries>> map = new HashMap<Integer, List<ISeries>>();
    for (ISeries series : seriesArray) {
        int axisId = series.getXAxisId();
        List<ISeries> list = map.get(axisId);
        if (list == null) {
            list = new ArrayList<ISeries>();
        }
        list.add(series);
        map.put(axisId, list);
    }
    // sort an each series list
    List<ISeries> sortedArray = new ArrayList<ISeries>();
    boolean isVertical = chart.getOrientation() == SWT.VERTICAL;
    for (Entry<Integer, List<ISeries>> entry : map.entrySet()) {
        boolean isCategoryEnabled = chart.getAxisSet().getXAxis(entry.getKey()).isCategoryEnabled();
        sortedArray.addAll(sort(entry.getValue(), isCategoryEnabled, isVertical));
    }
    return sortedArray.toArray(new ISeries[sortedArray.size()]);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ISeries(org.eclipse.swtchart.ISeries)

Aggregations

ISeries (org.eclipse.swtchart.ISeries)60 Point (org.eclipse.swt.graphics.Point)21 ISeriesSet (org.eclipse.swtchart.ISeriesSet)11 Chart (org.eclipse.swtchart.Chart)10 IAxis (org.eclipse.swtchart.IAxis)9 Range (org.eclipse.swtchart.Range)9 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 Color (org.eclipse.swt.graphics.Color)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 GC (org.eclipse.swt.graphics.GC)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2