Skip to content

Commit d335ade

Browse files
committed
fix: use d3-delaunay
1 parent bf2baaa commit d335ade

24 files changed

+3807
-2767
lines changed

.eslintrc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
2-
"parser": "babel-eslint",
3-
"extends": ["react-app", "prettier"],
4-
"env": {
5-
"es6": true
6-
},
7-
"parserOptions": {
8-
"sourceType": "module"
9-
}
2+
"extends": ["react-app", "prettier"]
3+
// "parser": "babel-eslint"
104
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build
99
dist
1010
artifacts
1111
.rpt2_cache
12+
d3/index.js
1213

1314
# misc
1415
.DS_Store

src/d3/entry.js renamed to d3/entry.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
export {voronoi} from 'd3-voronoi'
1+
export { Delaunay } from 'd3-delaunay'
22

3-
export {
4-
scaleLinear,
5-
scaleLog,
6-
scaleTime,
7-
scaleUtc,
8-
scaleBand
9-
} from "d3-scale"
3+
export { scaleLinear, scaleLog, scaleTime, scaleUtc, scaleBand } from 'd3-scale'
104

115
export {
126
arc,
@@ -31,4 +25,4 @@ export {
3125
curveStep,
3226
curveStepAfter,
3327
curveStepBefore,
34-
} from 'd3-shape'
28+
} from 'd3-shape'

d3/rollup.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from 'path'
2+
import node from 'rollup-plugin-node-resolve'
3+
// import { terser } from 'rollup-plugin-terser'
4+
5+
export default [
6+
{
7+
input: path.join(__dirname, 'entry.js'),
8+
output: {
9+
format: 'es',
10+
file: path.join(__dirname, 'index.js'),
11+
},
12+
plugins: [node()],
13+
onwarn,
14+
},
15+
]
16+
17+
function onwarn(message) {
18+
if (message.code === 'CIRCULAR_DEPENDENCY') {
19+
return
20+
}
21+
console.error(message)
22+
}

