Search in sources :

Example 1 with AxisRange

use of org.csstudio.javafx.rtplot.AxisRange in project org.csstudio.display.builder by kasemir.

the class ImagePlot method mouseUp.

/**
 * setOnMouseReleased
 */
private void mouseUp(final MouseEvent e) {
    final Point2D start = mouse_start.orElse(null);
    final Point2D current = mouse_current.orElse(null);
    if (start == null || current == null)
        return;
    if (mouse_mode == MouseMode.PAN_PLOT) {
        mouseMove(e);
        undo.add(new ChangeImageZoom(Messages.Pan, x_axis, mouse_start_x_range, x_axis.getValueRange(), y_axis, mouse_start_y_range, y_axis.getValueRange()));
        mouse_mode = MouseMode.PAN;
        mouse_start_x_range = null;
        mouse_start_y_range = null;
    } else if (mouse_mode == MouseMode.ZOOM_IN_X) {
        // X axis increases going _right_ just like mouse 'x' coordinate
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD) {
            final int low = (int) Math.min(start.getX(), current.getX());
            final int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<Double> original_x_range = x_axis.getValueRange();
            final AxisRange<Double> new_x_range = getRestrictedRange(x_axis.getValue(low), x_axis.getValue(high), min_x, max_x);
            undo.execute(new ChangeImageZoom(x_axis, original_x_range, new_x_range, null, null, null));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_Y) {
        // Mouse 'y' increases going _down_ the screen
        if (Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            final int high = (int) Math.min(start.getY(), current.getY());
            final int low = (int) Math.max(start.getY(), current.getY());
            final AxisRange<Double> original_y_range = y_axis.getValueRange();
            final AxisRange<Double> new_y_range = getRestrictedRange(y_axis.getValue(low), y_axis.getValue(high), min_y, max_y);
            undo.execute(new ChangeImageZoom(null, null, null, y_axis, original_y_range, new_y_range));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_PLOT) {
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD || Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            // X axis increases going _right_ just like mouse 'x' coordinate
            int low = (int) Math.min(start.getX(), current.getX());
            int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<Double> original_x_range = x_axis.getValueRange();
            final AxisRange<Double> new_x_range = getRestrictedRange(x_axis.getValue(low), x_axis.getValue(high), min_x, max_x);
            // Mouse 'y' increases going _down_ the screen
            high = (int) Math.min(start.getY(), current.getY());
            low = (int) Math.max(start.getY(), current.getY());
            final AxisRange<Double> original_y_range = y_axis.getValueRange();
            final AxisRange<Double> new_y_range = getRestrictedRange(y_axis.getValue(low), y_axis.getValue(high), min_y, max_y);
            undo.execute(new ChangeImageZoom(x_axis, original_x_range, new_x_range, y_axis, original_y_range, new_y_range));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    }
}
Also used : ChangeImageZoom(org.csstudio.javafx.rtplot.internal.undo.ChangeImageZoom) Point2D(javafx.geometry.Point2D) AxisRange(org.csstudio.javafx.rtplot.AxisRange)

Example 2 with AxisRange

use of org.csstudio.javafx.rtplot.AxisRange in project org.csstudio.display.builder by kasemir.

the class Plot method enableAutoScale.

/**
 * Enable autoscale
 *
 *  <p>.. for the value axis currently under the cursor,
 *  or all axes.
 */
public void enableAutoScale() {
    final Point2D current = mouse_current.orElse(null);
    if (current == null)
        return;
    // Which axes to autoscale?
    final List<YAxisImpl<XTYPE>> axes = new ArrayList<>();
    final List<AxisRange<Double>> ranges = new ArrayList<>();
    final List<Boolean> original_auto = new ArrayList<>();
    final List<Boolean> new_auto = new ArrayList<>();
    // Autoscale all if mouse in general plot region
    final boolean all = plot_area.getBounds().contains(current.getX(), current.getY());
    for (YAxisImpl<XTYPE> axis : y_axes) if (all || axis.getBounds().contains(current.getX(), current.getY())) {
        // Autoscale this axis
        if (!axis.isAutoscale()) {
            axes.add(axis);
            ranges.add(axis.getValueRange());
            original_auto.add(false);
            new_auto.add(true);
        }
        // Only this axis?
        if (!all)
            break;
    }
    if (!axes.isEmpty())
        undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In, null, null, null, false, false, axes, ranges, ranges, original_auto, new_auto));
}
Also used : ChangeAxisRanges(org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges) Point2D(javafx.geometry.Point2D) AxisRange(org.csstudio.javafx.rtplot.AxisRange) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with AxisRange

