@datarailsshared/dr_renderer 1.5.107 → 1.5.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @fileoverview Shared constants for chart options builders.
3
+ * These constants define default values for fonts, colors, and styling
4
+ * used across all chart option configurations.
5
+ * @module @datarailsshared/dr_renderer/options/constants
6
+ */
7
+
8
+ /**
9
+ * Chart color palette for various UI elements.
10
+ * @readonly
11
+ * @enum {string}
12
+ */
13
+ const CHART_COLORS = {
14
+ BACKGROUND: '#fff',
15
+ TEXT: '#151a41',
16
+ LABEL: '#cfd7dd',
17
+ LABEL_SECOND: '#85889c',
18
+ DRILL_UP_FILL: '#eef3f6',
19
+ DRILL_BUTTON_COLOR_FILL: 'white',
20
+ DRILL_BUTTON_COLOR: '#6D6E6F',
21
+ DRILL_BUTTON_COLOR_HOVER: '#333333',
22
+ PLOT_BORDER: '#606063',
23
+ MINOR_GRID_LINE: '#505053',
24
+ TICK_COLOR: '#666',
25
+ LABELS_OLD: '#D7D7D8',
26
+ DATA_LABELS: '#B0B0B3',
27
+ CONTRAST_TEXT: '#F0F0F3',
28
+ LEGEND_BACKGROUND: 'rgba(0, 0, 0, 0.5)',
29
+ MASK: 'rgba(255,255,255,0.3)',
30
+ };
31
+
32
+ /**
33
+ * Available font families for chart suboptions.
34
+ * @type {string[]}
35
+ */
36
+ const SUBOPTIONS_FONTS = [
37
+ 'Arial',
38
+ 'Arial Black',
39
+ 'Comic Sans MS',
40
+ 'Courier New',
41
+ 'Helvetica',
42
+ 'Impact',
43
+ 'Nunito Sans',
44
+ 'Tahoma',
45
+ 'Times New Roman',
46
+ 'Verdana',
47
+ 'Poppins'
48
+ ];
49
+
50
+ /**
51
+ * Default font family for Highcharts elements.
52
+ * @type {string}
53
+ */
54
+ const HIGHCHARTS_FONT_FAMILY = 'Poppins';
55
+
56
+ /**
57
+ * Default font family CSS value with fallback.
58
+ * @type {string}
59
+ */
60
+ const HIGHCHARTS_FONT_FAMILY_CSS = 'Poppins, sans-serif';
61
+
62
+ /**
63
+ * Default settings for tooltip styling.
64
+ * @typedef {Object} TooltipDefaultSettings
65
+ * @property {string} FONT_COLOR - Default tooltip font color
66
+ * @property {string} FONT_SIZE - Default tooltip font size
67
+ * @property {string} FONT_FAMILY - Default tooltip font family
68
+ */
69
+
70
+ /**
71
+ * @type {TooltipDefaultSettings}
72
+ */
73
+ const TOOLTIP_DEFAULT_SETTINGS = {
74
+ FONT_COLOR: '#545a6b',
75
+ FONT_SIZE: '12',
76
+ FONT_FAMILY: HIGHCHARTS_FONT_FAMILY,
77
+ };
78
+
79
+ /**
80
+ * Default settings for label styling.
81
+ * @typedef {Object} LabelDefaultSettings
82
+ * @property {string} FONT_COLOR - Default label font color
83
+ * @property {string} FONT_SIZE - Default label font size
84
+ * @property {string} FONT_FAMILY - Default label font family
85
+ */
86
+
87
+ /**
88
+ * @type {LabelDefaultSettings}
89
+ */
90
+ const LABEL_DEFAULT_SETTINGS = {
91
+ FONT_COLOR: CHART_COLORS.TEXT,
92
+ FONT_SIZE: '11',
93
+ FONT_FAMILY: HIGHCHARTS_FONT_FAMILY,
94
+ };
95
+
96
+ /**
97
+ * Default label options for Highcharts data labels.
98
+ * @type {{ style: { fontSize: string, fontFamily: string, fontWeight: string }, color: string }}
99
+ */
100
+ const LABEL_DEFAULT_OPTIONS = {
101
+ style: {
102
+ fontSize: LABEL_DEFAULT_SETTINGS.FONT_SIZE,
103
+ fontFamily: LABEL_DEFAULT_SETTINGS.FONT_FAMILY,
104
+ fontWeight: 'normal',
105
+ },
106
+ color: LABEL_DEFAULT_SETTINGS.FONT_COLOR,
107
+ };
108
+
109
+ /**
110
+ * Default tooltip options for Highcharts.
111
+ * @type {{ borderColor: string, shadow: Object, style: Object, enabled: boolean }}
112
+ */
113
+ const TOOLTIP_DEFAULT_OPTIONS = {
114
+ borderColor: CHART_COLORS.BACKGROUND,
115
+ shadow: {
116
+ color: '#9199b4',
117
+ width: 10,
118
+ opacity: 0.05
119
+ },
120
+ style: {
121
+ fontSize: TOOLTIP_DEFAULT_SETTINGS.FONT_SIZE,
122
+ fontFamily: TOOLTIP_DEFAULT_SETTINGS.FONT_FAMILY,
123
+ color: TOOLTIP_DEFAULT_SETTINGS.FONT_COLOR,
124
+ },
125
+ enabled: true,
126
+ };
127
+
128
+ /**
129
+ * Default label for chart axis.
130
+ * @type {string}
131
+ */
132
+ const CHART_AXIS_DEFAULT_LABEL = 'Axis (Category)';
133
+
134
+ /**
135
+ * Default label for chart legend.
136
+ * @type {string}
137
+ */
138
+ const CHART_LEGEND_DEFAULT_LABEL = 'Legend (Series)';
139
+
140
+ /**
141
+ * Generates font size options for select elements.
142
+ * Creates options from 6 to 24 (inclusive).
143
+ * @returns {Array<{label: number, value: number}>} Array of font size options
144
+ */
145
+ const generateFontSizeOptions = () => {
146
+ const options = [];
147
+ for (let i = 0; i < 19; i++) {
148
+ const fontValue = i + 6;
149
+ options.push({ label: fontValue, value: fontValue });
150
+ }
151
+ return options;
152
+ };
153
+
154
+ /**
155
+ * Pre-generated font size options for suboptions select elements.
156
+ * @type {Array<{label: number, value: number}>}
157
+ */
158
+ const SUBOPTIONS_FONT_SIZE_VALUES = generateFontSizeOptions();
159
+
160
+ /**
161
+ * Default CSS class for suboption categories.
162
+ * @type {string}
163
+ */
164
+ const DEFAULT_CATEGORY_CLASS = 'google-visualization-charteditor-mini-more';
165
+
166
+ // ============================================================================
167
+ // Chart Types Constants
168
+ // ============================================================================
169
+
170
+ /**
171
+ * Chart type string literal union.
172
+ * @typedef {'line-chart'|'line-chart-smooth'|'line-chart-forecast'|'column-chart'|'column-chart-stacked'|'column-chart-stacked-percent'|'combo-chart'|'combo-column-chart'|'combo-stacked-chart'|'bar-chart'|'bar-chart-stacked'|'bar-chart-stacked-percent'|'scatter-chart'|'area-chart'|'area-chart-smooth'|'table_only'|'polygon-chart'|'pie-chart'|'pie-chart-drilldown'|'gauge-solid-chart'|'gauge-chart'|'gauge-chart-enhanced'|'gauge-chart-dynamic-goal'|'gauge-chart-categories-summary'|'kpi-widget'|'smart-kpi'|'text-widget'|'waterfall-chart-breakdown'|'waterfall-chart-walkthrough'|'published_item'|'rich_text'|'excel_viewer'|'donut-chart'} ChartTypeValue
173
+ */
174
+
175
+ /**
176
+ * Chart types object type.
177
+ * @typedef {Object} ChartTypesMap
178
+ * @property {'line-chart'} LINE_CHART
179
+ * @property {'line-chart-smooth'} LINE_CHART_SMOOTH
180
+ * @property {'line-chart-forecast'} LINE_CHART_FORECAST
181
+ * @property {'column-chart'} COLUMN_CHART
182
+ * @property {'column-chart-stacked'} COLUMN_CHART_STACKED
183
+ * @property {'column-chart-stacked-percent'} COLUMN_CHART_STACKED_PERCENT
184
+ * @property {'combo-chart'} COMBO_CHART
185
+ * @property {'combo-column-chart'} COMBO_COLUMN_CHART
186
+ * @property {'combo-stacked-chart'} COMBO_STACKED_CHART
187
+ * @property {'bar-chart'} BAR_CHART
188
+ * @property {'bar-chart-stacked'} BAR_CHART_STACKED
189
+ * @property {'bar-chart-stacked-percent'} BAR_CHART_STACKED_PERCENT
190
+ * @property {'scatter-chart'} SCATTER_CHART
191
+ * @property {'area-chart'} AREA_CHART
192
+ * @property {'area-chart-smooth'} AREA_CHART_SMOOTH
193
+ * @property {'table_only'} TABLE_ONLY
194
+ * @property {'polygon-chart'} POLYGON_CHART
195
+ * @property {'pie-chart'} PIE_CHART
196
+ * @property {'pie-chart-drilldown'} PIE_CHART_DRILLDOWN
197
+ * @property {'gauge-solid-chart'} GAUGE_SOLID_CHART
198
+ * @property {'gauge-chart'} GAUGE_CHART
199
+ * @property {'gauge-chart-enhanced'} GAUGE_CHART_ENHANCED
200
+ * @property {'gauge-chart-dynamic-goal'} GAUGE_CHART_DYNAMIC_GOAL
201
+ * @property {'gauge-chart-categories-summary'} GAUGE_CHART_CATEGORIES_SUMMARY
202
+ * @property {'kpi-widget'} KPI_WIDGET
203
+ * @property {'smart-kpi'} SMART_KPI
204
+ * @property {'text-widget'} TEXT_WIDGET
205
+ * @property {'waterfall-chart-breakdown'} WATERFALL_BREAKDOWN
206
+ * @property {'waterfall-chart-walkthrough'} WATERFALL_WALKTHROUGH
207
+ * @property {'published_item'} PUBLISHED_ITEM
208
+ * @property {'rich_text'} RICH_TEXT
209
+ * @property {'excel_viewer'} EXCEL_VIEWER
210
+ * @property {'donut-chart'} DONUT_CHART
211
+ */
212
+
213
+ /**
214
+ * Chart type identifiers.
215
+ * @type {ChartTypesMap}
216
+ */
217
+ const CHART_TYPES = /** @type {const} */ ({
218
+ LINE_CHART: 'line-chart',
219
+ LINE_CHART_SMOOTH: 'line-chart-smooth',
220
+ LINE_CHART_FORECAST: 'line-chart-forecast',
221
+ COLUMN_CHART: 'column-chart',
222
+ COLUMN_CHART_STACKED: 'column-chart-stacked',
223
+ COLUMN_CHART_STACKED_PERCENT: 'column-chart-stacked-percent',
224
+ COMBO_CHART: 'combo-chart',
225
+ COMBO_COLUMN_CHART: 'combo-column-chart',
226
+ COMBO_STACKED_CHART: 'combo-stacked-chart',
227
+ BAR_CHART: 'bar-chart',
228
+ BAR_CHART_STACKED: 'bar-chart-stacked',
229
+ BAR_CHART_STACKED_PERCENT: 'bar-chart-stacked-percent',
230
+ SCATTER_CHART: 'scatter-chart',
231
+ AREA_CHART: 'area-chart',
232
+ AREA_CHART_SMOOTH: 'area-chart-smooth',
233
+ TABLE_ONLY: 'table_only',
234
+ POLYGON_CHART: 'polygon-chart',
235
+ PIE_CHART: 'pie-chart',
236
+ PIE_CHART_DRILLDOWN: 'pie-chart-drilldown',
237
+ GAUGE_SOLID_CHART: 'gauge-solid-chart',
238
+ GAUGE_CHART: 'gauge-chart',
239
+ GAUGE_CHART_ENHANCED: 'gauge-chart-enhanced',
240
+ GAUGE_CHART_DYNAMIC_GOAL: 'gauge-chart-dynamic-goal',
241
+ GAUGE_CHART_CATEGORIES_SUMMARY: 'gauge-chart-categories-summary',
242
+ KPI_WIDGET: 'kpi-widget',
243
+ SMART_KPI: 'smart-kpi',
244
+ TEXT_WIDGET: 'text-widget',
245
+ WATERFALL_BREAKDOWN: 'waterfall-chart-breakdown',
246
+ WATERFALL_WALKTHROUGH: 'waterfall-chart-walkthrough',
247
+ PUBLISHED_ITEM: 'published_item',
248
+ RICH_TEXT: 'rich_text',
249
+ EXCEL_VIEWER: 'excel_viewer',
250
+ DONUT_CHART: 'donut-chart',
251
+ });
252
+
253
+ module.exports = {
254
+ CHART_COLORS,
255
+ CHART_TYPES,
256
+ SUBOPTIONS_FONTS,
257
+ HIGHCHARTS_FONT_FAMILY,
258
+ HIGHCHARTS_FONT_FAMILY_CSS,
259
+ TOOLTIP_DEFAULT_SETTINGS,
260
+ TOOLTIP_DEFAULT_OPTIONS,
261
+ LABEL_DEFAULT_SETTINGS,
262
+ LABEL_DEFAULT_OPTIONS,
263
+ CHART_AXIS_DEFAULT_LABEL,
264
+ CHART_LEGEND_DEFAULT_LABEL,
265
+ SUBOPTIONS_FONT_SIZE_VALUES,
266
+ DEFAULT_CATEGORY_CLASS,
267
+ generateFontSizeOptions,
268
+ };
@@ -0,0 +1,377 @@
1
+ /**
2
+ * @fileoverview UI element factory functions for chart suboptions.
3
+ * Provides reusable factories to create consistent element definitions
4
+ * for the chart options editor UI.
5
+ * @module @datarailsshared/dr_renderer/options/elements
6
+ */
7
+
8
+ /**
9
+ * Element type literals for suboption elements.
10
+ * @typedef {'toggle'|'checkbox'|'input'|'select'|'radio'|'color_picker'|'devider'|'textarea'|'tag'|'text'} ElementType
11
+ */
12
+
13
+ /**
14
+ * Option item for select/radio elements.
15
+ * @typedef {Object} ElementOption
16
+ * @property {string|number} label - Display label
17
+ * @property {string|number} value - Option value
18
+ */
19
+
20
+ /**
21
+ * Tag element options configuration.
22
+ * @typedef {Object} TagElementOptions
23
+ * @property {boolean} [add_new_tag] - Whether new tags can be added
24
+ * @property {boolean} [searchable] - Whether tags are searchable
25
+ * @property {boolean} [multiple] - Whether multiple tags can be selected
26
+ */
27
+
28
+ /**
29
+ * Callback function that receives chart type and returns boolean.
30
+ * @callback ShowConditionCallback
31
+ * @param {string} chartType - The chart type identifier
32
+ * @returns {boolean} Whether to show the element
33
+ */
34
+
35
+ /**
36
+ * Callback function for handling value changes.
37
+ * @callback ValueChangeCallback
38
+ * @param {Record<string, unknown>} value - The current options value object
39
+ * @returns {void}
40
+ */
41
+
42
+ /**
43
+ * Callback function for disabled state.
44
+ * @callback DisabledConditionCallback
45
+ * @param {Record<string, unknown>} value - The current options value object
46
+ * @returns {boolean} Whether the element should be disabled
47
+ */
48
+
49
+ /**
50
+ * Suboption element definition.
51
+ * @typedef {Object} SuboptionElement
52
+ * @property {ElementType} element_type - Type of the UI element
53
+ * @property {string} [element_label] - Display label for the element
54
+ * @property {string} [value_name] - Property name in the options object
55
+ * @property {string|number|boolean|null|Array<unknown>} [default_value] - Default value for the element
56
+ * @property {Array<ElementOption>|TagElementOptions|string[]} [element_options] - Options for select/radio/tag elements
57
+ * @property {ShowConditionCallback} [showFn] - Function to determine if element should be shown
58
+ * @property {ValueChangeCallback} [clickFn] - Click handler function
59
+ * @property {ValueChangeCallback} [onChange] - Change handler function
60
+ * @property {string} [disabled_str] - String expression for disabled state
61
+ * @property {DisabledConditionCallback} [disabled_fn] - Function to determine disabled state
62
+ * @property {boolean} [hidden] - Whether element is hidden
63
+ * @property {boolean} [show_in_one_row] - Whether to show element in one row
64
+ * @property {string} [label_tooltip] - Tooltip text for the label
65
+ * @property {string} [element_sub_title] - Subtitle for the element
66
+ * @property {'number'|'string'} [value_type] - Value type for input elements
67
+ */
68
+
69
+ /**
70
+ * Toggle element options.
71
+ * @typedef {Object} ToggleElementOptions
72
+ * @property {string} [disabled_str] - Disabled state expression
73
+ * @property {DisabledConditionCallback} [disabled_fn] - Disabled state function
74
+ * @property {ShowConditionCallback} [showFn] - Show condition function
75
+ */
76
+
77
+ /**
78
+ * Creates a toggle element.
79
+ * @param {string} valueName - Property name in options
80
+ * @param {string} label - Display label
81
+ * @param {boolean} [defaultValue=false] - Default value
82
+ * @param {ToggleElementOptions} [options={}] - Additional options
83
+ * @returns {SuboptionElement}
84
+ */
85
+ const createToggle = (valueName, label, defaultValue = false, options = {}) => ({
86
+ element_type: 'toggle',
87
+ element_label: label,
88
+ value_name: valueName,
89
+ default_value: defaultValue,
90
+ ...options,
91
+ });
92
+
93
+ /**
94
+ * Checkbox element options.
95
+ * @typedef {Object} CheckboxElementOptions
96
+ * @property {ValueChangeCallback} [clickFn] - Click handler
97
+ * @property {ShowConditionCallback} [showFn] - Show condition function
98
+ * @property {DisabledConditionCallback} [disabled_fn] - Disabled state function
99
+ * @property {boolean} [hidden] - Whether element is hidden
100
+ */
101
+
102
+ /**
103
+ * Creates a checkbox element.
104
+ * @param {string} valueName - Property name in options
105
+ * @param {string} label - Display label
106
+ * @param {boolean} [defaultValue=false] - Default value
107
+ * @param {CheckboxElementOptions} [options={}] - Additional options
108
+ * @returns {SuboptionElement}
109
+ */
110
+ const createCheckbox = (valueName, label, defaultValue = false, options = {}) => ({
111
+ element_type: 'checkbox',
112
+ element_label: label,
113
+ value_name: valueName,
114
+ default_value: defaultValue,
115
+ ...options,
116
+ });
117
+
118
+ /**
119
+ * Input element options.
120
+ * @typedef {Object} InputElementOptions
121
+ * @property {ValueChangeCallback} [onChange] - Change handler
122
+ * @property {string} [label_tooltip] - Tooltip text
123
+ * @property {boolean} [show_in_one_row] - Show in one row
124
+ * @property {ShowConditionCallback} [showFn] - Show condition function
125
+ */
126
+
127
+ /**
128
+ * Creates an input element.
129
+ * @param {string} valueName - Property name in options
130
+ * @param {string} label - Display label
131
+ * @param {string|number|null} [defaultValue=''] - Default value
132
+ * @param {InputElementOptions} [options={}] - Additional options
133
+ * @returns {SuboptionElement}
134
+ */
135
+ const createInput = (valueName, label, defaultValue = '', options = {}) => ({
136
+ element_type: 'input',
137
+ element_label: label,
138
+ value_name: valueName,
139
+ default_value: defaultValue,
140
+ ...options,
141
+ });
142
+
143
+ /**
144
+ * Select element additional options.
145
+ * @typedef {Object} SelectElementOptions
146
+ * @property {ShowConditionCallback} [showFn] - Show condition function
147
+ * @property {DisabledConditionCallback} [disabled_fn] - Disabled state function
148
+ */
149
+
150
+ /**
151
+ * Creates a select element.
152
+ * @param {string} valueName - Property name in options
153
+ * @param {string} label - Display label
154
+ * @param {Array<ElementOption>|string[]} elementOptions - Options for the select
155
+ * @param {string|number} [defaultValue] - Default value
156
+ * @param {SelectElementOptions} [options={}] - Additional options
157
+ * @returns {SuboptionElement}
158
+ */
159
+ const createSelect = (valueName, label, elementOptions, defaultValue, options = {}) => ({
160
+ element_type: 'select',
161
+ element_label: label,
162
+ value_name: valueName,
163
+ element_options: elementOptions,
164
+ default_value: defaultValue,
165
+ ...options,
166
+ });
167
+
168
+ /**
169
+ * Radio element additional options.
170
+ * @typedef {Object} RadioElementOptions
171
+ * @property {string} [element_sub_title] - Subtitle for the element
172
+ * @property {ShowConditionCallback} [showFn] - Show condition function
173
+ */
174
+
175
+ /**
176
+ * Creates a radio element.
177
+ * @param {string} valueName - Property name in options
178
+ * @param {string} label - Display label
179
+ * @param {Array<ElementOption>} elementOptions - Options for the radio group
180
+ * @param {string} [defaultValue=''] - Default value
181
+ * @param {RadioElementOptions} [options={}] - Additional options
182
+ * @returns {SuboptionElement}
183
+ */
184
+ const createRadio = (valueName, label, elementOptions, defaultValue = '', options = {}) => ({
185
+ element_type: 'radio',
186
+ element_label: label,
187
+ value_name: valueName,
188
+ element_options: elementOptions,
189
+ default_value: defaultValue,
190
+ ...options,
191
+ });
192
+
193
+ /**
194
+ * Color picker element additional options.
195
+ * @typedef {Object} ColorPickerElementOptions
196
+ * @property {ShowConditionCallback} [showFn] - Show condition function
197
+ */
198
+
199
+ /**
200
+ * Creates a color picker element.
201
+ * @param {string} valueName - Property name in options
202
+ * @param {string} label - Display label
203
+ * @param {string} [defaultValue=''] - Default color value
204
+ * @param {ColorPickerElementOptions} [options={}] - Additional options
205
+ * @returns {SuboptionElement}
206
+ */
207
+ const createColorPicker = (valueName, label, defaultValue = '', options = {}) => ({
208
+ element_type: 'color_picker',
209
+ element_label: label,
210
+ value_name: valueName,
211
+ default_value: defaultValue,
212
+ ...options,
213
+ });
214
+
215
+ /**
216
+ * Creates a divider element.
217
+ * @param {string} [label] - Optional section label
218
+ * @returns {SuboptionElement}
219
+ */
220
+ const createDivider = (label) => {
221
+ /** @type {SuboptionElement} */
222
+ const element = { element_type: 'devider' };
223
+ if (label) {
224
+ element.element_label = label;
225
+ }
226
+ return element;
227
+ };
228
+
229
+ /**
230
+ * Textarea element additional options.
231
+ * @typedef {Object} TextareaElementOptions
232
+ * @property {ShowConditionCallback} [showFn] - Show condition function
233
+ */
234
+
235
+ /**
236
+ * Creates a textarea element.
237
+ * @param {string} valueName - Property name in options
238
+ * @param {string} label - Display label
239
+ * @param {string} [defaultValue=''] - Default value
240
+ * @param {TextareaElementOptions} [options={}] - Additional options
241
+ * @returns {SuboptionElement}
242
+ */
243
+ const createTextarea = (valueName, label, defaultValue = '', options = {}) => ({
244
+ element_type: 'textarea',
245
+ element_label: label,
246
+ value_name: valueName,
247
+ default_value: defaultValue,
248
+ ...options,
249
+ });
250
+
251
+ /**
252
+ * Tag element additional options.
253
+ * @typedef {Object} TagAdditionalOptions
254
+ * @property {ShowConditionCallback} [showFn] - Show condition function
255
+ */
256
+
257
+ /**
258
+ * Creates a tag element.
259
+ * @param {string} valueName - Property name in options
260
+ * @param {string} label - Display label
261
+ * @param {Array<string|number>} [defaultValue=[]] - Default value
262
+ * @param {TagElementOptions} [tagOptions={}] - Tag-specific options
263
+ * @param {TagAdditionalOptions} [options={}] - Additional options
264
+ * @returns {SuboptionElement}
265
+ */
266
+ const createTag = (valueName, label, defaultValue = [], tagOptions = {}, options = {}) => ({
267
+ element_type: 'tag',
268
+ element_label: label,
269
+ value_name: valueName,
270
+ default_value: defaultValue,
271
+ element_options: {
272
+ add_new_tag: tagOptions.add_new_tag ?? true,
273
+ searchable: tagOptions.searchable ?? true,
274
+ multiple: tagOptions.multiple ?? true,
275
+ },
276
+ ...options,
277
+ });
278
+
279
+ // ============================================================================
280
+ // Composite Element Groups (commonly used together)
281
+ // ============================================================================
282
+
283
+ const {
284
+ SUBOPTIONS_FONTS,
285
+ LABEL_DEFAULT_SETTINGS,
286
+ TOOLTIP_DEFAULT_SETTINGS,
287
+ SUBOPTIONS_FONT_SIZE_VALUES,
288
+ } = require('./constants');
289
+
290
+ /**
291
+ * Font styling default values.
292
+ * @typedef {Object} FontStylingDefaults
293
+ * @property {string} [fontStyle] - Default font style
294
+ * @property {string|number} [fontSize] - Default font size
295
+ * @property {string} [fontColor] - Default font color
296
+ */
297
+
298
+ /**
299
+ * Creates a standard font styling group (font style, size, color).
300
+ * @param {FontStylingDefaults} [defaults={}] - Default values
301
+ * @returns {SuboptionElement[]}
302
+ */
303
+ const createFontStylingGroup = (defaults = {}) => [
304
+ createSelect(
305
+ 'font_style',
306
+ 'Font style',
307
+ SUBOPTIONS_FONTS,
308
+ defaults.fontStyle ?? LABEL_DEFAULT_SETTINGS.FONT_FAMILY
309
+ ),
310
+ createSelect(
311
+ 'font_size',
312
+ 'Font size',
313
+ SUBOPTIONS_FONT_SIZE_VALUES,
314
+ defaults.fontSize ?? LABEL_DEFAULT_SETTINGS.FONT_SIZE
315
+ ),
316
+ createColorPicker(
317
+ 'font_color',
318
+ 'Font Color',
319
+ defaults.fontColor ?? LABEL_DEFAULT_SETTINGS.FONT_COLOR
320
+ ),
321
+ ];
322
+
323
+ /**
324
+ * Creates a label font styling group with divider.
325
+ * @param {FontStylingDefaults} [defaults={}] - Default values
326
+ * @returns {SuboptionElement[]}
327
+ */
328
+ const createLabelStyleGroup = (defaults = {}) => [
329
+ createDivider(),
330
+ createDivider('Label Style'),
331
+ ...createFontStylingGroup(defaults),
332
+ ];
333
+
334
+ /**
335
+ * Creates a tooltip font styling group with divider.
336
+ * @param {FontStylingDefaults} [defaults={}] - Default values
337
+ * @returns {SuboptionElement[]}
338
+ */
339
+ const createTooltipStyleGroup = (defaults = {}) => [
340
+ createDivider(),
341
+ createDivider('Tooltip Style'),
342
+ createSelect(
343
+ 'font_style',
344
+ 'Font style',
345
+ SUBOPTIONS_FONTS,
346
+ defaults.fontStyle ?? TOOLTIP_DEFAULT_SETTINGS.FONT_FAMILY
347
+ ),
348
+ createSelect(
349
+ 'font_size',
350
+ 'Font size',
351
+ SUBOPTIONS_FONT_SIZE_VALUES,
352
+ defaults.fontSize ?? TOOLTIP_DEFAULT_SETTINGS.FONT_SIZE
353
+ ),
354
+ createColorPicker(
355
+ 'font_color',
356
+ 'Font Color',
357
+ defaults.fontColor ?? TOOLTIP_DEFAULT_SETTINGS.FONT_COLOR
358
+ ),
359
+ ];
360
+
361
+ module.exports = {
362
+ // Basic element factories
363
+ createToggle,
364
+ createCheckbox,
365
+ createInput,
366
+ createSelect,
367
+ createRadio,
368
+ createColorPicker,
369
+ createDivider,
370
+ createTextarea,
371
+ createTag,
372
+
373
+ // Composite groups
374
+ createFontStylingGroup,
375
+ createLabelStyleGroup,
376
+ createTooltipStyleGroup,
377
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview Helper functions for chart options.
3
+ * Contains utility functions used by option builders.
4
+ * @module @datarailsshared/dr_renderer/options/helpers
5
+ */
6
+
7
+ const { CHART_TYPES } = require('./constants');
8
+
9
+ // ============================================================================
10
+ // Chart Type Helpers
11
+ // ============================================================================
12
+
13
+ /**
14
+ * Checks if a chart type supports vertical data labels option.
15
+ * Returns false for chart types that don't support vertical labels.
16
+ * @param {string} type - The chart type identifier
17
+ * @returns {boolean} True if the chart supports vertical data labels
18
+ */
19
+ const chartHasVerticalDataLabelsOption = (type) => {
20
+ /** @type {string[]} */
21
+ const noVerticalLabelsCharts = [
22
+ CHART_TYPES.LINE_CHART,
23
+ CHART_TYPES.LINE_CHART_SMOOTH,
24
+ CHART_TYPES.AREA_CHART,
25
+ CHART_TYPES.AREA_CHART_SMOOTH,
26
+ CHART_TYPES.BAR_CHART,
27
+ CHART_TYPES.BAR_CHART_STACKED,
28
+ ];
29
+ return !noVerticalLabelsCharts.includes(type);
30
+ };
31
+
32
+ module.exports = {
33
+ chartHasVerticalDataLabelsOption,
34
+ };