package.json

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
"test:dev": "jest --watch",
1313
"test:ci": "jest",
1414
"test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
15-
"build-d3": "rollup -c src/d3/rollup.config.js",
15+
"build-d3": "rollup -c d3/rollup.config.js",
1616
"build": "yarn build-d3 && NODE_ENV=production rollup -c",
1717
"now-build": "yarn && cd www && yarn && yarn build",
1818
"start": "yarn build-d3 && rollup -c -w",
19-
"prepare": "yarn build",
20-
"prepublishOnly": "yarn test:ci",
19+
"prepublishOnly": "yarn build && yarn test:ci",
2120
"release": "yarn publish",
2221
"releaseNext": "yarn publish --tag next",
2322
"format": "prettier {src,src/**,example/src,example/src/**}/*.{md,js,jsx,tsx} --write",
@@ -35,48 +34,58 @@
3534
"files": [
3635
"dist"
3736
],
38-
"peerDependencies": {
39-
"react": "^16.6.3"
40-
},
4137
"dependencies": {
4238
"@reach/observe-rect": "^1.1.0",
43-
"d3-delaunay": "^5.2.1",
39+
"@scarf/scarf": "^1.0.0",
40+
"d3-delaunay": "^5.3.0",
4441
"d3-scale": "^3.2.1",
45-
"d3-shape": "^1.3.7",
46-
"d3-voronoi": "^1.1.2"
42+
"d3-shape": "^1.3.7"
43+
},
44+
"peerDependencies": {
45+
"react": "^16.6.3"
4746
},
4847
"devDependencies": {
49-
"@babel/preset-env": "^7.9.0",
50-
"@babel/preset-react": "^7.9.4",
51-
"@rollup/plugin-node-resolve": "^7.1.1",
52-
"@rollup/plugin-replace": "^2.3.2",
53-
"@svgr/rollup": "^5.3.0",
48+
"@babel/core": "^7.8.6",
49+
"@babel/preset-env": "^7.8.6",
50+
"@babel/preset-react": "^7.8.3",
51+
"@rollup/plugin-replace": "^2.3.1",
52+
"@svgr/rollup": "^4.3.0",
53+
"@testing-library/react": "^9.4.1",
5454
"babel-core": "7.0.0-bridge.0",
55-
"babel-eslint": "10.1.0",
56-
"cross-env": "^7.0.2",
57-
"eslint": "6.8.0",
58-
"eslint-config-prettier": "^6.10.1",
59-
"eslint-config-react-app": "^5.2.1",
60-
"eslint-config-standard": "^14.1.1",
61-
"eslint-config-standard-react": "^9.2.0",
62-
"eslint-plugin-flowtype": "4.7.0",
63-
"eslint-plugin-import": "2.20.1",
64-
"eslint-plugin-jsx-a11y": "6.2.3",
65-
"eslint-plugin-node": "^11.0.0",
66-
"eslint-plugin-promise": "^4.2.1",
67-
"eslint-plugin-react": "7.19.0",
68-
"eslint-plugin-react-hooks": "2.5.1",
69-
"eslint-plugin-standard": "^4.0.1",
70-
"jest": "^26.0.1",
71-
"react": "^16.13.1",
72-
"react-dom": "^16.13.1",
73-
"rollup": "^2.2.0",
74-
"rollup-plugin-babel": "^4.4.0",
75-
"rollup-plugin-commonjs": "^10.1.0",
76-
"rollup-plugin-node-resolve": "^5.2.0",
55+
"babel-eslint": "9.x",
56+
"babel-jest": "^24.9.0",
57+
"babel-plugin-transform-async-to-promises": "^0.8.15",
58+
"cross-env": "^5.1.4",
59+
"dtslint": "^3.4.1",
60+
"eslint": "5.x",
61+
"eslint-config-prettier": "^4.3.0",
62+
"eslint-config-react-app": "^4.0.1",
63+
"eslint-config-standard": "^12.0.0",
64+
"eslint-config-standard-react": "^7.0.2",
65+
"eslint-plugin-flowtype": "2.x",
66+
"eslint-plugin-import": "2.x",
67+
"eslint-plugin-jsx-a11y": "6.x",
68+
"eslint-plugin-node": "^9.1.0",
69+
"eslint-plugin-prettier": "^3.1.2",
70+
"eslint-plugin-promise": "^4.1.1",
71+
"eslint-plugin-react": "7.18.3",
72+
"eslint-plugin-react-hooks": "1.5.0",
73+
"eslint-plugin-standard": "^4.0.0",
74+
"is-ci-cli": "^2.0.0",
75+
"jest": "^24.9.0",
76+
"prettier": "^1.19.1",
77+
"react": "^16.13.0",
78+
"react-dom": "^16.13.0",
79+
"react-error-boundary": "^2.2.1",
80+
"rollup": "^1.32.0",
81+
"rollup-plugin-babel": "^4.3.2",
82+
"rollup-plugin-commonjs": "^10.0.0",
83+
"rollup-plugin-jscc": "^1.0.0",
84+
"rollup-plugin-node-resolve": "^5.0.0",
7785
"rollup-plugin-peer-deps-external": "^2.2.2",
86+
"rollup-plugin-prettier": "^0.6.0",
7887
"rollup-plugin-size": "^0.2.2",
79-
"rollup-plugin-terser": "^5.3.0",
88+
"rollup-plugin-terser": "^5.2.0",
8089
"rollup-plugin-visualizer": "^4.0.4"
8190
}
8291
}

size-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"timestamp":1590788251975,"files":[{"filename":"react-charts.production.min.js","size":36178,"delta":19703}]},{"timestamp":1585154943498,"files":[{"filename":"react-charts.production.min.js","size":16475,"delta":16475}]}]
1+
[{"timestamp":1591076297995,"files":[{"filename":"react-charts.production.min.js","size":38874,"delta":2933}]},{"timestamp":1590960432591,"files":[{"filename":"react-charts.production.min.js","size":35941,"delta":-237}]},{"timestamp":1590788251975,"files":[{"filename":"react-charts.production.min.js","size":36178,"delta":19703}]},{"timestamp":1585154943498,"files":[{"filename":"react-charts.production.min.js","size":16475,"delta":16475}]}]

