UNPKG

10.7 kBTypeScriptView Raw
1import { MarkComponent } from '../runtime';
2import { Encode } from './encode';
3import { Transform } from './transform';
4import { Scale } from './scale';
5import { Coordinate } from './coordinate';
6import { Animation } from './animate';
7import { Interaction } from './interaction';
8import { Theme } from './theme';
9import { Data } from './data';
10import { AxisComponent, LegendComponent, ScrollbarComponent, SliderComponent, TitleComponent, TooltipComponent } from './component';
11import { Closeable, Literal2Object, Padding } from './utils';
12export type Mark = IntervalMark | RectMark | LineMark | PointMark | TextMark | CellMark | AreaMark | NodeMark | EdgeMark | ImageMark | PolygonMark | BoxMark | VectorMark | LineXMark | LineYMark | RangeMark | RangeXMark | RangeYMark | ConnectorMark | SankeyMark | ChordMark | PathMark | TreemapMark | PackMark | BoxPlotMark | ShapeMark | ForceGraphMark | TreeMark | WordCloudMark | DensityMark | CustomMark | CompositeMark;
13export type MarkTypes = 'auto' | 'interval' | 'rect' | 'line' | 'point' | 'text' | 'cell' | 'area' | 'node' | 'edge' | 'link' | 'image' | 'polygon' | 'box' | 'vector' | 'lineX' | 'lineY' | 'connector' | 'range' | 'rangeX' | 'rangeY' | 'sankey' | 'chord' | 'path' | 'treemap' | 'pack' | 'boxplot' | 'shape' | 'forceGraph' | 'tree' | 'wordCloud' | 'gauge' | 'density' | 'heatmap' | 'liquid' | MarkComponent | CompositeMarkType;
14export type ChannelTypes = 'x' | 'y' | 'z' | 'x1' | 'y1' | 'series' | 'color' | 'opacity' | 'shape' | 'size' | 'key' | 'groupKey' | 'position' | 'series' | 'enterType' | 'enterEasing' | 'enterDuration' | 'enterDelay' | 'updateType' | 'updateEasing' | 'updateDuration' | 'updateDelay' | 'exitType' | 'exitEasing' | 'exitDuration' | 'exitDelay' | `position${number}`;
15export type PositionChannelTypes = 'x' | 'y' | 'z' | 'position' | `position${number}`;
16export type AtheisticChanelTypes = 'size' | 'color' | 'shape' | 'opacity';
17export type BaseMark<T extends MarkTypes, C extends string = ChannelTypes> = {
18 type?: T | string;
19 class?: string;
20 key?: string;
21 x?: number;
22 y?: number;
23 width?: number;
24 height?: number;
25 paddingLeft?: Padding;
26 paddingRight?: Padding;
27 paddingBottom?: Padding;
28 paddingTop?: Padding;
29 padding?: Padding;
30 inset?: number;
31 insetLeft?: number;
32 insetBottom?: number;
33 insetTop?: number;
34 insetRight?: number;
35 margin?: number;
36 marginLeft?: number;
37 marginBottom?: number;
38 marginTop?: number;
39 marginRight?: number;
40 facet?: boolean;
41 frame?: boolean;
42 zIndex?: number;
43 cartesian?: boolean;
44 clip?: boolean;
45 data?: Data;
46 transform?: Transform[];
47 layout?: Record<string, any>;
48 encode?: Partial<Record<C, Encode | Encode[]>>;
49 scale?: Partial<Record<C, Scale>>;
50 coordinate?: Coordinate;
51 style?: Record<string, any>;
52 viewStyle?: Record<string, any>;
53 state?: Partial<Record<'active' | 'selected' | 'inactive' | 'unselected', Record<string, any>>>;
54 animate?: Closeable<Partial<Record<'enter' | 'update' | 'exit', Closeable<Animation>>>>;
55 labels?: Record<string, any>[];
56 tooltip?: TooltipComponent;
57 axis?: Closeable<Partial<Record<PositionChannelTypes, Closeable<AxisComponent>>>>;
58 legend?: Closeable<Partial<Record<AtheisticChanelTypes, Closeable<LegendComponent>>>>;
59 slider?: Closeable<Partial<Record<PositionChannelTypes, Closeable<SliderComponent>>>>;
60 scrollbar?: Closeable<Partial<Record<PositionChannelTypes, Closeable<ScrollbarComponent>>>>;
61 title?: string | TitleComponent;
62 interaction?: Literal2Object<Interaction> & Record<string, any>;
63 theme?: Theme;
64};
65export type CompositeMarkType = (options: Record<string, any>, context: Record<string, any>) => any[];
66export type CompositeMark = BaseMark<CompositeMarkType>;
67export type IntervalMark = BaseMark<'interval', ChannelTypes | 'series'>;
68export type RectMark = BaseMark<'rect', ChannelTypes>;
69export type LineMark = BaseMark<'line', ChannelTypes | 'position' | `position${number}`>;
70export type PointMark = BaseMark<'point'>;
71export type TextMark = BaseMark<'text', ChannelTypes | 'text' | 'fontSize' | 'fontWeight' | 'rotate'>;
72export type LineXMark = BaseMark<'lineX', ChannelTypes>;
73export type LineYMark = BaseMark<'lineY', ChannelTypes>;
74export type RangeMark = BaseMark<'range', ChannelTypes>;
75export type RangeXMark = BaseMark<'rangeX', ChannelTypes>;
76export type RangeYMark = BaseMark<'rangeY', ChannelTypes>;
77export type ConnectorMark = BaseMark<'connector', ChannelTypes>;
78export type CellMark = BaseMark<'cell', ChannelTypes>;
79export type AreaMark = BaseMark<'area', ChannelTypes>;
80export type NodeMark = BaseMark<'node', ChannelTypes>;
81export type EdgeMark = BaseMark<'edge', ChannelTypes>;
82export type LinkMark = BaseMark<'link', ChannelTypes>;
83export type ImageMark = BaseMark<'image', ChannelTypes | 'src'>;
84export type PolygonMark = BaseMark<'polygon', ChannelTypes>;
85export type BoxMark = BaseMark<'box', ChannelTypes>;
86export type BoxPlotMark = BaseMark<'box', ChannelTypes>;
87export type ShapeMark = BaseMark<'shape', ChannelTypes>;
88export type VectorMark = BaseMark<'vector', ChannelTypes | 'rotate' | 'size'>;
89export type SankeyMark = BaseMark<'sankey', 'source' | 'target' | 'value' | `node${Capitalize<ChannelTypes>}` | `link${Capitalize<ChannelTypes>}` | ChannelTypes> & {
90 layout?: {
91 nodeId?: (node: any) => string;
92 nodes?: (graph: any) => any;
93 links?: (graph: any) => any;
94 /**
95 * sankey.nodeSort(undefined) is the default and resorts by ascending breadth during each iteration.
96 * sankey.nodeSort(null) specifies the input order of nodes and never sorts.
97 * sankey.nodeSort(function) specifies the given order as a comparator function and sorts once on initialization.
98 */
99 nodeSort?: null | undefined | ((a: any, b: any) => number);
100 /**
101 * sankey.linkSort(undefined) is the default, indicating that vertical order of links within each node will be determined automatically by the layout. If
102 * sankey.linkSort(null) will resort by the input.
103 * sankey.linkSort(function) specifies the given order as a comparator function and sorts once on initialization.
104 */
105 linkSort?: null | undefined | ((a: any, b: any) => number);
106 nodeAlign?: 'left' | 'center' | 'right' | 'justify' | ((node: any, n: number) => number);
107 nodeWidth?: number;
108 nodePadding?: number;
109 iterations?: number;
110 nodeDepth?: (datum: any, maxDepth: number) => number;
111 };
112 nodeLabels: Record<string, any>[];
113 linkLabels: Record<string, any>[];
114};
115export type ChordMark = BaseMark<'chord', 'source' | 'target' | 'value' | `node${Capitalize<ChannelTypes>}` | `link${Capitalize<ChannelTypes>}` | ChannelTypes> & {
116 layout?: {
117 nodes?: (graph: any) => any;
118 links?: (graph: any) => any;
119 y?: number;
120 id?: (node: any) => any;
121 sortBy?: 'id' | 'weight' | 'frequency' | null | ((a: any, b: any) => number);
122 nodeWidthRatio?: number;
123 nodePaddingRatio?: number;
124 sourceWeight?(edge: any): number;
125 targetWeight?(edge: any): number;
126 };
127 nodeLabels: Record<string, any>[];
128 linkLabels: Record<string, any>[];
129};
130export type PathMark = BaseMark<'path', ChannelTypes | 'd'>;
131export type TreemapMark = BaseMark<'treemap', 'value' | ChannelTypes> & {
132 layout?: Record<string, any>;
133};
134export type PackMark = BaseMark<'pack', 'value' | ChannelTypes> & {
135 layout?: Record<string, any>;
136};
137export type ForceGraphMark = BaseMark<'forceGraph', 'source' | 'target' | 'color' | 'value' | `node${Capitalize<ChannelTypes>}` | `link${Capitalize<ChannelTypes>}`> & {
138 layout?: Record<string, any>;
139 nodeLabels: Record<string, any>[];
140 linkLabels: Record<string, any>[];
141};
142export type TreeMark = BaseMark<'tree', 'value' | ChannelTypes> & {
143 layout?: {
144 /**
145 * Layout field. Default: 'value'.
146 */
147 field?: string;
148 /**
149 * Sets this cluster layouts node size to the specified two-element array of numbers [width, height] and returns this cluster layout.
150 * Default: null.
151 */
152 nodeSize?: any;
153 /**
154 * The separation accessor is used to separate neighboring leaves. Default: (a, b) => a.parent == b.parent ? 1 : 2;
155 */
156 separation?: (a: any, b: any) => number;
157 /**
158 * Sort function by compare 2 nodes.
159 */
160 sortBy?: (a: any, b: any) => number;
161 /**
162 * Layout infomation saved into fields. Default: ['x', 'y'].
163 */
164 as?: [string, string];
165 };
166 nodeLabels: Record<string, any>[];
167 linkLabels: Record<string, any>[];
168};
169export type WordCloudMark = BaseMark<'wordCloud', 'value' | ChannelTypes | 'text'> & {
170 layout?: {
171 /**
172 * @description If specified, sets the rectangular [width, height] of the layout
173 * @default [1, 1]
174 */
175 size?: [number, number];
176 font?: string | ((word: any) => string);
177 fontStyle?: string | ((word: any) => string);
178 fontWeight?: any | ((word: any) => any);
179 fontSize?: number | [number, number] | ((word: any) => number);
180 padding?: number | ((word: any) => number);
181 /**
182 * @description sets the text accessor function, which indicates the text for each word
183 * @default (d) => d.text
184 */
185 text?: (word: any) => number;
186 rotate?: number | ((word: any) => number);
187 timeInterval?: number;
188 random?: number | (() => number);
189 /**
190 * @description sets the current type of spiral used for positioning words. This can either be one of the two built-in spirals, "archimedean" and "rectangular"
191 * @default "archimedean"
192 */
193 spiral?: 'archimedean' | 'rectangular' | ((size: [number, number]) => (t: number) => number[]);
194 imageMask?: HTMLImageElement | string;
195 on?: ((type: 'end', details?: {
196 cloud: any;
197 words: any;
198 bounds: any;
199 }) => void) | ((type: 'word', details?: {
200 cloud: any;
201 word: any;
202 }) => void);
203 };
204};
205export type GaugeMark = BaseMark<'gauge', `arc${Capitalize<ChannelTypes>}` | `indicator${Capitalize<ChannelTypes>}` | `pointer${Capitalize<ChannelTypes>}` | `pin${Capitalize<ChannelTypes>}` | ChannelTypes>;
206export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
207export type HeatmapMark = BaseMark<'heatmap'>;
208export type LiquidMark = BaseMark<'liquid'>;
209export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;
210
\No newline at end of file