Search in sources :

Example 1 with TimeGraphTreeRender

use of com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender in project lttng-scope by lttng.

the class TimeGraphStateLayer method drawContents.

@Override
public void drawContents(TimeGraphTreeRender treeRender, TimeRange timeRange, VerticalPosition vPos, @Nullable FutureTask<?> task) {
    final long resolution = Math.max(1, Math.round(getWidget().getCurrentNanosPerPixel()));
    final List<TimeGraphTreeElement> allTreeElements = treeRender.getAllTreeElements();
    final int nbElements = allTreeElements.size();
    final int entriesToPrefetch = getWidget().getDebugOptions().entryPadding.get();
    final int topEntry = Math.max(0, TimeGraphWidget.paneYPosToEntryListIndex(vPos.fTopPos, TimeGraphWidget.ENTRY_HEIGHT) - entriesToPrefetch);
    final int bottomEntry = Math.min(nbElements, TimeGraphWidget.paneYPosToEntryListIndex(vPos.fBottomPos, TimeGraphWidget.ENTRY_HEIGHT) + entriesToPrefetch);
    LOGGER.finest(() -> "topEntry=" + topEntry + ", bottomEntry=" + bottomEntry);
    List<TimeGraphStateRender> stateRenders = allTreeElements.subList(topEntry, bottomEntry).stream().map(treeElem -> fStateProvider.getStateRender(treeElem, timeRange, resolution, task)).collect(Collectors.toList());
    if (task != null && task.isCancelled()) {
        return;
    }
    Collection<StateRectangle> stateRectangles = prepareStateRectangles(stateRenders, topEntry);
    Node statesLayerContents = prepareTimeGraphStatesContents(stateRectangles);
    Node labelsLayerContents = prepareTimeGrahLabelsContents(stateRectangles, fWindowRange);
    /*
         * Go over all state rectangles, and bring the "multi-state"
         * ones to the front, to be sure they show on top of the others.
         * Note we cannot do the forEach() as part of the stream, that
         * would throw a ConcurrentModificationException.
         */
    ((Group) statesLayerContents).getChildren().stream().map(node -> (StateRectangle) node).filter(rect -> (rect.getStateInterval().isMultiState())).collect(Collectors.toList()).forEach(Node::toFront);
    Platform.runLater(() -> {
        getParentGroup().getChildren().clear();
        getLabelGroup().getChildren().clear();
        getParentGroup().getChildren().add(statesLayerContents);
        getLabelGroup().getChildren().add(labelsLayerContents);
    });
}
Also used : TimeRange(com.efficios.jabberwocky.common.TimeRange) IntStream(java.util.stream.IntStream) JfxTextUtils(org.lttng.scope.common.jfx.JfxTextUtils) StateRectangle(org.lttng.scope.views.timeline.widgets.timegraph.StateRectangle) TimeGraphTreeElement(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement) OverrunStyle(javafx.scene.control.OverrunStyle) FutureTask(java.util.concurrent.FutureTask) Function(java.util.function.Function) TimeGraphModelStateProvider(com.efficios.jabberwocky.views.timegraph.model.provider.states.TimeGraphModelStateProvider) Objects.requireNonNull(java.util.Objects.requireNonNull) TimeGraphTreeRender(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender) TimeGraphWidget(org.lttng.scope.views.timeline.widgets.timegraph.TimeGraphWidget) Color(javafx.scene.paint.Color) VerticalPosition(org.lttng.scope.views.timeline.widgets.timegraph.VerticalPosition) Node(javafx.scene.Node) Collection(java.util.Collection) Font(javafx.scene.text.Font) Group(javafx.scene.Group) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Stream(java.util.stream.Stream) JfxUtils(org.lttng.scope.common.jfx.JfxUtils) TimeGraphStateRender(com.efficios.jabberwocky.views.timegraph.model.render.states.TimeGraphStateRender) Collections(java.util.Collections) DebugOptions(org.lttng.scope.views.timeline.DebugOptions) StateRectangle(org.lttng.scope.views.timeline.widgets.timegraph.StateRectangle) Node(javafx.scene.Node) TimeGraphTreeElement(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement) TimeGraphStateRender(com.efficios.jabberwocky.views.timegraph.model.render.states.TimeGraphStateRender)

Example 2 with TimeGraphTreeRender

use of com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender in project lttng-scope by lttng.

the class TimeGraphWidget method paintArea.

/**
 * Paint the specified view area.
 *
 * @param windowRange
 *            The horizontal position where the visible window currently is
 * @param verticalPos
 *            The vertical position where the visible window currently is
 * @param movedHorizontally
 *            If we have moved horizontally since the last redraw. May be
 *            used to skip some operations. If you are not sure say "true".
 * @param movedVertically
 *            If we have moved vertically since the last redraw. May be used
 *            to skip some operations. If you are not sure say "true".
 * @param taskSeqNb
 *            The sequence number of this task, used for logging only
 */
