Search in sources :

Example 36 with ISeries

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

the class TestCreateSystemtapScript method testGraphContents.

@Test
public void testGraphContents() {
    final String valA1 = "A1";
    final String valB1 = "B1";
    createAndViewDummyData(new String[] { valA1, valB1 }, new Integer[] { 0, 0, 1, 2, 2, 4, 3, 6, 4, 8, 5, 10, 6, 12, 7, 14, 8, 16, 9, 18 });
    SWTBotEditor graphEditorA = bot.activeEditor();
    final String valA2 = "A2";
    final String valB2 = "B2";
    createAndViewDummyData(new String[] { valA2, valB2 }, new Integer[] { 2, 0, 5, 1, 7, 2, 10, 3 });
    SWTBotEditor graphEditorB = bot.activeEditor();
    // Add graphs.
    setupGraphWithTests("Others", true);
    String graphTitle2 = "Others - Scatter Graph";
    graphEditorA.show();
    setupGraphWithTests("Values", true);
    String graphTitle1 = "Values - Scatter Graph";
    // Test table & graph contents.
    graphEditorA.bot().cTabItem("Data View").activate();
    SWTBotTable dataTable = bot.table();
    List<String> colNames = dataTable.columns();
    assertEquals(3, colNames.size());
    assertEquals(valA1, colNames.get(1));
    assertEquals(valB1, colNames.get(2));
    assertEquals("2", dataTable.cell(2, 1));
    assertEquals("4", dataTable.cell(2, 2));
    graphEditorA.bot().cTabItem(graphTitle1).activate();
    Matcher<AbstractChartBuilder> matcher = widgetOfType(AbstractChartBuilder.class);
    AbstractChartBuilder cb = bot.widget(matcher);
    ISeries[] series = cb.getChart().getSeriesSet().getSeries();
    assertEquals(2, series.length);
    assertEquals(10, series[0].getXSeries().length);
    assertEquals(10, series[1].getXSeries().length);
    assertEquals(2, (int) series[0].getYSeries()[2]);
    assertEquals(4, (int) series[1].getYSeries()[2]);
    graphEditorB.show();
    graphEditorB.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    colNames = dataTable.columns();
    assertEquals(3, colNames.size());
    assertEquals(valA2, colNames.get(1));
    assertEquals(valB2, colNames.get(2));
    assertEquals("7", dataTable.cell(2, 1));
    assertEquals("2", dataTable.cell(2, 2));
    graphEditorB.bot().cTabItem(graphTitle2).activate();
    cb = bot.widget(matcher);
    series = cb.getChart().getSeriesSet().getSeries();
    assertEquals(2, series.length);
    assertEquals(4, series[0].getXSeries().length);
    assertEquals(4, series[1].getXSeries().length);
    assertEquals(7, (int) series[0].getYSeries()[2]);
    assertEquals(2, (int) series[1].getYSeries()[2]);
    // Test filters on the data table & graphs.
    graphEditorA.show();
    graphEditorA.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    new SWTBotMenu(ContextMenuHelper.contextMenu(dataTable, "Add filter...")).click();
    SWTBotShell shell = bot.shell("Create Filter");
    shell.setFocus();
    // Match Filter - Remove a matching
    bot.button("Match Filter").click();
    bot.button("Next >").click();
    bot.text().setText("2");
    deselectDefaultSelection(0);
    bot.radio(1).click();
    bot.button("Finish").click();
    bot.waitUntil(Conditions.shellCloses(shell));
    bot.waitUntil(new TableHasUpdated(graphEditorA.bot().table(), 9, true));
    assertEquals("3", dataTable.cell(2, 1));
    assertEquals("6", dataTable.cell(2, 2));
    // Filters should be applied to graphs as well as data tables.
    graphEditorA.bot().cTabItem(graphTitle1).activate();
    cb = bot.widget(matcher);
    series = cb.getChart().getSeriesSet().getSeries();
    bot.waitUntil(new ChartHasUpdated(cb.getChart(), 9));
    assertEquals(3, (int) series[0].getYSeries()[2]);
    assertEquals(6, (int) series[1].getYSeries()[2]);
    // Each graph set should have its own filters.
    graphEditorB.show();
    graphEditorB.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    assertEquals(4, dataTable.rowCount());
    assertEquals("2", dataTable.cell(0, 1));
    // Test removing a filter.
    graphEditorA.show();
    graphEditorA.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    new SWTBotMenu(ContextMenuHelper.contextMenu(dataTable, "Remove filter...", "Match Filter: \"" + valA1 + "\" removing \"2\"")).click();
    bot.waitUntil(new TableHasUpdated(graphEditorA.bot().table(), 10, true));
    assertEquals("2", dataTable.cell(2, 1));
    assertEquals("4", dataTable.cell(2, 2));
}
Also used : SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) AbstractChartBuilder(org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ISeries(org.swtchart.ISeries) Test(org.junit.Test)

Example 37 with ISeries

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

the class ChartWithAxisMouseMoveListener method mouseMove.

@Override
public void mouseMove(MouseEvent e) {
    super.mouseMove(e);
    double closestDistance = DIST_TOLERANCE;
    int closestIndex = -1;
    ISeries closestSeries = null;
    Point closestPoint = null;
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        for (int i = 0; i < series.getXSeries().length; i++) {
            Point dataPoint = series.getPixelCoordinates(i);
            if (dataPoint.x >= 0 && dataPoint.y >= 0) {
                double dist = Math.sqrt(Math.pow(dataPoint.x - e.x, 2) + Math.pow(dataPoint.y - e.y, 2));
                if (dist < closestDistance) {
                    closestDistance = dist;
                    closestIndex = i;
                    closestSeries = series;
                    closestPoint = dataPoint;
                }
            }
        }
    }
    if (closestPoint != null) {
        setTextTip(MessageFormat.format(Messages.AbstractChartWithAxisBuilder_ToolTipCoords, closestSeries.getId(), closestSeries.getXSeries()[closestIndex], closestSeries.getYSeries()[closestIndex]));
    } else {
        tipShell.setVisible(false);
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 38 with ISeries

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

the class PieChart method addPieChartSeries.

/**
 * Add data to this Pie Chart. We'll build one pie chart for each value in the array provided. The val matrix must
 * have an array of an array of values. Ex. labels = {'a', 'b'} val = {{1,2,3}, {4,5,6}} This will create 3 pie
 * charts. For the first one, 'a' will be 1 and 'b' will be 4. For the second chart 'a' will be 2 and 'b' will be 5.
 * For the third 'a' will be 3 and 'b' will be 6.
 * @param labels The titles of each series. (These are not the same as titles given to pies.)
 * @param val New values.
 */
public void addPieChartSeries(String[] labels, double[][] val) {
    setSeriesNames(val[0].length);
    for (ISeries s : this.getSeriesSet().getSeries()) {
        this.getSeriesSet().deleteSeries(s.getId());
    }
    int size = Math.min(labels.length, val.length);
    for (int i = 0; i < size; i++) {
        IBarSeries s = (IBarSeries) this.getSeriesSet().createSeries(ISeries.SeriesType.BAR, labels[i]);
        double[] d = new double[val[i].length];
        for (int j = 0; j < val[i].length; j++) {
            d[j] = val[i][j];
        }
        s.setXSeries(d);
        if (customColors != null) {
            s.setBarColor(customColors[i % customColors.length]);
        } else {
            s.setBarColor(new Color(this.getDisplay(), sliceColor(i)));
        }
    }
}
Also used : IBarSeries(org.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ISeries(org.swtchart.ISeries)

Example 39 with ISeries

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

the class PieChartPaintListener method getPieSeriesArray.

private void getPieSeriesArray() {
    ISeries[] series = this.chart.getSeriesSet().getSeries();
    if (series == null || series.length == 0) {
        seriesValues = new double[0][0];
        seriesNames = new String[0];
        return;
    }
    String[] names = this.chart.getAxisSet().getXAxis(0).getCategorySeries();
    Range range = chart.getAxisSet().getXAxis(0).getRange();
    int itemRange = (int) range.upper - (int) range.lower + 1;
    int itemOffset = (int) range.lower;
    seriesValues = new double[itemRange][series.length];
    seriesNames = new String[itemRange];
    for (int i = 0; i < seriesValues.length; i++) {
        seriesNames[i] = names[i + itemOffset];
        for (int j = 0; j < seriesValues[i].length; j++) {
            double[] d = series[j].getXSeries();
            if (d != null && d.length > 0) {
                seriesValues[i][j] = d[i + itemOffset];
            } else {
                seriesValues[i][j] = 0;
            }
        }
    }
    return;
}
Also used : Range(org.swtchart.Range) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 40 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class AccountListView method updateChart.

private void updateChart(Account account) {
    try {
        accountBalanceChart.suspendUpdate(true);
        for (ISeries s : accountBalanceChart.getSeriesSet().getSeries()) accountBalanceChart.getSeriesSet().deleteSeries(s.getId());
        if (account == null)
            return;
        List<AccountTransaction> tx = account.getTransactions();
        if (tx.isEmpty())
            return;
        CurrencyConverter converter = new CurrencyConverterImpl(factory, account.getCurrencyCode());
        Collections.sort(tx, new Transaction.ByDate());
        LocalDate now = LocalDate.now();
        LocalDate start = tx.get(0).getDateTime().toLocalDate();
        LocalDate end = tx.get(tx.size() - 1).getDateTime().toLocalDate();
        if (now.isAfter(end))
            end = now;
        if (now.isBefore(start))
            start = now;
        int days = (int) ChronoUnit.DAYS.between(start, end) + 2;
        LocalDate[] dates = new LocalDate[days];
        double[] values = new double[days];
        dates[0] = start.minusDays(1);
        values[0] = 0d;
        for (int ii = 1; ii < dates.length; ii++) {
            values[ii] = // 
            AccountSnapshot.create(account, converter, start).getFunds().getAmount() / Values.Amount.divider();
            dates[ii] = start;
            start = start.plusDays(1);
        }
        accountBalanceChart.addDateSeries(dates, values, Colors.CASH, account.getName());
        accountBalanceChart.adjustRange();
    } finally {
        accountBalanceChart.suspendUpdate(false);
    }
}
Also used : Transaction(name.abuchen.portfolio.model.Transaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) ISeries(org.swtchart.ISeries) LocalDate(java.time.LocalDate) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Aggregations

ISeries (org.swtchart.ISeries)68 Point (org.eclipse.swt.graphics.Point)27 IAxis (org.swtchart.IAxis)17 Date (java.util.Date)15 ArrayList (java.util.ArrayList)11 Range (org.swtchart.Range)10 LocalDate (java.time.LocalDate)7 HashMap (java.util.HashMap)5 GC (org.eclipse.swt.graphics.GC)5 IBarSeries (org.swtchart.IBarSeries)5 ILineSeries (org.swtchart.ILineSeries)5 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 DataPoint (org.netxms.ui.eclipse.charts.api.DataPoint)4 Series (org.swtchart.internal.series.Series)4 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)3 Interval (name.abuchen.portfolio.util.Interval)3 Pair (name.abuchen.portfolio.util.Pair)3 Color (org.eclipse.swt.graphics.Color)3