stream-charts 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +756 -343
- package/changes.md +7 -0
- package/dist/src/app/charts/Chart.d.ts +116 -87
- package/dist/src/app/charts/Chart.js +96 -101
- package/dist/src/app/charts/Chart.js.map +1 -1
- package/dist/src/app/charts/axes/AxesState.d.ts +64 -0
- package/dist/src/app/charts/axes/AxesState.js +97 -0
- package/dist/src/app/charts/axes/AxesState.js.map +1 -0
- package/dist/src/app/charts/axes/AxesState.test.js +30 -0
- package/dist/src/app/charts/axes/AxesState.test.js.map +1 -0
- package/dist/src/app/charts/axes/AxisInterval.d.ts +92 -0
- package/dist/src/app/charts/axes/AxisInterval.js +126 -0
- package/dist/src/app/charts/axes/AxisInterval.js.map +1 -0
- package/dist/src/app/charts/axes/AxisInterval.test.js +120 -0
- package/dist/src/app/charts/axes/AxisInterval.test.js.map +1 -0
- package/dist/src/app/charts/axes/BaseAxisRange.d.ts +83 -0
- package/dist/src/app/charts/axes/BaseAxisRange.js +58 -0
- package/dist/src/app/charts/axes/BaseAxisRange.js.map +1 -0
- package/dist/src/app/charts/axes/ContinuousAxis.d.ts +22 -0
- package/dist/src/app/charts/axes/ContinuousAxis.js +96 -0
- package/dist/src/app/charts/axes/ContinuousAxis.js.map +1 -0
- package/dist/src/app/charts/axes/ContinuousAxisRange.d.ts +59 -0
- package/dist/src/app/charts/axes/ContinuousAxisRange.js +84 -0
- package/dist/src/app/charts/axes/ContinuousAxisRange.js.map +1 -0
- package/dist/src/app/charts/axes/ContinuousAxisRange.test.js +47 -0
- package/dist/src/app/charts/axes/ContinuousAxisRange.test.js.map +1 -0
- package/dist/src/app/charts/axes/OrdinalAxis.d.ts +23 -0
- package/dist/src/app/charts/axes/OrdinalAxis.js +124 -0
- package/dist/src/app/charts/axes/OrdinalAxis.js.map +1 -0
- package/dist/src/app/charts/axes/OrdinalAxisRange.d.ts +69 -0
- package/dist/src/app/charts/axes/OrdinalAxisRange.js +100 -0
- package/dist/src/app/charts/axes/OrdinalAxisRange.js.map +1 -0
- package/dist/src/app/charts/axes/OrdinalAxisRange.test.js +48 -0
- package/dist/src/app/charts/axes/OrdinalAxisRange.test.js.map +1 -0
- package/dist/src/app/charts/axes/axes.d.ts +391 -0
- package/dist/src/app/charts/axes/axes.js +1046 -0
- package/dist/src/app/charts/axes/axes.js.map +1 -0
- package/dist/src/app/charts/d3types.d.ts +10 -10
- package/dist/src/app/charts/filters/regexFilter.d.ts +9 -0
- package/dist/src/app/charts/filters/regexFilter.js +18 -0
- package/dist/src/app/charts/filters/regexFilter.js.map +1 -0
- package/dist/src/app/charts/filters/regexFilter.test.d.ts +1 -0
- package/dist/src/app/charts/filters/regexFilter.test.js +11 -0
- package/dist/src/app/charts/filters/regexFilter.test.js.map +1 -0
- package/dist/src/app/charts/hooks/useAxes.d.ts +144 -0
- package/dist/src/app/charts/hooks/useAxes.js +187 -0
- package/dist/src/app/charts/hooks/useAxes.js.map +1 -0
- package/dist/src/app/charts/hooks/useChart.d.ts +30 -201
- package/dist/src/app/charts/hooks/useChart.js +33 -134
- package/dist/src/app/charts/hooks/useChart.js.map +1 -1
- package/dist/src/app/charts/hooks/useDataObservable.d.ts +74 -0
- package/dist/src/app/charts/hooks/useDataObservable.js +76 -0
- package/dist/src/app/charts/hooks/useDataObservable.js.map +1 -0
- package/dist/src/app/charts/hooks/useInitialData.d.ts +38 -0
- package/dist/src/app/charts/hooks/useInitialData.js +29 -0
- package/dist/src/app/charts/hooks/useInitialData.js.map +1 -0
- package/dist/src/app/charts/hooks/useMouse.d.ts +53 -0
- package/dist/src/app/charts/hooks/useMouse.js +65 -0
- package/dist/src/app/charts/hooks/useMouse.js.map +1 -0
- package/dist/src/app/charts/hooks/usePlotDimensions.d.ts +34 -0
- package/dist/src/app/charts/hooks/usePlotDimensions.js +73 -0
- package/dist/src/app/charts/hooks/usePlotDimensions.js.map +1 -0
- package/dist/src/app/charts/hooks/useTooltip.d.ts +64 -0
- package/dist/src/app/charts/hooks/useTooltip.js +52 -0
- package/dist/src/app/charts/hooks/useTooltip.js.map +1 -0
- package/dist/src/app/charts/observables/ChartData.d.ts +23 -0
- package/dist/src/app/charts/observables/ChartData.js +20 -0
- package/dist/src/app/charts/observables/ChartData.js.map +1 -0
- package/dist/src/app/charts/observables/iterates.d.ts +52 -0
- package/dist/src/app/charts/observables/iterates.js +121 -0
- package/dist/src/app/charts/observables/iterates.js.map +1 -0
- package/dist/src/app/charts/observables/iterates.test.d.ts +1 -0
- package/dist/src/app/charts/observables/iterates.test.js +180 -0
- package/dist/src/app/charts/observables/iterates.test.js.map +1 -0
- package/dist/src/app/charts/observables/ordinals.d.ts +75 -0
- package/dist/src/app/charts/observables/ordinals.js +141 -0
- package/dist/src/app/charts/observables/ordinals.js.map +1 -0
- package/dist/src/app/charts/observables/ordinals.test.d.ts +1 -0
- package/dist/src/app/charts/observables/ordinals.test.js +102 -0
- package/dist/src/app/charts/observables/ordinals.test.js.map +1 -0
- package/dist/src/app/charts/plots/BarPlot.d.ts +81 -0
- package/dist/src/app/charts/plots/BarPlot.js +557 -0
- package/dist/src/app/charts/plots/BarPlot.js.map +1 -0
- package/dist/src/app/charts/plots/PoincarePlot.d.ts +78 -0
- package/dist/src/app/charts/plots/PoincarePlot.js +504 -0
- package/dist/src/app/charts/plots/PoincarePlot.js.map +1 -0
- package/dist/src/app/charts/{RasterPlot.d.ts → plots/RasterPlot.d.ts} +1 -1
- package/dist/src/app/charts/{RasterPlot.js → plots/RasterPlot.js} +152 -133
- package/dist/src/app/charts/plots/RasterPlot.js.map +1 -0
- package/dist/src/app/charts/{ScatterPlot.d.ts → plots/ScatterPlot.d.ts} +10 -8
- package/dist/src/app/charts/plots/ScatterPlot.js +379 -0
- package/dist/src/app/charts/plots/ScatterPlot.js.map +1 -0
- package/dist/src/app/charts/{plot.d.ts → plots/plot.d.ts} +12 -14
- package/dist/src/app/charts/{plot.js → plots/plot.js} +19 -17
- package/dist/src/app/charts/plots/plot.js.map +1 -0
- package/dist/src/app/charts/series/baseSeries.d.ts +38 -0
- package/dist/src/app/charts/series/baseSeries.js +36 -0
- package/dist/src/app/charts/series/baseSeries.js.map +1 -0
- package/dist/src/app/charts/series/datumSeries.test.d.ts +1 -0
- package/dist/src/app/charts/series/datumSeries.test.js +50 -0
- package/dist/src/app/charts/series/datumSeries.test.js.map +1 -0
- package/dist/src/app/charts/series/iterateSeries.d.ts +42 -0
- package/dist/src/app/charts/series/iterateSeries.js +34 -0
- package/dist/src/app/charts/series/iterateSeries.js.map +1 -0
- package/dist/src/app/charts/series/ordinalSeries.d.ts +54 -0
- package/dist/src/app/charts/series/ordinalSeries.js +98 -0
- package/dist/src/app/charts/series/ordinalSeries.js.map +1 -0
- package/dist/src/app/charts/series/timeSeries.d.ts +30 -0
- package/dist/src/app/charts/series/timeSeries.js +19 -0
- package/dist/src/app/charts/series/timeSeries.js.map +1 -0
- package/dist/src/app/charts/{chartData.d.ts → series/timeSeriesChartData.d.ts} +11 -6
- package/dist/src/app/charts/series/timeSeriesChartData.js +32 -0
- package/dist/src/app/charts/series/timeSeriesChartData.js.map +1 -0
- package/dist/src/app/charts/styling/barPlotStyle.d.ts +41 -0
- package/dist/src/app/charts/styling/barPlotStyle.js +84 -0
- package/dist/src/app/charts/styling/barPlotStyle.js.map +1 -0
- package/dist/src/app/charts/{margins.d.ts → styling/margins.d.ts} +7 -5
- package/dist/src/app/charts/{margins.js → styling/margins.js} +19 -9
- package/dist/src/app/charts/styling/margins.js.map +1 -0
- package/dist/src/app/charts/styling/margins.test.d.ts +1 -0
- package/dist/src/app/charts/styling/margins.test.js +19 -0
- package/dist/src/app/charts/styling/margins.test.js.map +1 -0
- package/dist/src/app/charts/styling/svgStyle.d.ts +76 -0
- package/dist/src/app/charts/styling/svgStyle.js +84 -0
- package/dist/src/app/charts/styling/svgStyle.js.map +1 -0
- package/dist/src/app/charts/subscriptions/subscription.test.d.ts +1 -0
- package/dist/src/app/charts/subscriptions/subscription.test.js +395 -0
- package/dist/src/app/charts/subscriptions/subscription.test.js.map +1 -0
- package/dist/src/app/charts/subscriptions/subscriptions.d.ts +100 -0
- package/dist/src/app/charts/subscriptions/subscriptions.js +449 -0
- package/dist/src/app/charts/subscriptions/subscriptions.js.map +1 -0
- package/dist/src/app/charts/tooltips/BarPlotTooltipContent.d.ts +90 -0
- package/dist/src/app/charts/tooltips/BarPlotTooltipContent.js +302 -0
- package/dist/src/app/charts/tooltips/BarPlotTooltipContent.js.map +1 -0
- package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.d.ts +100 -0
- package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.js +190 -0
- package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.js.map +1 -0
- package/dist/src/app/charts/{RasterPlotTooltipContent.js → tooltips/RasterPlotTooltipContent.js} +40 -44
- package/dist/src/app/charts/tooltips/RasterPlotTooltipContent.js.map +1 -0
- package/dist/src/app/charts/tooltips/ScatterPlotTooltipContent.js +154 -0
- package/dist/src/app/charts/tooltips/ScatterPlotTooltipContent.js.map +1 -0
- package/dist/src/app/charts/{Tooltip.d.ts → tooltips/Tooltip.d.ts} +4 -2
- package/dist/src/app/charts/{Tooltip.js → tooltips/Tooltip.js} +23 -28
- package/dist/src/app/charts/tooltips/Tooltip.js.map +1 -0
- package/dist/src/app/charts/{tooltipUtils.d.ts → tooltips/tooltipUtils.d.ts} +11 -6
- package/dist/src/app/charts/{tooltipUtils.js → tooltips/tooltipUtils.js} +33 -17
- package/dist/src/app/charts/tooltips/tooltipUtils.js.map +1 -0
- package/dist/src/app/charts/{Tracker.d.ts → trackers/Tracker.d.ts} +6 -5
- package/dist/src/app/charts/trackers/Tracker.js +60 -0
- package/dist/src/app/charts/trackers/Tracker.js.map +1 -0
- package/dist/src/app/charts/{trackerUtils.d.ts → trackers/trackerUtils.d.ts} +13 -8
- package/dist/src/app/charts/trackers/trackerUtils.js +359 -0
- package/dist/src/app/charts/trackers/trackerUtils.js.map +1 -0
- package/dist/src/app/charts/utils.d.ts +22 -32
- package/dist/src/app/charts/utils.js +36 -37
- package/dist/src/app/charts/utils.js.map +1 -1
- package/dist/src/index.d.ts +48 -15
- package/dist/src/index.js +71 -15
- package/dist/src/index.js.map +1 -1
- package/package.json +30 -20
- package/src/app/charts/Chart.tsx +334 -0
- package/src/app/charts/axes/AxesState.test.ts +34 -0
- package/src/app/charts/axes/AxesState.ts +112 -0
- package/src/app/charts/axes/AxisInterval.test.ts +143 -0
- package/src/app/charts/axes/AxisInterval.ts +139 -0
- package/src/app/charts/axes/BaseAxisRange.ts +113 -0
- package/src/app/charts/axes/ContinuousAxis.tsx +192 -0
- package/src/app/charts/axes/ContinuousAxisRange.test.ts +55 -0
- package/src/app/charts/axes/ContinuousAxisRange.ts +96 -0
- package/src/app/charts/axes/OrdinalAxis.tsx +223 -0
- package/src/app/charts/axes/OrdinalAxisRange.test.ts +55 -0
- package/src/app/charts/axes/OrdinalAxisRange.ts +112 -0
- package/src/app/charts/axes/axes.ts +1569 -0
- package/src/app/charts/d3types.ts +16 -0
- package/src/app/charts/filters/regexFilter.test.ts +13 -0
- package/src/app/charts/filters/regexFilter.ts +17 -0
- package/src/app/charts/hooks/useAxes.tsx +341 -0
- package/src/app/charts/hooks/useChart.tsx +159 -0
- package/src/app/charts/hooks/useDataObservable.tsx +175 -0
- package/src/app/charts/hooks/useInitialData.tsx +65 -0
- package/src/app/charts/hooks/useMouse.tsx +125 -0
- package/src/app/charts/hooks/usePlotDimensions.tsx +120 -0
- package/src/app/charts/hooks/useTooltip.tsx +112 -0
- package/src/app/charts/observables/ChartData.ts +31 -0
- package/src/app/charts/observables/iterates.test.ts +201 -0
- package/src/app/charts/observables/iterates.ts +203 -0
- package/src/app/charts/observables/ordinals.test.ts +135 -0
- package/src/app/charts/observables/ordinals.ts +248 -0
- package/src/app/charts/plots/BarPlot.tsx +1088 -0
- package/src/app/charts/plots/PoincarePlot.tsx +832 -0
- package/src/app/charts/plots/RasterPlot.tsx +676 -0
- package/src/app/charts/plots/ScatterPlot.tsx +653 -0
- package/src/app/charts/plots/plot.ts +75 -0
- package/src/app/charts/series/baseSeries.ts +52 -0
- package/src/app/charts/series/datumSeries.test.ts +60 -0
- package/src/app/charts/series/iterateSeries.ts +56 -0
- package/src/app/charts/series/ordinalSeries.ts +164 -0
- package/src/app/charts/series/timeSeries.ts +40 -0
- package/src/app/charts/series/timeSeriesChartData.ts +68 -0
- package/src/app/charts/styling/barPlotStyle.ts +126 -0
- package/src/app/charts/styling/margins.test.ts +22 -0
- package/src/app/charts/styling/margins.ts +58 -0
- package/src/app/charts/styling/svgStyle.ts +118 -0
- package/src/app/charts/subscriptions/subscription.test.ts +499 -0
- package/src/app/charts/subscriptions/subscriptions.ts +635 -0
- package/src/app/charts/tooltips/BarPlotTooltipContent.tsx +440 -0
- package/src/app/charts/tooltips/PoincarePlotTooltipContent.tsx +352 -0
- package/src/app/charts/tooltips/RasterPlotTooltipContent.tsx +274 -0
- package/src/app/charts/tooltips/ScatterPlotTooltipContent.tsx +319 -0
- package/src/app/charts/tooltips/Tooltip.tsx +148 -0
- package/src/app/charts/tooltips/tooltipUtils.ts +216 -0
- package/src/app/charts/trackers/Tracker.tsx +129 -0
- package/src/app/charts/trackers/trackerUtils.ts +494 -0
- package/src/app/charts/utils.ts +109 -0
- package/dist/src/app/charts/CategoryAxis.d.ts +0 -20
- package/dist/src/app/charts/CategoryAxis.js +0 -112
- package/dist/src/app/charts/CategoryAxis.js.map +0 -1
- package/dist/src/app/charts/ContinuousAxis.d.ts +0 -16
- package/dist/src/app/charts/ContinuousAxis.js +0 -186
- package/dist/src/app/charts/ContinuousAxis.js.map +0 -1
- package/dist/src/app/charts/RasterPlot.js.map +0 -1
- package/dist/src/app/charts/RasterPlotTooltipContent.js.map +0 -1
- package/dist/src/app/charts/ScatterPlot.js +0 -351
- package/dist/src/app/charts/ScatterPlot.js.map +0 -1
- package/dist/src/app/charts/ScatterPlotTooltipContent.js +0 -163
- package/dist/src/app/charts/ScatterPlotTooltipContent.js.map +0 -1
- package/dist/src/app/charts/Tooltip.js.map +0 -1
- package/dist/src/app/charts/Tracker.js +0 -65
- package/dist/src/app/charts/Tracker.js.map +0 -1
- package/dist/src/app/charts/axes.d.ts +0 -132
- package/dist/src/app/charts/axes.js +0 -265
- package/dist/src/app/charts/axes.js.map +0 -1
- package/dist/src/app/charts/chartData.js +0 -32
- package/dist/src/app/charts/chartData.js.map +0 -1
- package/dist/src/app/charts/continuousAxisRangeFor.d.ts +0 -20
- package/dist/src/app/charts/continuousAxisRangeFor.js +0 -68
- package/dist/src/app/charts/continuousAxisRangeFor.js.map +0 -1
- package/dist/src/app/charts/datumSeries.d.ts +0 -59
- package/dist/src/app/charts/datumSeries.js +0 -55
- package/dist/src/app/charts/datumSeries.js.map +0 -1
- package/dist/src/app/charts/datumSeries.test.js +0 -50
- package/dist/src/app/charts/datumSeries.test.js.map +0 -1
- package/dist/src/app/charts/hooks/AxesState.d.ts +0 -37
- package/dist/src/app/charts/hooks/AxesState.js +0 -44
- package/dist/src/app/charts/hooks/AxesState.js.map +0 -1
- package/dist/src/app/charts/margins.js.map +0 -1
- package/dist/src/app/charts/margins.test.js +0 -14
- package/dist/src/app/charts/margins.test.js.map +0 -1
- package/dist/src/app/charts/plot.js.map +0 -1
- package/dist/src/app/charts/regexFilter.d.ts +0 -9
- package/dist/src/app/charts/regexFilter.js +0 -17
- package/dist/src/app/charts/regexFilter.js.map +0 -1
- package/dist/src/app/charts/regexFilter.test.js +0 -11
- package/dist/src/app/charts/regexFilter.test.js.map +0 -1
- package/dist/src/app/charts/subscriptions.d.ts +0 -43
- package/dist/src/app/charts/subscriptions.js +0 -213
- package/dist/src/app/charts/subscriptions.js.map +0 -1
- package/dist/src/app/charts/svgStyle.d.ts +0 -27
- package/dist/src/app/charts/svgStyle.js +0 -32
- package/dist/src/app/charts/svgStyle.js.map +0 -1
- package/dist/src/app/charts/timeRange.test.js +0 -54
- package/dist/src/app/charts/timeRange.test.js.map +0 -1
- package/dist/src/app/charts/tooltipUtils.js.map +0 -1
- package/dist/src/app/charts/trackerUtils.js +0 -130
- package/dist/src/app/charts/trackerUtils.js.map +0 -1
- /package/dist/src/app/charts/{datumSeries.test.d.ts → axes/AxesState.test.d.ts} +0 -0
- /package/dist/src/app/charts/{margins.test.d.ts → axes/AxisInterval.test.d.ts} +0 -0
- /package/dist/src/app/charts/{regexFilter.test.d.ts → axes/ContinuousAxisRange.test.d.ts} +0 -0
- /package/dist/src/app/charts/{timeRange.test.d.ts → axes/OrdinalAxisRange.test.d.ts} +0 -0
- /package/dist/src/app/charts/{RasterPlotTooltipContent.d.ts → tooltips/RasterPlotTooltipContent.d.ts} +0 -0
- /package/dist/src/app/charts/{ScatterPlotTooltipContent.d.ts → tooltips/ScatterPlotTooltipContent.d.ts} +0 -0
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import { Dimensions, Margin } from "../margins";
|
|
1
|
+
import { JSX } from "react";
|
|
3
2
|
import { GSelection } from "../d3types";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { AxesState } from "./AxesState";
|
|
12
|
-
export declare const defaultMargin: Margin;
|
|
3
|
+
import { BaseAxis, SeriesLineStyle, SeriesStyle } from "../axes/axes";
|
|
4
|
+
import { UseAxesValues } from "./useAxes";
|
|
5
|
+
import { UseMouseValues } from "./useMouse";
|
|
6
|
+
import { UseTooltipValues } from "./useTooltip";
|
|
7
|
+
import { SvgStyle } from "../styling/svgStyle";
|
|
8
|
+
import { BaseAxisRange } from "../axes/BaseAxisRange";
|
|
9
|
+
export type NoTooltipMetadata = {};
|
|
13
10
|
/**
|
|
14
11
|
* The values exposed through the {@link useChart} react hook
|
|
12
|
+
* @param chartId The unique ID for the chart
|
|
13
|
+
* @param mainG The root <g> element for the chart
|
|
14
|
+
* @param container The SVG element which is the container for this chart
|
|
15
|
+
* @template D The type of the series' datum
|
|
16
|
+
* @template S The type of the series style
|
|
17
|
+
* @template TM The type of the tooltip's metadata (data about the series data)
|
|
15
18
|
*/
|
|
16
|
-
interface UseChartValues {
|
|
19
|
+
interface UseChartValues<D, S extends SeriesStyle, TM, AR extends BaseAxisRange, A extends BaseAxis> {
|
|
17
20
|
/**
|
|
18
21
|
* Unique ID for the chart
|
|
19
22
|
*/
|
|
20
23
|
chartId: number;
|
|
21
|
-
/**
|
|
22
|
-
* The width and height (in pixels) of this chart
|
|
23
|
-
*/
|
|
24
|
-
plotDimensions: Dimensions;
|
|
25
24
|
/**
|
|
26
25
|
* The root <g> element for the chart
|
|
27
26
|
*/
|
|
@@ -30,221 +29,51 @@ interface UseChartValues {
|
|
|
30
29
|
* The SVG element which is the container for this chart
|
|
31
30
|
*/
|
|
32
31
|
container: SVGSVGElement | null;
|
|
33
|
-
/**
|
|
34
|
-
* The plot margins for the border of main G
|
|
35
|
-
*/
|
|
36
|
-
margin: Margin;
|
|
37
32
|
/**
|
|
38
33
|
* Base color
|
|
39
34
|
*/
|
|
40
35
|
color: string;
|
|
41
36
|
/**
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
seriesStyles: Map<string, SeriesLineStyle>;
|
|
45
|
-
/**
|
|
46
|
-
* The x-axes state holds the currently set x-axes, manipulation and accessor functions
|
|
47
|
-
*/
|
|
48
|
-
xAxesState: AxesState;
|
|
49
|
-
/**
|
|
50
|
-
* Adds an x-axis to the axes and updates the internal state
|
|
51
|
-
* @param axis The axis to add
|
|
52
|
-
* @param id The ID of the axis to add
|
|
53
|
-
*/
|
|
54
|
-
addXAxis: (axis: BaseAxis, id: string) => void;
|
|
55
|
-
/**
|
|
56
|
-
* The y-axes state holds the currently set x-axes, manipulation and accessor functions
|
|
57
|
-
*/
|
|
58
|
-
yAxesState: AxesState;
|
|
59
|
-
/**
|
|
60
|
-
* Adds a y-axis to the axes and updates the internal state
|
|
61
|
-
* @param axis The axis to add
|
|
62
|
-
* @param id The ID of the axis to add
|
|
63
|
-
*/
|
|
64
|
-
addYAxis: (axis: BaseAxis, id: string) => void;
|
|
65
|
-
/**
|
|
66
|
-
* Sets the axis assigned to each series. This should contain **all** the series used in
|
|
67
|
-
* the chart.
|
|
68
|
-
* @param assignments The assignment of the series to their axes
|
|
37
|
+
* The base/default background color. This can be overridden by the {@link Props.svgStyle} property.
|
|
69
38
|
*/
|
|
70
|
-
|
|
39
|
+
backgroundColor: string;
|
|
71
40
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @return The axes assigned to the specified series
|
|
41
|
+
* Overrides for the SVG style
|
|
74
42
|
*/
|
|
75
|
-
|
|
43
|
+
svgStyle: Partial<SvgStyle>;
|
|
76
44
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param axisId The ID of the axis for which to retrieve the time-range
|
|
79
|
-
* @return The time-range as a `[t_start, t_end]` tuple if the axis ID is found, `undefined` otherwise
|
|
80
|
-
*/
|
|
81
|
-
timeRangeFor: (axisId: string) => [start: number, end: number] | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* Sets the time-range for the specified axis ID to the specified range
|
|
84
|
-
* @param axisId The ID of the axis for which to set the range
|
|
85
|
-
* @param timeRange The new time range as an `[t_start, t_end]` tuple
|
|
86
|
-
*/
|
|
87
|
-
setTimeRangeFor: (axisId: string, timeRange: [start: number, end: number]) => void;
|
|
88
|
-
/**
|
|
89
|
-
* An array of time-series representing the initial data for the chart (i.e. static data
|
|
90
|
-
* before streaming starts)
|
|
91
|
-
*/
|
|
92
|
-
initialData: Array<Series>;
|
|
93
|
-
/**
|
|
94
|
-
* An observable source for chart data
|
|
95
|
-
*/
|
|
96
|
-
seriesObservable?: Observable<ChartData>;
|
|
97
|
-
/**
|
|
98
|
-
* When `true` the chart will subscribe to the observable, or if already subscribed, will remain
|
|
99
|
-
* subscribed. When `false` the chart will unsubscribe to the observable if subscribed, or will
|
|
100
|
-
* remain unsubscribed if not already subscribed.
|
|
101
|
-
*/
|
|
102
|
-
shouldSubscribe?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* The windowing time for aggregating chart-data events. Defines the update rate of the chart.
|
|
105
|
-
* For example if chart-data events occur every 1 ms, and the windowing time is set to 10 ms,
|
|
106
|
-
* then events will be aggregated for 10 ms, and then the chart will be updated. In this example,
|
|
107
|
-
* the chart would be updated only once per 10 ms.
|
|
45
|
+
* A `map(series_name -> series_line_style)`
|
|
108
46
|
*/
|
|
109
|
-
|
|
47
|
+
seriesStyles: Map<string, S>;
|
|
48
|
+
axes: UseAxesValues<AR, A>;
|
|
110
49
|
/**
|
|
111
50
|
* A regular expression uses against the series names to determine which series to show in the chart
|
|
112
51
|
*/
|
|
113
52
|
seriesFilter: RegExp;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* @param subscription The subscription resulting form the subscribe action
|
|
117
|
-
*/
|
|
118
|
-
onSubscribe: (subscription: Subscription) => void;
|
|
119
|
-
/**
|
|
120
|
-
* Callback when the time range changes.
|
|
121
|
-
* @param times The times (start, end) times for each axis in the plot
|
|
122
|
-
* @return void
|
|
123
|
-
*/
|
|
124
|
-
onUpdateTime?: (times: Map<string, [start: number, end: number]>) => void;
|
|
125
|
-
/**
|
|
126
|
-
* Callback function that is called when new data arrives to the chart.
|
|
127
|
-
* @param seriesName The name of the series for which new data arrived
|
|
128
|
-
* @param data The new data that arrived in the windowing tine
|
|
129
|
-
* @see UseChartValues.windowingTime
|
|
130
|
-
*/
|
|
131
|
-
onUpdateData?: (seriesName: string, data: Array<Datum>) => void;
|
|
132
|
-
/**
|
|
133
|
-
* Callback function that is called when the time ranges change. The time ranges could
|
|
134
|
-
* change because of a zoom action, a pan action, or as new data is streamed in.
|
|
135
|
-
* @param times A `map(axis_id -> time_range)` that associates the axis ID with the
|
|
136
|
-
* current time range.
|
|
137
|
-
*/
|
|
138
|
-
updateTimeRanges: (times: Map<string, ContinuousAxisRange>) => void;
|
|
139
|
-
/**
|
|
140
|
-
* Update the plot dimensions (for example, on a window resize)
|
|
141
|
-
* @param dimensions the new dimensions of the plot
|
|
142
|
-
*/
|
|
143
|
-
updateDimensions: (dimensions: Dimensions) => void;
|
|
144
|
-
/**
|
|
145
|
-
* Adds a handler for when the time is updated. The time could change because of a zoom action,
|
|
146
|
-
* a pan action, or as new data is streamed in.
|
|
147
|
-
* @param handlerId The unique ID of the handler to register/add
|
|
148
|
-
* @param handler The handler function
|
|
149
|
-
*/
|
|
150
|
-
addTimeUpdateHandler: (handlerId: string, handler: (updates: Map<string, ContinuousAxisRange>, plotDim: Dimensions) => void) => void;
|
|
151
|
-
/**
|
|
152
|
-
* Removes the time-update handler with the specified ID
|
|
153
|
-
* @param handlerId The ID of the handler to remove
|
|
154
|
-
*/
|
|
155
|
-
removeTimeUpdateHandler: (handlerId: string) => void;
|
|
156
|
-
/**
|
|
157
|
-
* Adds a mouse-over-series handler with the specified ID and handler function
|
|
158
|
-
* @param handlerId The handler ID
|
|
159
|
-
* @param handler The handler function called when a mouse-over-series event occurs
|
|
160
|
-
* @return The handler ID
|
|
161
|
-
*/
|
|
162
|
-
registerMouseOverHandler: (handlerId: string, handler: (seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => void) => string;
|
|
163
|
-
/**
|
|
164
|
-
* Removes the mouse-over-series handler with the specified ID
|
|
165
|
-
* @param handlerId The ID of the handler to remove
|
|
166
|
-
*/
|
|
167
|
-
unregisterMouseOverHandler: (handlerId: string) => void;
|
|
168
|
-
/**
|
|
169
|
-
* Attempts to retrieve the mouse-over-series handler for the specified ID
|
|
170
|
-
* @param handlerId The ID of the handler
|
|
171
|
-
* @return The mouse-over-series handler for the ID, or `undefined` if not found
|
|
172
|
-
*/
|
|
173
|
-
mouseOverHandlerFor: (handlerId: string) => ((seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => void) | undefined;
|
|
174
|
-
/**
|
|
175
|
-
* Adds a mouse-leave-series handler with the specified ID and handler function
|
|
176
|
-
* @param handlerId The handler ID
|
|
177
|
-
* @param handler The handler function called when a mouse-leave-series event occurs
|
|
178
|
-
* @return The handler ID
|
|
179
|
-
*/
|
|
180
|
-
registerMouseLeaveHandler: (handlerId: string, handler: (seriesName: string) => void) => string;
|
|
181
|
-
/**
|
|
182
|
-
* Removes the mouse-leave-series handler with the specified ID
|
|
183
|
-
* @param handlerId The ID of the handler to remove
|
|
184
|
-
*/
|
|
185
|
-
unregisterMouseLeaveHandler: (handlerId: string) => void;
|
|
186
|
-
/**
|
|
187
|
-
* Attempts to retrieve the mouse-leave-series handler for the specified ID
|
|
188
|
-
* @param handlerId The ID of the handler
|
|
189
|
-
* @return The mouse-leave-series handler for the ID, or `undefined` if not found
|
|
190
|
-
*/
|
|
191
|
-
mouseLeaveHandlerFor: (handlerId: string) => ((seriesName: string) => void) | undefined;
|
|
192
|
-
/**
|
|
193
|
-
* Registers the provider of the tooltip content (generally this will be registered by the plot).
|
|
194
|
-
* When this function is called again, overwrites the previously registered provider with the
|
|
195
|
-
* one specified. This function can be called repeatedly.
|
|
196
|
-
* @param provider The function that provides the content when called.
|
|
197
|
-
*/
|
|
198
|
-
registerTooltipContentProvider: (provider: (seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => TooltipDimensions) => void;
|
|
199
|
-
/**
|
|
200
|
-
* @return The registered function that provides the tooltip content. If no function has been
|
|
201
|
-
* registered, then returns `undefined`.
|
|
202
|
-
*/
|
|
203
|
-
tooltipContentProvider: () => ((seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => TooltipDimensions) | undefined;
|
|
53
|
+
mouse: UseMouseValues<D, TM>;
|
|
54
|
+
tooltip: UseTooltipValues<D, TM>;
|
|
204
55
|
}
|
|
205
56
|
interface Props {
|
|
206
57
|
chartId: number;
|
|
207
58
|
container: SVGSVGElement | null;
|
|
208
59
|
mainG: GSelection | null;
|
|
209
|
-
containerDimensions: Dimensions;
|
|
210
|
-
margin: Margin;
|
|
211
60
|
color: string;
|
|
61
|
+
backgroundColor: string;
|
|
62
|
+
svgStyle: Partial<SvgStyle>;
|
|
212
63
|
seriesStyles?: Map<string, SeriesLineStyle>;
|
|
213
|
-
initialData: Array<Series>;
|
|
214
64
|
seriesFilter?: RegExp;
|
|
215
|
-
seriesObservable?: Observable<ChartData>;
|
|
216
|
-
windowingTime?: number;
|
|
217
|
-
shouldSubscribe?: boolean;
|
|
218
|
-
/**
|
|
219
|
-
* Callback function that is called when the chart subscribes to the observable
|
|
220
|
-
* @param subscription The subscription resulting form the subscribe action
|
|
221
|
-
*/
|
|
222
|
-
onSubscribe?: (subscription: Subscription) => void;
|
|
223
|
-
/**
|
|
224
|
-
* Callback when the time range changes.
|
|
225
|
-
* @param times The times (start, end) times for each axis in the plot
|
|
226
|
-
* @return void
|
|
227
|
-
*/
|
|
228
|
-
onUpdateTime?: (times: Map<string, [start: number, end: number]>) => void;
|
|
229
|
-
/**
|
|
230
|
-
* Callback function that is called when new data arrives to the chart.
|
|
231
|
-
* @param seriesName The name of the series for which new data arrived
|
|
232
|
-
* @param data The new data that arrived in the windowing tine
|
|
233
|
-
* @see UseChartValues.windowingTime
|
|
234
|
-
*/
|
|
235
|
-
onUpdateData?: (seriesName: string, data: Array<Datum>) => void;
|
|
236
65
|
children: JSX.Element | Array<JSX.Element>;
|
|
237
66
|
}
|
|
238
67
|
/**
|
|
239
|
-
* The
|
|
68
|
+
* The React context provider for the {@link UseChartValues}
|
|
240
69
|
* @param props The properties
|
|
241
70
|
* @return The children wrapped in this provider
|
|
242
71
|
* @constructor
|
|
243
72
|
*/
|
|
244
73
|
export default function ChartProvider(props: Props): JSX.Element;
|
|
245
74
|
/**
|
|
246
|
-
* React hook that sets up the
|
|
247
|
-
* @return The {@link UseChartValues} held in the
|
|
75
|
+
* React hook that sets up the React context for the chart values.
|
|
76
|
+
* @return The {@link UseChartValues} held in the React context.
|
|
248
77
|
*/
|
|
249
|
-
export declare function useChart(): UseChartValues
|
|
78
|
+
export declare function useChart<D, S extends SeriesStyle, TM, AR extends BaseAxisRange, A extends BaseAxis>(): UseChartValues<D, S, TM, AR, A>;
|
|
250
79
|
export {};
|
|
@@ -1,158 +1,57 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { createContext, useContext
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
var defaultUseChartValues = {
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { defaultAxesValues, useAxes } from "./useAxes";
|
|
4
|
+
import { defaultMouseValues, useMouse } from "./useMouse";
|
|
5
|
+
import { defaultTooltipValues, useTooltip } from "./useTooltip";
|
|
6
|
+
const defaultUseChartValues = {
|
|
19
7
|
chartId: NaN,
|
|
20
8
|
container: null,
|
|
21
9
|
mainG: null,
|
|
22
|
-
plotDimensions: { width: 0, height: 0 },
|
|
23
|
-
margin: defaultMargin,
|
|
24
10
|
color: '#d2933f',
|
|
11
|
+
backgroundColor: '#EEE',
|
|
12
|
+
svgStyle: new Map(),
|
|
25
13
|
seriesStyles: new Map(),
|
|
26
14
|
// axes
|
|
27
|
-
|
|
28
|
-
yAxesState: createAxesState(),
|
|
29
|
-
addXAxis: noop,
|
|
30
|
-
addYAxis: noop,
|
|
31
|
-
setAxisAssignments: noop,
|
|
32
|
-
axisAssignmentsFor: function () { return ({ xAxis: "", yAxis: "" }); },
|
|
33
|
-
// timing
|
|
34
|
-
timeRangeFor: function () { return [NaN, NaN]; },
|
|
35
|
-
setTimeRangeFor: noop,
|
|
15
|
+
axes: defaultAxesValues(),
|
|
36
16
|
// data
|
|
37
|
-
initialData: [],
|
|
38
17
|
seriesFilter: /./,
|
|
39
|
-
windowingTime: NaN,
|
|
40
|
-
shouldSubscribe: false,
|
|
41
|
-
// user callbacks
|
|
42
|
-
onSubscribe: noop,
|
|
43
|
-
// internal event handlers
|
|
44
|
-
updateTimeRanges: noop,
|
|
45
|
-
updateDimensions: noop,
|
|
46
|
-
addTimeUpdateHandler: function () { return noop; },
|
|
47
|
-
removeTimeUpdateHandler: function () { return noop; },
|
|
48
18
|
// internal chart-interaction event handlers
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
mouseOverHandlerFor: function () { return undefined; },
|
|
52
|
-
registerMouseLeaveHandler: function () { return ''; },
|
|
53
|
-
unregisterMouseLeaveHandler: noop,
|
|
54
|
-
mouseLeaveHandlerFor: function () { return undefined; },
|
|
55
|
-
registerTooltipContentProvider: noop,
|
|
56
|
-
tooltipContentProvider: function () { return undefined; }
|
|
19
|
+
mouse: defaultMouseValues(),
|
|
20
|
+
tooltip: defaultTooltipValues()
|
|
57
21
|
};
|
|
58
|
-
|
|
22
|
+
const ChartContext = createContext(defaultUseChartValues);
|
|
59
23
|
/**
|
|
60
|
-
* The
|
|
24
|
+
* The React context provider for the {@link UseChartValues}
|
|
61
25
|
* @param props The properties
|
|
62
26
|
* @return The children wrapped in this provider
|
|
63
27
|
* @constructor
|
|
64
28
|
*/
|
|
65
29
|
export default function ChartProvider(props) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* @param updates A map holding the axis ID to the updated axis time-range
|
|
84
|
-
*/
|
|
85
|
-
function updateTimeRanges(updates) {
|
|
86
|
-
// update the current time-ranges reference
|
|
87
|
-
updates.forEach(function (range, id) {
|
|
88
|
-
return timeRangesRef.current.set(id, [range.start, range.end]);
|
|
89
|
-
});
|
|
90
|
-
// dispatch the updates to all the registered handlers
|
|
91
|
-
timeUpdateHandlersRef.current.forEach(function (handler) { return handler(updates, dimensions); });
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Retrieves the x-axis and y-axis assignments for the specified series. If the axes does not have
|
|
95
|
-
* an assignment, then is assumed to be using the default x- and y-axes.
|
|
96
|
-
* @param seriesName The name of the series for which to retrieve the axes assignments
|
|
97
|
-
* @return An {@link AxesAssignment} for the specified axes.
|
|
98
|
-
*/
|
|
99
|
-
function axisAssignmentsFor(seriesName) {
|
|
100
|
-
return axisAssignmentsRef.current.get(seriesName) || {
|
|
101
|
-
xAxis: xAxesRef.current.axisDefaultName(),
|
|
102
|
-
yAxis: yAxesRef.current.axisDefaultName()
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return _jsx(ChartContext.Provider, __assign({ value: {
|
|
106
|
-
chartId: chartId,
|
|
107
|
-
plotDimensions: dimensions,
|
|
108
|
-
margin: margin,
|
|
109
|
-
color: color,
|
|
110
|
-
seriesStyles: seriesStyles,
|
|
111
|
-
initialData: initialData,
|
|
112
|
-
seriesFilter: seriesFilter,
|
|
113
|
-
mainG: mainG,
|
|
114
|
-
container: container,
|
|
115
|
-
xAxesState: xAxesRef.current,
|
|
116
|
-
yAxesState: yAxesRef.current,
|
|
117
|
-
addXAxis: function (axis, id) { return xAxesRef.current = addAxisTo(xAxesRef.current, axis, id); },
|
|
118
|
-
addYAxis: function (axis, id) { return yAxesRef.current = addAxisTo(yAxesRef.current, axis, id); },
|
|
119
|
-
setAxisAssignments: function (assignments) { return axisAssignmentsRef.current = assignments; },
|
|
120
|
-
axisAssignmentsFor: function (seriesName) { return axisAssignmentsFor(seriesName); },
|
|
121
|
-
timeRangeFor: function (axisId) { return timeRangesRef.current.get(axisId); },
|
|
122
|
-
setTimeRangeFor: (function (axisId, timeRange) { return timeRangesRef.current.set(axisId, timeRange); }),
|
|
123
|
-
seriesObservable: seriesObservable,
|
|
124
|
-
windowingTime: windowingTime,
|
|
125
|
-
shouldSubscribe: shouldSubscribe,
|
|
126
|
-
onSubscribe: onSubscribe,
|
|
127
|
-
onUpdateTime: onUpdateTime,
|
|
128
|
-
onUpdateData: onUpdateData,
|
|
129
|
-
updateTimeRanges: updateTimeRanges,
|
|
130
|
-
updateDimensions: function (dimensions) { return setDimensions(dimensions); },
|
|
131
|
-
addTimeUpdateHandler: function (handlerId, handler) { return timeUpdateHandlersRef.current.set(handlerId, handler); },
|
|
132
|
-
removeTimeUpdateHandler: function (handlerId) { return timeUpdateHandlersRef.current.delete(handlerId); },
|
|
133
|
-
registerMouseOverHandler: function (handlerId, handler) {
|
|
134
|
-
mouseOverHandlersRef.current.set(handlerId, handler);
|
|
135
|
-
return handlerId;
|
|
136
|
-
},
|
|
137
|
-
unregisterMouseOverHandler: function (handlerId) { return mouseOverHandlersRef.current.delete(handlerId); },
|
|
138
|
-
mouseOverHandlerFor: function (handlerId) { return mouseOverHandlersRef.current.get(handlerId); },
|
|
139
|
-
registerMouseLeaveHandler: function (handlerId, handler) {
|
|
140
|
-
mouseLeaveHandlersRef.current.set(handlerId, handler);
|
|
141
|
-
return handlerId;
|
|
142
|
-
},
|
|
143
|
-
unregisterMouseLeaveHandler: function (handlerId) { return mouseLeaveHandlersRef.current.delete(handlerId); },
|
|
144
|
-
mouseLeaveHandlerFor: function (handlerId) { return mouseLeaveHandlersRef.current.get(handlerId); },
|
|
145
|
-
registerTooltipContentProvider: function (provider) { return tooltipContentProviderRef.current = provider; },
|
|
146
|
-
tooltipContentProvider: function () { return tooltipContentProviderRef.current; },
|
|
147
|
-
} }, { children: props.children }), void 0);
|
|
30
|
+
const { chartId, container, mainG, color, backgroundColor, seriesFilter = defaultUseChartValues.seriesFilter, svgStyle, seriesStyles = new Map(), } = props;
|
|
31
|
+
const axes = useAxes();
|
|
32
|
+
const mouse = useMouse();
|
|
33
|
+
const tooltip = useTooltip();
|
|
34
|
+
return _jsx(ChartContext.Provider, { value: {
|
|
35
|
+
chartId,
|
|
36
|
+
color,
|
|
37
|
+
backgroundColor,
|
|
38
|
+
svgStyle,
|
|
39
|
+
seriesStyles,
|
|
40
|
+
seriesFilter,
|
|
41
|
+
mainG,
|
|
42
|
+
container,
|
|
43
|
+
axes,
|
|
44
|
+
mouse,
|
|
45
|
+
tooltip,
|
|
46
|
+
}, children: props.children });
|
|
148
47
|
}
|
|
149
48
|
/**
|
|
150
|
-
* React hook that sets up the
|
|
151
|
-
* @return The {@link UseChartValues} held in the
|
|
49
|
+
* React hook that sets up the React context for the chart values.
|
|
50
|
+
* @return The {@link UseChartValues} held in the React context.
|
|
152
51
|
*/
|
|
153
52
|
export function useChart() {
|
|
154
|
-
|
|
155
|
-
|
|
53
|
+
const context = useContext(ChartContext);
|
|
54
|
+
const { chartId } = context;
|
|
156
55
|
if (isNaN(chartId)) {
|
|
157
56
|
throw new Error("useChart can only be used when the parent is a <ChartProvider/>");
|
|
158
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChart.js","sourceRoot":"","sources":["../../../../../src/app/charts/hooks/useChart.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useChart.js","sourceRoot":"","sources":["../../../../../src/app/charts/hooks/useChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAO,UAAU,EAAC,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAC,iBAAiB,EAAE,OAAO,EAAgB,MAAM,WAAW,CAAC;AACpE,OAAO,EAAC,kBAAkB,EAAE,QAAQ,EAAiB,MAAM,YAAY,CAAC;AACxE,OAAO,EAAC,oBAAoB,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAiEhF,MAAM,qBAAqB,GAA4C;IACnE,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,SAAS;IAChB,eAAe,EAAE,MAAM;IACvB,QAAQ,EAAE,IAAI,GAAG,EAAE;IACnB,YAAY,EAAE,IAAI,GAAG,EAAE;IAEvB,OAAO;IACP,IAAI,EAAE,iBAAiB,EAAE;IAEzB,OAAO;IACP,YAAY,EAAE,GAAG;IAEjB,4CAA4C;IAC5C,KAAK,EAAE,kBAAkB,EAAE;IAC3B,OAAO,EAAE,oBAAoB,EAAE;CAClC,CAAA;AAED,MAAM,YAAY,GAAG,aAAa,CAA0C,qBAAqB,CAAC,CAAA;AAelG;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAY;IAC9C,MAAM,EACF,OAAO,EACP,SAAS,EACT,KAAK,EACL,KAAK,EACL,eAAe,EACf,YAAY,GAAG,qBAAqB,CAAC,YAAY,EACjD,QAAQ,EACR,YAAY,GAAG,IAAI,GAAG,EAA2B,GACpD,GAAG,KAAK,CAAA;IAET,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IACxB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,OAAO,KAAC,YAAY,CAAC,QAAQ,IACzB,KAAK,EAAE;YACH,OAAO;YACP,KAAK;YACL,eAAe;YACf,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,KAAK;YACL,SAAS;YAET,IAAI;YACJ,KAAK;YACL,OAAO;SACV,YAEA,KAAK,CAAC,QAAQ,GACK,CAAA;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACpB,MAAM,OAAO,GAAG,UAAU,CAAkC,YAAY,CAAC,CAAA;IACzE,MAAM,EAAC,OAAO,EAAC,GAAG,OAAO,CAAA;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;IACtF,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { JSX } from "react";
|
|
2
|
+
import { Observable, Subscription } from "rxjs";
|
|
3
|
+
import { ChartData } from "../observables/ChartData";
|
|
4
|
+
/**
|
|
5
|
+
* The values exposed through the {@link useDataObservable} react hook
|
|
6
|
+
*/
|
|
7
|
+
interface UseObservableValues<CD extends ChartData, D> {
|
|
8
|
+
/**
|
|
9
|
+
* An observable source for chart data
|
|
10
|
+
*/
|
|
11
|
+
seriesObservable?: Observable<CD>;
|
|
12
|
+
/**
|
|
13
|
+
* When `true` the chart will subscribe to the observable, or if already subscribed, will remain
|
|
14
|
+
* subscribed. When `false` the chart will unsubscribe to the observable if subscribed, or will
|
|
15
|
+
* remain unsubscribed if not already subscribed.
|
|
16
|
+
*/
|
|
17
|
+
shouldSubscribe?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The windowing time for aggregating chart-data events. Defines the update rate of the chart.
|
|
20
|
+
* For example if chart-data events occur every 1 ms, and the windowing time is set to 10 ms,
|
|
21
|
+
* then events will be aggregated for 10 ms, and then the chart will be updated. In this example,
|
|
22
|
+
* the chart would be updated only once per 10 ms.
|
|
23
|
+
*/
|
|
24
|
+
windowingTime?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Callback function that is called when the chart subscribes to the observable
|
|
27
|
+
* @param subscription The subscription resulting form the subscribe action
|
|
28
|
+
*/
|
|
29
|
+
onSubscribe: (subscription: Subscription) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Callback function that is called when new data arrives to the chart.
|
|
32
|
+
* @param seriesName The name of the series for which new data arrived
|
|
33
|
+
* @param data The new data that arrived in the windowing tine
|
|
34
|
+
* @see UseChartValues.windowingTime
|
|
35
|
+
*/
|
|
36
|
+
onUpdateData?: (seriesName: string, data: Array<D>) => void;
|
|
37
|
+
/**
|
|
38
|
+
* todo
|
|
39
|
+
* @param time
|
|
40
|
+
*/
|
|
41
|
+
onUpdateChartTime?: (time: number) => void;
|
|
42
|
+
}
|
|
43
|
+
interface Props<CD extends ChartData, D> {
|
|
44
|
+
seriesObservable?: Observable<CD>;
|
|
45
|
+
windowingTime?: number;
|
|
46
|
+
shouldSubscribe?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Callback function that is called when the chart subscribes to the observable
|
|
49
|
+
* @param subscription The subscription resulting form the subscribe action
|
|
50
|
+
*/
|
|
51
|
+
onSubscribe?: (subscription: Subscription) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback function that is called when new data arrives to the chart.
|
|
54
|
+
* @param seriesName The name of the series for which new data arrived
|
|
55
|
+
* @param data The new data that arrived in the windowing tine
|
|
56
|
+
* @see UseChartValues.windowingTime
|
|
57
|
+
*/
|
|
58
|
+
onUpdateData?: (seriesName: string, data: Array<D>) => void;
|
|
59
|
+
onUpdateChartTime?: (time: number) => void;
|
|
60
|
+
children: JSX.Element | Array<JSX.Element>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The react context provider for the {@link UseObservableValues}
|
|
64
|
+
* @param props The properties
|
|
65
|
+
* @return The children wrapped in this provider
|
|
66
|
+
* @constructor
|
|
67
|
+
*/
|
|
68
|
+
export default function DataObservableProvider<CD extends ChartData, D>(props: Props<CD, D>): JSX.Element;
|
|
69
|
+
/**
|
|
70
|
+
* React hook that sets up the React context for the chart values.
|
|
71
|
+
* @return The {@link UseObservableValues} held in the React context.
|
|
72
|
+
*/
|
|
73
|
+
export declare function useDataObservable<CD extends ChartData, D>(): UseObservableValues<CD, D>;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { concat, from } from "rxjs";
|
|
4
|
+
import { useInitialData } from "./useInitialData";
|
|
5
|
+
// import {noop} from "../utils";
|
|
6
|
+
/**
|
|
7
|
+
* No operation function for use when a default function is needed
|
|
8
|
+
*/
|
|
9
|
+
const noop = () => {
|
|
10
|
+
/* empty on purpose */
|
|
11
|
+
};
|
|
12
|
+
const defaultObservableValues = {
|
|
13
|
+
windowingTime: NaN,
|
|
14
|
+
shouldSubscribe: false,
|
|
15
|
+
// user callbacks
|
|
16
|
+
onSubscribe: noop,
|
|
17
|
+
};
|
|
18
|
+
const DataObservableContext = createContext(defaultObservableValues);
|
|
19
|
+
/**
|
|
20
|
+
* The react context provider for the {@link UseObservableValues}
|
|
21
|
+
* @param props The properties
|
|
22
|
+
* @return The children wrapped in this provider
|
|
23
|
+
* @constructor
|
|
24
|
+
*/
|
|
25
|
+
export default function DataObservableProvider(props) {
|
|
26
|
+
const { seriesObservable, windowingTime = defaultObservableValues.windowingTime || 100, shouldSubscribe, onSubscribe = noop, onUpdateData = noop, onUpdateChartTime = noop, } = props;
|
|
27
|
+
// when initial data is provided, and importantly, when a function is provided that converts
|
|
28
|
+
// the initial data into an object of type ChartData, and when there is a defined series
|
|
29
|
+
// observable, then the initial data is prepended to the data observable.
|
|
30
|
+
const { initialData, asChartData } = useInitialData();
|
|
31
|
+
const observable = dataObservable(seriesObservable, initialData, asChartData);
|
|
32
|
+
return _jsx(DataObservableContext.Provider, { value: {
|
|
33
|
+
seriesObservable: observable,
|
|
34
|
+
windowingTime,
|
|
35
|
+
shouldSubscribe,
|
|
36
|
+
onSubscribe,
|
|
37
|
+
onUpdateData,
|
|
38
|
+
onUpdateChartTime,
|
|
39
|
+
}, children: props.children });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* When initial data is provided, and importantly, when a function is provided that converts
|
|
43
|
+
* the initial data into an object of type ChartData, and when there is a defined series
|
|
44
|
+
* observable, then the initial data is prepended to the data observable. When only initial data
|
|
45
|
+
* is provided and a conversion function, then a creates an observable from the initial data.
|
|
46
|
+
* And, when only a defined series observable is specified, then that is used (this is the default,
|
|
47
|
+
* and backward compatible behavior).
|
|
48
|
+
* @param seriesObservable An optional series observable
|
|
49
|
+
* @param initialData An array of initial data series
|
|
50
|
+
* @param asChartData A function that converts the initial data series into chart data
|
|
51
|
+
* @return An {@link Observable} of {@link ChartData}, or an `undefined`
|
|
52
|
+
*/
|
|
53
|
+
function dataObservable(seriesObservable, initialData, asChartData) {
|
|
54
|
+
if (seriesObservable !== undefined && initialData !== undefined && initialData.length > 0 && asChartData !== undefined) {
|
|
55
|
+
return concat(from([asChartData(initialData)]), seriesObservable);
|
|
56
|
+
}
|
|
57
|
+
else if (initialData !== undefined && initialData.length > 0 && asChartData !== undefined) {
|
|
58
|
+
return from([asChartData(initialData)]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return seriesObservable;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* React hook that sets up the React context for the chart values.
|
|
66
|
+
* @return The {@link UseObservableValues} held in the React context.
|
|
67
|
+
*/
|
|
68
|
+
export function useDataObservable() {
|
|
69
|
+
const context = useContext(DataObservableContext);
|
|
70
|
+
const { onSubscribe } = context;
|
|
71
|
+
if (onSubscribe === undefined) {
|
|
72
|
+
throw new Error("useDataObservable can only be used when the parent is a <DataObservableProvider/>");
|
|
73
|
+
}
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=useDataObservable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDataObservable.js","sourceRoot":"","sources":["../../../../../src/app/charts/hooks/useDataObservable.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAO,UAAU,EAAC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAC,MAAM,EAAE,IAAI,EAA2B,MAAM,MAAM,CAAC;AAE5D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,iCAAiC;AAEjC;;GAEG;AACH,MAAM,IAAI,GAAG,GAAG,EAAE;IACd,sBAAsB;AAC1B,CAAC,CAAA;AAkDD,MAAM,uBAAuB,GAAkC;IAC3D,aAAa,EAAE,GAAG;IAClB,eAAe,EAAE,KAAK;IAEtB,iBAAiB;IACjB,WAAW,EAAE,IAAI;CACpB,CAAA;AAED,MAAM,qBAAqB,GAAG,aAAa,CAAgC,uBAAuB,CAAC,CAAA;AA4BnG;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAA0B,KAAmB;IAEvF,MAAM,EACF,gBAAgB,EAChB,aAAa,GAAG,uBAAuB,CAAC,aAAa,IAAI,GAAG,EAC5D,eAAe,EAEf,WAAW,GAAG,IAAI,EAClB,YAAY,GAAG,IAAI,EACnB,iBAAiB,GAAG,IAAI,GAC3B,GAAG,KAAK,CAAA;IAET,4FAA4F;IAC5F,wFAAwF;IACxF,yEAAyE;IACzE,MAAM,EAAC,WAAW,EAAE,WAAW,EAAC,GAAG,cAAc,EAAS,CAAA;IAC1D,MAAM,UAAU,GAAG,cAAc,CAAQ,gBAAgB,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;IAEpF,OAAO,KAAC,qBAAqB,CAAC,QAAQ,IAClC,KAAK,EAAE;YACH,gBAAgB,EAAE,UAAU;YAC5B,aAAa;YACb,eAAe;YAEf,WAAW;YACX,YAAY;YACZ,iBAAiB;SACpB,YAEA,KAAK,CAAC,QAAQ,GACc,CAAA;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,cAAc,CACnB,gBAAiC,EACjC,WAAkC,EAClC,WAAsD;IAEtD,IAAI,gBAAgB,KAAK,SAAS,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACrH,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;IACrE,CAAC;SAAM,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC1F,OAAO,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACJ,OAAO,gBAAgB,CAAA;IAC3B,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC7B,MAAM,OAAO,GAAG,UAAU,CAA6B,qBAAqB,CAAC,CAAA;IAC7E,MAAM,EAAC,WAAW,EAAC,GAAG,OAAO,CAAA;IAC7B,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAA;IACxG,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
|