-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.esm.d.ts
105 lines (93 loc) · 2.34 KB
/
index.esm.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {
Chart,
ChartComponent,
DatasetController,
Element
} from 'chart.js';
declare module 'chart.js' {
/* raw data element */
interface SankeyDataPoint {
from: string;
to: string;
flow: number;
}
/* dataset configuration */
interface SankeyControllerDatasetOptions {
label: string;
data: Array<SankeyDataPoint>;
colorFrom: (data: ScriptableContext<'sankey'>) => string;
colorTo: (data: ScriptableContext<'sankey'>) => string;
colorMode: 'gradient' | 'from' | 'to';
/* Map<node.key, priority_value> */
priority?: Record<string, number>
/* Map<node.key, label> */
labels?: Record<string, string>
borderWidth?: number /* defaults to 1 */
nodeWidth?: number /* defaults to 10 */
color?: string /* defaults to 'black' */
borderColor?: string /* defaults to 'black' */
}
type FromToElement = {
addY: number
flow: number
key: string
node: SankeyNode
}
type SankeyNode = {
/* unique key of a node */
key: string
/* number of => in-connections */
in: number
/* number of out => connections */
out: number
from: Array<FromToElement>
to: Array<FromToElement>
/* priority extracted from the SankeyControllerDatasetOptions.priority map */
priority?: string
y?: number
}
interface SankeyParsedData {
x: number
y: number
_custom: {
from: SankeyNode,
to: SankeyNode
x: number
y: number
height: number,
}
}
interface ChartTypeRegistry {
sankey: {
datasetOptions: SankeyControllerDatasetOptions;
defaultDataPoint: SankeyDataPoint;
parsedDataType: SankeyParsedData;
/* TODO: define sankey chart options */
chartOptions: any;
scales: keyof CartesianScaleTypeRegistry;
};
}
}
type FlowOptions = {
colorMode: 'gradient' | 'from' | 'to';
colorFrom: string
colorTo: string
}
type FlowConfig = {
x: number;
y: number;
x2: number;
y2: number;
height: number;
options: FlowOptions
};
export type SankeyController = DatasetController
export const SankeyController: ChartComponent & {
prototype: SankeyController;
new(chart: Chart, datasetIndex: number): SankeyController;
};
export type Flow = Element<FlowConfig, FlowOptions>
export const Flow: ChartComponent & {
prototype: Flow;
new(cfg: FlowConfig): Flow;
};