Search in sources :

Example 41 with ISeries

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

the class RScriptExportHandler method printBarPlot.

private void printBarPlot(String fileName, PrintWriter printWriter, ScrollableChart scrollableChart, AxisSettings axisSettings) {
    IAxisSettings axisSettingsX = axisSettings.getAxisSettingsX();
    IAxisSettings axisSettingsY = axisSettings.getAxisSettingsY();
    boolean exportVisibleOnly = axisSettings.isExportVisibleOnly();
    // 
    BaseChart baseChart = scrollableChart.getBaseChart();
    ISeries[] series = baseChart.getSeriesSet().getSeries();
    /*
		 * Read from script.
		 */
    printExecuteInfo(fileName, printWriter);
    /*
		 * Header
		 */
    printWriter.println("# Header");
    printWriter.println("count_values<-NULL");
    printWriter.println("");
    /*
		 * Data
		 */
    printWriter.println("# Data");
    int widthPlotArea = baseChart.getPlotArea().getBounds().width;
    for (ISeries dataSeries : series) {
        if (dataSeries != null) {
            if (exportVisibleOnly) {
                if (dataSeries.isVisible()) {
                    printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
                }
            } else {
                printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
            }
        }
    }
    printWriter.println("");
    /*
		 * Footer
		 */
    printWriter.println("#  Footer");
    printWriter.println("hist(count_values, breaks = range(count_values)[2]-range(count_values)[1]+1, axes=FALSE, xlab='" + axisSettingsX.getLabel() + "', ylab='" + axisSettingsY.getLabel() + "', main='" + scrollableChart.getChartSettings().getTitle() + "')");
    printWriter.println("");
    printWriter.println("axis(2, at = NULL)");
    printWriter.println("lower_x <- NULL");
    printWriter.println("if(min(count_values) %% 10 != 0){");
    printWriter.println("  lower_x <- round(min(count_values) %/% 10,0)*10");
    printWriter.println("} else {");
    printWriter.println("  lower_x <- min(count_values)+0.5");
    printWriter.println("}");
    printWriter.println("");
    printWriter.println("upper_x <- round(max(count_values)/10,0)*10+0.5");
    printWriter.println("axis(1, at = seq(lower_x+0.5, upper_x+0.5, 10), labels=seq(lower_x, upper_x, 10), tick = TRUE )");
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 42 with ISeries

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

the class Legend method updateLayoutData.

/**
 * Update the layout data.
 */
public void updateLayoutData() {
    if (!visible) {
        setLayoutData(new ChartLayoutData(0, 0));
        return;
    }
    int width = 0;
    int height = 0;
    ISeries[] seriesArray = sort(chart.getSeriesSet().getSeries());
    Rectangle r = chart.getClientArea();
    Rectangle titleBounds = ((Title) chart.getTitle()).getBounds();
    int titleHeight = titleBounds.y + titleBounds.height;
    int cellHeight = Util.getExtentInGC(getFont(), null).y;
    if (position == SWT.RIGHT || position == SWT.LEFT) {
        int columns = 1;
        int yPosition = MARGIN;
        int maxCellWidth = 0;
        for (ISeries series : seriesArray) {
            if (!series.isVisibleInLegend()) {
                continue;
            }
            String label = getLegendLabel(series);
            int textWidth = Util.getExtentInGC(getFont(), label).x;
            int cellWidth = textWidth + SYMBOL_WIDTH + MARGIN * 3;
            maxCellWidth = Math.max(maxCellWidth, cellWidth);
            if (yPosition + cellHeight < r.height - titleHeight - MARGIN || yPosition == MARGIN) {
                yPosition += cellHeight + MARGIN;
            } else {
                columns++;
                yPosition = cellHeight + MARGIN * 2;
            }
            cellBounds.put(series.getId(), new Rectangle(maxCellWidth * (columns - 1), yPosition - cellHeight - MARGIN, cellWidth, cellHeight));
            height = Math.max(yPosition, height);
        }
        width = maxCellWidth * columns;
    } else if (position == SWT.TOP || position == SWT.BOTTOM) {
        int rows = 1;
        int xPosition = 0;
        for (ISeries series : seriesArray) {
            if (!series.isVisibleInLegend()) {
                continue;
            }
            String label = getLegendLabel(series);
            int textWidth = Util.getExtentInGC(getFont(), label).x;
            int cellWidth = textWidth + SYMBOL_WIDTH + MARGIN * 3;
            if (xPosition + cellWidth < r.width || xPosition == 0) {
                xPosition += cellWidth;
            } else {
                rows++;
                xPosition = cellWidth;
            }
            cellBounds.put(series.getId(), new Rectangle(xPosition - cellWidth, (cellHeight + MARGIN) * (rows - 1) + MARGIN, cellWidth, cellHeight));
            width = Math.max(xPosition, width);
        }
        height = (cellHeight + MARGIN) * rows + MARGIN;
    }
    setLayoutData(new ChartLayoutData(width, height));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ISeries(org.eclipse.swtchart.ISeries)

Example 43 with ISeries

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

the class PlotArea method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    Point p = getSize();
    GC gc = e.gc;
    // draw the plot area background
    Color oldBackground = gc.getBackground();
    gc.setBackground(getBackground());
    gc.fillRectangle(0, 0, p.x, p.y);
    // draw grid
    for (IAxis axis : chart.getAxisSet().getAxes()) {
        ((Grid) axis.getGrid()).draw(gc, p.x, p.y);
    }
    // draw behind series
    for (ICustomPaintListener listener : paintListeners) {
        if (listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    // draw series. The line series should be drawn on bar series.
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof IBarSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof ILineSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    // draw over series
    for (ICustomPaintListener listener : paintListeners) {
        if (!listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    e.gc.setBackground(oldBackground);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) ICustomPaintListener(org.eclipse.swtchart.ICustomPaintListener) IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Example 44 with ISeries

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

the class AbstractSeparatedValueHandler method execute.

@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    /*
		 * Select the export file.
		 */
    FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
    fileDialog.setOverwrite(true);
    fileDialog.setText(title);
    fileDialog.setFilterExtensions(new String[] { fileExtension });
    // 
    String fileName = fileDialog.open();
    if (fileName != null) {
        /*
			 * Select the X and Y axis to export.
			 */
        ExportSettingsDialog exportSettingsDialog = new ExportSettingsDialog(shell, baseChart);
        exportSettingsDialog.create();
        if (exportSettingsDialog.open() == Window.OK) {
            // 
            int indexAxisX = exportSettingsDialog.getIndexAxisSelectionX();
            int indexAxisY = exportSettingsDialog.getIndexAxisSelectionY();
            // 
            if (indexAxisX >= 0 && indexAxisY >= 0) {
                /*
					 * X Axis Settings
					 */
                IAxisSettings axisSettingsX = baseChart.getXAxisSettings(indexAxisX);
                IAxisScaleConverter axisScaleConverterX = null;
                if (axisSettingsX instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsX;
                    axisScaleConverterX = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Y Axis Settings
					 */
                IAxisSettings axisSettingsY = baseChart.getYAxisSettings(indexAxisY);
                IAxisScaleConverter axisScaleConverterY = null;
                if (axisSettingsY instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsY;
                    axisScaleConverterY = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Print the XY data.
					 */
                PrintWriter printWriter = null;
                try {
                    printWriter = new PrintWriter(new File(fileName));
                    /*
						 * Header
						 */
                    printWriter.print(axisSettingsX.getLabel());
                    printWriter.print(delimiter);
                    printWriter.println(axisSettingsY.getLabel());
                    /*
						 * Axis settings.
						 */
                    boolean exportVisibleOnly = exportSettingsDialog.isExportVisibleOnly();
                    AxisSettings axisSettings = new AxisSettings();
                    axisSettings.setIndexAxisX(indexAxisX);
                    axisSettings.setIndexAxisY(indexAxisY);
                    axisSettings.setAxisSettingsX(axisSettingsX);
                    axisSettings.setAxisScaleConverterX(axisScaleConverterX);
                    axisSettings.setAxisSettingsY(axisSettingsY);
                    axisSettings.setAxisScaleConverterY(axisScaleConverterY);
                    axisSettings.setExportVisibleOnly(exportVisibleOnly);
                    /*
						 * Data
						 */
                    int widthPlotArea = baseChart.getPlotArea().getBounds().width;
                    ISeries[] series = baseChart.getSeriesSet().getSeries();
                    for (ISeries dataSeries : series) {
                        if (dataSeries != null) {
                            if (exportVisibleOnly) {
                                if (dataSeries.isVisible()) {
                                    exportSeries(dataSeries, widthPlotArea, axisSettings, printWriter);
                                }
                            } else {
                                exportSeries(dataSeries, widthPlotArea, axisSettings, printWriter);
                            }
                        }
                    }
                    // 
                    printWriter.flush();
                    MessageDialog.openInformation(shell, title, MESSAGE_OK);
                } catch (FileNotFoundException e) {
                    MessageDialog.openError(shell, title, MESSAGE_ERROR);
                    System.out.println(e);
                } finally {
                    if (printWriter != null) {
                        printWriter.close();
                    }
                }
            }
        }
    }
}
Also used : ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) FileNotFoundException(java.io.FileNotFoundException) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 45 with ISeries

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

the class LineSeries_Selection_Part method initialize.

private void initialize() throws Exception {
    this.setLayout(new GridLayout(1, true));
    this.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    // 
    Composite compositeInfo = new Composite(this, SWT.NONE);
    GridData gridDataComposite = new GridData(GridData.FILL_HORIZONTAL);
    gridDataComposite.horizontalAlignment = SWT.BEGINNING;
    compositeInfo.setLayoutData(gridDataComposite);
    compositeInfo.setLayout(new GridLayout(13, false));
    // 
    createLabel(compositeInfo, "X-Start:");
    textRangeXStart = createText(compositeInfo);
    createLabel(compositeInfo, "X-Stop:");
    textRangeXStop = createText(compositeInfo);
    createLabel(compositeInfo, "Y-Start:");
    textRangeYStart = createText(compositeInfo);
    createLabel(compositeInfo, "Y-Stop:");
    textRangeYStop = createText(compositeInfo);
    createLabel(compositeInfo, "X:");
    textX = createText(compositeInfo);
    createLabel(compositeInfo, "Y:");
    textY = createText(compositeInfo);
    createButtonReset(compositeInfo);
    // 
    lineChart = new LineChart(this, SWT.NONE);
    lineChart.setLayoutData(new GridData(GridData.FILL_BOTH));
    lineChart.getBaseChart().addCustomRangeSelectionHandler(new ICustomSelectionHandler() {

        @Override
        public void handleUserSelection(Event event) {
            BaseChart baseChart = lineChart.getBaseChart();
            Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
            Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
            DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
            DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
            textRangeXStart.setText(decimalFormatX.format(rangeX.lower));
            textRangeXStop.setText(decimalFormatX.format(rangeX.upper));
            textRangeYStart.setText(decimalFormatY.format(rangeY.lower));
            textRangeYStop.setText(decimalFormatY.format(rangeY.upper));
        }
    });
    lineChart.getBaseChart().addCustomPointSelectionHandler(new ICustomSelectionHandler() {

        @Override
        public void handleUserSelection(Event event) {
            BaseChart baseChart = lineChart.getBaseChart();
            double x = baseChart.getSelectedPrimaryAxisValue(event.x, IExtendedChart.X_AXIS);
            double y = baseChart.getSelectedPrimaryAxisValue(event.y, IExtendedChart.Y_AXIS);
            // 
            DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
            DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
            textX.setText(decimalFormatX.format(x));
            textY.setText(decimalFormatY.format(y));
            // 
            try {
                ISeries series = baseChart.getSeriesSet().getSeries(DATA_POINT_SERIES);
                double xSelected = xValues.floor(x);
                double ySelected = yValues.get(xSelected);
                double[] xSeries = new double[] { xSelected };
                double[] ySeries = new double[] { ySelected };
                series.setXSeries(xSeries);
                series.setYSeries(ySeries);
                baseChart.redraw();
            } catch (Exception e) {
            // 
            }
        }
    });
    applyChartSettings();
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ICustomSelectionHandler(org.eclipse.swtchart.extensions.core.ICustomSelectionHandler) DecimalFormat(java.text.DecimalFormat) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart)

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