Search in sources :

Example 6 with IAxisSet

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

the class ChartLayout method parseControls.

/**
 * Parses the controls on given composite.
 *
 * @param composite
 *            the composite
 * @return true if all children found
 */
private boolean parseControls(Composite composite) {
    for (Control child : composite.getChildren()) {
        if (child instanceof Legend) {
            legend = (Legend) child;
        } else if (child instanceof PlotArea) {
            plot = (PlotArea) child;
        }
    }
    if (composite instanceof Chart) {
        IAxisSet axisSet = ((Chart) composite).getAxisSet();
        if (axisSet != null) {
            axes = (Axis[]) axisSet.getAxes();
            if (((Chart) composite).getOrientation() == SWT.HORIZONTAL) {
                horizontalAxes = (Axis[]) axisSet.getXAxes();
                verticalAxes = (Axis[]) axisSet.getYAxes();
            } else {
                verticalAxes = (Axis[]) axisSet.getXAxes();
                horizontalAxes = (Axis[]) axisSet.getYAxes();
            }
        }
        title = (ChartTitle) ((Chart) composite).getTitle();
    }
    if (title == null || legend == null || plot == null || axes == null) {
        // the initialization of chart is not completed yet
        return false;
    }
    return true;
}
Also used : Control(org.eclipse.swt.widgets.Control) IAxisSet(org.eclipse.swtchart.IAxisSet) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 7 with IAxisSet

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

the class ChartEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final ChartEditorInput input = (ChartEditorInput) getEditorInput();
    final HeapChart heapChart = input.getChart();
    control = new InteractiveChart(parent, SWT.FILL);
    heapChart.setChartControl(control);
    final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
    final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
    final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0);
    final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
    final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128);
    final int TICK_GAP = 40;
    control.setBackground(WHITE);
    control.getPlotArea().setBackground(LIGHTYELLOW);
    control.setProposedSaveAsFilename(heapChart.title.substring(0, heapChart.title.indexOf(' ')));
    FontData fd = JFaceResources.getDialogFont().getFontData()[0];
    fd.setStyle(SWT.BOLD);
    Font font = new Font(Display.getDefault(), fd);
    fd.setHeight(fd.getHeight() + 2);
    Font titleFont = new Font(Display.getDefault(), fd);
    ITitle title = control.getTitle();
    title.setFont(titleFont);
    title.setForeground(BLACK);
    title.setText(heapChart.title);
    IAxis xAxis = control.getAxisSet().getXAxis(0);
    xAxis.getGrid().setStyle(LineStyle.NONE);
    xAxis.getTick().setForeground(BLACK);
    ITitle xTitle = xAxis.getTitle();
    xTitle.setFont(font);
    xTitle.setForeground(BLACK);
    xTitle.setText(heapChart.xUnits);
    IAxis yAxis = control.getAxisSet().getYAxis(0);
    yAxis.getGrid().setStyle(LineStyle.SOLID);
    yAxis.getTick().setForeground(BLACK);
    yAxis.getTick().setTickMarkStepHint(TICK_GAP);
    ITitle yTitle = yAxis.getTitle();
    yTitle.setFont(font);
    yTitle.setText(heapChart.yUnits);
    yTitle.setForeground(BLACK);
    control.getLegend().setPosition(SWT.BOTTOM);
    // data
    final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Useful_Heap"));
    lsUseful.setXSeries(heapChart.time);
    lsUseful.setYSeries(heapChart.dataUseful);
    lsUseful.setSymbolType(PlotSymbolType.DIAMOND);
    lsUseful.setSymbolColor(RED);
    lsUseful.setLineColor(RED);
    final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Extra_Heap"));
    lsExtra.setXSeries(heapChart.time);
    lsExtra.setYSeries(heapChart.dataExtra);
    lsExtra.setSymbolType(PlotSymbolType.DIAMOND);
    lsExtra.setSymbolColor(ORANGE);
    lsExtra.setLineColor(ORANGE);
    if (heapChart.dataStacks != null) {
        final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
        Messages.getString("HeapChart.Stacks"));
        lsStack.setXSeries(heapChart.time);
        lsStack.setYSeries(heapChart.dataStacks);
        lsStack.setSymbolType(PlotSymbolType.DIAMOND);
        lsStack.setSymbolColor(DARK_BLUE);
        lsStack.setLineColor(DARK_BLUE);
    }
    final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Total_Heap"));
    lsTotal.setXSeries(heapChart.time);
    lsTotal.setYSeries(heapChart.dataTotal);
    lsTotal.setSymbolType(PlotSymbolType.DIAMOND);
    lsTotal.setSymbolColor(GREEN);
    lsTotal.setLineColor(GREEN);
    // adjust axes
    control.getAxisSet().adjustRange();
    IAxisSet axisSet = control.getAxisSet();
    Range xRange = axisSet.getXAxis(0).getRange();
    Range yRange = axisSet.getYAxis(0).getRange();
    double xExtra = 0.05 * (xRange.upper - xRange.lower);
    double yExtra = 0.05 * (yRange.upper - yRange.lower);
    axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra));
    axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra));
    // listeners
    control.getPlotArea().getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showView();
            TableViewer viewer = input.getView().getTableViewer();
            input.getView().setTopControl(viewer.getControl());
            Point p = new Point(e.x, e.y);
            int closest = 0;
            double d1, d2, d3, currMin;
            double globalMin = Double.MAX_VALUE;
            for (int i = 0; i < heapChart.time.length; i++) {
                // get distance from click event to data points for the given index
                d1 = distance(lsUseful.getPixelCoordinates(i), p);
                d2 = distance(lsExtra.getPixelCoordinates(i), p);
                d3 = distance(lsTotal.getPixelCoordinates(i), p);
                // find the closest data point to the click event
                currMin = Math.min(Math.min(d1, d2), d3);
                if (currMin < globalMin) {
                    closest = i;
                    globalMin = currMin;
                }
            }
            MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest);
            viewer.setSelection(new StructuredSelection(snapshot), true);
            if (e.count == 2 && snapshot.isDetailed()) {
                ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell());
                dialog.setInput(snapshot);
                if (dialog.open() == Window.OK) {
                    dialog.openEditorForResult();
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) ILineSeries(org.eclipse.swtchart.ILineSeries) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MassifSnapshot(org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point) Range(org.eclipse.swtchart.Range) ITitle(org.eclipse.swtchart.ITitle) InteractiveChart(org.eclipse.swtchart.extensions.charts.InteractiveChart) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) IAxis(org.eclipse.swtchart.IAxis) IAxisSet(org.eclipse.swtchart.IAxisSet) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 8 with IAxisSet

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

