Search in sources :

Example 1 with TableSubscription

use of io.deephaven.web.client.api.subscription.TableSubscription 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 2 with TableSubscription

use of io.deephaven.web.client.api.subscription.TableSubscription 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)2 Promise (elemental2.promise.Promise)2 SubscriptionTableData (io.deephaven.web.client.api.subscription.SubscriptionTableData)2 TableSubscription (io.deephaven.web.client.api.subscription.TableSubscription)2 CustomEvent (elemental2.dom.CustomEvent)1 DateWrapper (io.deephaven.web.client.api.DateWrapper)1 JsTable (io.deephaven.web.client.api.JsTable)1 LongWrapper (io.deephaven.web.client.api.LongWrapper)1 JsLog (io.deephaven.web.client.fu.JsLog)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1