Skip to content

Commit

Permalink
feat(parallel-coords): migrate to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed May 8, 2023
1 parent 5ee7cba commit 85d307a
Show file tree
Hide file tree
Showing 34 changed files with 647 additions and 837 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rules:
'@typescript-eslint/no-empty-interface': 'warn'
'@typescript-eslint/no-empty-function': 'warn'
'@typescript-eslint/no-use-before-define': 'warn'
'@typescript-eslint/no-non-null-assertion': 'off'
'no-use-before-define': 'off'

settings:
Expand Down
51 changes: 27 additions & 24 deletions packages/generators/src/parallelCoordinates.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import random from 'lodash/random'
import range from 'lodash/range'
import shuffle from 'lodash/shuffle'

interface IdSpec {
id: string
label?: string
}

interface VariableSpec {
id: string
range: [number, number]
}

type Options = Partial<{
size: number
keys: Array<{
key: string
random?: [number, number]
shuffle?: string[]
}>
ids: IdSpec[]
variables: VariableSpec[]
}>

export const generateParallelCoordinatesData = ({
size = 26,
keys = [
{ key: 'temp', random: [-10, 40] },
{ key: 'cost', random: [200, 400000] },
{ key: 'color', shuffle: ['red', 'yellow', 'green'] },
{ key: 'target', shuffle: ['A', 'B', 'C', 'D', 'E'] },
{ key: 'volume', random: [0.2, 7.6] },
ids = [{ id: 'A' }, { id: 'B' }, { id: 'C' }, { id: 'D' }, { id: 'E' }],
variables = [
{ id: 'temp', range: [-10, 40] },
{ id: 'cost', range: [200, 40000] },
{ id: 'weight', range: [10, 300] },
{ id: 'volume', range: [0.2, 7.6] },
],
}: Options = {}) => {
const datumGenerator = () =>
keys.reduce((acc, key) => {
let value
if (key.random !== undefined) {
value = random(...key.random)
} else if (key.shuffle !== undefined) {
value = shuffle(key.shuffle)[0]
}
variables.reduce((acc, variable) => {
const value = random(...variable.range)

return { ...acc, [key.key]: value }
return { ...acc, [variable.id]: value }
}, {})

return range(size).map(datumGenerator)
return ids.map(id => {
return {
...datumGenerator(),
...id,
}
})
}
13 changes: 8 additions & 5 deletions packages/parallel-coordinates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@
"charts",
"parrallel-coordinates-chart"
],
"sideEffects": false,
"main": "./dist/nivo-parallel-coordinates.cjs.js",
"module": "./dist/nivo-parallel-coordinates.es.js",
"types": "./index.d.ts",
"types": "./dist/types/index.d.ts",
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
"dist/",
"!dist/tsconfig.tsbuildinfo"
],
"dependencies": {
"@nivo/axes": "workspace:*",
"@nivo/colors": "workspace:*",
"@nivo/core": "workspace:*",
"@nivo/scales": "workspace:*",
"@nivo/tooltip": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-scale": "^3.2.3",
"@types/d3-shape": "^2.0.0",
"d3-scale": "^3.2.3",
"d3-shape": "^1.3.5",
"prop-types": "^15.7.2"
"d3-shape": "^1.3.5"
},
"peerDependencies": {
"react": ">= 16.14.0 < 19.0.0"
Expand Down
92 changes: 0 additions & 92 deletions packages/parallel-coordinates/src/ParallelCoordinates.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 85d307a

Please sign in to comment.