@windborne/grapher 1.0.24 → 1.0.25

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +180 -263
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windborne/grapher",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Graphing library",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/bundle.esm.js",
package/readme.md CHANGED
@@ -1,19 +1,23 @@
1
1
 
2
2
  # WindBorne Grapher
3
+
4
+ [![npm version](https://img.shields.io/npm/v/@windborne/grapher.svg)](https://www.npmjs.com/package/@windborne/grapher)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@windborne/grapher.svg)](https://www.npmjs.com/package/@windborne/grapher)
6
+
3
7
  Powerful, performant graphing.
4
8
 
5
- Grapher is designed primarily for internal infrastructure with lots of data and lots of axes.
9
+ **Grapher** is designed primarily for internal infrastructure with lots of data and lots of axes.
6
10
  Key features include:
7
- - Performance. Grapher can render a million points in 100ms and support new data coming in at hundreds of points per second without degraded performance.
8
- - Async data sources. Grapher supports observables directly as well as generator functions to generate data on the fly
9
- - Axis management. Series can be moved between axes and new axes created with ease.
10
- - Long data ranges.
11
+ - *Performance*. Grapher can render a million points in 100ms and support new data coming in at hundreds of points per second without degraded performance.
12
+ - *Async data sources*. Grapher supports observables directly as well as generator functions to generate data on the fly
13
+ - *Axis management*. Series can be moved between axes and new axes created with ease.
14
+ - *Long data ranges*.
11
15
 
12
16
  You _shouldn't_ use this package if:
13
- - You need to support older browsers. While it may work in older browsers, no guarantees are made.
17
+ - *You need to support older browsers*. While it may work in older browsers, no guarantees are made.
14
18
  New features will be used as they become available without regard for maintaining legacy support.
15
- - You don't want to add a react dependency (though the rendering engine may be used without react).
16
- - Asset size is a big concern. Despite not having dependencies, this is a relatively heavy engine compared to alternatives.
19
+ - *You don't want to add a react dependency* (though the rendering engine may be used without react).
20
+ - *Asset size is a big concern*. Despite not having dependencies, this is a relatively heavy engine compared to alternatives.
17
21
 
18
22
  ## As a developer importing this package
19
23
 
@@ -48,63 +52,12 @@ You can find a full list in the package.json devDependencies, but they can be su
48
52
 
49
53
  # Grapher Component
50
54
 
51
- ## Props
52
- Like any React component, Grapher is primarily configured via props.
53
- Refer to the Grapher PropTypes for complete type information.
54
-
55
- ### Core Props
56
-
57
- **series** (required)
58
- This sets the data for the graph and is the only property that is truly required.
59
- See "Series" section for more details.
60
-
61
- **webgl**
62
- If true, will render with WebGL rather than a 2D context.
63
- This is more performant, but uses more resources.
64
-
65
- **requireWASM**
66
- If true, will wait until the WASM extensions are ready before it renders.
67
- This can be useful when your app has expensive initialization.
68
-
69
- ### Series Format
70
- The `series` prop requires an array of objects, where each object represents a data series with the following properties:
71
-
72
- - **data** (required): The actual data points (see Data Formats below)
73
- - **type**: Data type or 'infer' to automatically detect
74
- - **xKey**: Property name for x-values when using object data
75
- - **yKey**: Property name for y-values when using object data
76
- - **xUnixDates**: Whether x-values are Unix timestamps (boolean)
77
- - **color**: Series color (string or number)
78
- - **name**: Series name for display in legend
79
- - **xLabel**: Label for x-axis
80
- - **yLabel**: Label for y-axis
81
- - **rendering**: Visual representation ('line', 'bar', 'area', or 'shadow', defaults to 'line'). The 'shadow' option creates an area chart with individual point-based (trapezoid) gradients extending downward.
82
- - **ignoreDiscontinuities**: Whether to connect points across gaps (boolean)
83
- - **dashed**: Whether to use dashed lines (boolean)
84
- - **dashPattern**: Array defining dash pattern (array of numbers)
85
- - **width**: Line width (number)
86
- - **axis**: Axis specification for the series (string or object)
87
- - **rangeSelectorWidth**: Width of the range selector for this series (number)
88
- - **expandYWith**: Values to include when calculating y-axis range (array of numbers)
89
- - **defaultAlwaysTooltipped**: Whether to always show tooltip for this series (boolean)
90
- - **square**: Whether to render the series with square points (boolean)
91
- - **shiftXBy**: Value to shift x-coordinates by (number)
92
- - **graph**: Affects which graph this series belongs to in multigrapher (number)
93
- - **background**: Background configuration (object)
94
- - **hideFromKey**: Whether to hide this series from the legend (boolean)
95
- - **showIndividualPoints**: Whether to show individual data points (boolean)
96
- - **negativeColor**: Color for negative values
97
- - **gradient**: Gradient configuration, only applies to area rendering (array)
98
- - **zeroLineWidth**: Width of the zero line, only applies to bar and area rendering (number)
99
- - **zeroLineColor**: Color of the zero line, only applies to bar and area rendering (string)
100
- - **zeroLineY**: Y-coordinate of the zero line, only applies to bar and area rendering (number or "bottom"). Defaults to zero; may also be the string "bottom".
101
- - **pointRadius**: Radius of points, only applies to area rendering (number)
102
- - **tooltipWidth**: Expected width of the tooltip (number). Will make the tooltip switch sides when this width plus the tooltip left position is greater than the graph width.
103
- - **hasAreaBottom**: read the bottom of the area from data (boolean). By default, the bottom of an area will just be zero; this allows changing that via passing in `[[x1, bottom], [x1, top], [x2, bottom], [x2, top]]` to data (see [examples/dynamic_bottom_area_chart.js](examples/dynamic_bottom_area_chart.js)).
104
- - **shadowColor**: color of the shadow (string)
105
- - **rangeKey**: if provided, will draw range bars (string). The range value should be of shape `{min: number, max: number}`. Not compatible with webgl.
106
-
107
- #### Series Data Formats
55
+ ### Props
56
+
57
+ Like any other React component, Grapher is primarily configured via props. Refer to the [GrapherProps](#grapherprops) schema for complete type information.
58
+
59
+ ### Series Data Formats
60
+
108
61
  Grapher supports multiple data formats within a series:
109
62
 
110
63
  1. **Array of y-values**: Simple array where index is used as x-value
@@ -113,204 +66,168 @@ Grapher supports multiple data formats within a series:
113
66
  4. **Observable**: Object with an observe method, which may emit tuples or objects
114
67
  5. **Generator function**: Function that generates an array data points as a function of zoom
115
68
 
116
- ### Event Handlers
117
-
118
- **onAxisChange**
119
- If passed in, this function will be called every time the axes change.
120
- It will be called with an array of objects, where each object is a single series object with the `axis`
121
- property set to {left, right}-{index}. This can be useful for saving state between reloads.
122
-
123
- **onRenderTime**
124
- If passed in, this function will be called every time the grapher renders.
125
- It will be called with diagnostic information about how long rendering took.
126
-
127
- **onPointDrag**
128
- Callback function that fires when draggable points are moved.
129
-
130
- **onDraggablePointsDoubleClick**
131
- Callback function that fires when draggable points are double-clicked.
132
-
133
- **timingFrameCount**
134
- Sets the number of frames for when the state controller's `averageLoopTime` method is called.
135
-
136
- ### Appearance
137
-
138
- **theme**
139
- Sets the theme of grapher to either 'day', 'night', or 'export'.
140
- You can also override any CSS property directly in a stylesheet.
141
-
142
- **title**
143
- Sets the title text for the graph.
144
-
145
- **fullscreen**
146
- If true, displays the graph in fullscreen mode.
147
-
148
- **bodyHeight**
149
- Sets the height of the graph body (i.e., excluding range graph, series controls, etc.).
150
-
151
- **height**
152
- Sets the height of the entire graph.
153
-
154
- **width**
155
- Sets the width of the graph.
156
-
157
- ### Display Options
158
-
159
- **showAxes**
160
- Whether to show the axes on the graph.
161
-
162
- **showRangeGraph**
163
- Whether to show the smaller range graph below the main graph.
164
-
165
- **showRangeSelectors**
166
- Whether to show the top bar with range selection (e.g., "last day" button) and other options.
167
-
168
- **showSeriesKey**
169
- Whether to show the key of which series have which colors.
170
-
171
- **showTooltips**
172
- Whether to display tooltips when hovering over data points.
173
-
174
- **showGrid**
175
- Whether to show grid lines on the graph.
176
-
177
- **showAxisColors**
178
- Whether to color-code axes based on the series they represent.
179
-
180
- **bigLabels**
181
- If true, uses larger text for labels.
182
-
183
- **xTickUnit**
184
- Specifies the unit for x-axis ticks. Currently supports 'year'.
185
-
186
- **xAxisIntegersOnly**
187
- If true, only displays integer values on the x-axis.
188
-
189
- **formatXAxisLabel**
190
- A custom function to format the x-axis labels. This function should take a single argument (the raw x-value) and return a string to display as the label.
191
-
192
- **clockStyle**
193
- Format for displaying time, either '12h' or '24h'.
194
-
195
- **timeZone**
196
- Time zone for date/time display. Can be 'local', 'utc', or a full timezone string.
197
-
198
- **markRangeGraphDates**
199
- Whether to mark significant dates on the range graph.
200
-
201
- **tooltipOptions**
202
- Configures tooltip appearance and behavior with properties including:
203
- - `includeSeriesLabel`: Whether to show series name in tooltip
204
- - `includeXLabel`: Whether to show x-axis label in tooltip
205
- - `includeYLabel`: Whether to show y-axis label in tooltip
206
- - `includeXValue`: Whether to show x-axis value in tooltip
207
- - `includeYValue`: Whether to show y-axis value in tooltip
208
- - `floating`: Whether tooltip floats or is fixed position
209
- - `alwaysFixedPosition`: Forces tooltip to always use fixed position
210
- - `floatPosition`: Placement of floating tooltip ('top' or 'bottom')
211
- - `floatDelta`: Pixel offset for floating tooltip positioning
212
- - `savingDisabled`: Prevents tooltip settings from being saved
213
- - `customTooltip`: A react component to use as a custom tooltip. See [examples/custom_tooltips_graph.js](examples/custom_tooltips_graph.js) for an example. If used in conjunction with `combineTooltips`, see [examples/combined_tooltips_graph.js](examples/combined_tooltips_graph.js)
214
- - `combineTooltips`: If true, combines multiple tooltips into one when multiple series are shown. Can alternatively be set to a threshold in pixels for how close values need to be in order to be combined.
215
-
216
- **customBoundsSelectors**
217
- Array of custom range selector objects with properties:
218
- - `label`: Display text for the selector
219
- - `calculator`: Function that determines the bounds
220
- - `datesOnly`: If true, only works with date values
221
-
222
- **customBoundsSelectorsOnly**
223
- If true, only displays custom bounds selectors.
224
-
225
- **defaultBoundsCalculator**
226
- String identifier for the default bounds calculator to use.
227
-
228
- **defaultShowOptions**
229
- Default visibility of the options panel.
230
-
231
- **defaultShowIndividualPoints**
232
- Default setting for showing individual data points.
233
-
234
- **defaultShowSidebar**
235
- Default visibility of the sidebar.
236
-
237
- **defaultShowAnnotations**
238
- Default visibility of annotations.
239
-
240
- **defaultLineWidth**
241
- Default width of the lines in the graph.
242
-
243
- **boundsSelectionEnabled**
244
- Whether to enable the bounds selection feature.
245
-
246
- **sidebarEnabled**
247
- Whether to enable the sidebar.
248
-
249
- **percentile**
250
- Sets the percentile value for calculations.
251
-
252
-
253
- ### Advanced Features
254
-
255
- **tooltipOptions**
256
- Configures tooltip appearance and behavior with properties including:
257
- - `includeSeriesLabel`: Whether to show series name in tooltip
258
- - `includeXLabel`: Whether to show x-axis label in tooltip
259
- - `includeYLabel`: Whether to show y-axis label in tooltip
260
- - `includeXValue`: Whether to show x-axis value in tooltip
261
- - `includeYValue`: Whether to show y-axis value in tooltip
262
- - `floating`: Whether tooltip floats or is fixed position
263
- - `alwaysFixedPosition`: Forces tooltip to always use fixed position
264
- - `floatPosition`: Placement of floating tooltip ('top' or 'bottom')
265
- - `floatDelta`: Pixel offset for floating tooltip positioning
266
- - `savingDisabled`: Prevents tooltip settings from being saved
267
-
268
- **customBoundsSelectors**
269
- Array of custom range selector objects with properties:
270
- - `label`: Display text for the selector
271
- - `calculator`: Function that determines the bounds
272
- - `datesOnly`: If true, only works with date values
273
-
274
- **customBoundsSelectorsOnly**
275
- If true, only displays custom bounds selectors.
276
-
277
- **defaultBoundsCalculator**
278
- String identifier for the default bounds calculator to use.
279
-
280
- **annotations**
281
- Array of annotation objects to display on the graph with properties:
282
- - `x`: Position on x-axis (string, number, or Date) where annotation should appear
283
- - `xEnd`: Optional end position for range annotations
284
- - `series`: Optional array of series names the annotation applies to
285
- - `content`: Text content of the annotation
286
-
287
- **draggablePoints**
288
- Array of interactive point objects with properties:
289
- - `x`: X-coordinate position
290
- - `y`: Y-coordinate position
291
- - `radius`: Optional size of the point
292
- - `fillColor`: Optional interior color
293
- - `strokeColor`: Optional outline color
294
- - `strokeWidth`: Optional outline width
295
- - `onClick`: Optional click handler function
296
- - `onDoubleClick`: Optional double-click handler function
297
-
298
- **verticalLines**
299
- Array of vertical line objects to display on the graph with properties:
300
- - `x`: X-coordinate position where the line should appear
301
- - `color`: Optional line color
302
- - `width`: Optional line width
303
- - `markTop`: Whether to add a marker at the top of the line
304
- - `style`: Optional styling object for the line
305
- - `markerStyle`: Optional styling object for the marker
306
- - `lineTop`: Optional value to specify the top position of the line
307
- - `text`: Optional text to display alongside the line
308
- - `textTop`: Optional value to specify the vertical position of the text
309
- - `textStyle`: Optional styling object for the text
310
- - `minPixelX`: Optional number. If the x position of the line in pixels is less than this value, the line will be hidden
311
- - `maxPixelX`: Optional number. If the x position of the line in pixels is greater than this value, the line will be hidden
312
- - `onRangeGraph`: If true, will show the line on the range graph as well. This may also be an object with any of the above options to adjust the styling
313
- - `onRangeGraphOnly`: If true, the vertical line will only appear on the range graph and not the primary graph
69
+ ### <a id="grapherprops"></a>Schema `GrapherProps`
70
+
71
+ | Prop | Type | Required |
72
+ |------|------|----------|
73
+ | **series** | [SeriesData](#seriesdata)`[]` | **✓** |
74
+ | id | `string` | |
75
+ | webgl | `boolean` | ✗ |
76
+ | requireWASM | `boolean` | ✗ |
77
+ | checkIntersection | `boolean` | |
78
+ | onAxisChange | `(axes: any) => void` | |
79
+ | onRenderTime | `(time: number) => void` | ✗ |
80
+ | exportStateController | `(controller: any) => void` | ✗ |
81
+ | onPointDrag | `(point: any) => void` | ✗ |
82
+ | onDraggablePointsDoubleClick | `(point: any) => void` | ✗ |
83
+ | onPointClick | `(point: any) => void` | ✗ |
84
+ | timingFrameCount | `number` | |
85
+ | stateControllerInitialization | `object` | ✗ |
86
+ | syncPool | `SyncPool` | ✗ |
87
+ | dragPositionYOffset | `number` | |
88
+ | theme | `'day' \| 'night' \| 'export'` | ✗ |
89
+ | title | `string` | ✗ |
90
+ | fullscreen | `boolean` | ✗ |
91
+ | bodyHeight | `number` | ✗ |
92
+ | height | `number \| string` | |
93
+ | width | `number \| string` | |
94
+ | showAxes | `boolean` | ✗ |
95
+ | showRangeGraph | `boolean` | ✗ |
96
+ | showRangeSelectors | `boolean` | |
97
+ | showSeriesKey | `boolean` | ✗ |
98
+ | showTooltips | `boolean` | ✗ |
99
+ | showGrid | `boolean` | |
100
+ | showAxisColors | `boolean` | ✗ |
101
+ | bigLabels | `boolean` | ✗ |
102
+ | xTickUnit | `'year'` | |
103
+ | formatXAxisLabel | `(value: any) => string` | ✗ |
104
+ | xAxisIntegersOnly | `boolean` | ✗ |
105
+ | clockStyle | `'12h' \| '24h'` | ✗ |
106
+ | timeZone | `string` | ✗ |
107
+ | markRangeGraphDates | `boolean` | ✗ |
108
+ | boundsSelectionEnabled | `boolean` | ✗ |
109
+ | customBoundsSelectors | [CustomBoundsSelector](#customboundsselector)`[]` | ✗ |
110
+ | customBoundsSelectorsOnly | `boolean` | ✗ |
111
+ | sidebarEnabled | `boolean` | ✗ |
112
+ | defaultBoundsCalculator | `string` | ✗ |
113
+ | percentile | `number` | |
114
+ | defaultShowAnnotations | `boolean` | ✗ |
115
+ | defaultShowOptions | `boolean` | ✗ |
116
+ | defaultShowIndividualPoints | `boolean` | |
117
+ | defaultShowSidebar | `boolean` | ✗ |
118
+ | defaultLineWidth | `number` | ✗ |
119
+ | tooltipOptions | [TooltipOptions](#tooltipoptions) | |
120
+ | annotations | [Annotation](#annotation)`[]` | ✗ |
121
+ | draggablePoints | [DraggablePoint](#draggablepoint)`[]` | ✗ |
122
+ | verticalLines | [VerticalLine](#verticalline)`[]` | |
123
+
124
+ ### <a id="seriesdata"></a>Schema `SeriesData`
125
+
126
+ | Prop | Type | Required |
127
+ |------|------|----------|
128
+ | **data** | `any[] \| Observable \| Function` | **✓** |
129
+ | type | `'values' \| 'tuples' \| 'objects' \| 'tuple_observable' \| 'object_observable' \| 'infer'` | ✗ |
130
+ | xKey | `string` | ✗ |
131
+ | yKey | `string` | |
132
+ | xUnixDates | `boolean` | ✗ |
133
+ | color | `string \| number` | ✗ |
134
+ | name | `string` | |
135
+ | xLabel | `string` | ✗ |
136
+ | yLabel | `string` | ✗ |
137
+ | rendering | `'line' \| 'bar' \| 'area' \| 'shadow'` | ✗ |
138
+ | ignoreDiscontinuities | `boolean` | ✗ |
139
+ | dashed | `boolean` | ✗ |
140
+ | dashPattern | `number[]` | |
141
+ | width | `number` | ✗ |
142
+ | axis | `string \| object` | ✗ |
143
+ | rangeSelectorWidth | `number` | |
144
+ | expandYWith | `number[]` | ✗ |
145
+ | defaultAlwaysTooltipped | `boolean` | ✗ |
146
+ | square | `boolean` | |
147
+ | shiftXBy | `number` | ✗ |
148
+ | graph | `number` | ✗ |
149
+ | background | `object` | |
150
+ | hideFromKey | `boolean` | ✗ |
151
+ | showIndividualPoints | `boolean` | ✗ |
152
+ | negativeColor | `string` | |
153
+ | gradient | `string[] \| [number, string][]` | ✗ |
154
+ | zeroLineWidth | `number` | ✗ |
155
+ | zeroLineColor | `string` | |
156
+ | zeroLineY | `number \| 'bottom'` | |
157
+ | pointRadius | `number` | |
158
+ | tooltipWidth | `number` | |
159
+ | hasAreaBottom | `boolean` | |
160
+ | shadowColor | `string` | |
161
+ | rangeKey | `string` | |
162
+ | cutoffTime | `number \| Date \| 'now'` | |
163
+
164
+ ### <a id="tooltipoptions"></a>Schema `TooltipOptions`
165
+
166
+ | Prop | Type | Required |
167
+ |------|------|----------|
168
+ | includeSeriesLabel | `boolean` | ✗ |
169
+ | includeXLabel | `boolean` | ✗ |
170
+ | includeYLabel | `boolean` | |
171
+ | includeXValue | `boolean` | |
172
+ | includeYValue | `boolean` | |
173
+ | floating | `boolean` | |
174
+ | alwaysFixedPosition | `boolean` | ✗ |
175
+ | floatPosition | `'top' \| 'bottom'` | ✗ |
176
+ | floatDelta | `number` | |
177
+ | savingDisabled | `boolean` | ✗ |
178
+ | customTooltip | `React.ComponentType<any>` | ✗ |
179
+ | combineTooltips | `boolean \| number` | |
180
+
181
+ ### <a id="customboundsselector"></a>Schema `CustomBoundsSelector`
182
+
183
+ | Prop | Type | Required |
184
+ |------|------|----------|
185
+ | **label** | `string` | **✓** |
186
+ | **calculator** | `(globalBounds?: any) => any` | **✓** |
187
+ | datesOnly | `boolean` | ✗ |
188
+
189
+ ### <a id="annotation"></a>Schema `Annotation`
190
+
191
+ | Prop | Type | Required |
192
+ |------|------|----------|
193
+ | x | `string \| number \| Date` | ✗ |
194
+ | startX | `string \| number \| Date` | ✗ |
195
+ | endX | `string \| number \| Date` | ✗ |
196
+ | series | `string[]` | ✗ |
197
+ | content | `string` | |
198
+ | lineOnly | `boolean` | ✗ |
199
+
200
+ ### <a id="draggablepoint"></a>Schema `DraggablePoint`
201
+
202
+ | Prop | Type | Required |
203
+ |------|------|----------|
204
+ | **x** | `number` | **✓** |
205
+ | **y** | `number` | **✓** |
206
+ | radius | `number` | ✗ |
207
+ | fillColor | `string` | ✗ |
208
+ | strokeColor | `string` | ✗ |
209
+ | strokeWidth | `number` | |
210
+ | onClick | `(point: `[DraggablePoint](#draggablepoint)`) => void` | |
211
+ | onDoubleClick | `(point: `[DraggablePoint](#draggablepoint)`) => void` | |
212
+
213
+ ### <a id="verticalline"></a>Schema `VerticalLine`
214
+
215
+ | Prop | Type | Required |
216
+ |------|------|----------|
217
+ | **x** | `number` | **✓** |
218
+ | color | `string` | |
219
+ | lineTop | `number` | |
220
+ | width | `number` | ✗ |
221
+ | markTop | `boolean` | ✗ |
222
+ | style | `object` | |
223
+ | markerStyle | `object` | |
224
+ | text | `string` | |
225
+ | textTop | `number` | |
226
+ | textStyle | `object` | ✗ |
227
+ | minPixelX | `number` | ✗ |
228
+ | maxPixelX | `number` | |
229
+ | onRangeGraph | `boolean \| object` | ✗ |
230
+ | onRangeGraphOnly | `boolean` | ✗ |
314
231
 
315
232
  ## Developing
316
233
  Other than an `npm install`, you'll need to install rust and [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/).