chart.model.ts 925 Bytes
Newer Older
Léonard Treille's avatar
Léonard Treille committed
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
import * as d3 from 'd3';

export enum ChartPadding {
	TOP = 0,
	RIGHT = 1,
	BOTTOM = 2,
	LEFT = 3,
}

export interface Point {
	x: number | string;
	y: number | string;
}

export interface Axis {
	grouped?: boolean;
	isDate?: boolean;
	tooltipFormatter?: (value: any, point?: Point, dataset?: Dataset) => string;
}

export interface Dataset {
	points: Point[][];
	axis?: {
		x?: Axis;
		y?: Axis;
	};
	options?: {
28
29
30
		padding?: number | [number, number, number, number],
		empty?: boolean,
		unavailable?: boolean,
Léonard Treille's avatar
Léonard Treille committed
31
		ghost?: boolean,
Léonard Treille's avatar
Léonard Treille committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	}
}

export interface ChartContext {
	height: number;
	width: number;
	chart: d3.Selection;
}

export interface ChartType {
	readonly type: string;

	padding: number;
	scaleX: d3.Scale;
	scaleY: d3.Scale;

	udpate(dataset: Dataset, context: ChartContext): void;

	destroy(context: ChartContext): void;

	globalMouseUpdate(dataset: Dataset, context: ChartContext, event: MouseEvent): void;
}