UNPKG

8.09 kBPlain TextView Raw
1import { renderers } from './renderer/renderers';
2import { toolbarDialogAddons, toolbarActions } from './ui/toolbar';
3import type { Column, Ranking, IGroupData, IGroupItem } from './model';
4import type { IDataProvider } from './provider';
5import type { ICellRendererFactory, ERenderMode } from './renderer';
6import type { 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 /**
211 * option to enable to copy selected rows using ctrl-c
212 * @default false
213 */
214 copyableRows: boolean;
215}
216
217export interface ITaggleOptions extends ILineUpOptions {
218 /**
219 * whether the overview mode is enabled by default
220 * @default false
221 */
222 overviewMode: boolean;
223}
224
225export interface ILineUpLike {
226 readonly node: HTMLElement;
227 readonly data: IDataProvider;
228
229 dump(): any;
230
231 destroy(): void;
232}
233
234function resolveToolbarActions(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarAction>) {
235 const actions: IToolbarAction[] = [];
236
237 keys.forEach((key) => {
238 if (lookup.hasOwnProperty(key)) {
239 actions.push(lookup[key]);
240 } else {
241 console.warn(`cannot find toolbar action of type: "${col.desc.type}" with key "${key}"`);
242 }
243 });
244 return actions;
245}
246
247function resolveToolbarDialogAddons(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarDialogAddon>) {
248 const actions: IToolbarDialogAddon[] = [];
249
250 keys.forEach((key) => {
251 if (lookup.hasOwnProperty(key)) {
252 actions.push(lookup[key]);
253 } else {
254 console.warn(`cannot find toolbar dialog addon of type: "${col.desc.type}" with key "${key}"`);
255 }
256 });
257 return actions;
258}
259
260export function defaultOptions(): ITaggleOptions {
261 return {
262 toolbarActions,
263 toolbarDialogAddons,
264 resolveToolbarActions,
265 resolveToolbarDialogAddons,
266 renderers: Object.assign({}, renderers),
267 canRender: () => true,
268
269 labelRotation: 0,
270 summaryHeader: true,
271 animated: true,
272 expandLineOnHover: false,
273 sidePanel: true,
274 sidePanelCollapsed: false,
275 hierarchyIndicator: true,
276 defaultSlopeGraphMode: 'item',
277 overviewMode: false,
278
279 livePreviews: {
280 search: true,
281 filter: true,
282 vis: true,
283 sort: true,
284 group: true,
285 groupSort: true,
286 colorMapping: true,
287 },
288 onDialogBackgroundClick: 'confirm',
289
290 rowHeight: 18,
291 groupHeight: 40,
292 groupPadding: 5,
293 rowPadding: 2,
294
295 levelOfDetail: () => 'high',
296 customRowUpdate: () => undefined,
297 dynamicHeight: () => null,
298
299 flags: {
300 disableFrozenColumns: true, //disable by default for speed navigator.userAgent.includes('Firefox/52') // disable by default in Firefox ESR 52
301 advancedRankingFeatures: true,
302 advancedModelFeatures: true,
303 advancedUIFeatures: true,
304 },
305
306 ignoreUnsupportedBrowser: false,
307 copyableRows: true,
308 };
309}