Skip to content

Commit 987ed7b

Browse files
committed
[readme] remove enumeration of data-ui packages [xy-chart] update readme with onClick deets, add onClick support to <Voronoi />
1 parent f0973b2 commit 987ed7b

File tree

10 files changed

+34
-68
lines changed

10 files changed

+34
-68
lines changed

packages/data-table/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,3 @@ See the <a href="https://williaster.github.io/data-ui" target="_blank">@data-ui/
2424
npm install
2525
npm run dev # or 'npm run prod'
2626
```
27-
28-
## @data-ui packages
29-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/xy-chart" target="_blank">@data-ui/xy-chart</a>[![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)
30-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/histogram" target="_blank">@data-ui/histogram</a>[![Version](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)
31-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/radial-chart" target="_blank">@data-ui/radial-chart</a> [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
32-
- @data-ui/data-table [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
33-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-ui-theme" target="_blank">@data-ui/theme</a> [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
34-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/demo" target="_blank">@data-ui/demo</a>

packages/data-ui-theme/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,3 @@ This package exports theme variables that can be used by other packages. On the
66
```js
77
import { font, svgFont, label, size, color, chartTheme } from `@data-ui/theme`;
88
```
9-
10-
## @data-ui packages
11-
- [@data-ui/xy-chart](https://github.com/williaster/data-ui/tree/master/packages/xy-chart) [![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)
12-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/histogram" target="_blank">@data-ui/histogram</a> [![Version](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)
13-
- [@data-ui/radial-chart](https://github.com/williaster/data-ui/tree/master/packages/radial-chart) [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
14-
- [@data-ui/data-table](https://github.com/williaster/data-ui/tree/master/packages/data-table) [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
15-
- @data-ui/theme [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
16-
- [@data-ui/demo](https://github.com/williaster/data-ui/tree/master/packages/demo)

packages/demo/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
# @data-ui/demo
22
Storybook of @data-ui examples. See it live at [williaster.github.io/data-ui](https://williaster.github.io/data-ui).
3-
4-
## @data-ui packages
5-
- [@data-ui/xy-chart](https://github.com/williaster/data-ui/tree/master/packages/xy-chart) [![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat-square)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat-square)
6-
- [@data-ui/radial-chart](https://github.com/williaster/data-ui/tree/master/packages/radial-chart) [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat-square)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat-square)
7-
- [@data-ui/data-table](https://github.com/williaster/data-ui/tree/master/packages/data-table) [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat-square)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat-square)
8-
- [@data-ui/theme](https://github.com/williaster/data-ui/tree/master/packages/theme)
9-
- @data-ui/demo

packages/histogram/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,3 @@ export const themeShape = PropTypes.shape({
225225
npm install
226226
npm run dev # or 'build'
227227
```
228-
229-
## @data-ui packages
230-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/xy-chart" target="_blank">@data-ui/xy-chart</a> [![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)
231-
- @data-ui/histogram [![Version](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)
232-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/radial-chart" target="_blank">@data-ui/radial-chart</a> [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
233-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-table" target="_blank">@data-ui/data-table</a> [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
234-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-ui-theme" target="_blank">@data-ui/theme</a> [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
235-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/demo" target="_blank">@data-ui/demo</a>

packages/network/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,3 @@ Tooltips are controlled with the `renderTooltip` function passed to `<Network />
1717
### Roadmap
1818
- more layout algorithms
1919
- dragging interaction enabled
20-
21-
22-
## @data-ui packages
23-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/xy-chart" target="_blank">@data-ui/xy-chart</a>[![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)
24-
- @data-ui/radial-chart [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
25-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-table" target="_blank">@data-ui/data-table</a> [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
26-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-ui-theme" target="_blank">@data-ui/theme</a> [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
27-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/demo" target="_blank">@data-ui/demo</a>

packages/radial-chart/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,3 @@ Note that currently this is implemented with `@vx/tooltips`'s `withTooltip` HOC,
8787

8888
### NOTE ‼️
8989
Although pie 🍰 and donut 🍩 charts are frequently encountered, they are not the most _effective_ visualization for conveying quantitative information. With that caveat, when used well they can effectively give an overview of population makeup which is an entirely reasonable use of these charts. We don't recommend using >7 slices for user readability.
90-
91-
92-
## @data-ui packages
93-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/xy-chart" target="_blank">@data-ui/xy-chart</a>[![Version](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/xy-chart.svg?style=flat)
94-
- @data-ui/radial-chart [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
95-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-table" target="_blank">@data-ui/data-table</a> [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
96-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-ui-theme" target="_blank">@data-ui/theme</a> [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
97-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/demo" target="_blank">@data-ui/demo</a>

packages/xy-chart/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ width | PropTypes.number.isRequired | - | Required width of the chart (including
6464
height | PropTypes.number.isRequired | - | Required height of the chart (including margin). Check out `withParentSize` in the examples for responsive charts.
6565
margin | PropTypes.shape({ top: PropTypes.number, right: PropTypes.number, bottom: PropTypes.number, left: PropTypes.number }) | { top: 64, right: 64, bottom: 64, left: 64 } | chart margin, leave room for axes and labels! note 0 may clip LineSeries and PointSeries.
6666
renderTooltip | PropTypes.func | - | `({ data, datum, event, color }) => node`, should return the inner tooltip contents on trigger.
67+
onClick | PropTypes.func | - | `func({ data, datum, event, color [, seriesKey] })`, passed to all child series (or voronoi)
6768
onMouseMove | PropTypes.func | - | `func({ data, datum, event, color })`, passed to all child series (or voronoi). only needed if you are rolling your own tooltips (see below)
6869
onMouseLeave | PropTypes.func | - | `func()`, passed to all child series (or voronoi). only needed if you are rolling your own tooltips (see below)
6970
xScale | scaleShape.isRequired | - | scale config, see below.
@@ -165,6 +166,7 @@ Series | supported x scale type | supported y scale types | data shape | voronoi
165166
`<BarSeries/>` | time, linear, band | linear | `{ x, y [, fill, stroke] }` | no
166167
`<LineSeries/>` | time, linear | linear | `{ x, y [, stroke] }` | yes
167168
`<PointSeries/>` | time, linear | time, linear | `{ x, y [size, fill, stroke, label] }` | yes
169+
`<AreaSeries/>` | time, linear | linear | `{ x, y [, [stackKey(s)]] }`* | no
168170
`<StackedBarSeries/>` | band | linear | `{ x, y }` (colors controlled with stackFills & stackKeys) | no
169171
`<GroupedBarSeries/>` | band | linear | `{ x, y }` (colors controlled with groupFills & groupKeys) | no
170172
`<CirclePackSeries/>` | time, linear | y is computed | `{ x [, size] }` | no
@@ -174,7 +176,7 @@ Series | supported x scale type | supported y scale types | data shape | voronoi
174176
- defined `y0` and `y1` values or
175177
- a single `y` value, in which case its lower bound is set to 0 (a "closed" area series)
176178

177-
It is worth noting that voronoi overlays require a defined `y` attribute, so use of voronoi with only `y0` and `y1` values will not work.
179+
It is worth noting that voronoi overlays require a defined `y` attribute, so use of voronoi with only `y0` and `y1` values will not work.
178180

179181
#### CirclePackSeries
180182

@@ -187,14 +189,19 @@ This series implements the Circle packing algorithm described by <a href="https:
187189
Note that only `x` values are needed for `CirclePackSeries`, `y` values are computed based on `x` and `size` (if specified). Similar to `PointSeries`, `size`, `fill`, and `fillOpacity` may be set on datum themseleves or passed as props to the `CirclePackSeries` component.
188190

189191

190-
### Tooltips
191-
Tooltips are supported for all series types, but how you configure them will likely depend on which series combinations you're using and how much customization you need. The _easiest_ way to use tooltips out of the box is by passing a `renderTooltip` function to `<XYChart />` as shown in the above example. This function takes an object with the shape `{ event, datum, data, color }` as input and should return the inner contents of the tooltip (not the tooltip container!) as shown above.
192+
### Mouse events
193+
194+
#### Overview
195+
`XYChart` and all series support `onMouseMove({ data, datum, event, color [, seriesKey] })`, `onMouseLeave()`, and `onClick({ data, datum, event, color [, seriesKey] })` event handlers. `XYChart` will pass along event handlers to its child series unless a series has `disableMouseEvents` set to `true`, and any event handlers defined at the series level will override those defined at the `XYChart` level.
196+
197+
#### Tooltips
198+
Tooltips are supported for all series types, but how you configure them will likely depend on which series combinations you're using and how much customization you need. The _easiest_ way to use tooltips out of the box is by passing a `renderTooltip` function to `<XYChart />` as shown in the above example. This function takes an object with the shape `{ data, datum, event, color [, seriesKey] }` as input and should return the inner contents of the tooltip (not the tooltip container!) as shown above.
192199

193200
Under the covers this will wrap the `<XYChart />` component in the exported `<WithTooltip />` HOC, which wraps the `<svg />` in a `<div />` and handles the positioning and rendering of an HTML-based tooltip with the contents returned by `renderTooltip()`. This tooltip is aware of the bounds of its container and should position itself "smartly".
194201

195202
If you'd like more customizability over tooltip rendering you can do either of the following:
196203

197-
1) Roll your own tooltip positioning logic and pass `onMouseMove` and `onMouseLeave` functions to `XYChart`. These functions are passed to series-type children and are called with the signature `onMouseMove({ data, datum, event, color })` and `onMouseLeave()` upon appropriate trigger. Note that you must also pass `tooltipData` to `XYChart` if you are using the `CrossHair` component, which has an expected shape of `{ datum }` containing the datum to emphasize.
204+
1) Roll your own tooltip positioning logic and pass `onMouseMove` and `onMouseLeave` functions to `XYChart`. These functions are passed to series-type children and are called with the signature `onMouseMove({ data, datum, event, color [, seriesKey] })` and `onMouseLeave()` upon appropriate trigger. Note that you must also pass `tooltipData` to `XYChart` if you are using the `CrossHair` component, which has an expected shape of `{ datum }` containing the datum to emphasize.
198205

199206
2) Wrap `<XYChart />` with `<WithTooltip />` yourself, which accepts props for additional customization:
200207

@@ -254,11 +261,3 @@ These <a href="https://github.com/hshoff/vx/blob/master/" target="_blank">vx</a>
254261
npm install
255262
npm run dev # or 'build'
256263
```
257-
258-
## @data-ui packages
259-
- @data-ui/xy-chart
260-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/histogram" target="_blank">@data-ui/histogram</a> [![Version](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/histogram.svg?style=flat)
261-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/radial-chart" target="_blank">@data-ui/radial-chart</a> [![Version](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/radial-chart.svg?style=flat)
262-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-table" target="_blank">@data-ui/data-table</a> [![Version](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/data-table.svg?style=flat)
263-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/data-ui-theme" target="_blank">@data-ui/theme</a> [![Version](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)](https://img.shields.io/npm/v/@data-ui/theme.svg?style=flat)
264-
- <a href="https://github.com/williaster/data-ui/tree/master/packages/demo" target="_blank">@data-ui/demo</a>

packages/xy-chart/src/chart/Voronoi.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import VoronoiPolygon from '@vx/voronoi/build/components/VoronoiPolygon';
88

99
const propTypes = {
1010
data: PropTypes.array.isRequired,
11+
onClick: PropTypes.func,
1112
onMouseMove: PropTypes.func,
1213
onMouseLeave: PropTypes.func,
1314
showVoronoi: PropTypes.bool,
@@ -18,8 +19,9 @@ const propTypes = {
1819
};
1920

2021
const defaultProps = {
21-
onMouseMove: () => {},
22-
onMouseLeave: () => {},
22+
onClick: null,
23+
onMouseMove: null,
24+
onMouseLeave: null,
2325
showVoronoi: false,
2426
};
2527

@@ -43,7 +45,7 @@ class Voronoi extends React.PureComponent {
4345
}
4446

4547
render() {
46-
const { onMouseLeave, onMouseMove, showVoronoi } = this.props;
48+
const { onMouseLeave, onMouseMove, onClick, showVoronoi } = this.props;
4749
const { voronoi } = this.state;
4850
return (
4951
<Group>
@@ -54,10 +56,13 @@ class Voronoi extends React.PureComponent {
5456
fill="transparent"
5557
stroke={showVoronoi ? '#ddd' : 'transparent'}
5658
strokeWidth={1}
57-
onMouseMove={() => (event) => {
59+
onClick={onClick && (() => (event) => {
60+
onClick({ event, datum: polygon.data });
61+
})}
62+
onMouseMove={onMouseMove && (() => (event) => {
5863
onMouseMove({ event, datum: polygon.data });
59-
}}
60-
onMouseLeave={() => onMouseLeave}
64+
})}
65+
onMouseLeave={onMouseLeave && (() => onMouseLeave)}
6166
/>
6267
))}
6368
</Group>

packages/xy-chart/src/chart/XYChart.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class XYChart extends React.PureComponent {
7575
static collectScalesFromProps(props) {
7676
const { xScale: xScaleObject, yScale: yScaleObject, children } = props;
7777
const { innerWidth, innerHeight } = XYChart.getDimmensions(props);
78-
const { allData, dataBySeriesType, dataByIndex, data } = collectDataFromChildSeries(children);
78+
const { allData } = collectDataFromChildSeries(children);
7979

8080
const xScale = getScaleForAccessor({
8181
allData,
@@ -97,7 +97,6 @@ class XYChart extends React.PureComponent {
9797
const name = componentName(Child);
9898
if (isBarSeries(name) && xScale.type !== 'band') {
9999
const dummyBand = getScaleForAccessor({
100-
// allData: dataBySeriesType[name],
101100
allData,
102101
minAccessor: xString,
103102
maxAccessor: xString,
@@ -117,7 +116,6 @@ class XYChart extends React.PureComponent {
117116
});
118117

119118
return {
120-
dataByIndex,
121119
xScale,
122120
yScale,
123121
};

packages/xy-chart/test/Voronoi.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ describe('<Voronoi />', () => {
4747
expect(onMouseLeave).toHaveBeenCalledTimes(1);
4848
});
4949

50+
test('it should pass the relevant datum to onClick on trigger', () => {
51+
const onClick = jest.fn();
52+
const wrapper = mount(<Voronoi {...props} onClick={onClick} />);
53+
const polygon = wrapper.find(VoronoiPolygon).first();
54+
polygon.simulate('click');
55+
56+
expect(onClick).toHaveBeenCalledTimes(1);
57+
const datum = onClick.mock.calls[0][0].datum;
58+
expect(props.data.includes(datum)).toBe(true);
59+
});
60+
5061
test('it should update its voronoi if the data update', () => {
5162
const wrapper = shallow(<Voronoi {...props} />);
5263
const voronoi0 = wrapper.state('voronoi');

0 commit comments

Comments
 (0)