Skip to content

Commit

Permalink
Expose table downsample on JS API (#5409)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon authored Apr 26, 2024
1 parent aeeedd8 commit 87a9dc4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,17 @@ public void revive(ClientTableState state) {
}
}

public Promise<JsTable> downsample(LongWrapper[] zoomRange, int pixelCount, String xCol, String[] yCols) {
/**
* Get a downsampled version of the table. Currently only supports downsampling with an Instant or long `xCol`.
*
* @param zoomRange The visible range as `[start, end]` or null to always use all data.
* @param pixelCount The width of the visible area in pixels.
* @param xCol The name of the X column to downsample. Must be an Instant or long.
* @param yCols The names of the Y columns to downsample.
* @return A promise that resolves to the downsampled table.
*/
public Promise<JsTable> downsample(LongWrapper[] zoomRange, int pixelCount, String xCol,
String[] yCols) {
JsLog.info("downsample", zoomRange, pixelCount, xCol, yCols);
final String fetchSummary = "downsample(" + Arrays.toString(zoomRange) + ", " + pixelCount + ", " + xCol + ", "
+ Arrays.toString(yCols) + ")";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.web.client.api.widget.plot;

import elemental2.promise.Promise;
import io.deephaven.web.client.api.*;
import jsinterop.annotations.JsIgnore;
import jsinterop.annotations.JsNullable;
import jsinterop.annotations.JsOptional;
import jsinterop.annotations.JsType;

/**
* Helper class for plot downsampling methods.
*/
@JsType(namespace = "dh.plot")
public class Downsample {
/**
* Downsamples a table so that the data can be used for a time-series line plot. The downsampled table should have
* the same visual fidelity as the original table, but with fewer rows.
*
* @param table The table to downsample.
* @param xCol The name of the X column to downsample. Must be an Instant or long.
* @param yCols The names of the Y columns to downsample.
* @param width The width of the visible area in pixels.
* @param xRange The visible range as `[start, end]` or null to always use all data.
*
* @return A promise that resolves to the downsampled table.
*/
public static Promise<JsTable> runChartDownsample(JsTable table, String xCol, String[] yCols, int width,
@JsOptional @JsNullable LongWrapper[] xRange) {
return table.downsample(xRange, width, xCol, yCols);
}

@JsIgnore
private Downsample() {}
}

0 comments on commit 87a9dc4

Please sign in to comment.