use of org.csstudio.javafx.rtplot.AxisRange in project org.csstudio.display.builder by kasemir.

the class Plot method mouseUp.

/**
 * setOnMouseReleased
 */
private void mouseUp(final MouseEvent e) {
    deselectPlotMarker();
    deselectMouseAnnotation();
    final Point2D start = mouse_start.orElse(null);
    final Point2D current = mouse_current.orElse(null);
    if (start == null || current == null)
        return;
    if (mouse_mode == MouseMode.PAN_X) {
        mouseMove(e);
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan_X, x_axis, mouse_start_x_range, x_axis.getValueRange(), false, false));
        fireXAxisChange();
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.PAN_Y) {
        mouseMove(e);
        final YAxisImpl<XTYPE> y_axis = y_axes.get(mouse_y_axis);
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan_Y, Arrays.asList(y_axis), mouse_start_y_ranges, Arrays.asList(y_axis.getValueRange()), pre_pan_auto_scales));
        if (y_axis.setAutoscale(false))
            fireAutoScaleChange(y_axis);
        fireYAxisChange(y_axis);
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.PAN_PLOT) {
        mouseMove(e);
        final List<AxisRange<Double>> current_y_ranges = new ArrayList<>();
        for (YAxisImpl<XTYPE> axis : y_axes) current_y_ranges.add(axis.getValueRange());
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan, x_axis, mouse_start_x_range, x_axis.getValueRange(), false, false, y_axes, mouse_start_y_ranges, current_y_ranges, pre_pan_auto_scales));
        fireXAxisChange();
        for (YAxisImpl<XTYPE> axis : y_axes) {
            if (axis.setAutoscale(false))
                fireAutoScaleChange(axis);
            fireYAxisChange(axis);
        }
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_X) {
        // X axis increases going _right_ just like mouse 'x' coordinate
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD) {
            final int low = (int) Math.min(start.getX(), current.getX());
            final int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<XTYPE> original_x_range = x_axis.getValueRange();
            final AxisRange<XTYPE> new_x_range = new AxisRange<>(x_axis.getValue(low), x_axis.getValue(high));
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In_X, x_axis, original_x_range, new_x_range, x_axis.isAutoscale(), false));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_Y) {
        // Mouse 'y' increases going _down_ the screen
        if (Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            final int high = (int) Math.min(start.getY(), current.getY());
            final int low = (int) Math.max(start.getY(), current.getY());
            final YAxisImpl<XTYPE> axis = y_axes.get(mouse_y_axis);
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In_Y, Arrays.asList(axis), Arrays.asList(axis.getValueRange()), Arrays.asList(new AxisRange<Double>(axis.getValue(low), axis.getValue(high))), Arrays.asList(axis.isAutoscale())));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_PLOT) {
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD || Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            // X axis increases going _right_ just like mouse 'x' coordinate
            int low = (int) Math.min(start.getX(), current.getX());
            int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<XTYPE> original_x_range = x_axis.getValueRange();
            final AxisRange<XTYPE> new_x_range = new AxisRange<>(x_axis.getValue(low), x_axis.getValue(high));
            // Mouse 'y' increases going _down_ the screen
            final List<AxisRange<Double>> original_y_ranges = new ArrayList<>();
            final List<AxisRange<Double>> new_y_ranges = new ArrayList<>();
            final List<Boolean> original_autoscale_values = new ArrayList<>();
            high = (int) Math.min(start.getY(), current.getY());
            low = (int) Math.max(start.getY(), current.getY());
            for (YAxisImpl<XTYPE> axis : y_axes) {
                original_y_ranges.add(axis.getValueRange());
                new_y_ranges.add(new AxisRange<Double>(axis.getValue(low), axis.getValue(high)));
                original_autoscale_values.add(axis.isAutoscale());
            }
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In, x_axis, original_x_range, new_x_range, x_axis.isAutoscale(), false, y_axes, original_y_ranges, new_y_ranges, original_autoscale_values));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ChangeAxisRanges(org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges) Point2D(javafx.geometry.Point2D) AxisRange(org.csstudio.javafx.rtplot.AxisRange) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with AxisRange

