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));
}
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);
}
}
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)));
}
}
}
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;
}
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);
}
}
Aggregations