use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class TestCreateSystemtapScript method continuousControlTests.
private static void continuousControlTests(AbstractChartBuilder cb, boolean isXAxis) {
// Continuous scaling/scrolling is less strict/predictable than discrete scrolling,
// so just check that the controls perform their intended actions.
IAxis axis;
SWTBotButton zoomInButton, zoomOutButton;
SWTBotScale zoomScale;
SWTBotSlider scrollBar;
int flipSign;
if (isXAxis) {
axis = cb.getChart().getAxisSet().getXAxis(0);
zoomInButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ZoomInTooltip);
zoomOutButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ZoomOutTooltip);
zoomScale = bot.scaleWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ScaleMessage);
scrollBar = bot.sliderWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ScrollMessage);
flipSign = 1;
} else {
axis = cb.getChart().getAxisSet().getYAxis(0);
zoomInButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ZoomInTooltip);
zoomOutButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ZoomOutTooltip);
zoomScale = bot.scaleWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ScaleMessage);
scrollBar = bot.sliderWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ScrollMessage);
flipSign = -1;
}
double scale = getAxisScale(cb, isXAxis);
double scroll = getAxisScroll(cb, isXAxis);
int thumb = scrollBar.getThumb();
// Default range should be 100%, so zooming out shouldn't have an effect yet.
assertEquals(scale, 1.0, 0);
int zoomValue = zoomScale.getValue();
Range range = axis.getRange();
zoomOutButton.click();
Range range2 = axis.getRange();
assertTrue(range.upper == range2.upper && range.lower == range2.lower && zoomScale.getValue() == zoomValue && getAxisScale(cb, isXAxis) == scale && scrollBar.getThumb() == thumb);
// Zoom in & back out with the zoom buttons.
zoomInButton.click();
range2 = axis.getRange();
assertTrue(range2.upper - range2.lower < range.upper - range.lower && flipSign * (zoomScale.getValue() - zoomValue) > 0 && getAxisScale(cb, isXAxis) < scale && scrollBar.getThumb() < thumb);
zoomOutButton.click();
range2 = axis.getRange();
assertTrue(range.upper == range2.upper && range.lower == range2.lower && zoomScale.getValue() == zoomValue && getAxisScale(cb, isXAxis) == scale && scrollBar.getThumb() == thumb);
// Zoom in with the Scale control.
int controlRange = zoomScale.getMaximum() - zoomScale.getMinimum();
zoomScale.setValue(zoomScale.getValue() + controlRange / 2 * flipSign);
// Note: the charts need some time to be updated after using the scale/slider controls.
// Sleeping for a brief moment is faster than using a bot wait condition.
bot.sleep(100);
range2 = axis.getRange();
assertTrue(range2.upper - range2.lower < range.upper - range.lower && getAxisScale(cb, isXAxis) < scale && scrollBar.getThumb() < thumb);
range = range2;
thumb = scrollBar.getThumb();
scale = getAxisScale(cb, isXAxis);
zoomScale.setValue(zoomScale.getValue() - controlRange / 4 * flipSign);
bot.sleep(100);
range2 = axis.getRange();
assertTrue(range2.upper - range2.lower > range.upper - range.lower && getAxisScale(cb, isXAxis) > scale && scrollBar.getThumb() > thumb);
// Test scrolling. Don't assume an initial scroll position, as it may be changed
// in future versions (it's more likely to change than default zoom, at least).
thumb = scrollBar.getThumb();
controlRange = scrollBar.getMaximum() - scrollBar.getThumb() - scrollBar.getMinimum();
scrollBar.setSelection(controlRange / 2);
bot.sleep(100);
assertEquals(scrollBar.getThumb(), thumb);
// Scroll towards origin.
range = axis.getRange();
scrollBar.setSelection(scrollBar.getSelection() - controlRange / 4 * flipSign);
bot.sleep(100);
range2 = axis.getRange();
assertTrue(range2.upper - range2.lower == range.upper - range.lower && range2.upper < range.upper && getAxisScroll(cb, isXAxis) < scroll);
// Scroll away from origin.
range = range2;
scroll = getAxisScroll(cb, isXAxis);
scrollBar.setSelection(scrollBar.getSelection() + controlRange / 8 * flipSign);
bot.sleep(100);
range2 = axis.getRange();
assertTrue(range2.upper - range2.lower == range.upper - range.lower && range2.upper > range.upper && getAxisScroll(cb, isXAxis) > scroll);
}
use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class TestCreateSystemtapScript method discreteXControlTests.
private static void discreteXControlTests(AbstractChartBuilder cb, int numAxisItems) {
// Check that default range shows 100% of data.
IAxis axis = cb.getChart().getAxisSet().getXAxis(0);
Range range = axis.getRange();
double scale = cb.getScale();
double scroll = cb.getScroll();
assertTrue(range.upper - range.lower == axis.getCategorySeries().length - 1 && range.upper - range.lower == numAxisItems - 1);
assertTrue(scale == 1.0 && scroll == 1.0);
// Check that scroll buttons are disabled at 100% range.
SWTBotButton firstButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_First);
SWTBotButton leftButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Left);
SWTBotButton rightButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Right);
SWTBotButton lastButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Last);
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// Test zooming in. The amount of zoom is arbitrary for this test--just make sure zooming happened.
SWTBotButton zoomInButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomIn);
SWTBotButton zoomOutButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomOut);
SWTBotButton allButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_All);
assertTrue(zoomInButton.isEnabled());
assertFalse(zoomOutButton.isEnabled());
assertFalse(allButton.isEnabled());
zoomInButton.click();
assertTrue(zoomOutButton.isEnabled());
assertTrue(allButton.isEnabled());
// By default, zooming in should zoom in on the end of the axis (newest data).
range = axis.getRange();
assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScale() < scale && cb.getScroll() == 1.0);
// Left scrolling should now be enabled.
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// Test scrolling left. Again, the specific amount is arbitrary, just make sure scrolling happened.
leftButton.click();
range = axis.getRange();
assertTrue(range.upper < numAxisItems - 1 && cb.getScroll() < scroll);
int rstore = (int) range.lower;
assertTrue(rightButton.isEnabled());
assertTrue(lastButton.isEnabled());
// Zooming out should bring the range back to 100%.
zoomOutButton.click();
range = axis.getRange();
assertTrue(range.upper - range.lower == numAxisItems - 1 && cb.getScale() == 1.0 && cb.getScroll() < scroll);
assertTrue(zoomInButton.isEnabled());
assertFalse(zoomOutButton.isEnabled());
assertFalse(allButton.isEnabled());
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// For convenience, zooming out after having scrolled somewhere should make zooming in
// zoom back to the area that was scrolled to.
scroll = cb.getScroll();
zoomInButton.click();
assertTrue(rstore == axis.getRange().lower && scroll == cb.getScroll());
// Scrolling right should take the range back to the end of the axis.
rightButton.click();
range = axis.getRange();
assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScroll() > scroll);
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
// and step right/left. Add a loop limit for safety.
for (int i = 0; i < numAxisItems; i++) {
range = axis.getRange();
if (range.upper == range.lower) {
break;
}
zoomInButton.click();
}
range = axis.getRange();
assertTrue(range.upper == range.lower && range.upper == numAxisItems - 1);
assertTrue(!zoomInButton.isEnabled());
for (int i = 0; i < numAxisItems; i++) {
if (axis.getRange().lower == 0) {
break;
}
leftButton.click();
assertTrue(axis.getRange().lower < range.lower);
range = axis.getRange();
assertEquals(range.lower, range.upper, 0.0);
}
assertEquals(axis.getRange().lower, 0, 0.0);
for (int i = 0; i < numAxisItems; i++) {
if (axis.getRange().upper == numAxisItems - 1) {
break;
}
rightButton.click();
assertTrue(axis.getRange().upper > range.upper);
range = axis.getRange();
assertEquals(range.lower, range.upper, 0.0);
}
assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
firstButton.click();
assertEquals(axis.getRange().lower, 0, 0);
assertFalse(firstButton.isEnabled());
assertFalse(leftButton.isEnabled());
assertTrue(rightButton.isEnabled());
assertTrue(lastButton.isEnabled());
lastButton.click();
assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
assertTrue(firstButton.isEnabled());
assertTrue(leftButton.isEnabled());
assertFalse(rightButton.isEnabled());
assertFalse(lastButton.isEnabled());
}
use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class ChartEditor method createPartControl.
@Override
public void createPartControl(Composite parent) {
final ChartEditorInput input = (ChartEditorInput) getEditorInput();
final HeapChart heapChart = input.getChart();
control = new InteractiveChart(parent, SWT.FILL);
heapChart.setChartControl(control);
final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0);
final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128);
final int TICK_GAP = 40;
control.setBackground(WHITE);
control.getPlotArea().setBackground(LIGHTYELLOW);
control.setProposedSaveAsFilename(heapChart.title.substring(0, heapChart.title.indexOf(' ')));
FontData fd = JFaceResources.getDialogFont().getFontData()[0];
fd.setStyle(SWT.BOLD);
Font font = new Font(Display.getDefault(), fd);
fd.setHeight(fd.getHeight() + 2);
Font titleFont = new Font(Display.getDefault(), fd);
ITitle title = control.getTitle();
title.setFont(titleFont);
title.setForeground(BLACK);
title.setText(heapChart.title);
IAxis xAxis = control.getAxisSet().getXAxis(0);
xAxis.getGrid().setStyle(LineStyle.NONE);
xAxis.getTick().setForeground(BLACK);
ITitle xTitle = xAxis.getTitle();
xTitle.setFont(font);
xTitle.setForeground(BLACK);
xTitle.setText(heapChart.xUnits);
IAxis yAxis = control.getAxisSet().getYAxis(0);
yAxis.getGrid().setStyle(LineStyle.SOLID);
yAxis.getTick().setForeground(BLACK);
yAxis.getTick().setTickMarkStepHint(TICK_GAP);
ITitle yTitle = yAxis.getTitle();
yTitle.setFont(font);
yTitle.setText(heapChart.yUnits);
yTitle.setForeground(BLACK);
control.getLegend().setPosition(SWT.BOTTOM);
// data
final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Useful_Heap"));
lsUseful.setXSeries(heapChart.time);
lsUseful.setYSeries(heapChart.dataUseful);
lsUseful.setSymbolType(PlotSymbolType.DIAMOND);
lsUseful.setSymbolColor(RED);
lsUseful.setLineColor(RED);
final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Extra_Heap"));
lsExtra.setXSeries(heapChart.time);
lsExtra.setYSeries(heapChart.dataExtra);
lsExtra.setSymbolType(PlotSymbolType.DIAMOND);
lsExtra.setSymbolColor(ORANGE);
lsExtra.setLineColor(ORANGE);
if (heapChart.dataStacks != null) {
final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Stacks"));
lsStack.setXSeries(heapChart.time);
lsStack.setYSeries(heapChart.dataStacks);
lsStack.setSymbolType(PlotSymbolType.DIAMOND);
lsStack.setSymbolColor(DARK_BLUE);
lsStack.setLineColor(DARK_BLUE);
}
final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Total_Heap"));
lsTotal.setXSeries(heapChart.time);
lsTotal.setYSeries(heapChart.dataTotal);
lsTotal.setSymbolType(PlotSymbolType.DIAMOND);
lsTotal.setSymbolColor(GREEN);
lsTotal.setLineColor(GREEN);
// adjust axes
control.getAxisSet().adjustRange();
IAxisSet axisSet = control.getAxisSet();
Range xRange = axisSet.getXAxis(0).getRange();
Range yRange = axisSet.getYAxis(0).getRange();
double xExtra = 0.05 * (xRange.upper - xRange.lower);
double yExtra = 0.05 * (yRange.upper - yRange.lower);
axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra));
axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra));
// listeners
control.getPlotArea().getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showView();
TableViewer viewer = input.getView().getTableViewer();
input.getView().setTopControl(viewer.getControl());
Point p = new Point(e.x, e.y);
int closest = 0;
double d1, d2, d3, currMin;
double globalMin = Double.MAX_VALUE;
for (int i = 0; i < heapChart.time.length; i++) {
// get distance from click event to data points for the given index
d1 = distance(lsUseful.getPixelCoordinates(i), p);
d2 = distance(lsExtra.getPixelCoordinates(i), p);
d3 = distance(lsTotal.getPixelCoordinates(i), p);
// find the closest data point to the click event
currMin = Math.min(Math.min(d1, d2), d3);
if (currMin < globalMin) {
closest = i;
globalMin = currMin;
}
}
MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest);
viewer.setSelection(new StructuredSelection(snapshot), true);
if (e.count == 2 && snapshot.isDetailed()) {
ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell());
dialog.setInput(snapshot);
if (dialog.open() == Window.OK) {
dialog.openEditorForResult();
}
}
}
});
}
use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class GraphDiscreteXControl method handleUpdateEvent.
@Override
public void handleUpdateEvent() {
IAxis xAxis = builder.getChart().getAxisSet().getXAxis(0);
Range range = xAxis.getRange();
zoomInButton.setEnabled(range.upper - range.lower > 0);
boolean showingAll = builder.getScale() == 1;
zoomOutButton.setEnabled(!showingAll);
allButton.setEnabled(!showingAll);
boolean hitLeft = showingAll || range.lower == 0;
boolean hitRight = showingAll || range.upper == getNumItems() - 1;
leftButton.setEnabled(!hitLeft);
rightButton.setEnabled(!hitRight);
firstButton.setEnabled(!hitLeft);
lastButton.setEnabled(!hitRight);
}
use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class AbstractChartWithAxisBuilder method applyRangeY.
/**
* Updates the visible range of the chart's y-axis.
* @param min The smallest y-value that should be in range.
* @param max The largest y-value that should be in range.
* @since 3.0
*/
protected void applyRangeY(double min, double max) {
IAxis axis = chart.getAxisSet().getYAxis(0);
double actualRange = max - min;
double scaledRange = actualRange * scaleY;
double marginL = scaledRange > 0 ? scaledRange * getChartMarginYL() : 1;
double marginU = scaledRange > 0 ? scaledRange * getChartMarginYU() : 1;
double lower = (actualRange - scaledRange) * scrollY + min;
axis.setRange(new Range(lower - marginL, lower + scaledRange + marginU));
}
Aggregations