Search in sources :

Example 1 with AxisRange

use of org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange in project tracecompass by tracecompass.

the class TmfXyUiUtils method zoom.

/**
 * Provides horizontal zooming for a given viewer at given position.
 *
 * @param viewer
 *            the chart time provider to use for zooming
 * @param xAxis
 *            the axis reference to use the zooming
 * @param zoomIn
 *            true to zoomIn else zoomOut
 * @param x
 *            x location to center the zoom
 */
public static void zoom(ITmfChartTimeProvider viewer, IAxis xAxis, boolean zoomIn, final int x) {
    if (xAxis == null) {
        return;
    }
    // Compute the new time range
    long newDuration = viewer.getWindowDuration();
    if (newDuration == 0) {
        return;
    }
    double ratio = 1.0;
    if (zoomIn) {
        ratio = ZOOM_FACTOR_AT_X_POSITION;
        newDuration = Math.round(ZOOM_FACTOR_AT_X_POSITION * newDuration);
    } else {
        ratio = 1.0 / ZOOM_FACTOR_AT_X_POSITION;
        newDuration = (long) Math.ceil(newDuration * ratio);
    }
    newDuration = Math.max(MIN_WINDOW_SIZE, newDuration);
    // Center the zoom on mouse position, distribute new duration and adjust
    // for boundaries.
    long timeAtXPos = limitXDataCoordinate(viewer, xAxis.getDataCoordinate(x)) + viewer.getTimeOffset();
    // Note: ratio = newDuration/oldDuration
    long newWindowStartTime = timeAtXPos - Math.round(ratio * (timeAtXPos - viewer.getWindowStartTime()));
    long newWindowEndTime = validateWindowEndTime(viewer, newWindowStartTime, newWindowStartTime + newDuration);
    newWindowStartTime = validateWindowStartTime(viewer, newWindowStartTime);
    viewer.updateWindow(newWindowStartTime, newWindowEndTime);
    xAxis.setRange(new AxisRange(newWindowStartTime - viewer.getTimeOffset(), newWindowEndTime - viewer.getTimeOffset()));
}
Also used : AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)

Example 2 with AxisRange

use of org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange in project tracecompass by tracecompass.

the class TmfXyUiUtils method zoomOut.

private static void zoomOut(ITmfChartTimeProvider viewer, IAxis xAxis) {
    if (xAxis == null) {
        return;
    }
    long prevTime0 = viewer.getWindowStartTime();
    long prevTime1 = viewer.getWindowEndTime();
    long selTime = (viewer.getSelectionEndTime() + viewer.getSelectionBeginTime()) / 2;
    if (selTime < prevTime0 || selTime > prevTime1) {
        selTime = (prevTime0 + prevTime1) / 2;
    }
    long newInterval;
    long time0;
    if (prevTime1 - prevTime0 <= 1) {
        newInterval = 2;
        time0 = selTime - 1;
    } else {
        newInterval = (long) Math.ceil((prevTime1 - prevTime0) * ZOOM_FACTOR_SELECTION_CENTERED);
        time0 = selTime - (long) Math.ceil((selTime - prevTime0) * ZOOM_FACTOR_SELECTION_CENTERED);
    }
    /* snap to bounds if zooming out of range */
    time0 = validateWindowStartTime(viewer, Math.max(MIN_WINDOW_SIZE, Math.min(time0, viewer.getEndTime() - newInterval)));
    long time1 = validateWindowEndTime(viewer, time0, time0 + newInterval);
    viewer.updateWindow(time0, time1);
    xAxis.setRange(new AxisRange(time0 - viewer.getTimeOffset(), time1 - viewer.getTimeOffset()));
}
Also used : AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)

Example 3 with AxisRange

use of org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange in project tracecompass by tracecompass.

the class LockRangeDialog method lockAxis.

private void lockAxis() {
    double min = 0;
    double max = 0;
    try {
        min = Double.parseDouble(fMinText.getText());
        max = Double.parseDouble(fMaxText.getText());
        fChartViewer.setFixedYRange(new AxisRange(min, max));
    } catch (NumberFormatException e) {
    // Suppose values are already validated
    }
}
Also used : AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)

Example 4 with AxisRange

use of org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange 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();
}
Also used : ILegend(org.eclipse.swtchart.ILegend) DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) Range(org.eclipse.swtchart.Range) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) SegmentStoreWithRange(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) IAxis(org.eclipse.swtchart.IAxis) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment)

Example 5 with AxisRange

use of org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange in project tracecompass by tracecompass.

the class MouseSelectionProvider method mouseUp.

@Override
public void mouseUp(@Nullable MouseEvent e) {
    if ((fIsUpdate)) {
        if (fStartCoordinate > fEndCoordinate) {
            double tmp = fStartCoordinate;
            fStartCoordinate = fEndCoordinate;
            fEndCoordinate = tmp;
        }
        if (!isEmptySelection()) {
            getDensityViewer().select(new AxisRange(AbstractSegmentStoreDensityView.DEFAULT_RANGE.getFirst(), AbstractSegmentStoreDensityView.DEFAULT_RANGE.getSecond()));
        } else {
            getDensityViewer().select(new AxisRange(fStartCoordinate, fEndCoordinate));
        }
        fIsUpdate = false;
        redraw();
    }
}
Also used : AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)

Aggregations

AxisRange (org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IAxis (org.eclipse.swtchart.IAxis)2 ILegend (org.eclipse.swtchart.ILegend)2 Range (org.eclipse.swtchart.Range)2 DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)2 Format (java.text.Format)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Predicate (java.util.function.Predicate)1 StreamSupport (java.util.stream.StreamSupport)1