the class ScrollableChart method updateLinkedCharts.

private void updateLinkedCharts() {
    IAxisSet axisSet = baseChart.getAxisSet();
    Range rangeX = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
    Range rangeY = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
    /*
		 * Adjust the range of the linked charts.
		 */
    for (ScrollableChart linkedScrollableChart : linkedScrollableCharts) {
        IAxisSet axisSetLinked = linkedScrollableChart.getBaseChart().getAxisSet();
        axisSetLinked.getXAxis(BaseChart.ID_PRIMARY_X_AXIS).setRange(rangeX);
        axisSetLinked.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).setRange(rangeY);
        linkedScrollableChart.getBaseChart().adjustSecondaryAxes();
        linkedScrollableChart.getBaseChart().redraw();
        /*
			 * The method setSliderSelection(...) is private.
			 * But as we are in the same class, it works.
			 * Funny, I assumed that only protected and public
			 * methods are accessible.
			 */
        linkedScrollableChart.setSliderSelection(false);
        if (linkedScrollableChart.getChartSettings().isEnableRangeSelector()) {
            linkedScrollableChart.getRangeSelector().adjustRanges(false);
        }
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Range(org.eclipse.swtchart.Range) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 9 with IAxisSet

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

the class ScrollableChart method addPrimaryAxisX.

private void addPrimaryAxisX(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    IAxis xAxisPrimary = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
    IPrimaryAxisSettings primaryAxisSettings = chartSettings.getPrimaryAxisSettingsX();
    setAxisSettings(xAxisPrimary, primaryAxisSettings);
    baseChart.putXAxisSettings(BaseChart.ID_PRIMARY_X_AXIS, primaryAxisSettings);
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) IAxis(org.eclipse.swtchart.IAxis)

Example 10 with IAxisSet

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

the class ScrollableChart method addSecondaryAxesX.

private void addSecondaryAxesX(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    for (int id : axisSet.getXAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_X_AXIS) {
            axisSet.deleteXAxis(id);
        }
    }
    /*
		 * Remove all items except the primary axis settings.
		 */
    baseChart.removeXAxisSettings();
    /*
		 * Add the axis settings.
		 */
    for (ISecondaryAxisSettings secondaryAxisSettings : chartSettings.getSecondaryAxisSettingsListX()) {
        int xAxisId = axisSet.createXAxis();
        IAxis xAxisSecondary = axisSet.getXAxis(xAxisId);
        setAxisSettings(xAxisSecondary, secondaryAxisSettings);
        baseChart.putXAxisSettings(xAxisId, secondaryAxisSettings);
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

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