Search in sources :

Example 21 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class TableMap method notifyKeyAdded.

@JsIgnore
public void notifyKeyAdded(Object key) {
    LocalKey k = LocalKey.of(key);
    if (!tables.containsKey(k)) {
        put(key, k);
        CustomEventInit init = CustomEventInit.create();
        init.setDetail(key);
        fireEvent(EVENT_KEYADDED, init);
    }
}
Also used : CustomEventInit(elemental2.dom.CustomEventInit) JsIgnore(jsinterop.annotations.JsIgnore)

Example 22 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class RequestBatcher method failTable.

private void failTable(JsTable t, String failureMessage) {
    final CustomEventInit event = CustomEventInit.create();
    ClientTableState best = t.state();
    for (ClientTableState state : best.reversed()) {
        if (allStates().anyMatch(state::equals)) {
            best = state;
            break;
        }
    }
    event.setDetail(JsPropertyMap.of("errorMessage", failureMessage, "configuration", best.toJs()));
    try {
        t.rollback();
    } catch (Exception e) {
        JsLog.warn("An exception occurred trying to rollback the table. This means that there will be no ticking data until the table configuration is applied again in a way that makes sense. See IDS-5199 for more detail.", e);
    }
    t.fireEvent(HasEventHandling.EVENT_REQUEST_FAILED, event);
}
Also used : ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit)

Example 23 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class FigureSubscription method replaceSeries.

/**
 * Ensures that all of these series are present in this subscription, and returns the ones which were added, if any,
 * so they can get a notification of their current data.
 *
 * Replacement series must match this subscription already - the only facet that will be checked is that the columns
 * match.
 */
public Set<JsSeries> replaceSeries(final Set<JsSeries> replacements) {
    final Set<JsSeries> copy = new HashSet<>(replacements);
    copy.removeAll(includedSeries);
    assert requiredColumns.containsAll(copy.stream().flatMap(s -> Arrays.stream(s.getSources())).map(s -> s.getDescriptor().getColumnName()).collect(Collectors.toSet()));
    includedSeries.addAll(copy);
    // For each of the series in copy, if this subscription is downsampled we need to notify of this fact.
    if (downsampleAxisRange != null) {
        CustomEventInit init = CustomEventInit.create();
        init.setDetail(replacements.toArray());
        figure.fireEvent(JsFigure.EVENT_DOWNSAMPLESTARTED, init);
    }
    if (firstEventFired) {
        // Next, if any data has loaded, regardless of downsample state, we need to fire an update event for those
        // series
        CustomEventInit event = CustomEventInit.create();
        event.setDetail(new DataUpdateEvent(replacements.toArray(new JsSeries[0]), currentData, null));
        figure.fireEvent(JsFigure.EVENT_UPDATED, event);
        // is complete
        if (downsampleAxisRange != null) {
            CustomEventInit successInit = CustomEventInit.create();
            successInit.setDetail(replacements.toArray());
            figure.fireEvent(JsFigure.EVENT_DOWNSAMPLEFINISHED, successInit);
        }
    }
    return copy;
}
Also used : java.util(java.util) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription) SubscriptionTableData(io.deephaven.web.client.api.subscription.SubscriptionTableData) JsTable(io.deephaven.web.client.api.JsTable) JsLog(io.deephaven.web.client.fu.JsLog) LongWrapper(io.deephaven.web.client.api.LongWrapper) CustomEventInit(elemental2.dom.CustomEventInit) Promise(elemental2.promise.Promise) CustomEvent(elemental2.dom.CustomEvent) Collectors(java.util.stream.Collectors) DateWrapper(io.deephaven.web.client.api.DateWrapper) CustomEventInit(elemental2.dom.CustomEventInit)

Example 24 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class FigureSubscription method subscribe.

private Promise<TableSubscription> subscribe(final Promise<JsTable> tablePromise) {
    assert currentData == null;
    return tablePromise.then(table -> {
        if (subscription == null) {
            // do we need this?
            table.close();
            // noinspection unchecked
            return (Promise<TableSubscription>) (Promise) Promise.reject("Already closed");
        }
        TableSubscription sub = table.subscribe(table.getColumns());
        // TODO, technically we can probably unsubscribe to the table at this point, since we're listening to the
        // subscription itself
        this.currentData = new ChartData(table);
        sub.addEventListener(TableSubscription.EVENT_UPDATED, e -> {
            // refire with specifics for the columns that we're watching here, after updating data arrays
            SubscriptionTableData.UpdateEventData subscriptionUpdateData = (SubscriptionTableData.UpdateEventData) ((CustomEvent) e).detail;
            currentData.update(subscriptionUpdateData);
            CustomEventInit event = CustomEventInit.create();
            event.setDetail(new DataUpdateEvent(includedSeries.toArray(new JsSeries[0]), currentData, subscriptionUpdateData));
            figure.fireEvent(JsFigure.EVENT_UPDATED, event);
            if (!firstEventFired) {
                firstEventFired = true;
                if (downsampleAxisRange != null) {
                    CustomEventInit successInit = CustomEventInit.create();
                    successInit.setDetail(includedSeries.toArray());
                    figure.fireEvent(JsFigure.EVENT_DOWNSAMPLEFINISHED, successInit);
                }
            }
        });
        return Promise.resolve(sub);
    });
}
Also used : Promise(elemental2.promise.Promise) CustomEventInit(elemental2.dom.CustomEventInit) SubscriptionTableData(io.deephaven.web.client.api.subscription.SubscriptionTableData) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription)