use of org.csstudio.javafx.rtplot.AxisRange in project org.csstudio.display.builder by kasemir.

the class PlotProcessor method stagger.

/**
 * Stagger the range of axes
 */
public void stagger() {
    thread_pool.execute(() -> {
        final double GAP = 0.1;
        // Arrange all axes so they don't overlap by assigning 1/Nth of
        // the vertical range to each one
        // Determine range of each axes' traces in parallel
        final List<YAxisImpl<XTYPE>> y_axes = new ArrayList<>();
        final List<AxisRange<Double>> original_ranges = new ArrayList<>();
        final List<AxisRange<Double>> new_ranges = new ArrayList<>();
        final List<Future<ValueRange>> ranges = new ArrayList<Future<ValueRange>>();
        for (YAxisImpl<XTYPE> axis : plot.getYAxes()) {
            y_axes.add(axis);
            // As fallback, assume that new range matches old range
            new_ranges.add(axis.getValueRange());
            original_ranges.add(axis.getValueRange());
            ranges.add(determineValueRange(axis, plot.getXAxis().getValueRange()));
        }
        final int N = y_axes.size();
        for (int i = 0; i < N; ++i) {
            final YAxisImpl<XTYPE> axis = y_axes.get(i);
            // Does axis handle itself in another way?
            if (axis.isAutoscale())
                continue;
            // Fetch range of values on this axis
            final ValueRange axis_range;
            try {
                axis_range = ranges.get(i).get();
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Axis stagger error", ex);
                continue;
            }
            // Skip axis which for some reason cannot determine its range
            double low = axis_range.getLow();
            double high = axis_range.getHigh();
            if (low > high)
                continue;
            if (low == high) {
                // Center trace with constant value (empty range)
                final double half = Math.abs(low / 2);
                low -= half;
                high += half;
            }
            if (axis.isLogarithmic()) {
                // Transition into log space
                low = Log10.log10(low);
                high = Log10.log10(high);
            }
            double span = high - low;
            // Make some extra space
            low -= GAP * span;
            high += GAP * span;
            span = high - low;
            // With N axes, assign 1/Nth of the vertical plot space to this axis
            // by shifting the span down according to the axis index,
            // using a total of N*range.
            low -= (N - i - 1) * span;
            high += i * span;
            final ValueRange rounded = roundValueRange(low, high);
            low = rounded.getLow();
            high = rounded.getHigh();
            if (axis.isLogarithmic()) {
                // Revert from log space
                low = Log10.pow10(low);
                high = Log10.pow10(high);
            }
            // Sanity check for empty traces
            if (low < high && !Double.isInfinite(low) && !Double.isInfinite(high)) {
                final AxisRange<Double> orig = original_ranges.get(i);
                final boolean normal = orig.getLow() < orig.getHigh();
                new_ranges.set(i, normal ? new AxisRange<Double>(low, high) : new AxisRange<Double>(high, low));
            }
        }
        // 'Stagger' tends to be on-demand,
        // or executed infrequently as archived data arrives after a zoom operation
        // -> Use undo, which also notifies listeners
        plot.getUndoableActionManager().execute(new ChangeAxisRanges<>(plot, Messages.Zoom_Stagger, y_axes, original_ranges, new_ranges, null));
    });
}
Also used : ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) ValueRange(org.csstudio.javafx.rtplot.data.ValueRange) AxisRange(org.csstudio.javafx.rtplot.AxisRange) Future(java.util.concurrent.Future)

