Search in sources :

Example 1 with IAxis

use of org.swtchart.IAxis in project linuxtools by eclipse.

the class PieChart method setSeriesNames.

/**
 * Sets this chart's category names such that the number of names
 * is equal to the number of pies. This method will only make changes
 * to category series if they are not already properly set.
 * @param numExpected The number of pies / the expected number of category names.
 */
private void setSeriesNames(int numExpected) {
    IAxis xAxis = getAxisSet().getXAxis(0);
    if (xAxis.getCategorySeries().length != numExpected) {
        String[] seriesNames = new String[numExpected];
        for (int i = 0, n = Math.min(xAxis.getCategorySeries().length, numExpected); i < n; i++) {
            seriesNames[i] = xAxis.getCategorySeries()[i];
        }
        for (int i = xAxis.getCategorySeries().length; i < numExpected; i++) {
            // $NON-NLS-1$
            seriesNames[i] = "";
        }
        xAxis.setCategorySeries(seriesNames);
    }
}
Also used : IAxis(org.swtchart.IAxis)

Example 2 with IAxis

use of org.swtchart.IAxis in project linuxtools by eclipse.

the class ChartEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final ChartEditorInput input = (ChartEditorInput) getEditorInput();
    final HeapChart heapChart = input.getChart();
    control = new Chart(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.setBackgroundInPlotArea(LIGHTYELLOW);
    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().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.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.swtchart.Range) ITitle(org.swtchart.ITitle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) IAxis(org.swtchart.IAxis) IAxisSet(org.swtchart.IAxisSet) TableViewer(org.eclipse.jface.viewers.TableViewer) Chart(org.swtchart.Chart)

Example 3 with IAxis

use of org.swtchart.IAxis in project linuxtools by eclipse.

the class BarChartMouseMoveListener method mouseMove.

@Override
public void mouseMove(MouseEvent e) {
    super.mouseMove(e);
    ISeries[] allSeries = chart.getSeriesSet().getSeries();
    if (allSeries.length == 0) {
        return;
    }
    IAxis xAxis = chart.getAxisSet().getXAxis(0);
    String[] categorySeries = ((BarChart) chart).getCategorySeries();
    int barIndex = (int) xAxis.getDataCoordinate(e.x);
    if (0 <= barIndex && barIndex < categorySeries.length) {
        // $NON-NLS-1$
        String textTip = "";
        for (int i = 0; i < allSeries.length; i++) {
            textTip = textTip.concat((i > 0 ? "\n" : "") + // $NON-NLS-1$ //$NON-NLS-2$
            MessageFormat.format(// $NON-NLS-1$ //$NON-NLS-2$
            Messages.BarChartBuilder_ToolTipCoords, allSeries[i].getId(), ((BarChart) chart).getBarValue(i, barIndex)));
        }
        setTextTip(textTip);
    } else {
        tipShell.setVisible(false);
    }
    chart.redraw();
}
Also used : BarChart(org.eclipse.linuxtools.internal.systemtap.graphing.ui.charts.BarChart) ISeries(org.swtchart.ISeries) IAxis(org.swtchart.IAxis)

Example 4 with IAxis

use of org.swtchart.IAxis in project linuxtools by eclipse.

the class GraphDiscreteXControl method handleUpdateEvent.

@Override
public void handleUpdateEvent() {
    IAxis xAxis = builder.getChart().getAxisSet().getXAxis(0);
    Range range = xAxis.getRange();
    zoomInButton.setEnabled(range.upper - range.lower > 0);
    boolean showingAll = builder.getScale() == 1;
    zoomOutButton.setEnabled(!showingAll);
    allButton.setEnabled(!showingAll);
    boolean hitLeft = showingAll || range.lower == 0;
    boolean hitRight = showingAll || range.upper == getNumItems() - 1;
    leftButton.setEnabled(!hitLeft);
    rightButton.setEnabled(!hitRight);
    firstButton.setEnabled(!hitLeft);
    lastButton.setEnabled(!hitRight);
}
Also used : Range(org.swtchart.Range) IAxis(org.swtchart.IAxis)

Example 5 with IAxis

use of org.swtchart.IAxis in project linuxtools by eclipse.

the class TestCreateSystemtapScript method discreteXControlTests.

