use of org.eclipse.swtchart.IAxis in project tracecompass by tracecompass.
the class AbstractSegmentStoreDensityViewer method clearContent.
/**
* Clears the view content.
*/
private void clearContent() {
final Chart chart = fChart;
if (!chart.isDisposed()) {
ISeriesSet set = chart.getSeriesSet();
ISeries<?>[] series = set.getSeries();
for (int i = 0; i < series.length; i++) {
set.deleteSeries(series[i].getId());
}
for (IAxis axis : chart.getAxisSet().getAxes()) {
axis.setRange(new Range(0, 1));
}
chart.redraw();
}
}
use of org.eclipse.swtchart.IAxis in project tracecompass by tracecompass.
the class AbstractSegmentStoreDensityViewer method updateDisplay.
private synchronized void updateDisplay(String name, Iterable<ISegment> data) {
ISeries<Integer> series = fSeriesType.equals(Type.BAR) ? createSeries() : createAreaSeries(name);
int barWidth = 4;
int preWidth = fOverrideNbPoints == 0 ? fChart.getPlotArea().getSize().x / barWidth : fOverrideNbPoints;
if (!fSeriesType.equals(Type.BAR)) {
preWidth += 2;
}
final int width = preWidth;
double[] xOrigSeries = new double[width];
double[] yOrigSeries = new double[width];
// Set a positive value that is greater than 0 and less than 1.0
Arrays.fill(yOrigSeries, Double.MIN_VALUE);
Optional<ISegment> maxSegment = StreamSupport.stream(data.spliterator(), false).max(SegmentComparators.INTERVAL_LENGTH_COMPARATOR);
long maxLength = Long.MIN_VALUE;
if (maxSegment.isPresent()) {
maxLength = maxSegment.get().getLength();
} else {
for (ISegment segment : data) {
maxLength = Math.max(maxLength, segment.getLength());
}
if (maxLength == Long.MIN_VALUE) {
maxLength = 1;
}
}
double maxFactor = 1.0 / (maxLength + 1.0);
long minX = Long.MAX_VALUE;
for (ISegment segment : data) {
double xBox = segment.getLength() * maxFactor * width;
if (yOrigSeries[(int) xBox] < 1) {
yOrigSeries[(int) xBox] = 1;
} else {
yOrigSeries[(int) xBox]++;
}
minX = Math.min(minX, segment.getLength());
}
double timeWidth = (double) maxLength / (double) width;
for (int i = 0; i < width; i++) {
xOrigSeries[i] = i * timeWidth;
if (!fSeriesType.equals(Type.BAR)) {
xOrigSeries[i] += timeWidth / 2;
}
}
double maxY = Double.NEGATIVE_INFINITY;
for (int i = 0; i < width; i++) {
maxY = Math.max(maxY, yOrigSeries[i]);
}
if (minX == maxLength) {
maxLength++;
minX--;
}
series.setDataModel(new DoubleArraySeriesModel(xOrigSeries, yOrigSeries));
final IAxis xAxis = fChart.getAxisSet().getXAxis(0);
/*
* adjustrange appears to bring origin back since we pad the series with
* 0s, not interesting.
*/
AxisRange currentDurationRange = fCurrentDurationRange;
if (Double.isFinite(currentDurationRange.getLower()) && Double.isFinite(currentDurationRange.getUpper())) {
xAxis.setRange(new Range(currentDurationRange.getLower(), currentDurationRange.getUpper()));
} else {
xAxis.adjustRange();
}
xAxis.getTick().setFormat(DENSITY_TIME_FORMATTER);
ILegend legend = fChart.getLegend();
legend.setVisible(fSegmentStoreProviders.size() > 1);
legend.setPosition(SWT.BOTTOM);
/*
* Clamp range lower to 0.9 to make it log, 0.1 would be scientifically
* accurate, but we cannot have partial counts.
*/
for (ISeries<?> internalSeries : fChart.getSeriesSet().getSeries()) {
maxY = Math.max(maxY, internalSeries.getDataModel().getMaxY().doubleValue());
}
fChart.getAxisSet().getYAxis(0).setRange(new Range(0.9, Math.max(1.0, maxY)));
fChart.getAxisSet().getYAxis(0).enableLogScale(true);
new Thread(() -> {
for (ISegmentStoreDensityViewerDataListener l : fListeners) {
l.chartUpdated();
}
}).start();
}
use of org.eclipse.swtchart.IAxis in project tracecompass by tracecompass.
the class SWTBotCustomChartUtils method assertCategoriesAxis.
/**
* Verify the categories of an axis correspond to the excpected values. This
* method should be called on axis using discrete string values.
*
* @param chart
* The chart to verify
* @param axisType
* The axis to test for
* @param categories
* The expected categories
*/
public static void assertCategoriesAxis(Chart chart, AxisType axisType, String[] categories) {
IAxis axis = (axisType == AxisType.X ? chart.getAxisSet().getXAxes()[0] : chart.getAxisSet().getYAxes()[0]);
assertTrue(axis.isCategoryEnabled());
String[] categorySeries = axis.getCategorySeries();
assertArrayEquals(categories, categorySeries);
}
use of org.eclipse.swtchart.IAxis in project olca-app by GreenDelta.
the class ContributionChart method create.
public static ContributionChart create(Composite parent, FormToolkit tk) {
Composite comp = UI.formComposite(parent, tk);
UI.gridLayout(comp, 2);
UI.gridData(comp, true, true);
// create and configure the chart
Chart chart = new Chart(comp, SWT.NONE);
GridData gdata = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gdata.heightHint = 300;
gdata.widthHint = 700;
chart.setLayoutData(gdata);
chart.setOrientation(SWT.HORIZONTAL);
chart.getLegend().setVisible(false);
// we set a white title just to fix the problem
// that the y-axis is cut sometimes
chart.getTitle().setText(".");
chart.getTitle().setFont(UI.defaultFont());
chart.getTitle().setForeground(Colors.white());
chart.getTitle().setVisible(true);
// configure the x-axis with one category
IAxis x = chart.getAxisSet().getXAxis(0);
x.getTitle().setVisible(false);
x.getTick().setForeground(Colors.darkGray());
x.enableCategory(true);
x.setCategorySeries(new String[] { "" });
// configure the y-axis
IAxis y = chart.getAxisSet().getYAxis(0);
y.getTitle().setVisible(false);
y.getTick().setForeground(Colors.darkGray());
y.getGrid().setStyle(LineStyle.NONE);
y.getTick().setFormat(new DecimalFormat("0.0E0#", new DecimalFormatSymbols(Locale.US)));
y.getTick().setTickMarkStepHint(10);
return new ContributionChart(chart, new ChartLegend(comp));
}
use of org.eclipse.swtchart.IAxis in project netxms by netxms.
the class LineChart method adjustYAxis.
public void adjustYAxis(boolean repaint) {
zoomedToSelectionY = false;
final IAxis yAxis = getAxisSet().getYAxis(0);
yAxis.adjustRange();
final Range range = yAxis.getRange();
if (!configuration.isModifyYBase() && (range.lower > 0))
range.lower = 0;
else if (range.lower < 0)
range.lower = -adjustRange(Math.abs(range.lower));
range.upper = adjustRange(range.upper);
yAxis.setRange(range);
if (repaint)
redraw();
}
Aggregations