void paintArea(TimeRange windowRange, VerticalPosition verticalPos, boolean movedHorizontally, boolean movedVertically, long taskSeqNb) {
    final TimeRange fullTimeGraphRange = getViewContext().getCurrentProjectFullRange();
    /*
         * Request the needed renders and prepare the corresponding UI objects.
         * We may ask for some padding on each side, clamped by the trace's
         * start and end.
         */
    final long timeRangePadding = Math.round(windowRange.getDuration() * getDebugOptions().renderRangePadding.get());
    final long renderingStartTime = Math.max(fullTimeGraphRange.getStartTime(), windowRange.getStartTime() - timeRangePadding);
    final long renderingEndTime = Math.min(fullTimeGraphRange.getEndTime(), windowRange.getEndTime() + timeRangePadding);
    final TimeRange renderingRange = TimeRange.of(renderingStartTime, renderingEndTime);
    /*
         * Start a new repaint, display the "loading" overlay. The next
         * paint task to finish will put it back to non-visible.
         */
    if (getDebugOptions().isLoadingOverlayEnabled.get()) {
        fTimeGraphLoadingOverlay.fadeIn();
    }
    JabberwockyTask<Void> task = new JabberwockyTask<>("Updating Timegraph " + getName(), it -> {
        // $NON-NLS-1$
        LOGGER.finer(() -> "Starting paint task #" + taskSeqNb);
        ITimeGraphModelProvider modelProvider = getControl().getRenderProvider();
        TimeGraphTreeRender treeRender = modelProvider.getTreeRender();
        if (it.isCancelled()) {
            return null;
        }
        /* Prepare the tree part, if needed */
        if (!treeRender.equals(fLatestTreeRender)) {
            fLatestTreeRender = treeRender;
            fTreeArea.updateTreeContents(treeRender);
        }
        if (it.isCancelled()) {
            return null;
        }
        /* Paint the background. It's very quick so we can do it every time. */
        fBackgroundLayer.drawContents(treeRender, renderingRange, verticalPos, it);
        /*
             * The state rectangles should be redrawn as soon as we move,
             * either horizontally or vertically.
             */
        fStateLayer.setWindowRange(windowRange);
        fStateLayer.drawContents(treeRender, renderingRange, verticalPos, it);
        if (it.isCancelled()) {
            return null;
        }
        /*
             * Arrows and drawn events are drawn for the full vertical
             * range. Only refetch/repaint them if we moved horizontally.
             */
        if (movedHorizontally) {
            fArrowLayer.drawContents(treeRender, renderingRange, verticalPos, it);
            fDrawnEventLayer.drawContents(treeRender, renderingRange, verticalPos, it);
        }
        if (it.isCancelled()) {
            return null;
        }
        /* Painting is finished, turn off the loading overlay */
        Platform.runLater(() -> {
            // $NON-NLS-1$
            LOGGER.finest(() -> "fading out overlay");
            fTimeGraphLoadingOverlay.fadeOut();
            if (fRepaintLatch != null) {
                fRepaintLatch.countDown();
            }
        });
        return null;
    });
    // $NON-NLS-1$
    LOGGER.finer(() -> "Queueing task #" + taskSeqNb);
    /*
         * Attach a listener to the task to receive exceptions thrown within the
         * task.
         */
    task.exceptionProperty().addListener((obs, oldVal, newVal) -> {
        if (newVal != null) {
            newVal.printStackTrace();
        }
    });
    fTaskExecutor.schedule(task);
}
Also used : TimeRange(com.efficios.jabberwocky.common.TimeRange) TimeGraphTreeRender(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender) ITimeGraphModelProvider(com.efficios.jabberwocky.views.timegraph.model.provider.ITimeGraphModelProvider) JabberwockyTask(com.efficios.jabberwocky.task.JabberwockyTask)

Example 3 with TimeGraphTreeRender

use of com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender in project lttng-scope by lttng.

the class TimeGraphBackgroundLayer method drawContents.

