Search in sources :

Example 11 with CustomEventInit

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

the class JsFigureFactory method create.

private static Promise<JsFigure> create(JsFigureDescriptor descriptor) {
    JsArray<JsTable> tables = descriptor.getTables();
    if (tables == null || tables.length == 0) {
        return (Promise<JsFigure>) (Promise) Promise.reject("No tables provided for Figure creation");
    }
    FigureDescriptor figureDescriptor = convertJsFigureDescriptor(descriptor);
    FetchObjectResponse response = new FetchObjectResponse();
    response.setData(figureDescriptor.serializeBinary());
    Promise<?>[] tableCopyPromises = tables.map((table, index, all) -> table.copy(false)).asArray(new Promise[0]);
    return Promise.all(tableCopyPromises).then(unknownTableCopies -> {
        JsArray<JsTable> jsTableCopies = Js.cast(unknownTableCopies);
        JsTable[] tableCopies = jsTableCopies.asArray(new JsTable[0]);
        return new JsFigure(c -> c.apply(null, response), (figure, descriptor1) -> {
            // We need to listen for disconnects and reconnects
            boolean[] isTableDisconnected = new boolean[tableCopies.length];
            ArrayList<RemoverFn> removerFns = new ArrayList<>(tableCopies.length * 3);
            for (int i = 0; i < tableCopies.length; i++) {
                final int tableIndex = i;
                // Tables are closed when the figure is closed, no need to remove listeners later
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_DISCONNECT, ignore -> {
                    isTableDisconnected[tableIndex] = true;
                    for (int j = 0; j < isTableDisconnected.length; j++) {
                        if (isTableDisconnected[j] && j != tableIndex) {
                            return;
                        }
                    }
                    figure.fireEvent(JsFigure.EVENT_DISCONNECT);
                    figure.unsubscribe();
                }));
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_RECONNECT, ignore -> {
                    isTableDisconnected[tableIndex] = false;
                    for (int j = 0; j < isTableDisconnected.length; j++) {
                        if (isTableDisconnected[j]) {
                            return;
                        }
                    }
                    try {
                        figure.verifyTables();
                        figure.fireEvent(JsFigure.EVENT_RECONNECT);
                        figure.enqueueSubscriptionCheck();
                    } catch (JsFigure.FigureSourceException e) {
                        final CustomEventInit init = CustomEventInit.create();
                        init.setDetail(e);
                        figure.fireEvent(JsFigure.EVENT_RECONNECTFAILED, init);
                    }
                }));
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_RECONNECTFAILED, err -> {
                    for (RemoverFn removerFn : removerFns) {
                        removerFn.remove();
                    }
                    figure.unsubscribe();
                    final CustomEventInit init = CustomEventInit.create();
                    init.setDetail(err);
                    figure.fireEvent(JsFigure.EVENT_RECONNECTFAILED, init);
                }));
            }
            return Promise.resolve(new JsFigure.FigureTableFetchData(tableCopies, new TableMap[0], Collections.emptyMap()));
        }).refetch();
    });
}
Also used : IThenable(elemental2.promise.IThenable) TableMap(io.deephaven.web.client.api.TableMap) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) FigureDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor) JsMethod(jsinterop.annotations.JsMethod) HashMap(java.util.HashMap) CustomEventInit(elemental2.dom.CustomEventInit) Promise(elemental2.promise.Promise) JsPropertyMap(jsinterop.base.JsPropertyMap) JsArray(elemental2.core.JsArray) ArrayList(java.util.ArrayList) Js(jsinterop.base.Js) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) JsTable(io.deephaven.web.client.api.JsTable) Map(java.util.Map) Collections(java.util.Collections) io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor) ArrayList(java.util.ArrayList) Promise(elemental2.promise.Promise) JsTable(io.deephaven.web.client.api.JsTable) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) CustomEventInit(elemental2.dom.CustomEventInit) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) FigureDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor)

Example 12 with CustomEventInit

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

the class JsMultiSeries method requestTable.

private void requestTable(TableMap tableMap, Object key) {
    // TODO ask the server in parallel for the series name
    String seriesName = descriptor.getName() + ": " + key;
    tableMap.getTable(key).then(table -> {
        SeriesDescriptor seriesInstance = new SeriesDescriptor();
        seriesInstance.setName(seriesName);
        seriesInstance.setPlotStyle(getPlotStyle());
        seriesInstance.setLineColor(getOrDefault(seriesName, descriptor.getLineColor()));
        seriesInstance.setShapeColor(getOrDefault(seriesName, descriptor.getPointColor()));
        seriesInstance.setLinesVisible(getOrDefault(seriesName, descriptor.getLinesVisible()));
        seriesInstance.setShapesVisible(getOrDefault(seriesName, descriptor.getPointsVisible()));
        Boolean gradientVisible = getOrDefault(seriesName, descriptor.getGradientVisible());
        if (gradientVisible != null) {
            seriesInstance.setGradientVisible(gradientVisible);
        }
        seriesInstance.setYToolTipPattern(getOrDefault(seriesName, descriptor.getYToolTipPattern()));
        seriesInstance.setXToolTipPattern(getOrDefault(seriesName, descriptor.getXToolTipPattern()));
        seriesInstance.setShapeLabel(getOrDefault(seriesName, descriptor.getPointLabel()));
        seriesInstance.setShapeSize(getOrDefault(seriesName, descriptor.getPointSize()));
        seriesInstance.setShape(getOrDefault(seriesName, descriptor.getPointShape()));
        seriesInstance.setPointLabelFormat(getOrDefault(seriesName, descriptor.getPointLabelFormat()));
        int tableId = figure.registerTable(table);
        seriesInstance.setDataSourcesList(descriptor.getDataSourcesList().map((multiSeriesSource, p1, p2) -> {
            SourceDescriptor sourceDescriptor = new SourceDescriptor();
            sourceDescriptor.setColumnName(multiSeriesSource.getColumnName());
            sourceDescriptor.setAxisId(multiSeriesSource.getAxisId());
            sourceDescriptor.setTableId(tableId);
            sourceDescriptor.setType(multiSeriesSource.getType());
            return sourceDescriptor;
        }));
        JsSeries series = new JsSeries(seriesInstance, figure, axes);
        series.setMultiSeries(this);
        series.initSources(Collections.singletonMap(tableId, table), Collections.emptyMap());
        CustomEventInit init = CustomEventInit.create();
        init.setDetail(series);
        parent.addSeriesFromMultiSeries(series);
        figure.fireEvent(JsFigure.EVENT_SERIES_ADDED, init);
        parent.fireEvent(JsChart.EVENT_SERIES_ADDED, init);
        return null;
    });
}
Also used : JsProperty(jsinterop.annotations.JsProperty) JsIgnore(jsinterop.annotations.JsIgnore) TableMap(io.deephaven.web.client.api.TableMap) Map(java.util.Map) CustomEventInit(elemental2.dom.CustomEventInit) CustomEvent(elemental2.dom.CustomEvent) Collections(java.util.Collections) io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor) CustomEventInit(elemental2.dom.CustomEventInit)

