Search in sources :

Example 1 with XYGraph

use of org.eclipse.nebula.visualization.xygraph.figures.XYGraph in project nebula by eclipse.

the class SimpleExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(300, 250);
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // create a new XY Graph.
    XYGraph xyGraph = new XYGraph();
    xyGraph.setTitle("Simple Example");
    // set it as the content of LightwightSystem
    lws.setContents(xyGraph);
    // create a trace data provider, which will provide the data to the trace.
    CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(false);
    traceDataProvider.setBufferSize(100);
    traceDataProvider.setCurrentXDataArray(new double[] { 10, 23, 34, 45, 56, 78, 88, 99 });
    traceDataProvider.setCurrentYDataArray(new double[] { 11, 44, 55, 45, 88, 98, 52, 23 });
    // create the trace
    Trace trace = new Trace("Trace1-XY Plot", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);
    // set trace property
    trace.setPointStyle(PointStyle.XCROSS);
    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) Shell(org.eclipse.swt.widgets.Shell) LightweightSystem(org.eclipse.draw2d.LightweightSystem) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Display(org.eclipse.swt.widgets.Display)

Example 2 with XYGraph

use of org.eclipse.nebula.visualization.xygraph.figures.XYGraph in project nebula by eclipse.

the class ComprehensiveExample method createXYGraph.

