Skip to content

Commit 9924609

Browse files
committed
feat(parallel-coords): migrate to TypeScript
1 parent 5ee7cba commit 9924609

34 files changed

+25964
-34567
lines changed

.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rules:
1212
'@typescript-eslint/no-empty-interface': 'warn'
1313
'@typescript-eslint/no-empty-function': 'warn'
1414
'@typescript-eslint/no-use-before-define': 'warn'
15+
'@typescript-eslint/no-non-null-assertion': 'off'
1516
'no-use-before-define': 'off'
1617

1718
settings:
+27-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
import random from 'lodash/random'
2-
import range from 'lodash/range'
3-
import shuffle from 'lodash/shuffle'
2+
3+
interface IdSpec {
4+
id: string
5+
label?: string
6+
}
7+
8+
interface VariableSpec {
9+
id: string
10+
range: [number, number]
11+
}
412

513
type Options = Partial<{
6-
size: number
7-
keys: Array<{
8-
key: string
9-
random?: [number, number]
10-
shuffle?: string[]
11-
}>
14+
ids: IdSpec[]
15+
variables: VariableSpec[]
1216
}>
1317

1418
export const generateParallelCoordinatesData = ({
15-
size = 26,
16-
keys = [
17-
{ key: 'temp', random: [-10, 40] },
18-
{ key: 'cost', random: [200, 400000] },
19-
{ key: 'color', shuffle: ['red', 'yellow', 'green'] },
20-
{ key: 'target', shuffle: ['A', 'B', 'C', 'D', 'E'] },
21-
{ key: 'volume', random: [0.2, 7.6] },
19+
ids = [{ id: 'A' }, { id: 'B' }, { id: 'C' }, { id: 'D' }, { id: 'E' }],
20+
variables = [
21+
{ id: 'temp', range: [-10, 40] },
22+
{ id: 'cost', range: [200, 40000] },
23+
{ id: 'weight', range: [10, 300] },
24+
{ id: 'volume', range: [0.2, 7.6] },
2225
],
2326
}: Options = {}) => {
2427
const datumGenerator = () =>
25-
keys.reduce((acc, key) => {
26-
let value
27-
if (key.random !== undefined) {
28-
value = random(...key.random)
29-
} else if (key.shuffle !== undefined) {
30-
value = shuffle(key.shuffle)[0]
31-
}
28+
variables.reduce((acc, variable) => {
29+
const value = random(...variable.range)
3230

33-
return { ...acc, [key.key]: value }
31+
return { ...acc, [variable.id]: value }
3432
}, {})
3533

36-
return range(size).map(datumGenerator)
34+
return ids.map(id => {
35+
return {
36+
...datumGenerator(),
37+
...id,
38+
}
39+
})
3740
}

packages/parallel-coordinates/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@
1919
"charts",
2020
"parrallel-coordinates-chart"
2121
],
22+
"sideEffects": false,
2223
"main": "./dist/nivo-parallel-coordinates.cjs.js",
2324
"module": "./dist/nivo-parallel-coordinates.es.js",
24-
"types": "./index.d.ts",
25+
"types": "./dist/types/index.d.ts",
2526
"files": [
2627
"README.md",
2728
"LICENSE.md",
28-
"index.d.ts",
29-
"dist/"
29+
"dist/",
30+
"!dist/tsconfig.tsbuildinfo"
3031
],
3132
"dependencies": {
3233
"@nivo/axes": "workspace:*",
3334
"@nivo/colors": "workspace:*",
3435
"@nivo/core": "workspace:*",
36+
"@nivo/scales": "workspace:*",
3537
"@nivo/tooltip": "workspace:*",
3638
"@react-spring/web": "9.4.5 || ^9.7.2",
39+
"@types/d3-scale": "^3.2.3",
40+
"@types/d3-shape": "^2.0.0",
3741
"d3-scale": "^3.2.3",
38-
"d3-shape": "^1.3.5",
39-
"prop-types": "^15.7.2"
42+
"d3-shape": "^1.3.5"
4043
},
4144
"peerDependencies": {
4245
"react": ">= 16.14.0 < 19.0.0"

packages/parallel-coordinates/src/ParallelCoordinates.js

-92
This file was deleted.

packages/parallel-coordinates/src/ParallelCoordinatesAxisDensity.js

-45
This file was deleted.

packages/parallel-coordinates/src/ParallelCoordinatesAxisDensityCircles.js

-64
This file was deleted.

packages/parallel-coordinates/src/ParallelCoordinatesAxisDensityPoly.js

-83
This file was deleted.

0 commit comments

Comments
 (0)