@datarailsshared/dr_renderer 1.5.107 → 1.5.116
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.
- package/package.json +13 -2
- package/src/graph-table-renderer.js +1 -1
- package/src/highcharts_renderer.js +476 -1648
- package/src/index.d.ts +9 -0
- package/src/index.js +8 -0
- package/src/options/builders.js +933 -0
- package/src/options/constants.js +268 -0
- package/src/options/elements.js +377 -0
- package/src/options/helpers.js +34 -0
- package/src/options/index.js +215 -0
- package/src/options/presets.js +388 -0
- package/src/types/graph-table-renderer.d.ts +2 -2
- package/src/types/index.d.ts +11 -1
- package/src/types/options/builders.d.ts +615 -0
- package/src/types/options/constants.d.ts +235 -0
- package/src/types/options/elements.d.ts +456 -0
- package/src/types/options/helpers.d.ts +7 -0
- package/src/types/options/index.d.ts +178 -0
- package/src/types/options/presets.d.ts +98 -0
- package/tests/__snapshots__/suboptions.test.js.snap +5017 -0
- package/tests/options-builder.test.js +1710 -0
- package/tests/suboptions.test.js +322 -0
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -7
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Chart Options Builder API
|
|
3
|
+
*
|
|
4
|
+
* This module provides a functional builder pattern for creating chart suboption
|
|
5
|
+
* configurations. It allows for composable, reusable option definitions with
|
|
6
|
+
* full type support.
|
|
7
|
+
*
|
|
8
|
+
* @module @datarailsshared/dr_renderer/options
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Import builders
|
|
12
|
+
* const { withLabel, withTooltip, buildSuboptions } = require('@datarailsshared/dr_renderer').options;
|
|
13
|
+
*
|
|
14
|
+
* // Build custom suboptions
|
|
15
|
+
* const suboptions = buildSuboptions([withLabel, withTooltip]);
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Get preset for a chart type
|
|
19
|
+
* const { getPresetForChart, buildSuboptionsForChart } = require('@datarailsshared/dr_renderer').options;
|
|
20
|
+
*
|
|
21
|
+
* const columnChartOptions = buildSuboptionsForChart('column-chart');
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Re-export constants
|
|
25
|
+
const constants = require('./constants');
|
|
26
|
+
|
|
27
|
+
// Re-export element factories
|
|
28
|
+
const elements = require('./elements');
|
|
29
|
+
|
|
30
|
+
// Re-export builders
|
|
31
|
+
const builders = require('./builders');
|
|
32
|
+
|
|
33
|
+
// Re-export presets
|
|
34
|
+
const presets = require('./presets');
|
|
35
|
+
|
|
36
|
+
// Re-export helpers
|
|
37
|
+
const helpers = require('./helpers');
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Factory Functions
|
|
41
|
+
// ============================================================================
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Feature flag checker callback.
|
|
45
|
+
* @callback FeatureChecker
|
|
46
|
+
* @param {string} featureName - The feature flag name to check
|
|
47
|
+
* @returns {boolean} Whether the feature is enabled
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for createDefaultSuboptions.
|
|
52
|
+
* @typedef {Object} CreateDefaultSuboptionsConfig
|
|
53
|
+
* @property {import('./constants').ChartTypesMap} [CHART_TYPES] - Chart types enum (for table options)
|
|
54
|
+
* @property {FeatureChecker} [hasFeature] - Feature flag checker function
|
|
55
|
+
* @property {string} [ENABLE_GAUGE_DYNAMIC_GOAL] - Feature flag name for gauge dynamic goal
|
|
56
|
+
* @property {import('./builders').GaugeSegment[]} [defaultGaugeSegments] - Default gauge segments array
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates the default suboptions object for highchartsRenderer.
|
|
61
|
+
* This generates the complete suboptions object with all chart options.
|
|
62
|
+
* @param {CreateDefaultSuboptionsConfig} [config={}] - Configuration options
|
|
63
|
+
* @returns {Record<string, import('./builders').SuboptionDefinition>} Complete suboptions object
|
|
64
|
+
*/
|
|
65
|
+
const createDefaultSuboptions = (config = {}) => ({
|
|
66
|
+
'widget_library': builders.withWidgetLibrary(),
|
|
67
|
+
'table_options': builders.withTableOptions(),
|
|
68
|
+
'table_options_transpose': builders.withTableOptionsTranspose({ CHART_TYPES: config.CHART_TYPES }),
|
|
69
|
+
'table_options_gauge': builders.withTableOptionsGauge(),
|
|
70
|
+
'table_design_options': builders.withTableDesignOptions(),
|
|
71
|
+
'value': builders.withValue(),
|
|
72
|
+
'range': builders.withRange(),
|
|
73
|
+
'name': builders.withName(),
|
|
74
|
+
'subtitle': builders.withSubtitle(),
|
|
75
|
+
'chart': builders.withChart(),
|
|
76
|
+
'chart_grid': builders.withChartGrid(),
|
|
77
|
+
'chart_forecast': builders.withChartForecast(),
|
|
78
|
+
'total_value_label_donut': builders.withTotalValueLabelDonut(),
|
|
79
|
+
'chart_position': builders.withChartPosition(),
|
|
80
|
+
'label': builders.withLabel(),
|
|
81
|
+
'label_pie': builders.withLabelPie(),
|
|
82
|
+
'label_gauge': builders.withLabelGauge({
|
|
83
|
+
hasFeature: config.hasFeature,
|
|
84
|
+
ENABLE_GAUGE_DYNAMIC_GOAL: config.ENABLE_GAUGE_DYNAMIC_GOAL
|
|
85
|
+
}),
|
|
86
|
+
'label_with_percentage': builders.withLabelWithPercentage(),
|
|
87
|
+
'label_with_percentage_percent_stacked': builders.withLabelWithPercentagePercentStacked(),
|
|
88
|
+
'axisY': builders.withAxisY(),
|
|
89
|
+
'axisY_percent_stacked': builders.withAxisYPercentStacked(),
|
|
90
|
+
'axisX': builders.withAxisX(),
|
|
91
|
+
'ticks': builders.withTicks(),
|
|
92
|
+
'tooltips': builders.withTooltip(),
|
|
93
|
+
'tooltips_pie': builders.withTooltipPie(),
|
|
94
|
+
'tooltips_gauge': builders.withTooltipGauge(),
|
|
95
|
+
'negative_number_format': builders.withNegativeNumberFormat(),
|
|
96
|
+
'delta_column': builders.withDeltaColumn(),
|
|
97
|
+
'delta_column_for_drill_down': builders.withDeltaColumnForDrillDown(),
|
|
98
|
+
'advanced': builders.withAdvanced(),
|
|
99
|
+
'legends': builders.withLegends(),
|
|
100
|
+
'gauge_goal': builders.withGaugeGoal(),
|
|
101
|
+
'gauge_segments': builders.withGaugeSegments({ defaultSegments: config.defaultGaugeSegments }),
|
|
102
|
+
'gauge_is_absolute': builders.withGaugeIsAbsolute(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ============================================================================
|
|
106
|
+
// Public API
|
|
107
|
+
// ============================================================================
|
|
108
|
+
|
|
109
|
+
module.exports = {
|
|
110
|
+
// Constants
|
|
111
|
+
CHART_COLORS: constants.CHART_COLORS,
|
|
112
|
+
SUBOPTIONS_FONTS: constants.SUBOPTIONS_FONTS,
|
|
113
|
+
HIGHCHARTS_FONT_FAMILY: constants.HIGHCHARTS_FONT_FAMILY,
|
|
114
|
+
HIGHCHARTS_FONT_FAMILY_CSS: constants.HIGHCHARTS_FONT_FAMILY_CSS,
|
|
115
|
+
TOOLTIP_DEFAULT_SETTINGS: constants.TOOLTIP_DEFAULT_SETTINGS,
|
|
116
|
+
TOOLTIP_DEFAULT_OPTIONS: constants.TOOLTIP_DEFAULT_OPTIONS,
|
|
117
|
+
LABEL_DEFAULT_SETTINGS: constants.LABEL_DEFAULT_SETTINGS,
|
|
118
|
+
LABEL_DEFAULT_OPTIONS: constants.LABEL_DEFAULT_OPTIONS,
|
|
119
|
+
SUBOPTIONS_FONT_SIZE_VALUES: constants.SUBOPTIONS_FONT_SIZE_VALUES,
|
|
120
|
+
DEFAULT_CATEGORY_CLASS: constants.DEFAULT_CATEGORY_CLASS,
|
|
121
|
+
|
|
122
|
+
// Element factories
|
|
123
|
+
createToggle: elements.createToggle,
|
|
124
|
+
createCheckbox: elements.createCheckbox,
|
|
125
|
+
createInput: elements.createInput,
|
|
126
|
+
createSelect: elements.createSelect,
|
|
127
|
+
createRadio: elements.createRadio,
|
|
128
|
+
createColorPicker: elements.createColorPicker,
|
|
129
|
+
createDivider: elements.createDivider,
|
|
130
|
+
createTextarea: elements.createTextarea,
|
|
131
|
+
createTag: elements.createTag,
|
|
132
|
+
createFontStylingGroup: elements.createFontStylingGroup,
|
|
133
|
+
createLabelStyleGroup: elements.createLabelStyleGroup,
|
|
134
|
+
createTooltipStyleGroup: elements.createTooltipStyleGroup,
|
|
135
|
+
|
|
136
|
+
// Label builders
|
|
137
|
+
withLabel: builders.withLabel,
|
|
138
|
+
withLabelPie: builders.withLabelPie,
|
|
139
|
+
withLabelGauge: builders.withLabelGauge,
|
|
140
|
+
withLabelWithPercentage: builders.withLabelWithPercentage,
|
|
141
|
+
withLabelWithPercentagePercentStacked: builders.withLabelWithPercentagePercentStacked,
|
|
142
|
+
|
|
143
|
+
// Tooltip builders
|
|
144
|
+
withTooltip: builders.withTooltip,
|
|
145
|
+
withTooltipPie: builders.withTooltipPie,
|
|
146
|
+
withTooltipGauge: builders.withTooltipGauge,
|
|
147
|
+
|
|
148
|
+
// Axis builders
|
|
149
|
+
withAxisY: builders.withAxisY,
|
|
150
|
+
withAxisYPercentStacked: builders.withAxisYPercentStacked,
|
|
151
|
+
withAxisX: builders.withAxisX,
|
|
152
|
+
|
|
153
|
+
// Table builders
|
|
154
|
+
withTableOptions: builders.withTableOptions,
|
|
155
|
+
withTableOptionsTranspose: builders.withTableOptionsTranspose,
|
|
156
|
+
withTableOptionsGauge: builders.withTableOptionsGauge,
|
|
157
|
+
withTableDesignOptions: builders.withTableDesignOptions,
|
|
158
|
+
|
|
159
|
+
// Chart config builders
|
|
160
|
+
withChart: builders.withChart,
|
|
161
|
+
withChartGrid: builders.withChartGrid,
|
|
162
|
+
withChartForecast: builders.withChartForecast,
|
|
163
|
+
withChartPosition: builders.withChartPosition,
|
|
164
|
+
|
|
165
|
+
// Other builders
|
|
166
|
+
withWidgetLibrary: builders.withWidgetLibrary,
|
|
167
|
+
withSubtitle: builders.withSubtitle,
|
|
168
|
+
withName: builders.withName,
|
|
169
|
+
withNegativeNumberFormat: builders.withNegativeNumberFormat,
|
|
170
|
+
withValue: builders.withValue,
|
|
171
|
+
withRange: builders.withRange,
|
|
172
|
+
withTicks: builders.withTicks,
|
|
173
|
+
withLegends: builders.withLegends,
|
|
174
|
+
withDeltaColumn: builders.withDeltaColumn,
|
|
175
|
+
withDeltaColumnForDrillDown: builders.withDeltaColumnForDrillDown,
|
|
176
|
+
withAdvanced: builders.withAdvanced,
|
|
177
|
+
withTotalValueLabelDonut: builders.withTotalValueLabelDonut,
|
|
178
|
+
withGaugeGoal: builders.withGaugeGoal,
|
|
179
|
+
withGaugeSegments: builders.withGaugeSegments,
|
|
180
|
+
withGaugeIsAbsolute: builders.withGaugeIsAbsolute,
|
|
181
|
+
|
|
182
|
+
// Helper function
|
|
183
|
+
createSuboption: builders.createSuboption,
|
|
184
|
+
|
|
185
|
+
// Reusable disabled conditions
|
|
186
|
+
LABEL_DISABLED_CONDITION: builders.LABEL_DISABLED_CONDITION,
|
|
187
|
+
LABEL_PIE_DISABLED_CONDITION: builders.LABEL_PIE_DISABLED_CONDITION,
|
|
188
|
+
TOOLTIP_DISABLED_CONDITION: builders.TOOLTIP_DISABLED_CONDITION,
|
|
189
|
+
TOOLTIP_PIE_DISABLED_CONDITION: builders.TOOLTIP_PIE_DISABLED_CONDITION,
|
|
190
|
+
|
|
191
|
+
// Reusable elements
|
|
192
|
+
LABEL_SHOW_TOGGLE: builders.LABEL_SHOW_TOGGLE,
|
|
193
|
+
LABEL_PIE_SHOW_TOGGLE: builders.LABEL_PIE_SHOW_TOGGLE,
|
|
194
|
+
LABEL_OVERLAP_TOGGLE: builders.LABEL_OVERLAP_TOGGLE,
|
|
195
|
+
TOOLTIP_SHOW_TOGGLE: builders.TOOLTIP_SHOW_TOGGLE,
|
|
196
|
+
TOOLTIP_PIE_SHOW_TOGGLE: builders.TOOLTIP_PIE_SHOW_TOGGLE,
|
|
197
|
+
GAUGE_SHOW_TOGGLE: builders.GAUGE_SHOW_TOGGLE,
|
|
198
|
+
|
|
199
|
+
// Presets and utilities
|
|
200
|
+
CHART_TYPES: constants.CHART_TYPES,
|
|
201
|
+
CHART_PRESETS: presets.CHART_PRESETS,
|
|
202
|
+
BUILDER_KEY_MAP: presets.BUILDER_KEY_MAP,
|
|
203
|
+
getBuilderKey: presets.getBuilderKey,
|
|
204
|
+
getPresetForChart: presets.getPresetForChart,
|
|
205
|
+
buildSuboptionsForChart: presets.buildSuboptionsForChart,
|
|
206
|
+
buildSuboptions: presets.buildSuboptions,
|
|
207
|
+
getChartTypes: presets.getChartTypes,
|
|
208
|
+
hasPreset: presets.hasPreset,
|
|
209
|
+
|
|
210
|
+
// Helpers
|
|
211
|
+
chartHasVerticalDataLabelsOption: helpers.chartHasVerticalDataLabelsOption,
|
|
212
|
+
|
|
213
|
+
// Factory functions
|
|
214
|
+
createDefaultSuboptions,
|
|
215
|
+
};
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Chart-specific option presets.
|
|
3
|
+
* Defines which suboptions are available for each chart type.
|
|
4
|
+
* @module @datarailsshared/dr_renderer/options/presets
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { CHART_TYPES } = require('./constants');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
// Label builders
|
|
11
|
+
withLabel,
|
|
12
|
+
withLabelPie,
|
|
13
|
+
withLabelGauge,
|
|
14
|
+
withLabelWithPercentage,
|
|
15
|
+
withLabelWithPercentagePercentStacked,
|
|
16
|
+
|
|
17
|
+
// Tooltip builders
|
|
18
|
+
withTooltip,
|
|
19
|
+
withTooltipPie,
|
|
20
|
+
withTooltipGauge,
|
|
21
|
+
|
|
22
|
+
// Axis builders
|
|
23
|
+
withAxisY,
|
|
24
|
+
withAxisYPercentStacked,
|
|
25
|
+
withAxisX,
|
|
26
|
+
|
|
27
|
+
// Table builders
|
|
28
|
+
withTableOptions,
|
|
29
|
+
withTableOptionsTranspose,
|
|
30
|
+
withTableOptionsGauge,
|
|
31
|
+
withTableDesignOptions,
|
|
32
|
+
|
|
33
|
+
// Chart config builders
|
|
34
|
+
withChart,
|
|
35
|
+
withChartGrid,
|
|
36
|
+
withChartForecast,
|
|
37
|
+
withChartPosition,
|
|
38
|
+
|
|
39
|
+
// Other builders
|
|
40
|
+
withWidgetLibrary,
|
|
41
|
+
withSubtitle,
|
|
42
|
+
withName,
|
|
43
|
+
withNegativeNumberFormat,
|
|
44
|
+
withValue,
|
|
45
|
+
withRange,
|
|
46
|
+
withLegends,
|
|
47
|
+
withDeltaColumn,
|
|
48
|
+
withDeltaColumnForDrillDown,
|
|
49
|
+
withAdvanced,
|
|
50
|
+
withTotalValueLabelDonut,
|
|
51
|
+
withGaugeGoal,
|
|
52
|
+
withGaugeSegments,
|
|
53
|
+
withGaugeIsAbsolute,
|
|
54
|
+
withTicks,
|
|
55
|
+
} = require('./builders');
|
|
56
|
+
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Suboption Key Mapping
|
|
59
|
+
// ============================================================================
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Suboption key string literal.
|
|
63
|
+
* @typedef {'label'|'label_pie'|'label_gauge'|'label_with_percentage'|'label_with_percentage_percent_stacked'|'tooltips'|'tooltips_pie'|'tooltips_gauge'|'axisY'|'axisY_percent_stacked'|'axisX'|'table_options'|'table_options_transpose'|'table_options_gauge'|'table_design_options'|'chart'|'chart_grid'|'chart_forecast'|'chart_position'|'widget_library'|'subtitle'|'name'|'negative_number_format'|'value'|'range'|'legends'|'delta_column'|'delta_column_for_drill_down'|'advanced'|'total_value_label_donut'|'gauge_goal'|'gauge_segments'|'gauge_is_absolute'|'ticks'} SuboptionKey
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Maps builder functions to their suboption keys.
|
|
68
|
+
* Used to build the suboptions object with correct keys.
|
|
69
|
+
* @type {Map<BuilderFunction, SuboptionKey>}
|
|
70
|
+
*/
|
|
71
|
+
const BUILDER_KEY_MAP = new Map([
|
|
72
|
+
[withLabel, 'label'],
|
|
73
|
+
[withLabelPie, 'label_pie'],
|
|
74
|
+
[withLabelGauge, 'label_gauge'],
|
|
75
|
+
[withLabelWithPercentage, 'label_with_percentage'],
|
|
76
|
+
[withLabelWithPercentagePercentStacked, 'label_with_percentage_percent_stacked'],
|
|
77
|
+
[withTooltip, 'tooltips'],
|
|
78
|
+
[withTooltipPie, 'tooltips_pie'],
|
|
79
|
+
[withTooltipGauge, 'tooltips_gauge'],
|
|
80
|
+
[withAxisY, 'axisY'],
|
|
81
|
+
[withAxisYPercentStacked, 'axisY_percent_stacked'],
|
|
82
|
+
[withAxisX, 'axisX'],
|
|
83
|
+
[withTableOptions, 'table_options'],
|
|
84
|
+
[withTableOptionsTranspose, 'table_options_transpose'],
|
|
85
|
+
[withTableOptionsGauge, 'table_options_gauge'],
|
|
86
|
+
[withTableDesignOptions, 'table_design_options'],
|
|
87
|
+
[withChart, 'chart'],
|
|
88
|
+
[withChartGrid, 'chart_grid'],
|
|
89
|
+
[withChartForecast, 'chart_forecast'],
|
|
90
|
+
[withChartPosition, 'chart_position'],
|
|
91
|
+
[withWidgetLibrary, 'widget_library'],
|
|
92
|
+
[withSubtitle, 'subtitle'],
|
|
93
|
+
[withName, 'name'],
|
|
94
|
+
[withNegativeNumberFormat, 'negative_number_format'],
|
|
95
|
+
[withValue, 'value'],
|
|
96
|
+
[withRange, 'range'],
|
|
97
|
+
[withLegends, 'legends'],
|
|
98
|
+
[withDeltaColumn, 'delta_column'],
|
|
99
|
+
[withDeltaColumnForDrillDown, 'delta_column_for_drill_down'],
|
|
100
|
+
[withAdvanced, 'advanced'],
|
|
101
|
+
[withTotalValueLabelDonut, 'total_value_label_donut'],
|
|
102
|
+
[withGaugeGoal, 'gauge_goal'],
|
|
103
|
+
[withGaugeSegments, 'gauge_segments'],
|
|
104
|
+
[withGaugeIsAbsolute, 'gauge_is_absolute'],
|
|
105
|
+
[withTicks, 'ticks'],
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// Chart Preset Definitions
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Chart presets mapping chart types to their suboption builders.
|
|
114
|
+
* Each preset defines which builders are used for that chart type.
|
|
115
|
+
* @type {Record<import('./constants').ChartTypeValue, BuilderFunction[]>}
|
|
116
|
+
*/
|
|
117
|
+
const CHART_PRESETS = {
|
|
118
|
+
// Line charts
|
|
119
|
+
[CHART_TYPES.LINE_CHART]: [
|
|
120
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
121
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
122
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
123
|
+
],
|
|
124
|
+
[CHART_TYPES.LINE_CHART_SMOOTH]: [
|
|
125
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
126
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
127
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
128
|
+
],
|
|
129
|
+
[CHART_TYPES.LINE_CHART_FORECAST]: [
|
|
130
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
131
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
132
|
+
withChartForecast, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
133
|
+
],
|
|
134
|
+
|
|
135
|
+
// Area charts
|
|
136
|
+
[CHART_TYPES.AREA_CHART]: [
|
|
137
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
138
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
139
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
140
|
+
],
|
|
141
|
+
[CHART_TYPES.AREA_CHART_SMOOTH]: [
|
|
142
|
+
withTooltip, withLabel, withSubtitle,
|
|
143
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
144
|
+
withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
145
|
+
],
|
|
146
|
+
|
|
147
|
+
// Polygon chart
|
|
148
|
+
[CHART_TYPES.POLYGON_CHART]: [
|
|
149
|
+
withTooltip, withLabel, withSubtitle,
|
|
150
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
151
|
+
withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
152
|
+
],
|
|
153
|
+
|
|
154
|
+
// Column charts
|
|
155
|
+
[CHART_TYPES.COLUMN_CHART]: [
|
|
156
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
157
|
+
withWidgetLibrary, withTableOptions, withTableDesignOptions,
|
|
158
|
+
withChart, withNegativeNumberFormat, withDeltaColumnForDrillDown, withAdvanced, withLegends,
|
|
159
|
+
],
|
|
160
|
+
[CHART_TYPES.COLUMN_CHART_STACKED]: [
|
|
161
|
+
withAxisY, withAxisX, withTooltip, withLabelWithPercentage, withSubtitle,
|
|
162
|
+
withWidgetLibrary, withTableOptions, withTableDesignOptions,
|
|
163
|
+
withChartGrid, withDeltaColumn, withAdvanced, withLegends,
|
|
164
|
+
],
|
|
165
|
+
[CHART_TYPES.COLUMN_CHART_STACKED_PERCENT]: [
|
|
166
|
+
withAxisYPercentStacked, withAxisX, withTooltip, withLabelWithPercentagePercentStacked, withSubtitle,
|
|
167
|
+
withWidgetLibrary, withTableOptions, withTableDesignOptions,
|
|
168
|
+
withChartGrid, withAdvanced, withLegends,
|
|
169
|
+
],
|
|
170
|
+
|
|
171
|
+
// Combo charts
|
|
172
|
+
[CHART_TYPES.COMBO_CHART]: [
|
|
173
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
174
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
175
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
176
|
+
],
|
|
177
|
+
[CHART_TYPES.COMBO_COLUMN_CHART]: [
|
|
178
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
179
|
+
withWidgetLibrary, withTableOptions, withTableDesignOptions,
|
|
180
|
+
withChart, withNegativeNumberFormat, withDeltaColumnForDrillDown, withAdvanced, withLegends,
|
|
181
|
+
],
|
|
182
|
+
[CHART_TYPES.COMBO_STACKED_CHART]: [
|
|
183
|
+
withAxisY, withAxisX, withTooltip, withLabelWithPercentage, withSubtitle,
|
|
184
|
+
withWidgetLibrary, withTableOptions, withTableDesignOptions,
|
|
185
|
+
withChartGrid, withDeltaColumn, withAdvanced, withLegends,
|
|
186
|
+
],
|
|
187
|
+
|
|
188
|
+
// Bar charts
|
|
189
|
+
[CHART_TYPES.BAR_CHART]: [
|
|
190
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
191
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
192
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
193
|
+
],
|
|
194
|
+
[CHART_TYPES.BAR_CHART_STACKED]: [
|
|
195
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
196
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
197
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
198
|
+
],
|
|
199
|
+
[CHART_TYPES.BAR_CHART_STACKED_PERCENT]: [
|
|
200
|
+
withAxisYPercentStacked, withAxisX, withTooltip, withLabelWithPercentagePercentStacked, withSubtitle,
|
|
201
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
202
|
+
withChartGrid, withAdvanced, withLegends,
|
|
203
|
+
],
|
|
204
|
+
|
|
205
|
+
// Scatter chart
|
|
206
|
+
[CHART_TYPES.SCATTER_CHART]: [
|
|
207
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
208
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
209
|
+
withChartGrid, withNegativeNumberFormat, withDeltaColumn, withAdvanced, withLegends,
|
|
210
|
+
],
|
|
211
|
+
|
|
212
|
+
// Pie charts
|
|
213
|
+
[CHART_TYPES.PIE_CHART]: [
|
|
214
|
+
withTooltipPie, withLabelPie, withSubtitle,
|
|
215
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
216
|
+
withChart, withNegativeNumberFormat, withAdvanced, withLegends,
|
|
217
|
+
],
|
|
218
|
+
[CHART_TYPES.PIE_CHART_DRILLDOWN]: [
|
|
219
|
+
withTooltipPie, withLabelPie, withSubtitle,
|
|
220
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
221
|
+
withChart, withNegativeNumberFormat, withAdvanced, withLegends,
|
|
222
|
+
],
|
|
223
|
+
[CHART_TYPES.DONUT_CHART]: [
|
|
224
|
+
withTooltipPie, withLabelPie, withSubtitle,
|
|
225
|
+
withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
226
|
+
withChart, withNegativeNumberFormat, withAdvanced, withLegends,
|
|
227
|
+
withChartPosition, withTotalValueLabelDonut,
|
|
228
|
+
],
|
|
229
|
+
|
|
230
|
+
// Gauge charts
|
|
231
|
+
[CHART_TYPES.GAUGE_CHART_ENHANCED]: [
|
|
232
|
+
withLabelGauge, withTooltipGauge, withSubtitle,
|
|
233
|
+
withTableOptionsGauge, withTableDesignOptions,
|
|
234
|
+
withGaugeGoal, withGaugeSegments, withGaugeIsAbsolute,
|
|
235
|
+
],
|
|
236
|
+
[CHART_TYPES.GAUGE_CHART_DYNAMIC_GOAL]: [
|
|
237
|
+
withLabelGauge, withTooltipGauge, withSubtitle,
|
|
238
|
+
withTableOptionsGauge, withTableDesignOptions,
|
|
239
|
+
withGaugeGoal, withGaugeSegments, withGaugeIsAbsolute,
|
|
240
|
+
],
|
|
241
|
+
[CHART_TYPES.GAUGE_CHART_CATEGORIES_SUMMARY]: [
|
|
242
|
+
withLabelGauge, withTooltipGauge, withSubtitle,
|
|
243
|
+
],
|
|
244
|
+
|
|
245
|
+
// KPI widgets
|
|
246
|
+
[CHART_TYPES.KPI_WIDGET]: [
|
|
247
|
+
withValue, withRange, withWidgetLibrary, withName,
|
|
248
|
+
withTableOptionsTranspose, withTableDesignOptions,
|
|
249
|
+
withNegativeNumberFormat, withLegends,
|
|
250
|
+
],
|
|
251
|
+
[CHART_TYPES.SMART_KPI]: [
|
|
252
|
+
withValue, withRange, withWidgetLibrary, withName,
|
|
253
|
+
withTableOptionsTranspose, withTableDesignOptions,
|
|
254
|
+
withNegativeNumberFormat, withLegends,
|
|
255
|
+
],
|
|
256
|
+
|
|
257
|
+
// Text widget
|
|
258
|
+
[CHART_TYPES.TEXT_WIDGET]: [
|
|
259
|
+
withName, withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
260
|
+
withNegativeNumberFormat, withLegends,
|
|
261
|
+
],
|
|
262
|
+
|
|
263
|
+
// Table only
|
|
264
|
+
[CHART_TYPES.TABLE_ONLY]: [
|
|
265
|
+
withSubtitle, withWidgetLibrary, withTableOptionsTranspose, withTableDesignOptions,
|
|
266
|
+
withNegativeNumberFormat, withDeltaColumn, withAdvanced,
|
|
267
|
+
],
|
|
268
|
+
|
|
269
|
+
// Waterfall charts
|
|
270
|
+
[CHART_TYPES.WATERFALL_BREAKDOWN]: [
|
|
271
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
272
|
+
withWidgetLibrary, withChart, withNegativeNumberFormat, withAdvanced, withLegends,
|
|
273
|
+
],
|
|
274
|
+
[CHART_TYPES.WATERFALL_WALKTHROUGH]: [
|
|
275
|
+
withAxisY, withAxisX, withTooltip, withLabel, withSubtitle,
|
|
276
|
+
withWidgetLibrary, withChart, withNegativeNumberFormat, withAdvanced, withLegends,
|
|
277
|
+
],
|
|
278
|
+
|
|
279
|
+
// Legacy gauge charts (kept for backwards compatibility)
|
|
280
|
+
[CHART_TYPES.GAUGE_SOLID_CHART]: [],
|
|
281
|
+
[CHART_TYPES.GAUGE_CHART]: [],
|
|
282
|
+
|
|
283
|
+
// Non-chart types (kept for type completeness)
|
|
284
|
+
[CHART_TYPES.PUBLISHED_ITEM]: [],
|
|
285
|
+
[CHART_TYPES.RICH_TEXT]: [],
|
|
286
|
+
[CHART_TYPES.EXCEL_VIEWER]: [],
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// ============================================================================
|
|
290
|
+
// Utility Functions
|
|
291
|
+
// ============================================================================
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Gets the suboption key for a builder function.
|
|
295
|
+
* @param {BuilderFunction} builder - The builder function
|
|
296
|
+
* @returns {SuboptionKey|undefined} The suboption key
|
|
297
|
+
*/
|
|
298
|
+
const getBuilderKey = (builder) => BUILDER_KEY_MAP.get(builder);
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Gets the preset configuration for a chart type.
|
|
302
|
+
* @param {import('./constants').ChartTypeValue} chartType - The chart type identifier
|
|
303
|
+
* @returns {BuilderFunction[]|undefined} Array of builder functions or undefined if not found
|
|
304
|
+
*/
|
|
305
|
+
const getPresetForChart = (chartType) => CHART_PRESETS[chartType];
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Builder configuration options passed to builder functions.
|
|
309
|
+
* @typedef {Object} BuilderConfig
|
|
310
|
+
* @property {import('./constants').ChartTypesMap} [CHART_TYPES] - Chart types enum
|
|
311
|
+
* @property {(featureName: string) => boolean} [hasFeature] - Feature flag checker
|
|
312
|
+
* @property {string} [ENABLE_GAUGE_DYNAMIC_GOAL] - Feature flag name
|
|
313
|
+
* @property {import('./builders').GaugeSegment[]} [defaultSegments] - Default gauge segments
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Builder function type.
|
|
318
|
+
* @callback BuilderFunction
|
|
319
|
+
* @param {BuilderConfig} [config] - Configuration options
|
|
320
|
+
* @returns {import('./builders').SuboptionDefinition} The suboption definition
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Builds the suboptions object for a chart type using its preset.
|
|
325
|
+
* @param {string} chartType - The chart type identifier
|
|
326
|
+
* @param {BuilderConfig} [config={}] - Configuration to pass to builders
|
|
327
|
+
* @returns {Record<string, import('./builders').SuboptionDefinition>} The suboptions object
|
|
328
|
+
*/
|
|
329
|
+
const buildSuboptionsForChart = (chartType, config = {}) => {
|
|
330
|
+
const preset = CHART_PRESETS[/** @type {import('./constants').ChartTypeValue} */ (chartType)];
|
|
331
|
+
if (!preset) {
|
|
332
|
+
return {};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** @type {Record<string, import('./builders').SuboptionDefinition>} */
|
|
336
|
+
const suboptions = {};
|
|
337
|
+
preset.forEach((builder) => {
|
|
338
|
+
const key = BUILDER_KEY_MAP.get(builder);
|
|
339
|
+
if (key) {
|
|
340
|
+
suboptions[key] = builder(config);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
return suboptions;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Builds a complete suboptions object from an array of builders.
|
|
349
|
+
* @param {BuilderFunction[]} builders - Array of builder functions
|
|
350
|
+
* @param {BuilderConfig} [config={}] - Configuration to pass to builders
|
|
351
|
+
* @returns {Record<string, import('./builders').SuboptionDefinition>} The suboptions object
|
|
352
|
+
*/
|
|
353
|
+
const buildSuboptions = (builders, config = {}) => {
|
|
354
|
+
/** @type {Record<string, import('./builders').SuboptionDefinition>} */
|
|
355
|
+
const suboptions = {};
|
|
356
|
+
builders.forEach((builder) => {
|
|
357
|
+
const key = BUILDER_KEY_MAP.get(builder);
|
|
358
|
+
if (key) {
|
|
359
|
+
suboptions[key] = builder(config);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
return suboptions;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Gets all available chart types.
|
|
367
|
+
* @returns {import('./constants').ChartTypeValue[]} Array of chart type identifiers
|
|
368
|
+
*/
|
|
369
|
+
const getChartTypes = () => /** @type {import('./constants').ChartTypeValue[]} */ (Object.values(CHART_TYPES));
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Checks if a chart type has a preset defined.
|
|
373
|
+
* @param {string} chartType - The chart type identifier
|
|
374
|
+
* @returns {boolean} True if preset exists
|
|
375
|
+
*/
|
|
376
|
+
const hasPreset = (chartType) => chartType in CHART_PRESETS;
|
|
377
|
+
|
|
378
|
+
module.exports = {
|
|
379
|
+
CHART_TYPES,
|
|
380
|
+
CHART_PRESETS,
|
|
381
|
+
BUILDER_KEY_MAP,
|
|
382
|
+
getBuilderKey,
|
|
383
|
+
getPresetForChart,
|
|
384
|
+
buildSuboptionsForChart,
|
|
385
|
+
buildSuboptions,
|
|
386
|
+
getChartTypes,
|
|
387
|
+
hasPreset,
|
|
388
|
+
};
|
|
@@ -35,9 +35,9 @@ export class GraphTableRenderer {
|
|
|
35
35
|
* Creates Pivot Data Model that works we BE data response to aggregate data to render with Chart and Table
|
|
36
36
|
* @param {Rows} rows BE data response
|
|
37
37
|
* @param {GTROptions} options
|
|
38
|
-
* @returns {
|
|
38
|
+
* @returns {GraphTableRenderer}
|
|
39
39
|
*/
|
|
40
|
-
createPivotModel(rows: Rows, options: GTROptions):
|
|
40
|
+
createPivotModel(rows: Rows, options: GTROptions): GraphTableRenderer;
|
|
41
41
|
/**
|
|
42
42
|
* @returns {void}
|
|
43
43
|
*/
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
// Re-export error types
|
|
2
|
+
export * from './errors';
|
|
3
|
+
|
|
4
|
+
// Re-export GraphTableRenderer types
|
|
1
5
|
export * from './graph-table-renderer';
|
|
2
|
-
|
|
6
|
+
|
|
7
|
+
// Re-export options module types
|
|
8
|
+
export * from './options/builders';
|
|
9
|
+
export * from './options/constants';
|
|
10
|
+
export * from './options/elements';
|
|
11
|
+
export * from './options/helpers';
|
|
12
|
+
export * from './options/presets';
|