private static ToolbarArmedXYGraph createXYGraph() {
    final Trace trace2;
    final Trace trace3;
    final IXYGraph xyGraph;
    Runnable updater;
    final CircularBufferDataProvider trace2Provider;
    final Trace trace4;
    final ToolbarArmedXYGraph toolbarArmedXYGraph;
    xyGraph = new XYGraph();
    xyGraph.setTitle("XY Graph Test");
    xyGraph.setFont(XYGraphMediaFactory.getInstance().getFont(XYGraphMediaFactory.FONT_TAHOMA));
    xyGraph.getPrimaryXAxis().setTitle("Time");
    xyGraph.getPrimaryYAxis().setTitle("Amplitude");
    xyGraph.getPrimaryXAxis().setRange(new Range(0, 200));
    xyGraph.getPrimaryXAxis().setDateEnabled(true);
    xyGraph.getPrimaryYAxis().setAutoScale(true);
    xyGraph.getPrimaryXAxis().setAutoScale(true);
    xyGraph.getPrimaryXAxis().setShowMajorGrid(true);
    xyGraph.getPrimaryYAxis().setShowMajorGrid(true);
    xyGraph.getPrimaryXAxis().setAutoScaleThreshold(0);
    final Axis x2Axis = new Axis("X-2", false);
    x2Axis.setTickLabelSide(LabelSide.Secondary);
    // x2Axis.setAutoScale(true);
    xyGraph.addAxis(x2Axis);
    final Axis y2Axis = new Axis("Log Scale", true);
    y2Axis.setRange(10, 500);
    y2Axis.setLogScale(true);
    // y2Axis.setAutoScale(true);
    y2Axis.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_PINK));
    y2Axis.setTickLabelSide(LabelSide.Secondary);
    xyGraph.addAxis(y2Axis);
    Axis y3Axis = new Axis("Y-3", true);
    y3Axis.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLUE));
    y3Axis.setTickLabelSide(LabelSide.Secondary);
    y3Axis.setRange(new Range(-2, 3));
    y3Axis.setShowMajorGrid(false);
    y3Axis.setAutoScale(true);
    // xyGraph.addAxis(y3Axis);
    trace2Provider = new CircularBufferDataProvider(true);
    trace2Provider.setBufferSize(100);
    trace2Provider.setUpdateDelay(100);
    trace2 = new Trace("Trace 2", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), trace2Provider);
    trace2.setDataProvider(trace2Provider);
    trace2.setTraceType(TraceType.SOLID_LINE);
    trace2.setLineWidth(1);
    trace2.setPointStyle(PointStyle.POINT);
    trace2.setPointSize(4);
    trace2.setBaseLine(BaseLine.NEGATIVE_INFINITY);
    trace2.setAreaAlpha(100);
    trace2.setAntiAliasing(true);
    trace2.setErrorBarEnabled(false);
    // trace2.setDrawYErrorInArea(true);
    trace2.setYErrorBarType(ErrorBarType.BOTH);
    trace2.setXErrorBarType(ErrorBarType.NONE);
    trace2.setErrorBarCapWidth(3);
    final CircularBufferDataProvider trace3Provider = new CircularBufferDataProvider(true);
    trace3 = new Trace("Trace3", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), trace3Provider);
    trace3.setPointStyle(PointStyle.XCROSS);
    trace3.setTraceType(TraceType.BAR);
    trace3.setLineWidth(4);
    trace3Provider.setUpdateDelay(100);
    xyGraph.addTrace(trace3);
    xyGraph.addTrace(trace2);
    final CircularBufferDataProvider trace4Provider = new CircularBufferDataProvider(false);
    trace4 = new Trace("Trace 4-Lissajous", x2Axis, y2Axis, trace4Provider);
    // trace4.setPointStyle(PointStyle.POINT);
    trace4.setPointSize(2);
    trace4Provider.setUpdateDelay(100);
    trace4Provider.setBufferSize(100);
    xyGraph.addTrace(trace4);
    toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);
    // add key listener to XY-Graph. The key pressing will only be monitored
    // when the
    // graph gains focus.
    xyGraph.setFocusTraversable(true);
    xyGraph.setRequestFocusEnabled(true);
    xyGraph.getPlotArea().addMouseListener(new MouseListener.Stub() {

        @Override
        public void mousePressed(final MouseEvent me) {
            xyGraph.requestFocus();
        }
    });
    xyGraph.addKeyListener(new KeyListener.Stub() {

        @Override
        public void keyPressed(final KeyEvent ke) {
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'z')) {
                xyGraph.getOperationsManager().undo();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'y')) {
                xyGraph.getOperationsManager().redo();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'x')) {
                xyGraph.performAutoScale();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 's')) {
                final ImageLoader loader = new ImageLoader();
                loader.data = new ImageData[] { xyGraph.getImage().getImageData() };
                final FileDialog dialog = new FileDialog(Display.getDefault().getShells()[0], SWT.SAVE);
                dialog.setFilterNames(new String[] { "PNG Files", "All Files (*.*)" });
                // Windows
                dialog.setFilterExtensions(new String[] { "*.png", "*.*" });
                final String path = dialog.open();
                if ((path != null) && !path.equals("")) {
                    loader.save(path, SWT.IMAGE_PNG);
                }
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode + 'a' - 97 == 't')) {
                switch(xyGraph.getZoomType()) {
                    case RUBBERBAND_ZOOM:
                        xyGraph.setZoomType(ZoomType.HORIZONTAL_ZOOM);
                        break;
                    case HORIZONTAL_ZOOM:
                        xyGraph.setZoomType(ZoomType.VERTICAL_ZOOM);
                        break;
                    case VERTICAL_ZOOM:
                        xyGraph.setZoomType(ZoomType.ZOOM_IN);
                        break;
                    case ZOOM_IN:
                        xyGraph.setZoomType(ZoomType.ZOOM_OUT);
                        break;
                    case ZOOM_OUT:
                        xyGraph.setZoomType(ZoomType.PANNING);
                        break;
                    case PANNING:
                        xyGraph.setZoomType(ZoomType.NONE);
                        break;
                    case NONE:
                        xyGraph.setZoomType(ZoomType.RUBBERBAND_ZOOM);
                        break;
                    default:
                        break;
                }
            }
        }
    });
    updater = new Runnable() {

        private double updateIndex;

        private long t = System.currentTimeMillis();

        private boolean running = true;

        public void run() {
            t += 60000;
            trace3Provider.setCurrentYData(Math.cos(updateIndex), t);
            if (((updateIndex >= 10) && (updateIndex <= 10.5)) || ((updateIndex >= 20) && (updateIndex <= 20.2))) {
                trace2Provider.addSample(new Sample(t, Double.NaN));
                running = false;
            } else {
                final Sample sampe = new Sample(t, Math.sin(updateIndex), 0.1 * Math.random(), 0.1 * Math.random(), t * 0.0000001 * Math.random(), t * 0.0000001 * Math.random(), "sdfsf");
                trace2Provider.addSample(sampe);
            }
            trace2Provider.setCurrentYDataTimestamp(t);
            trace4Provider.setCurrentXData(Math.sin(updateIndex + 10) * 20 + 50);
            trace4Provider.setCurrentYData(Math.cos(updateIndex) * 30 + 50);
            updateIndex += 0.1;
            if (running) {
                Display.getCurrent().timerExec(1, this);
            }
        }
    };
    Display.getCurrent().timerExec(1000, updater);
    return toolbarArmedXYGraph;
}
Also used : MouseEvent(org.eclipse.draw2d.MouseEvent) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) Sample(org.eclipse.nebula.visualization.xygraph.dataprovider.Sample) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) Range(org.eclipse.nebula.visualization.xygraph.linearscale.Range) Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) KeyEvent(org.eclipse.draw2d.KeyEvent) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) MouseListener(org.eclipse.draw2d.MouseListener) ImageData(org.eclipse.swt.graphics.ImageData) KeyListener(org.eclipse.draw2d.KeyListener) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog) Axis(org.eclipse.nebula.visualization.xygraph.figures.Axis)

