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);
}
}
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);
}
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;
}
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);
});
}
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);
}
});
}
Aggregations