Search in sources :

Example 26 with Range

use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.

the class AbstractChartWithAxisBuilder method applyRangeX.

/**
 * Updates the visible range of the chart's x-axis.
 * @param min The smallest x-value that should be in range.
 * @param max The largest x-value that should be in range.
 */
private void applyRangeX(double min, double max) {
    IAxis axis = chart.getAxisSet().getXAxis(0);
    double actualRange = max - min;
    double scaledRange = actualRange * scale;
    double marginL = scaledRange > 0 ? scaledRange * getChartMarginXL() : 1;
    double marginU = scaledRange > 0 ? scaledRange * getChartMarginXU() : 1;
    double lower = (actualRange - scaledRange) * scroll + min;
    axis.setRange(new Range(lower - marginL, lower + scaledRange + marginU));
}
Also used : Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 27 with Range

use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.

the class BarChartBuilder method applyCategoryRange.

/**
 * This updates the visible range of the chart's x-axis.
 */
private void applyCategoryRange(int numItems) {
    // The number of items to display
    int itemRange = Math.max(1, (int) Math.ceil(numItems * scale));
    int lower = (int) Math.round((numItems - itemRange) * scroll);
    chart.getAxisSet().getXAxis(0).setRange(new Range(lower, lower + itemRange - 1));
}
Also used : Range(org.eclipse.swtchart.Range)

Example 28 with Range

use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.

the class PieChartBuilder method applyCategoryRange.

/**
 * This updates the visible range of the chart's x-axis.
 */
private void applyCategoryRange(int numItems) {
    // The number of items to display
    int itemRange = Math.max(1, (int) Math.ceil(numItems * scale));
    int lower = (int) Math.round((numItems - itemRange) * scroll);
    chart.getAxisSet().getXAxis(0).setRange(new Range(lower, lower + itemRange - 1));
}
Also used : Range(org.eclipse.swtchart.Range)

Example 29 with Range

use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.

the class BarChart method fitLabels.

/**
 * Given an array of label names, return a new set of names that have been trimmed down
 * in order to fit in the chart axis without getting cut off.
 * @param labels An array of label names that may be trimmed.
 * @return A new array containing label names that have been trimmed to fit in the axis display.
 */
private String[] fitLabels(String[] labels) {
    Range range = xAxis.getRange();
    int maxLabelSize = (int) Math.max(getClientArea().width / (Math.max(range.upper - range.lower, 1) * fontSize), MIN_LABEL_SIZE);
    String[] trimlabels = new String[labels.length];
    for (int i = 0; i < labels.length; i++) {
        if (labels[i].length() > maxLabelSize) {
            trimlabels[i] = labels[i].substring(0, maxLabelSize - MIN_LABEL_SIZE).concat(Messages.BarChartBuilder_LabelTrimTag);
        } else {
            trimlabels[i] = labels[i];
        }
    }
    return trimlabels;
}
Also used : Range(org.eclipse.swtchart.Range)

Example 30 with Range

use of org.eclipse.swtchart.Range in project tracecompass by tracecompass.

the class PatternScatterChartViewTest method testWithTrace.

/**
 * Test the pattern latency scatter graph. This method test if the chart has one
 * series and the series has data
 */
@Test
public void testWithTrace() {
    // Get the chart viewer and wait for the view to be ready
    WaitUtils.waitForJobs();
    TmfXYChartViewer chartViewer = getChartViewer();
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    // Check all the items in the tree
    final Chart chart = fScatterChart;
    assertNotNull(chart);
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    SWTBotTreeItem[] items = viewBot.bot().tree().getAllItems();
    for (SWTBotTreeItem item : items) {
        item.check();
    }
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 0, chart, "No data available");
    // Look at the presence of data in the chart
    SWTBotChart chartBot = new SWTBotChart(chart);
    assertVisible(chartBot);
    final Range range = chart.getAxisSet().getXAxes()[0].getRange();
    assertEquals(100000000, range.upper - range.lower, 0);
    ISeriesSet seriesSet = fScatterChart.getSeriesSet();
    assertNotNull(seriesSet);
    ISeries<?>[] series = seriesSet.getSeries();
    assertNotNull(series);
    // Verify that the chart has more than 1 series
    assertTrue(series.length > 1);
    // Verify that each series has data
    for (int i = 0; i < series.length; i++) {
        assertTrue("Verifying series " + i, ((IndexedSeriesModel<?>) series[i].getDataModel()).size() > 0);
    }
}
Also used : TmfXYChartViewer(org.eclipse.tracecompass.tmf.ui.viewers.xychart.TmfXYChartViewer) ISeriesSet(org.eclipse.swtchart.ISeriesSet) IndexedSeriesModel(org.eclipse.swtchart.model.IndexedSeriesModel) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test)

Aggregations

Range (org.eclipse.swtchart.Range)53 IAxis (org.eclipse.swtchart.IAxis)20 Point (org.eclipse.swt.graphics.Point)13 ISeries (org.eclipse.swtchart.ISeries)9 GridData (org.eclipse.swt.layout.GridData)5 IAxisSet (org.eclipse.swtchart.IAxisSet)5 DecimalFormat (java.text.DecimalFormat)4 StyleRange (org.eclipse.swt.custom.StyleRange)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Event (org.eclipse.swt.widgets.Event)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Chart (org.eclipse.swtchart.Chart)3 ISeriesSet (org.eclipse.swtchart.ISeriesSet)3 AxisRange (org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)3 ParseException (java.text.ParseException)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 Color (org.eclipse.swt.graphics.Color)2