src/.eslintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/components/Voronoi.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react'
2-
import { voronoi, line } from '../d3'
2+
import { Delaunay, line } from '../../d3'
33
//
44
import ChartContext from '../utils/ChartContext'
55
import Path from '../primitives/Path'
6-
// import Utils from '../utils/Utils'
76

87
const lineFn = line()
98

@@ -143,23 +142,28 @@ export default function Voronoi() {
143142
})
144143
})
145144

146-
vor = voronoi()
147-
.x(d => d.x)
148-
.y(d => d.y)
149-
.extent(extent)(voronoiData)
145+
const delaunay = Delaunay.from(
146+
voronoiData,
147+
d => d.x,
148+
d => d.y
149+
)
150+
151+
const voronoi = delaunay.voronoi(extent.flat())
150152

151-
polygons = vor.polygons()
153+
polygons = [...voronoi.cellPolygons()]
152154

153155
return (
154156
<VoronoiElement>
155157
{polygons.map((points, i) => {
158+
const index = points.index
159+
const datum = voronoiData[index].datum
156160
const path = lineFn(points)
157161
return (
158162
<Path
159163
key={i}
160164
d={path}
161165
className="action-voronoi"
162-
onMouseEnter={e => onHover(points.data.datum)}
166+
onMouseEnter={e => onHover(datum)}
163167
onMouseLeave={e => onHover(null)}
164168
style={{
165169
fill: 'rgba(0,0,0,.2)',
@@ -175,6 +179,7 @@ export default function Voronoi() {
175179
gridHeight,
176180
gridWidth,
177181
height,
182+
needsVoronoi,
178183
onHover,
179184
primaryAxes.length,
180185
secondaryAxes.length,

src/d3/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/d3/rollup.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/hooks/usePropsMemo.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/primitives/Circle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import React from "react";
1+
import React from 'react'
22
//
33

44
const defaultStyle = {
55
r: 2,
6-
strokeWidth: "1",
7-
stroke: "#000000",
8-
fill: "#000000",
9-
opacity: 1
10-
};
6+
strokeWidth: '1',
7+
stroke: '#000000',
8+
fill: '#000000',
9+
opacity: 1,
10+
}
1111

1212
export default function Circle({ x, y, r, style, ...rest }) {
1313
const resolvedStyle = {
1414
...defaultStyle,
15-
...style
16-
};
15+
...style,
16+
}
1717

1818
return (
1919
<circle {...rest} cx={x || 0} cy={y || 0} r={1} style={resolvedStyle} />
20-
);
20+
)
2121
}

src/primitives/Group.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react";
1+
import React from 'react'
22

33
export default React.forwardRef(function Group(props, ref) {
4-
return <g {...props} ref={ref} />;
5-
});
4+
return <g {...props} ref={ref} />
5+
})

src/primitives/Line.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import React from "react";
1+
import React from 'react'
22
//
33

44
const defaultStyle = {
55
strokeWidth: 1,
6-
fill: "transparent",
7-
opacity: 1
8-
};
9-
10-
export default class Line extends React.Component {
11-
render() {
12-
const { style, ...rest } = this.props;
13-
14-
const resolvedStyle = {
15-
...defaultStyle,
16-
...style
17-
};
6+
fill: 'transparent',
7+
opacity: 1,
8+
}
189

19-
return <line {...rest} style={resolvedStyle} />;
10+
export default function Line({ style, ...rest }) {
11+
const resolvedStyle = {
12+
...defaultStyle,
13+
...style,
2014
}
15+
16+
return <line {...rest} style={resolvedStyle} />
2117
}

src/primitives/Path.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from "react";
1+
import React from 'react'
22
//
33

44
const defaultStyle = {
55
strokeWidth: 2,
6-
stroke: "#6b6b6b",
7-
fill: "transparent",
8-
opacity: 1
9-
};
6+
stroke: '#6b6b6b',
7+
fill: 'transparent',
8+
opacity: 1,
9+
}
1010

1111
export default function Path({ style, ...rest }) {
1212
const resolvedStyle = {
1313
...defaultStyle,
14-
...style
15-
};
14+
...style,
15+
}
1616

17-
return <path {...rest} style={resolvedStyle} />;
17+
return <path {...rest} style={resolvedStyle} />
1818
}

0 commit comments

Comments
 (0)