Skip to content

Commit bc6b53d

Browse files
committed
docs
1 parent 68e6b5e commit bc6b53d

File tree

2 files changed

+112
-5
lines changed

2 files changed

+112
-5
lines changed

README.md

+108
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,114 @@ The scatter plot shown below has 30 time-series of test data, with two time axes
230230

231231
## usage
232232

233+
The `stream-charts` module wraps [d3](http://d3js.org) elements with functional [react](http://reactjs.org) in a way that keeps the chart (d3) updates out of the react render cycle. All `stream-charts` start with the [`<Chart/>`](./src/app/charts/Chart.tsx) root element.
234+
235+
### `<Chart/>`
236+
237+
The `Chart` component creates the main SVG element (container) holding the chart, manages a reference to that container, and is the wraps the children in the chart context provider so that they have access to the [useChart](./src/app/charts/hooks/useChart.tsx) hook which holds properties, styles, callbacks, subscription needed to construct the charts and make them interactive.
238+
239+
The `Chart`s properties fall into four categories:
240+
1. container dimensions
241+
2. chart style
242+
3. initial (static data)
243+
4. streamed data and how to manage the stream of data
244+
245+
#### Chart dimensions
246+
> **width (pixels)**<br>
247+
> The width (in pixels) of the container that holds the chart. The actual plot will be smaller based on the margins.
248+
249+
> **height (pixels)**<br>
250+
> The height (in pixels) of the container that holds the chart. The actual plot will be smaller based on the margins.
251+
252+
#### Chart styling
253+
> **margin ([Margin](./src/app/charts/margins.ts), optional)**
254+
> The margin (in pixels) around plot. For example, if the container has a (h, w) = (300, 600) and a margin of 10 pixels for the top, left, right, bottom, then the actual plot will have a (h, w) = (290, 590), leaving only 10 pixels around the plot for axis titles, ticks, and axis labels.
255+
>
256+
> The Margin has the following shape
257+
>```typescript
258+
>interface Margin {
259+
> top: number
260+
> bottom: number
261+
> left: number
262+
> right: number
263+
>}
264+
>```
265+
266+
267+
> **color (string, optional)**<br>
268+
> The color of the axis lines and text, which can be overridden specifically by the axes styles.
269+
270+
> **backgroundColor (string, optional)**<br>
271+
> The color of the chart background (the whole chart, not just the plot).
272+
273+
> **svgStyle ([SvgStyle](./src/app/charts/svgStyle.ts), optional)**<br>
274+
> The style attributes for the main SVG element, in case you want to change those. Generally, this is not needed.
275+
>
276+
> The SvgStyle has the following shape
277+
>```typescript
278+
>interface SvgStyle {
279+
> height?: string | number
280+
> width?: string | number
281+
> outline?: string
282+
> // any valid SVG CSS attribute
283+
> [propName: string]: any
284+
>}
285+
>```
286+
287+
> **seriesStyles (Map<string, [SeriesLineStyle](./src/app/charts/axes.ts)>, optional)**<br>
288+
> A map holding the data series name with an associated SeriesLineStyle. Any series listed in this map will use the associated styles for that series. Any series not in the map will use the default series styles.
289+
>
290+
> The SeriesLineStyle has the following shape
291+
> ```typescript
292+
> interface SeriesLineStyle {
293+
> color: string
294+
> lineWidth: number
295+
> // the color of the series when the user mouses over the series
296+
> highlightColor: string
297+
> // the line width of the series when the user mouses over the series
298+
> highlightWidth: number
299+
> // the line margin used for raster charts
300+
> margin?: number
301+
> }
302+
>```
303+
304+
#### Chart initial data
305+
306+
Holds the initial (static data). This data is displayed in the chart even before subscribing to the chart-data observable. The initial data can be used to generate static charts.
307+
308+
> **initialData (Array<[Series](./src/app/charts/datumSeries.ts)>)**<br>
309+
> An array holding the initial data series to be plotted before subscribing to the chart-data observable.
310+
>
311+
> The Series has the following shape
312+
> ```typescript
313+
> interface Series {
314+
> // the series name
315+
> readonly name: string;
316+
> // the array of time-value pairs
317+
> data: Array<Datum>;
318+
> // ... accessor functions
319+
> .
320+
> .
321+
> .
322+
> }
323+
>
324+
>```
325+
> And the [Datum](./src/app/charts/datumSeries.ts) has the following shape
326+
> ```typescript
327+
> interface Datum {
328+
> readonly time: number;
329+
> readonly value: number;
330+
> }
331+
>```
332+
> Please note that there are a number of helper functions for creating `Series` and `Datum`.
333+
>
334+
335+
todo list the factory functions
336+
337+
initialData: Array<Series>
338+
seriesFilter?: RegExp
339+
340+
233341
### properties
234342
235343
The [examples](https://github.com/robphilipp/stream-charts-examples) project has example code that was used to generate the charts in the images above. The [StreamingRasterChart](https://github.com/robphilipp/stream-charts-examples/blob/master/src/app/examples/StreamingRasterChart.tsx) provides an example of using the raster chart. The [StreamingScatterChart](https://github.com/robphilipp/stream-charts-examples/blob/master/src/app/examples/StreamingScatterChart.tsx) provides an example of using the scatter chart. Both of these examples provide controls for enabling the filtering, tooltip, tracker, and magnifier enhancements.

src/app/charts/Chart.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ const defaultBackground = '#202020';
1717
interface Props {
1818
width: number
1919
height: number
20+
21+
// styling
2022
margin?: Partial<Margin>
21-
// axisLabelFont?: Partial<AxesLabelFont>
22-
// axisStyle?: Partial<CSSProperties>
2323
color?: string
2424
backgroundColor?: string
2525
svgStyle?: Partial<SvgStyle>
2626
seriesStyles?: Map<string, SeriesLineStyle>
2727

2828
// initial data
29-
// initialData: Map<string, Series>
3029
initialData: Array<Series>
3130
seriesFilter?: RegExp
3231

@@ -38,8 +37,8 @@ interface Props {
3837
onUpdateData?: (seriesName: string, data: Array<Datum>) => void
3938
onUpdateTime?: (time: number) => void
4039

41-
// regex filter used to select which series are displayed
42-
filter?: RegExp
40+
// // regex filter used to select which series are displayed
41+
// filter?: RegExp
4342

4443
children: JSX.Element | Array<JSX.Element>;
4544
}

0 commit comments

Comments
 (0)