@Override
public void drawContents(TimeGraphTreeRender treeRender, TimeRange timeRange, VerticalPosition vPos, @Nullable FutureTask<?> task) {
    final double entryHeight = TimeGraphWidget.ENTRY_HEIGHT;
    final int entriesToPrefetch = getWidget().getDebugOptions().entryPadding.get();
    int totalNbEntries = treeRender.getAllTreeElements().size();
    final double timeGraphWidth = getWidget().getTimeGraphPane().getWidth();
    final double paintTopPos = Math.max(0.0, vPos.fTopPos - entriesToPrefetch * entryHeight);
    final double paintBottomPos = Math.min(vPos.fBottomPos + entriesToPrefetch * entryHeight, /*
                 * If there are less tree elements than can fill the window,
                 * stop at the end of the real tree elements.
                 */
    totalNbEntries * entryHeight);
    LinkedList<Line> lines = new LinkedList<>();
    DoubleStream.iterate((entryHeight / 2), y -> y + entryHeight).filter(y -> y > paintTopPos).peek(y -> {
        Line line = new Line(0, y, timeGraphWidth, y);
        line.setStroke(TimeGraphWidget.BACKGROUD_LINES_COLOR);
        line.setStrokeWidth(1.0);
        lines.add(line);
    }).allMatch(y -> y < paintBottomPos);
    // we don't want it.
    if (!lines.isEmpty()) {
        lines.removeLast();
    }
    Platform.runLater(() -> {
        getParentGroup().getChildren().clear();
        getParentGroup().getChildren().addAll(lines);
    });
}
Also used : Line(javafx.scene.shape.Line) TimeRange(com.efficios.jabberwocky.common.TimeRange) Platform(javafx.application.Platform) Line(javafx.scene.shape.Line) Nullable(org.jetbrains.annotations.Nullable) JfxUtils(org.lttng.scope.common.jfx.JfxUtils) VerticalPosition(org.lttng.scope.views.timeline.widgets.timegraph.VerticalPosition) FutureTask(java.util.concurrent.FutureTask) TimeGraphTreeRender(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender) Group(javafx.scene.Group) LinkedList(java.util.LinkedList) TimeGraphWidget(org.lttng.scope.views.timeline.widgets.timegraph.TimeGraphWidget) DoubleStream(java.util.stream.DoubleStream) LinkedList(java.util.LinkedList)

Example 4 with TimeGraphTreeRender

use of com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender in project lttng-scope by lttng.

the class TimeGraphDrawnEventLayer method trackEventProvider.

private void trackEventProvider(TimeGraphDrawnEventProvider provider) {
    Group newGroup = new Group();
    Group oldGroup = fEventProviders.put(provider, newGroup);
    if (oldGroup == null) {
        Platform.runLater(() -> {
            getParentGroup().getChildren().add(newGroup);
        });
    } else {
        /* Remove the old group in case there was already one. */
        Platform.runLater(() -> {
            getParentGroup().getChildren().remove(oldGroup);
            getParentGroup().getChildren().add(newGroup);
        });
    }
    /*
         * Add a listener to this provider's "enabled" property, so that when it
         * changes from enabled to disabled and vice versa, we update the view
         * accordingly.
         */
    provider.enabledProperty().addListener((obs, oldValue, newValue) -> {
        if (newValue) {
            /* The provider was just enabled */
            TimeRange timeRange = getWidget().getViewContext().getVisibleTimeRange();
            TimeGraphTreeRender treeRender = getWidget().getLatestTreeRender();
            // FIXME Use a Task?
            paintEventsOfProvider(treeRender, timeRange, provider, null);
        } else {
            /* Provider was disabled. Clear the children of its group. */
            Group group = fEventProviders.get(provider);
            if (group == null) {
                return;
            }
            Platform.runLater(() -> group.getChildren().clear());
        }
    });
    getWidget().getTimelineWidgetUpdateTask().forceRedraw();
}
Also used : Group(javafx.scene.Group) TimeRange(com.efficios.jabberwocky.common.TimeRange) TimeGraphTreeRender(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender)

Aggregations

TimeRange (com.efficios.jabberwocky.common.TimeRange)4 TimeGraphTreeRender (com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender)4 Group (javafx.scene.Group)3 FutureTask (java.util.concurrent.FutureTask)2 Platform (javafx.application.Platform)2 Nullable (org.jetbrains.annotations.Nullable)2 JfxUtils (org.lttng.scope.common.jfx.JfxUtils)2 TimeGraphWidget (org.lttng.scope.views.timeline.widgets.timegraph.TimeGraphWidget)2 VerticalPosition (org.lttng.scope.views.timeline.widgets.timegraph.VerticalPosition)2 JabberwockyTask (com.efficios.jabberwocky.task.JabberwockyTask)1 ITimeGraphModelProvider (com.efficios.jabberwocky.views.timegraph.model.provider.ITimeGraphModelProvider)1 TimeGraphModelStateProvider (com.efficios.jabberwocky.views.timegraph.model.provider.states.TimeGraphModelStateProvider)1 TimeGraphStateRender (com.efficios.jabberwocky.views.timegraph.model.render.states.TimeGraphStateRender)1 TimeGraphTreeElement (com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Objects (java.util.Objects)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1