forked from airbnb/visx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typescript(vx-mock-data): re-write packge in TypeScript
- Loading branch information
Showing
36 changed files
with
264 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export type CountFunction = (idx: number, number: number) => number; | ||
export type BinFunction = (idx: number, number?: number) => number; | ||
|
||
export interface Bin { | ||
bin: number; | ||
count: number; | ||
} | ||
|
||
const defaultCount: CountFunction = (idx, number) => { | ||
return Math.random() * (25 * (number - idx)); | ||
}; | ||
|
||
const defaultBin: BinFunction = (idx, length) => { | ||
return idx * 150; | ||
}; | ||
|
||
export default function genBin( | ||
length: number, | ||
bin: BinFunction = defaultBin, | ||
count: CountFunction = defaultCount, | ||
): Bin[] { | ||
return new Array(length).fill(1).reduce((data, d, i) => { | ||
return data.concat([ | ||
{ | ||
bin: bin(i, length), | ||
count: count(i, length), | ||
}, | ||
]); | ||
}, []); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import genBin, { Bin, BinFunction, CountFunction } from './genBin'; | ||
|
||
export type Bins = { | ||
bin: number; | ||
bins: Bin[]; | ||
}; | ||
|
||
export default function genBins( | ||
length: number, | ||
height: number, | ||
bin?: BinFunction, | ||
count?: CountFunction, | ||
): Bins[] { | ||
return new Array(length).fill(1).reduce((arr, _, i) => { | ||
return arr.concat([ | ||
{ | ||
bin: i, | ||
bins: genBin(height, bin, count), | ||
}, | ||
]); | ||
}, []); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type DateValue = { | ||
date: Date; | ||
value: number; | ||
}; | ||
|
||
export default function genDateValue(length: number): DateValue[] { | ||
return new Array(length).fill(1).map((_, idx: number) => { | ||
return { | ||
date: new Date(Date.now() - idx * 3600000), | ||
// eslint-disable-next-line no-bitwise | ||
value: Math.max(250, (Math.random() * 3000) | 0), | ||
}; | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export interface GenPhyllotaxis { | ||
radius: number; | ||
width: number; | ||
height: number; | ||
} | ||
export interface PhyllotaxisPoint { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export type GenPhyllotaxisFunction = (idx: number) => PhyllotaxisPoint; | ||
|
||
export default function genPhyllotaxis({ | ||
radius, | ||
width, | ||
height, | ||
}: GenPhyllotaxis): GenPhyllotaxisFunction { | ||
const theta = Math.PI * (3 - Math.sqrt(5)); | ||
return idx => { | ||
const r = radius * Math.sqrt(idx); | ||
const a = theta * idx; | ||
return { | ||
x: width / 2 + r * Math.cos(a), | ||
y: height / 2 + r * Math.sin(a), | ||
}; | ||
}; | ||
} |
22 changes: 0 additions & 22 deletions
22
packages/vx-mock-data/src/generators/genRandomNormalPoints.js
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
packages/vx-mock-data/src/generators/genRandomNormalPoints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { randomNormal } from 'd3-random'; | ||
|
||
export type PointConfig = [number, number, number]; | ||
export type PointsRange = [number, number, number]; | ||
|
||
const random = randomNormal(0, 0.2); | ||
const sqrt3: number = Math.sqrt(3); | ||
|
||
function range(length: number): number[] { | ||
return new Array(length).fill(1); | ||
} | ||
|
||
export function genPointsRange( | ||
length: number, | ||
[offsetX, offsetY, index]: PointConfig, | ||
): PointsRange[] { | ||
return range(length).map(() => { | ||
return [random() + offsetX, random() + offsetY, index]; | ||
}); | ||
} | ||
|
||
export default function genPoints(count: number = 300): PointsRange[] { | ||
return [ | ||
...genPointsRange(count, [sqrt3, 1, 0]), | ||
...genPointsRange(count, [-sqrt3, 1, 1]), | ||
...genPointsRange(count, [0, -1, 2]), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.