Example 3 with XYGraph

use of org.eclipse.nebula.visualization.xygraph.figures.XYGraph in project nebula by eclipse.

the class XYGraphTest2 method main.

public static void main(final String[] args) {
    // if testName is Default, the original Axis implementation will be
    // used. If Diamond, the new DAxis implementation will be used to
    // generate the tick marks.
    String testName = "Default";
    String[] testNames = new String[] { "Default", "Diamond" };
    final Shell shell = new Shell();
    shell.setSize(800, 500);
    shell.open();
    final LightweightSystem lws = new LightweightSystem(shell);
    XYGraphTest2 testFigure = null;
    if (testName.equals(testNames[0])) {
        testFigure = new XYGraphTest2(new XYGraph(new DefaultAxesFactory()), new Axis("X-2", false), new Axis("Log Scale", true));
    } else {
        testFigure = new XYGraphTest2(new XYGraph(new DAxesFactory()), new DAxis("X-2", false), new DAxis("Log Scale", true));
    }
    lws.setContents(testFigure);
    shell.setText("XY Graph Test");
    final Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
// System.out.println(Calendar.getInstance().getTime());
}
Also used : Shell(org.eclipse.swt.widgets.Shell) DefaultAxesFactory(org.eclipse.nebula.visualization.xygraph.figures.DefaultAxesFactory) DAxesFactory(org.eclipse.nebula.visualization.xygraph.figures.DAxesFactory) DAxis(org.eclipse.nebula.visualization.xygraph.figures.DAxis) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) DAxis(org.eclipse.nebula.visualization.xygraph.figures.DAxis) Axis(org.eclipse.nebula.visualization.xygraph.figures.Axis) Display(org.eclipse.swt.widgets.Display)

Example 4 with XYGraph

use of org.eclipse.nebula.visualization.xygraph.figures.XYGraph in project nebula by eclipse.

the class SimpleToolbarArmedXYGraphExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(600, 400);
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // create a new XY Graph.
    IXYGraph xyGraph = new XYGraph();
    ToolbarArmedXYGraph toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);
    xyGraph.setTitle("Simple Toolbar Armed XYGraph Example");
    // set it as the content of LightwightSystem
    lws.setContents(toolbarArmedXYGraph);
    xyGraph.getPrimaryXAxis().setShowMajorGrid(true);
    xyGraph.getPrimaryYAxis().setShowMajorGrid(true);
    // create a trace data provider, which will provide the data to the
    // trace.
    CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(false);
    traceDataProvider.setBufferSize(100);
    traceDataProvider.setCurrentXDataArray(new double[] { 10, 23, 34, 45, 56, 78, 88, 99 });
    traceDataProvider.setCurrentYDataArray(new double[] { 11, 44, 55, 45, 88, 98, 52, 23 });
    // create the trace
    Trace trace = new Trace("Trace1-XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), traceDataProvider);
    // set trace property
    trace.setPointStyle(PointStyle.XCROSS);
    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) Shell(org.eclipse.swt.widgets.Shell) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) LightweightSystem(org.eclipse.draw2d.LightweightSystem) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Display(org.eclipse.swt.widgets.Display)

Example 5 with XYGraph

use of org.eclipse.nebula.visualization.xygraph.figures.XYGraph in project nebula by eclipse.

the class StaircaseExample method main.

