UNPKG

7.93 kBPlain TextView Raw
1import { renderers } from './renderer/renderers';
2import { toolbarActions, toolbarDialogAddons } from './ui/toolbar';
3import { Column, Ranking, IGroupData, IGroupItem } from './model';
4import { IDataProvider } from './provider';
5import { ICellRendererFactory, ERenderMode } from './renderer';
6import { IToolbarAction, IToolbarDialogAddon } from './ui';
7
8/**
9 * custom height implementation logic
10 */
11export interface IDynamicHeight {
12 /**
13 * default height for a row for optimized styling
14 */
15 defaultHeight: number;
16
17 /**
18 * returns the height in pixel for the given row
19 * @param {IGroupItem | IGroupData} item the item to show
20 * @returns {number} its height in pixel
21 */
22 height(item: IGroupItem | IGroupData): number;
23
24 /**
25 * returns the padding in pixel after the given row
26 * @param {IGroupItem | IGroupData | null} item item to show
27 * @returns {number} its padding in pixel
28 */
29 padding(item: IGroupItem | IGroupData | null): number;
30}
31
32export interface ILineUpFlags {
33 /**
34 * optimization flag to disable frozen columns for optimizing rendering performance
35 * @default true
36 */
37 disableFrozenColumns: boolean;
38 /**
39 * flag whether advanced ranking features are enabled
40 * @default true
41 */
42 advancedRankingFeatures: boolean;
43 /**
44 * flag whether advanced model features are enabled
45 * @default true
46 */
47 advancedModelFeatures: boolean;
48 /**
49 * flag whether advanced UI features are enabled
50 * @default true
51 */
52 advancedUIFeatures: boolean;
53}
54
55export interface IToolbarLookup<T> {
56 [key: string]: T;
57}
58
59export interface ILivePreviewOptions {
60 search: boolean;
61 filter: boolean;
62 vis: boolean;
63 sort: boolean;
64 group: boolean;
65 groupSort: boolean;
66 colorMapping: boolean;
67 dataMapping: boolean;
68 reduce: boolean;
69 rename: boolean;
70 cutOff: boolean;
71}
72
73export interface ILineUpOptions {
74 /**
75 * option to enable/disable showing a summary (histogram, ...) in the header
76 * @default true
77 */
78 summaryHeader: boolean;
79 /**
80 * option to enable/disable animated transitions
81 * @default true
82 */
83 animated: boolean;
84 /**
85 * option to enforce that the whole row is shown upon hover without overflow hidden
86 * @default false
87 */
88 expandLineOnHover: boolean;
89 /**
90 * option to enable/disable the panel
91 * @default true
92 */
93 sidePanel: boolean;
94 /**
95 * option to specify whether the panel should be collapsed by default
96 * @default false
97 */
98 sidePanelCollapsed: boolean;
99 /**
100 * show the sorting and grouping hierarchy indicators in the side panel
101 * @default true
102 */
103 hierarchyIndicator: boolean;
104
105 /**
106 * flag whether dialogs should confirm or cancel on clicking the background
107 * @default cancel
108 */
109 onDialogBackgroundClick: 'cancel' | 'confirm';
110
111 /**
112 * flag whether to shows filter previews as soon as the user changes the filter in the dialog
113 * @default {search: true,filter: true, vis: true,sort: true, group: true, groupSort: true, colorMapping: true}
114 */
115 livePreviews: Partial<ILivePreviewOptions>;
116
117 /**
118 * option to specify the default slope graph mode
119 * @default 'item'
120 */
121 defaultSlopeGraphMode: 'item' | 'band';
122
123 /**
124 * how many degrees should a label be rotated in case of narrow columns
125 * @default 0 no rotation
126 */
127 labelRotation: number;
128
129 /**
130 * height of a row
131 * @default 18
132 */
133 rowHeight: number;
134 /**
135 * padding between two rows
136 * @default 2
137 */
138 rowPadding: number;
139 /**
140 * height of an aggregated group in pixel
141 * @default 40
142 */
143 groupHeight: number;
144 /**
145 * padding between two groups in pixel
146 * @default 5
147 */
148 groupPadding: number;
149
150 /**
151 * custom function to compute the level of detail for a row
152 * @param {number} rowIndex the current row index to be rendered
153 * @returns {"high" | "low"}
154 */
155 levelOfDetail: (rowIndex: number) => 'high' | 'low';
156 /**
157 * custom function to compute the height of a row (group or item)
158 * @param {(IGroupItem | IGroupData)[]} data the data to render
159 * @param {Ranking} ranking the ranking of the data
160 * @returns {IDynamicHeight | null} the height compute function or null to use the default
161 */
162 dynamicHeight: (data: (IGroupItem | IGroupData)[], ranking: Ranking) => IDynamicHeight | null;
163 /**
164 * custom function to be called when updating a HTML row
165 * @param {HTMLElement} row node element to be updated
166 * @param {number} rowIndex row index to be rendered in the row
167 */
168 customRowUpdate: (row: HTMLElement, rowIndex: number) => void;
169
170 /**
171 * register custom toolbar actions and dialog addons
172 */
173 toolbarActions: IToolbarLookup<IToolbarAction>;
174 toolbarDialogAddons: IToolbarLookup<IToolbarDialogAddon>;
175
176 /**
177 * hook for postprocess the toolbar actions for a column
178 */
179 resolveToolbarActions: (col: Column, keys: string[], lookup: IToolbarLookup<IToolbarAction>) => IToolbarAction[];
180 /**
181 * hook for postprocess the toolbar dialog addons for a column
182 */
183 resolveToolbarDialogAddons: (
184 col: Column,
185 keys: string[],
186 lookup: IToolbarLookup<IToolbarDialogAddon>
187 ) => IToolbarDialogAddon[];
188
189 /**
190 * register custom renderer factories
191 */
192 renderers: { [type: string]: ICellRendererFactory };
193
194 /**
195 * custom check whether a given renderer can render the given column in the given mode
196 */
197 canRender: (type: string, renderer: ICellRendererFactory, col: Column, mode: ERenderMode) => boolean;
198
199 /**
200 * custom flags for optimization
201 */
202 flags: Partial<ILineUpFlags>;
203
204 /**
205 * ignore incompatible browser and always show (on own risk)
206 * @default false
207 */
208 ignoreUnsupportedBrowser: boolean;
209}
210
211export interface ITaggleOptions extends ILineUpOptions {
212 /**
213 * whether the overview mode is enabled by default
214 * @default false
215 */
216 overviewMode: boolean;
217}
218
219export interface ILineUpLike {
220 readonly node: HTMLElement;
221 readonly data: IDataProvider;
222
223 dump(): any;
224
225 destroy(): void;
226}
227
228function resolveToolbarActions(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarAction>) {
229 const actions: IToolbarAction[] = [];
230
231 keys.forEach((key) => {
232 if (lookup.hasOwnProperty(key)) {
233 actions.push(lookup[key]);
234 } else {
235 console.warn(`cannot find toolbar action of type: "${col.desc.type}" with key "${key}"`);
236 }
237 });
238 return actions;
239}
240
241function resolveToolbarDialogAddons(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarDialogAddon>) {
242 const actions: IToolbarDialogAddon[] = [];
243
244 keys.forEach((key) => {
245 if (lookup.hasOwnProperty(key)) {
246 actions.push(lookup[key]);
247 } else {
248 console.warn(`cannot find toolbar dialog addon of type: "${col.desc.type}" with key "${key}"`);
249 }
250 });
251 return actions;
252}
253
254export function defaultOptions(): ITaggleOptions {
255 return {
256 toolbarActions,
257 toolbarDialogAddons,
258 resolveToolbarActions,
259 resolveToolbarDialogAddons,
260 renderers: Object.assign({}, renderers),
261 canRender: () => true,
262
263 labelRotation: 0,
264 summaryHeader: true,
265 animated: true,
266 expandLineOnHover: false,
267 sidePanel: true,
268 sidePanelCollapsed: false,
269 hierarchyIndicator: true,
270 defaultSlopeGraphMode: 'item',
271 overviewMode: false,
272
273 livePreviews: {
274 search: true,
275 filter: true,
276 vis: true,
277 sort: true,
278 group: true,
279 groupSort: true,
280 colorMapping: true,
281 },
282 onDialogBackgroundClick: 'cancel',
283
284 rowHeight: 18,
285 groupHeight: 40,
286 groupPadding: 5,
287 rowPadding: 2,
288
289 levelOfDetail: () => 'high',
290 customRowUpdate: () => undefined,
291 dynamicHeight: () => null,
292
293 flags: {
294 disableFrozenColumns: true, //disable by default for speed navigator.userAgent.includes('Firefox/52') // disable by default in Firefox ESR 52
295 advancedRankingFeatures: true,
296 advancedModelFeatures: true,
297 advancedUIFeatures: true,
298 },
299
300 ignoreUnsupportedBrowser: false,
301 };
302}