Example 13 with CustomEventInit

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

the class OneClick method fetchTable.

private void fetchTable() {
    Object[] keys = getCurrentKeys();
    if (allKeysMatch(keys, currentKeys) && currentTable != null) {
        return;
    }
    currentKeys = keys;
    doFetchTable(keys).then(table -> {
        if (currentKeys != keys) {
            // A newer request is running instead, throw away this result
            table.close();
        } else {
            if (currentTable != null) {
                // Get rid of the current table
                currentTable.close();
                currentTable = null;
            }
            if (table == null) {
                // No table, no need to change the figure subscription, just trigger a
                // synthetic event indicating no items
                CustomEventInit event = CustomEventInit.create();
                event.setDetail(DataUpdateEvent.empty(jsSeries));
                jsFigure.fireEvent(JsFigure.EVENT_UPDATED, event);
            } else {
                // Subscribe to this key and wait for it...
                currentTable = table;
                jsFigure.enqueueSubscriptionCheck();
            }
        }
        return null;
    });
}
Also used : CustomEventInit(elemental2.dom.CustomEventInit)

Example 14 with CustomEventInit

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

the class JsTreeTable method handleUpdate.

private void handleUpdate(Column[] columns, List<Sort> nextSort, List<FilterCondition> nextFilters, TreeTableResult result, boolean alwaysFireEvent) {
    JsLog.debug("tree table response arrived", result);
    lastResult = result;
    if (closed) {
        if (viewportUpdateTimeoutId != null) {
            DomGlobal.clearTimeout(viewportUpdateTimeoutId);
        }
        sourceTable.then(t -> {
            t.close();
            return null;
        });
        expandedMap.clear();
        baseTable.unretain(this);
        return;
    }
    final RangeSet includedRows;
    if (result.getSnapshotEnd() < result.getSnapshotStart()) {
        // this is TSQ for "no items"
        includedRows = RangeSet.empty();
    } else {
        includedRows = RangeSet.ofRange(result.getSnapshotStart(), result.getSnapshotEnd());
    }
    TreeViewportData vd = new TreeViewportData(includedRows, result.getSnapshotData(), result.getKeyColumn(), result.getParentKeyColumn(), result.getChildPresence(), result.getSnapshotStart(), columns, baseTable.getRowFormatColumn() == null ? NO_ROW_FORMAT_COLUMN : baseTable.getRowFormatColumn().getIndex(), result.getConstituentColumnNames(), result.getConstituentColumnData());
    // if requested to fire the event, or if the data has changed in some way, fire the event
    final boolean fireEvent = alwaysFireEvent || !vd.containsSameDataAs(currentViewportData);
    this.currentViewportData = vd;
    Set<Key> presentKeys = new HashSet<>();
    for (int i = 0; i < result.getTableDetails().length; i++) {
        TableDetails detail = result.getTableDetails()[i];
        TreeNodeState treeNodeState = expandedMap.get(detail.getKey());
        Set<Key> expandedChildren = new HashSet<>(Arrays.asList(detail.getChildren()));
        expandedChildren.retainAll(expandedMap.keySet());
        treeNodeState.expandedChildren = expandedChildren;
        presentKeys.add(detail.getKey());
    }
    expandedMap.entrySet().removeIf(e -> {
        if (!presentKeys.contains(e.getKey())) {
            return true;
        } else {
            return false;
        }
    });
    this.sorts = nextSort;
    this.filters = nextFilters;
    if (fireEvent) {
        CustomEventInit updatedEvent = CustomEventInit.create();
        updatedEvent.setDetail(vd);
        fireEvent(EVENT_UPDATED, updatedEvent);
    }
}
Also used : TableDetails(io.deephaven.web.shared.data.treetable.TableDetails) CustomEventInit(elemental2.dom.CustomEventInit) Key(io.deephaven.web.shared.data.treetable.Key)

Example 15 with CustomEventInit

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

the class HasEventHandling method failureHandled.

public boolean failureHandled(String failure) {
    if (failure != null) {
        if (hasListeners(EVENT_REQUEST_FAILED)) {
            final CustomEventInit event = CustomEventInit.create();
            event.setDetail(failure);
            fireEvent(EVENT_REQUEST_FAILED, event);
        } else {
            DomGlobal.console.error(logPrefix() + failure);
        }
        return true;
    }
    return false;
}
Also used : CustomEventInit(elemental2.dom.CustomEventInit)

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