public static void main(final String[] args) {
    // Main window (shell)
    final Shell shell = new Shell();
    shell.setSize(800, 500);
    shell.open();
    // XYGraph
    final LightweightSystem lws = new LightweightSystem(shell);
    final ToolbarArmedXYGraph plot = new ToolbarArmedXYGraph(new XYGraph(), XYGraphFlags.SEPARATE_ZOOM | XYGraphFlags.STAGGER);
    final XYGraph xygraph = (XYGraph) plot.getXYGraph();
    xygraph.setTransparent(false);
    xygraph.setTitle("You should see a line. Zoom out to see more data");
    lws.setContents(plot);
    // Add data & trace
    final CircularBufferDataProvider data = new CircularBufferDataProvider(true);
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 2, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 3, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    // Add Double.NaN gap, single point
    data.addSample(new Sample(next_x++, Double.NaN, 0, 0, 0, 0, "Disconnected"));
    data.addSample(new Sample(next_x++, 1, 0, 0, 0, 0));
    // Another gap, single point
    data.addSample(new Sample(next_x++, Double.NaN, 0, 0, 0, 0, "Disconnected"));
    data.addSample(new Sample(next_x++, 2, 0, 0, 0, 0));
    // Last value is valid 'forever'
    data.addSample(new Sample(Double.MAX_VALUE, 2, 0, 0, 0, 0));
    // Always looked OK with this range
    xygraph.getPrimaryXAxis().setRange(data.getXDataMinMax());
    xygraph.getPrimaryYAxis().setRange(data.getYDataMinMax());
    // With STEP_HORIZONTALLY this should have shown just a horizontal
    // line, but a bug resulted in nothing when both the 'start' and 'end'
    // point of the horizontal line were outside the plot range.
    // Similarly, using STEP_VERTICALLY failed to draw anything when
    // both end-points of the horizontal or vertical section of the step
    // were outside the plot. (fixed)
    // 
    // There's still a question about handling 'YErrorInArea':
    // For now, the axis intersection removes x/y errors,
    // so when moving a sample with y error left or right outside
    // of the plot range, the error area suddenly shrinks when
    // the axis intersection is assumed to have +-0 y error.
    xygraph.getPrimaryXAxis().setRange(4.1, 4.9);
    // Gap, start of X range, sample @ x==8, gap @ 9, end of range.
    // Bug failed to show line from that sample up to gap @ 9.
    xygraph.getPrimaryXAxis().setRange(7.5, 9.5);
    final Trace trace = new Trace("Demo", xygraph.getPrimaryXAxis(), xygraph.getPrimaryYAxis(), data);
    trace.setTraceType(TraceType.STEP_HORIZONTALLY);
    // trace.setTraceType(TraceType.STEP_VERTICALLY);
    // // SOLID_LINE does not show individual points
    // trace.setTraceType(TraceType.SOLID_LINE);
    // trace.setPointStyle(PointStyle.CIRCLE);
    trace.setErrorBarEnabled(true);
    trace.setDrawYErrorInArea(true);
    xygraph.addTrace(trace);
    Font LEGEND_FONT = XYGraphMediaFactory.getInstance().getFont(new FontData("Lucida Sans", 11, SWT.BOLD));
    Legend legend = xygraph.getLegend(trace);
    legend.setDrawBorder(true);
    legend.setPreferredHeight(100);
    legend.setTextFont(LEGEND_FONT);
    // SWT main loop
    final Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) Shell(org.eclipse.swt.widgets.Shell) Legend(org.eclipse.nebula.visualization.xygraph.figures.Legend) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) Sample(org.eclipse.nebula.visualization.xygraph.dataprovider.Sample) FontData(org.eclipse.swt.graphics.FontData) LightweightSystem(org.eclipse.draw2d.LightweightSystem) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Font(org.eclipse.swt.graphics.Font) Display(org.eclipse.swt.widgets.Display)

Aggregations

XYGraph (org.eclipse.nebula.visualization.xygraph.figures.XYGraph)21 LightweightSystem (org.eclipse.draw2d.LightweightSystem)16 CircularBufferDataProvider (org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider)16 Trace (org.eclipse.nebula.visualization.xygraph.figures.Trace)16 IXYGraph (org.eclipse.nebula.visualization.xygraph.figures.IXYGraph)12 ToolbarArmedXYGraph (org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph)11 Display (org.eclipse.swt.widgets.Display)10 Shell (org.eclipse.swt.widgets.Shell)10 Axis (org.eclipse.nebula.visualization.xygraph.figures.Axis)8 Canvas (org.eclipse.swt.widgets.Canvas)5 Sample (org.eclipse.nebula.visualization.xygraph.dataprovider.Sample)3 Annotation (org.eclipse.nebula.visualization.xygraph.figures.Annotation)3 Legend (org.eclipse.nebula.visualization.xygraph.figures.Legend)3 Font (org.eclipse.swt.graphics.Font)3 FontData (org.eclipse.swt.graphics.FontData)3 DAxesFactory (org.eclipse.nebula.visualization.xygraph.figures.DAxesFactory)2 KeyEvent (org.eclipse.draw2d.KeyEvent)1 KeyListener (org.eclipse.draw2d.KeyListener)1 MouseEvent (org.eclipse.draw2d.MouseEvent)1 MouseListener (org.eclipse.draw2d.MouseListener)1