private static void discreteXControlTests(AbstractChartBuilder cb, int numAxisItems) {
    // Check that default range shows 100% of data.
    IAxis axis = cb.getChart().getAxisSet().getXAxis(0);
    Range range = axis.getRange();
    double scale = cb.getScale();
    double scroll = cb.getScroll();
    assertTrue(range.upper - range.lower == axis.getCategorySeries().length - 1 && range.upper - range.lower == numAxisItems - 1);
    assertTrue(scale == 1.0 && scroll == 1.0);
    // Check that scroll buttons are disabled at 100% range.
    SWTBotButton firstButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_First);
    SWTBotButton leftButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Left);
    SWTBotButton rightButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Right);
    SWTBotButton lastButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Last);
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // Test zooming in. The amount of zoom is arbitrary for this test--just make sure zooming happened.
    SWTBotButton zoomInButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomIn);
    SWTBotButton zoomOutButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomOut);
    SWTBotButton allButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_All);
    assertTrue(zoomInButton.isEnabled());
    assertFalse(zoomOutButton.isEnabled());
    assertFalse(allButton.isEnabled());
    zoomInButton.click();
    assertTrue(zoomOutButton.isEnabled());
    assertTrue(allButton.isEnabled());
    // By default, zooming in should zoom in on the end of the axis (newest data).
    range = axis.getRange();
    assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScale() < scale && cb.getScroll() == 1.0);
    // Left scrolling should now be enabled.
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // Test scrolling left. Again, the specific amount is arbitrary, just make sure scrolling happened.
    leftButton.click();
    range = axis.getRange();
    assertTrue(range.upper < numAxisItems - 1 && cb.getScroll() < scroll);
    int rstore = (int) range.lower;
    assertTrue(rightButton.isEnabled());
    assertTrue(lastButton.isEnabled());
    // Zooming out should bring the range back to 100%.
    zoomOutButton.click();
    range = axis.getRange();
    assertTrue(range.upper - range.lower == numAxisItems - 1 && cb.getScale() == 1.0 && cb.getScroll() < scroll);
    assertTrue(zoomInButton.isEnabled());
    assertFalse(zoomOutButton.isEnabled());
    assertFalse(allButton.isEnabled());
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // For convenience, zooming out after having scrolled somewhere should make zooming in
    // zoom back to the area that was scrolled to.
    scroll = cb.getScroll();
    zoomInButton.click();
    assertTrue(rstore == axis.getRange().lower && scroll == cb.getScroll());
    // Scrolling right should take the range back to the end of the axis.
    rightButton.click();
    range = axis.getRange();
    assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScroll() > scroll);
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // and step right/left. Add a loop limit for safety.
    for (int i = 0; i < numAxisItems; i++) {
        range = axis.getRange();
        if (range.upper == range.lower) {
            break;
        }
        zoomInButton.click();
    }
    range = axis.getRange();
    assertTrue(range.upper == range.lower && range.upper == numAxisItems - 1);
    assertTrue(!zoomInButton.isEnabled());
    for (int i = 0; i < numAxisItems; i++) {
        if (axis.getRange().lower == 0) {
            break;
        }
        leftButton.click();
        assertTrue(axis.getRange().lower < range.lower);
        range = axis.getRange();
        assertEquals(range.lower, range.upper, 0.0);
    }
    assertEquals(axis.getRange().lower, 0, 0.0);
    for (int i = 0; i < numAxisItems; i++) {
        if (axis.getRange().upper == numAxisItems - 1) {
            break;
        }
        rightButton.click();
        assertTrue(axis.getRange().upper > range.upper);
        range = axis.getRange();
        assertEquals(range.lower, range.upper, 0.0);
    }
    assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
    firstButton.click();
    assertEquals(axis.getRange().lower, 0, 0);
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertTrue(rightButton.isEnabled());
    assertTrue(lastButton.isEnabled());
    lastButton.click();
    assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
}
Also used : SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) Range(org.swtchart.Range) IAxis(org.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Aggregations

IAxis (org.swtchart.IAxis)41 Point (org.eclipse.swt.graphics.Point)16 Range (org.swtchart.Range)15 ISeries (org.swtchart.ISeries)9 Date (java.util.Date)6 Color (org.eclipse.swt.graphics.Color)6 ILineSeries (org.swtchart.ILineSeries)6 LocalDate (java.time.LocalDate)5 Composite (org.eclipse.swt.widgets.Composite)5 Chart (org.swtchart.Chart)5 ITitle (org.swtchart.ITitle)4 DecimalFormat (java.text.DecimalFormat)3 Period (java.time.Period)3 ZoneId (java.time.ZoneId)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ArrayList (java.util.ArrayList)3 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)3 Action (org.eclipse.jface.action.Action)3 MessageFormat (com.ibm.icu.text.MessageFormat)2 Instant (java.time.Instant)2