Example 25 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class FigureSubscription method subscribe.

public void subscribe() {
    assert subscription == null;
    // Copy the table so we can optionally filter it - we'll need to release this table later
    // Assign the promise to the subscription field so we can kill it mid-work
    subscription = originalTable.copy(false).then(table -> {
        Promise<JsTable> tablePromise = Promise.resolve(table);
        // then downsample, subscribe
        if (downsampleAxisRange == null) {
            // check if there are too many items, and downsampling isn't outright disabled
            if (table.getSize() > DownsampleOptions.MAX_SERIES_SIZE) {
                if (includedSeries.stream().map(JsSeries::getDownsampleOptions).noneMatch(options -> options == DownsampleOptions.DISABLE)) {
                    // stop, we can't downsample, we haven't been told to disable, and there are too many items to
                    // fetch them outright
                    figure.downsampleNeeded("Disable downsampling to retrieve all items", includedSeries, table.getSize());
                    // noinspection unchecked
                    return (Promise<TableSubscription>) (Promise) Promise.reject("Too many items to display, disable downsampling to display this series or size the axes");
                } else if (table.getSize() > DownsampleOptions.MAX_SUBSCRIPTION_SIZE) {
                    figure.downsampleNeeded("Too many items to disable downsampling", includedSeries, table.getSize());
                    // noinspection unchecked
                    return (Promise<TableSubscription>) (Promise) Promise.reject("Too many items to disable downsampling");
                }
            }
            // we actually sub to a copy, so that we can close it no matter what when we're done
            return subscribe(tablePromise);
        } else if (table.getSize() < 2 * (1 + downsampleParams.getyCols().length) * downsampleParams.getPixelCount() * MIN_DOWNSAMPLE_FACTOR) {
            // greater than the pixel size. The MIN_DOWNSAMPLE_FACTOR field is used to define "sufficiently greater"
            return subscribe(tablePromise);
        // TODO revisit this so we can watch the row count and downsample later if needed
        } else {
            final LongWrapper[] zoomRange;
            if (downsampleAxisRange.min != null && downsampleAxisRange.getMax() != null) {
                zoomRange = new LongWrapper[] { DateWrapper.of(downsampleAxisRange.getMin()), DateWrapper.of(downsampleAxisRange.getMax()) };
                JsLog.info("zoom range provided: ", zoomRange);
            } else {
                zoomRange = null;
            }
            CustomEventInit init = CustomEventInit.create();
            init.setDetail(includedSeries.toArray());
            figure.fireEvent(JsFigure.EVENT_DOWNSAMPLESTARTED, init);
            Promise<JsTable> downsampled = tablePromise.then(t -> t.downsample(zoomRange, downsampleParams.getPixelCount(), downsampleAxisRange.getxCol(), downsampleParams.getyCols()).then(resultTable -> Promise.resolve(resultTable), err -> {
                figure.downsampleFailed(err.toString(), includedSeries, table.getSize());
                if (table.getSize() > DownsampleOptions.MAX_SERIES_SIZE) {
                    if (includedSeries.stream().map(JsSeries::getDownsampleOptions).noneMatch(options -> options == DownsampleOptions.DISABLE)) {
                        // noinspection unchecked
                        return (Promise<JsTable>) (Promise) Promise.reject("");
                    }
                } else if (table.getSize() > DownsampleOptions.MAX_SUBSCRIPTION_SIZE) {
                    // noinspection unchecked
                    return (Promise<JsTable>) (Promise) Promise.reject("");
                }
                return Promise.resolve(table);
            }));
            return subscribe(downsampled);
        }
    });
}
Also used : java.util(java.util) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription) SubscriptionTableData(io.deephaven.web.client.api.subscription.SubscriptionTableData) JsTable(io.deephaven.web.client.api.JsTable) JsLog(io.deephaven.web.client.fu.JsLog) LongWrapper(io.deephaven.web.client.api.LongWrapper) CustomEventInit(elemental2.dom.CustomEventInit) Promise(elemental2.promise.Promise) CustomEvent(elemental2.dom.CustomEvent) Collectors(java.util.stream.Collectors) DateWrapper(io.deephaven.web.client.api.DateWrapper) Promise(elemental2.promise.Promise) JsTable(io.deephaven.web.client.api.JsTable) LongWrapper(io.deephaven.web.client.api.LongWrapper) CustomEventInit(elemental2.dom.CustomEventInit) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription)

Aggregations

CustomEventInit (elemental2.dom.CustomEventInit)28 Promise (elemental2.promise.Promise)6 JsIgnore (jsinterop.annotations.JsIgnore)6 JsTable (io.deephaven.web.client.api.JsTable)4 ClientTableState (io.deephaven.web.client.state.ClientTableState)4 Map (java.util.Map)4 JsArray (elemental2.core.JsArray)3 CustomEvent (elemental2.dom.CustomEvent)3 TableMap (io.deephaven.web.client.api.TableMap)3 SubscriptionTableData (io.deephaven.web.client.api.subscription.SubscriptionTableData)3 TableSubscription (io.deephaven.web.client.api.subscription.TableSubscription)3 ViewportData (io.deephaven.web.client.api.subscription.ViewportData)3 JsLog (io.deephaven.web.client.fu.JsLog)3 HashMap (java.util.HashMap)3 JsProperty (jsinterop.annotations.JsProperty)3 JsObject (elemental2.core.JsObject)2 FigureDescriptor (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor)2 io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor)2 FetchObjectResponse (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse)2 DateWrapper (io.deephaven.web.client.api.DateWrapper)2