Example 5 with AxisRange

use of org.csstudio.javafx.rtplot.AxisRange in project org.csstudio.display.builder by kasemir.

the class PlotProcessor method autoscale.

/**
 * Perform autoscale for all axes that are marked as such
 */
public void autoscale() {
    // Determine range of each axes' traces in parallel
    final List<YAxisImpl<XTYPE>> all_y_axes = plot.getYAxes();
    final List<YAxisImpl<XTYPE>> y_axes = new ArrayList<>();
    final List<Future<ValueRange>> ranges = new ArrayList<Future<ValueRange>>();
    for (YAxisImpl<XTYPE> axis : all_y_axes) if (axis.isAutoscale()) {
        y_axes.add(axis);
        ranges.add(determineValueRange(axis, plot.getXAxis().getValueRange()));
    }
    // If X axis is auto-scale, schedule fetching its range
    final Future<AxisRange<XTYPE>> pos_range = plot.getXAxis().isAutoscale() ? determinePositionRange(all_y_axes) : null;
    final int N = y_axes.size();
    for (int i = 0; i < N; ++i) {
        final YAxisImpl<XTYPE> axis = y_axes.get(i);
        try {
            final ValueRange new_range = ranges.get(i).get();
            double low = new_range.getLow(), high = new_range.getHigh();
            if (low > high)
                continue;
            if (low == high) {
                // Center trace with constant value (empty range)
                final double half = Math.abs(low / 2);
                low -= half;
                high += half;
            }
            if (axis.isLogarithmic()) {
                // But first, refuse to deal with <= 0
                if (low <= 0.0)
                    low = 1;
                if (high <= low)
                    high = 100;
                low = Log10.log10(low);
                high = Log10.log10(high);
            }
            final ValueRange rounded = roundValueRange(low, high);
            low = rounded.getLow();
            high = rounded.getHigh();
            if (axis.isLogarithmic()) {
                low = Log10.pow10(low);
                high = Log10.pow10(high);
            } else {
                // Stretch range a little bit
                // (but not for log scale, where low just above 0
                // could be stretched to <= 0)
                final double headroom = (high - low) * 0.05;
                low -= headroom;
                high += headroom;
            }
            // Do not use undo, but notify listeners.
            if (low != high) {
                final AxisRange<Double> orig = axis.getValueRange();
                final boolean normal = orig.getLow() < orig.getHigh();
                final boolean changed = normal ? axis.setValueRange(low, high) : axis.setValueRange(high, low);
                if (changed)
                    plot.fireYAxisChange(axis);
            }
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Axis autorange error for " + axis, ex);
        }
    }
    if (pos_range == null)
        return;
    try {
        final AxisRange<XTYPE> range = pos_range.get();
        if (range == null)
            return;
        plot.getXAxis().setValueRange(range.getLow(), range.getHigh());
        plot.fireXAxisChange();
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Axis autorange error for " + plot.getXAxis(), ex);
    }
}
Also used : ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) ValueRange(org.csstudio.javafx.rtplot.data.ValueRange) AxisRange(org.csstudio.javafx.rtplot.AxisRange) Future(java.util.concurrent.Future)

Aggregations

AxisRange (org.csstudio.javafx.rtplot.AxisRange)5 ArrayList (java.util.ArrayList)4 Point2D (javafx.geometry.Point2D)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 ValueRange (org.csstudio.javafx.rtplot.data.ValueRange)2 ChangeAxisRanges (org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges)2 List (java.util.List)1 ChangeImageZoom (org.csstudio.javafx.rtplot.internal.undo.ChangeImageZoom)1