@gitlab/ui 72.12.0 → 72.12.1

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.
Files changed (209) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/charts.js +14 -0
  3. package/dist/components/base/accordion/accordion.js +73 -0
  4. package/dist/components/base/accordion/accordion_item.js +133 -0
  5. package/dist/components/base/alert/alert.js +222 -0
  6. package/dist/components/base/avatar/avatar.js +160 -0
  7. package/dist/components/base/avatar_labeled/avatar_labeled.js +107 -0
  8. package/dist/components/base/avatar_link/avatar_link.js +47 -0
  9. package/dist/components/base/avatars_inline/avatars_inline.js +119 -0
  10. package/dist/components/base/badge/badge.js +105 -0
  11. package/dist/components/base/banner/banner.js +139 -0
  12. package/dist/components/base/breadcrumb/breadcrumb.js +122 -0
  13. package/dist/components/base/breadcrumb/breadcrumb_item.js +73 -0
  14. package/dist/components/base/broadcast_message/broadcast_message.js +112 -0
  15. package/dist/components/base/broadcast_message/constants.js +5 -0
  16. package/dist/components/base/button/button.js +151 -0
  17. package/dist/components/base/button_group/button_group.js +47 -0
  18. package/dist/components/base/card/card.js +71 -0
  19. package/dist/components/base/carousel/carousel.js +48 -0
  20. package/dist/components/base/carousel/carousel_slide.js +47 -0
  21. package/dist/components/base/collapse/collapse.js +59 -0
  22. package/dist/components/base/datepicker/datepicker.js +386 -0
  23. package/dist/components/base/daterange_picker/daterange_picker.js +288 -0
  24. package/dist/components/base/drawer/drawer.js +127 -0
  25. package/dist/components/base/dropdown/dropdown.js +261 -0
  26. package/dist/components/base/dropdown/dropdown_divider.js +48 -0
  27. package/dist/components/base/dropdown/dropdown_form.js +48 -0
  28. package/dist/components/base/dropdown/dropdown_item.js +131 -0
  29. package/dist/components/base/dropdown/dropdown_section_header.js +48 -0
  30. package/dist/components/base/dropdown/dropdown_text.js +48 -0
  31. package/dist/components/base/filtered_search/common_story_options.js +14 -0
  32. package/dist/components/base/filtered_search/filtered_search.js +388 -0
  33. package/dist/components/base/filtered_search/filtered_search_suggestion.js +89 -0
  34. package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +138 -0
  35. package/dist/components/base/filtered_search/filtered_search_term.js +203 -0
  36. package/dist/components/base/filtered_search/filtered_search_token.js +384 -0
  37. package/dist/components/base/filtered_search/filtered_search_token_segment.js +420 -0
  38. package/dist/components/base/filtered_search/filtered_search_utils.js +242 -0
  39. package/dist/components/base/form/form.js +49 -0
  40. package/dist/components/base/form/form_checkbox/form_checkbox.js +78 -0
  41. package/dist/components/base/form/form_checkbox/form_checkbox_group.js +60 -0
  42. package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +79 -0
  43. package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +138 -0
  44. package/dist/components/base/form/form_checkbox_tree/models/constants.js +12 -0
  45. package/dist/components/base/form/form_checkbox_tree/models/node.js +51 -0
  46. package/dist/components/base/form/form_checkbox_tree/models/tree.js +199 -0
  47. package/dist/components/base/form/form_combobox/constants.js +55 -0
  48. package/dist/components/base/form/form_combobox/form_combobox.js +230 -0
  49. package/dist/components/base/form/form_date/form_date.js +143 -0
  50. package/dist/components/base/form/form_fields/form_field_validator.js +93 -0
  51. package/dist/components/base/form/form_fields/form_fields.js +214 -0
  52. package/dist/components/base/form/form_fields/mappers.js +13 -0
  53. package/dist/components/base/form/form_fields/validators.js +48 -0
  54. package/dist/components/base/form/form_group/form_group.js +97 -0
  55. package/dist/components/base/form/form_input/form_input.js +121 -0
  56. package/dist/components/base/form/form_input_group/form_input_group.js +108 -0
  57. package/dist/components/base/form/form_input_group/form_input_group_mixin.js +41 -0
  58. package/dist/components/base/form/form_radio/form_radio.js +65 -0
  59. package/dist/components/base/form/form_radio_group/form_radio_group.js +78 -0
  60. package/dist/components/base/form/form_select/constants.js +12 -0
  61. package/dist/components/base/form/form_select/form_select.js +82 -0
  62. package/dist/components/base/form/form_text/form_text.js +38 -0
  63. package/dist/components/base/form/form_textarea/form_textarea.js +112 -0
  64. package/dist/components/base/form/input_group_text/input_group_text.js +48 -0
  65. package/dist/components/base/icon/icon.js +111 -0
  66. package/dist/components/base/infinite_scroll/infinite_scroll.js +197 -0
  67. package/dist/components/base/keyset_pagination/keyset_pagination.js +151 -0
  68. package/dist/components/base/label/label.js +163 -0
  69. package/dist/components/base/link/link.js +50 -0
  70. package/dist/components/base/loading_icon/loading_icon.js +111 -0
  71. package/dist/components/base/markdown/markdown.js +52 -0
  72. package/dist/components/base/modal/modal.js +204 -0
  73. package/dist/components/base/nav/nav.js +48 -0
  74. package/dist/components/base/nav/nav_item.js +48 -0
  75. package/dist/components/base/nav/nav_item_dropdown.js +62 -0
  76. package/dist/components/base/navbar/navbar.js +48 -0
  77. package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +453 -0
  78. package/dist/components/base/new_dropdowns/base_dropdown/constants.js +4 -0
  79. package/dist/components/base/new_dropdowns/constants.js +21 -0
  80. package/dist/components/base/new_dropdowns/disclosure/constants.js +8 -0
  81. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +370 -0
  82. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_group.js +110 -0
  83. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +143 -0
  84. package/dist/components/base/new_dropdowns/disclosure/mock_data.js +147 -0
  85. package/dist/components/base/new_dropdowns/disclosure/utils.js +39 -0
  86. package/dist/components/base/new_dropdowns/listbox/listbox.js +767 -0
  87. package/dist/components/base/new_dropdowns/listbox/listbox_group.js +58 -0
  88. package/dist/components/base/new_dropdowns/listbox/listbox_item.js +91 -0
  89. package/dist/components/base/new_dropdowns/listbox/listbox_search_input.js +93 -0
  90. package/dist/components/base/new_dropdowns/listbox/mock_data.js +118 -0
  91. package/dist/components/base/new_dropdowns/listbox/utils.js +34 -0
  92. package/dist/components/base/paginated_list/paginated_list.js +180 -0
  93. package/dist/components/base/pagination/pagination.js +399 -0
  94. package/dist/components/base/path/data.js +34 -0
  95. package/dist/components/base/path/path.js +189 -0
  96. package/dist/components/base/popover/popover.js +110 -0
  97. package/dist/components/base/progress_bar/progress_bar.js +48 -0
  98. package/dist/components/base/search_box_by_click/search_box_by_click.js +235 -0
  99. package/dist/components/base/search_box_by_type/search_box_by_type.js +167 -0
  100. package/dist/components/base/segmented_control/segmented_control.js +109 -0
  101. package/dist/components/base/skeleton_loader/skeleton_loader.js +224 -0
  102. package/dist/components/base/sorting/sorting.js +171 -0
  103. package/dist/components/base/sorting/sorting_item.js +109 -0
  104. package/dist/components/base/table/constants.js +5 -0
  105. package/dist/components/base/table/table.js +89 -0
  106. package/dist/components/base/table_lite/table_lite.js +72 -0
  107. package/dist/components/base/tabs/constants.js +3 -0
  108. package/dist/components/base/tabs/tab/tab.js +83 -0
  109. package/dist/components/base/tabs/tabs/scrollable_tabs.js +143 -0
  110. package/dist/components/base/tabs/tabs/tabs.js +224 -0
  111. package/dist/components/base/toast/toast.js +82 -0
  112. package/dist/components/base/toggle/toggle.js +180 -0
  113. package/dist/components/base/token/token.js +85 -0
  114. package/dist/components/base/token_selector/helpers.js +5 -0
  115. package/dist/components/base/token_selector/token_container.js +165 -0
  116. package/dist/components/base/token_selector/token_selector.js +403 -0
  117. package/dist/components/base/token_selector/token_selector_dropdown.js +199 -0
  118. package/dist/components/base/tooltip/tooltip.js +55 -0
  119. package/dist/components/charts/area/area.js +311 -0
  120. package/dist/components/charts/bar/bar.js +253 -0
  121. package/dist/components/charts/chart/chart.js +215 -0
  122. package/dist/components/charts/column/column.js +226 -0
  123. package/dist/components/charts/discrete_scatter/discrete_scatter.js +203 -0
  124. package/dist/components/charts/gauge/gauge.js +208 -0
  125. package/dist/components/charts/heatmap/heatmap.js +295 -0
  126. package/dist/components/charts/heatmap/index.js +2 -0
  127. package/dist/components/charts/legend/legend.js +228 -0
  128. package/dist/components/charts/line/line.js +308 -0
  129. package/dist/components/charts/series_label/series_label.js +100 -0
  130. package/dist/components/charts/single_stat/single_stat.js +152 -0
  131. package/dist/components/charts/sparkline/sparkline.js +261 -0
  132. package/dist/components/charts/stacked_column/stacked_column.js +335 -0
  133. package/dist/components/charts/tooltip/tooltip.js +251 -0
  134. package/dist/components/experimental/duo/chat/components/duo_chat_conversation/duo_chat_conversation.js +83 -0
  135. package/dist/components/experimental/duo/chat/components/duo_chat_loader/duo_chat_loader.js +100 -0
  136. package/dist/components/experimental/duo/chat/components/duo_chat_message/copy_code_element.js +35 -0
  137. package/dist/components/experimental/duo/chat/components/duo_chat_message/duo_chat_message.js +115 -0
  138. package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +104 -0
  139. package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +64 -0
  140. package/dist/components/experimental/duo/chat/constants.js +23 -0
  141. package/dist/components/experimental/duo/chat/duo_chat.js +359 -0
  142. package/dist/components/experimental/duo/chat/mock_data.js +83 -0
  143. package/dist/components/experimental/duo/user_feedback/user_feedback.js +94 -0
  144. package/dist/components/experimental/duo/user_feedback/user_feedback_modal.js +124 -0
  145. package/dist/components/experimental/experiment_badge/constants.js +4 -0
  146. package/dist/components/experimental/experiment_badge/experiment_badge.js +107 -0
  147. package/dist/components/mixins/button_mixin.js +11 -0
  148. package/dist/components/mixins/safe_link_mixin.js +30 -0
  149. package/dist/components/mixins/tooltip_mixin.js +21 -0
  150. package/dist/components/regions/dashboard_skeleton/dashboard_skeleton.js +53 -0
  151. package/dist/components/regions/empty_state/empty_state.js +154 -0
  152. package/dist/components/shared_components/charts/tooltip_default_format.js +53 -0
  153. package/dist/components/shared_components/clear_icon_button/clear_icon_button.js +64 -0
  154. package/dist/components/shared_components/close_button/close_button.js +54 -0
  155. package/dist/components/utilities/animated_number/animated_number.js +131 -0
  156. package/dist/components/utilities/friendly_wrap/friendly_wrap.js +75 -0
  157. package/dist/components/utilities/intersection_observer/intersection_observer.js +88 -0
  158. package/dist/components/utilities/intersperse/intersperse.js +86 -0
  159. package/dist/components/utilities/sprintf/sprintf.js +172 -0
  160. package/dist/components/utilities/truncate/constants.js +7 -0
  161. package/dist/components/utilities/truncate/truncate.js +111 -0
  162. package/dist/components/utilities/truncate_text/constants.js +7 -0
  163. package/dist/components/utilities/truncate_text/truncate_text.js +146 -0
  164. package/dist/config.js +86 -0
  165. package/dist/directives/collapse_toggle.js +1 -0
  166. package/dist/directives/hover_load/hover_load.js +45 -0
  167. package/dist/directives/modal.js +1 -0
  168. package/dist/directives/outside/get_event_like_time_stamp.js +33 -0
  169. package/dist/directives/outside/outside.js +106 -0
  170. package/dist/directives/resize_observer/resize_observer.js +51 -0
  171. package/dist/directives/safe_html/constants.js +6 -0
  172. package/dist/directives/safe_html/safe_html.js +39 -0
  173. package/dist/directives/safe_link/mock_data.js +10 -0
  174. package/dist/directives/safe_link/safe_link.js +65 -0
  175. package/dist/directives/tooltip.js +1 -0
  176. package/dist/index.css +7 -0
  177. package/dist/index.css.map +1 -0
  178. package/dist/index.js +105 -0
  179. package/dist/tokens/common_story_options.js +54 -0
  180. package/dist/tokens/css/tokens.css +1 -1
  181. package/dist/tokens/css/tokens.dark.css +1 -1
  182. package/dist/tokens/js/tokens.dark.js +1 -1
  183. package/dist/tokens/js/tokens.js +1 -1
  184. package/dist/tokens/scss/_tokens.dark.scss +1 -1
  185. package/dist/tokens/scss/_tokens.scss +1 -1
  186. package/dist/utils/breakpoints.js +20 -0
  187. package/dist/utils/charts/config.js +556 -0
  188. package/dist/utils/charts/constants.js +63 -0
  189. package/dist/utils/charts/mock_data.js +211 -0
  190. package/dist/utils/charts/story_config.js +42 -0
  191. package/dist/utils/charts/theme.js +192 -0
  192. package/dist/utils/charts/utils.js +54 -0
  193. package/dist/utils/constants.js +288 -0
  194. package/dist/utils/data_utils.js +21 -0
  195. package/dist/utils/datetime_utility.js +61 -0
  196. package/dist/utils/i18n.js +15 -0
  197. package/dist/utils/is_slot_empty.js +38 -0
  198. package/dist/utils/number_utils.js +124 -0
  199. package/dist/utils/stories_constants.js +29 -0
  200. package/dist/utils/stories_utils.js +13 -0
  201. package/dist/utils/story_decorators/container.js +16 -0
  202. package/dist/utils/string_utils.js +69 -0
  203. package/dist/utils/svgs/svg_paths.js +7 -0
  204. package/dist/utils/test_utils.js +33 -0
  205. package/dist/utils/use_fake_date.js +29 -0
  206. package/dist/utils/use_mock_intersection_observer.js +108 -0
  207. package/dist/utils/utils.js +197 -0
  208. package/dist/utils.js +5 -0
  209. package/package.json +1 -1
@@ -0,0 +1,556 @@
1
+ import castArray from 'lodash/castArray';
2
+ import merge from 'lodash/merge';
3
+ import { BLUE_500 } from '../../../dist/tokens/js/tokens';
4
+ import { GlBreakpointInstance } from '../breakpoints';
5
+ import { columnOptions } from '../constants';
6
+ import { areDatesEqual } from '../datetime_utility';
7
+ import { engineeringNotation } from '../number_utils';
8
+ import { hexToRgba } from '../utils';
9
+ import { arrowSymbol, ANNOTATIONS_SERIES_NAME, CHART_TYPE_BAR, CHART_TYPE_LINE } from './constants';
10
+
11
+ const defaultAreaOpacity = 0.2;
12
+ const defaultFontSize = 12;
13
+ const defaultHeight = 400;
14
+ const defaultWidth = 300;
15
+ const validRenderers = ['canvas', 'svg'];
16
+ const toolboxHeight = 14;
17
+ const axes = {
18
+ name: 'Value',
19
+ type: 'value',
20
+ nameLocation: 'center'
21
+ };
22
+ const xAxis = merge({}, axes, {
23
+ boundaryGap: false,
24
+ splitLine: {
25
+ show: false
26
+ }
27
+ });
28
+ const yAxis = merge({}, axes, {
29
+ nameGap: 50,
30
+ axisLabel: {
31
+ formatter: num => engineeringNotation(num, 2)
32
+ }
33
+ });
34
+ const grid = {
35
+ top: 16,
36
+ bottom: 44,
37
+ left: 64,
38
+ right: 32
39
+ };
40
+ const defaultChartOptions = {
41
+ grid,
42
+ xAxis,
43
+ yAxis
44
+ };
45
+ const gridWithSecondaryYAxis = {
46
+ ...grid,
47
+ right: 64
48
+ };
49
+ const lineStyle = {
50
+ symbol: 'circle',
51
+ type: 'line',
52
+ width: 2
53
+ };
54
+
55
+ /**
56
+ * Annotations series consists of annotations lines
57
+ * along with markers. Annotations co-exist with data
58
+ * series but have their own virtual coords so that they stay put
59
+ * irrespective of data series extents.
60
+ */
61
+ const annotationsYAxisCoords = {
62
+ min: 0,
63
+ pos: 3,
64
+ // 3% height of chart's grid
65
+ max: 100,
66
+ show: false
67
+ };
68
+ const symbolSize = 6;
69
+
70
+ /**
71
+ * These comparison operators are currently in monitoring
72
+ * charts that have alerting related data.
73
+ *
74
+ * {Array} Possible values for greater than
75
+ */
76
+ const GREATER_THAN = ['>', '>'];
77
+
78
+ /**
79
+ * These comparison operators are currently in monitoring
80
+ * charts that have alerting related data.
81
+ *
82
+ * {Array} Possible values for less than
83
+ */
84
+ const LESS_THAN = ['<', '&lt;'];
85
+
86
+ /**
87
+ * All default dataZoom configs will have slider & inside
88
+ * (for reference, see https://gitlab.com/gitlab-org/gitlab-ui/issues/240)
89
+ * Inside is disabled for larger viewports (lg and xl)
90
+ * and is specifically to enable touch zoom for mobile devices
91
+ * @param {Object} options
92
+ */
93
+ const getDataZoomConfig = function () {
94
+ let {
95
+ filterMode = 'none'
96
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
97
+ const disabledBreakpoints = ['lg', 'xl'];
98
+ const disabled = disabledBreakpoints.includes(GlBreakpointInstance.getBreakpointSize());
99
+ const minSpan = filterMode === 'none' ? 0.01 : null;
100
+ return {
101
+ grid: {
102
+ bottom: 81
103
+ },
104
+ xAxis: {
105
+ nameGap: 67
106
+ },
107
+ dataZoom: [{
108
+ type: 'slider',
109
+ bottom: 22,
110
+ filterMode,
111
+ minSpan
112
+ }, {
113
+ type: 'inside',
114
+ filterMode,
115
+ minSpan,
116
+ disabled
117
+ }]
118
+ };
119
+ };
120
+
121
+ // All chart options can be merged but series
122
+ // needs to be concatenated.
123
+ // Series can be an object for single series or
124
+ // an array of objects.
125
+ const mergeSeriesToOptions = function (options) {
126
+ let series = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
127
+ const {
128
+ series: optSeries = []
129
+ } = options;
130
+ return {
131
+ ...options,
132
+ series: [...castArray(series), ...castArray(optSeries)]
133
+ };
134
+ };
135
+
136
+ /**
137
+ * If an annotation series exists, the chart options should have an
138
+ * array of yAxis settings so that the series can exist in its own
139
+ * coordinate system without interfering with the data series
140
+ *
141
+ * @param {Object} options options to merge annotation series yAxis with
142
+ * @param {Boolean} hasAnnotations if annotation series yAxis should be merged
143
+ * @returns {Object} options
144
+ */
145
+ const mergeAnnotationAxisToOptions = function (options) {
146
+ let hasAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
147
+ return {
148
+ ...options,
149
+ ...(hasAnnotations && {
150
+ yAxis: [options.yAxis, annotationsYAxisCoords]
151
+ })
152
+ };
153
+ };
154
+ const dataZoomAdjustments = dataZoom => {
155
+ // handle cases where dataZoom is array and object.
156
+ const useSlider = dataZoom && Array.isArray(dataZoom) ? dataZoom.length : Boolean(dataZoom);
157
+ return useSlider ? getDataZoomConfig({
158
+ filterMode: 'weakFilter'
159
+ }) : [];
160
+ };
161
+
162
+ /**
163
+ * Generate eCharts markArea arrays for thresholds and annotations.
164
+ *
165
+ * This method purposefully has no knowledge of comparison
166
+ * operators used in thresholds as it is not necessary and instead
167
+ * expects explict value bounds
168
+ *
169
+ * Examples:
170
+ * { min: 7, max: 10 } => markArea from 7 to 10
171
+ * { min: 1, max: 7 } => markArea from 1 to 7
172
+ *
173
+ * If min and max are equal it would be markLine and would be
174
+ * generated by `generateMarkLines`
175
+ *
176
+ * @param {Object} threshold Threshold/Annotation object with min and max values
177
+ * @param {String} axis markArea is generated against this axis
178
+ * @returns {Array}
179
+ */
180
+ const generateMarkArea = function (_ref) {
181
+ let {
182
+ min,
183
+ max
184
+ } = _ref;
185
+ let axis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yAxis';
186
+ return [{
187
+ [axis]: min
188
+ }, {
189
+ [axis]: max
190
+ }];
191
+ };
192
+
193
+ /**
194
+ * Generate eCharts markLine objects for thresholds and annotations.
195
+ *
196
+ * This method purposefully has no knowledge of comparison
197
+ * operators used in thresholds as it is not necessary and instead
198
+ * expects explict value bounds
199
+ *
200
+ * In order to continue supporting existing thresholds format, min
201
+ * is passed as undefined so the correct markLine object is generated.
202
+ *
203
+ * For annotations, min and max will be the same value.
204
+ *
205
+ * Threshold Examples:
206
+ * { max: 7 } => markLine at 7
207
+ *
208
+ * Annotation Examples:
209
+ * { min: 7, max: 7 } => markLine at 7
210
+ *
211
+ * @param {Object} threshold Threshold/Annotation object with min and max values
212
+ * @param {String} axis markLine is generated against this axis
213
+ * @returns {Object}
214
+ */
215
+ const generateMarkLines = function (_ref2) {
216
+ let {
217
+ min,
218
+ max
219
+ } = _ref2;
220
+ let axis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yAxis';
221
+ if (min) {
222
+ return {
223
+ [axis]: min
224
+ };
225
+ }
226
+ return {
227
+ [axis]: max
228
+ };
229
+ };
230
+
231
+ /**
232
+ * Generates markPoints that are placed under the markLines.
233
+ *
234
+ * These are used only in annotation lines. For annotation lines,
235
+ * both min and max are same values so only one is enough to generate
236
+ * the markPoint.
237
+ *
238
+ * @param {Object} annotation object
239
+ * @return {Object}
240
+ */
241
+ const generateMarkPoints = _ref3 => {
242
+ let {
243
+ min,
244
+ tooltipData
245
+ } = _ref3;
246
+ return {
247
+ name: 'annotations',
248
+ xAxis: min,
249
+ yAxis: 0,
250
+ tooltipData
251
+ };
252
+ };
253
+
254
+ /**
255
+ * Generate set of markAreas and markLines to draw on charts
256
+ * as alert thresholds.
257
+ *
258
+ * Alert thresholds always have a markLine associated with a markArea
259
+ *
260
+ * @param {Array} thresholds Array of alert thresholds
261
+ * @returns {Object} markAreas and markLines
262
+ */
263
+ function getThresholdConfig(thresholds) {
264
+ if (!thresholds.length) {
265
+ return {};
266
+ }
267
+ const data = thresholds.reduce((acc, alert) => {
268
+ const {
269
+ threshold,
270
+ operator
271
+ } = alert;
272
+ if (GREATER_THAN.includes(operator)) {
273
+ acc.areas.push(generateMarkArea({
274
+ min: threshold,
275
+ max: Infinity
276
+ }));
277
+ } else if (LESS_THAN.includes(operator)) {
278
+ acc.areas.push(generateMarkArea({
279
+ min: Number.NEGATIVE_INFINITY,
280
+ max: threshold
281
+ }));
282
+ }
283
+ acc.lines.push(generateMarkLines({
284
+ max: threshold
285
+ }));
286
+ return acc;
287
+ }, {
288
+ lines: [],
289
+ areas: []
290
+ });
291
+ return {
292
+ markLine: {
293
+ data: data.lines
294
+ },
295
+ markArea: {
296
+ data: data.areas,
297
+ zlevel: -1
298
+ }
299
+ };
300
+ }
301
+
302
+ /**
303
+ * This method is only for testing both markLines and markAreas
304
+ * that are used for annotations.
305
+ *
306
+ * `getAnnotationsConfig` as of %12.10 supports only markLines.
307
+ * But this method can generate lines, points and areas.
308
+ *
309
+ * @param {Array} annotations Array of annotation objects
310
+ * @returns {Object} { areas, lines, points }
311
+ */
312
+ const parseAnnotations = annotations => annotations.reduce((acc, annotation) => {
313
+ // because only markLines are supported all cases will
314
+ // satisfy this condition. This is more of a sanity check
315
+ // until markAreas are supported.
316
+ // https://gitlab.com/gitlab-org/gitlab/-/issues/212910
317
+ if (areDatesEqual(annotation.min, annotation.max)) {
318
+ acc.lines.push(generateMarkLines(annotation, 'xAxis'));
319
+ acc.points.push(generateMarkPoints(annotation));
320
+ return acc;
321
+ }
322
+ acc.areas.push(generateMarkArea(annotation, 'xAxis'));
323
+ return acc;
324
+ }, {
325
+ areas: [],
326
+ lines: [],
327
+ points: []
328
+ });
329
+
330
+ /**
331
+ * Generate set of markAreas and markLines to draw on charts
332
+ * as annotations.
333
+ *
334
+ * Annotations as of %12.10 will only be markLines.
335
+ * markAreas are not supported yet. They are generated by
336
+ * `parseAnnotations` but not rendered.
337
+ *
338
+ * @param {Array} annotations Array of annotations
339
+ * @returns {Object} { markLines }
340
+ */
341
+ const getAnnotationsConfig = annotations => {
342
+ if (!annotations.length) {
343
+ return {};
344
+ }
345
+
346
+ // annotations parsing is moved out so that it can be tested
347
+ // for markLines and markAreas.
348
+ const {
349
+ lines,
350
+ points
351
+ } = parseAnnotations(annotations);
352
+ return {
353
+ markLine: {
354
+ lineStyle: {
355
+ color: BLUE_500
356
+ },
357
+ silent: true,
358
+ data: lines
359
+ },
360
+ markPoint: {
361
+ itemStyle: {
362
+ color: BLUE_500
363
+ },
364
+ symbol: arrowSymbol,
365
+ symbolSize: '8',
366
+ symbolOffset: [0, ' 60%'],
367
+ data: points
368
+ }
369
+ };
370
+ };
371
+
372
+ /**
373
+ * Given thresholds and annotations options, this method generates
374
+ * an annotation series that co-exists along with the data series.
375
+ *
376
+ * yAxis option is useful in cases where multiple yAxis settings
377
+ * are used in a chart. Currently, all of our charts have single
378
+ * yAxis settings.
379
+ *
380
+ * @param {Object} params Thresholds, annotations and yAxis options
381
+ * @returns {Object} Annotation series
382
+ */
383
+ const generateAnnotationSeries = function (annotations) {
384
+ let yAxisIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
385
+ if (!annotations.length) {
386
+ return null;
387
+ }
388
+ return merge({
389
+ name: ANNOTATIONS_SERIES_NAME,
390
+ yAxisIndex,
391
+ type: 'scatter',
392
+ data: []
393
+ }, getAnnotationsConfig(annotations));
394
+ };
395
+
396
+ /**
397
+ * This method generates the data series and relevant defaults for a bar chart
398
+ *
399
+ * @param {Object} options
400
+ * @param {string} options.name - xAxis name for the chart
401
+ * @param {string} options.color - color to render the data series
402
+ * @param {Array} options.data - data set to be rendered
403
+ * @param {string} [options.stack] - controls how the stacked charts should render either `stacked` or `tiled`
404
+ * @param {number} [options.yAxisIndex] - specifies the yAxis to use (if there are multiple)
405
+ * @returns {Object} Bar chart series
406
+ */
407
+ const generateBarSeries = _ref4 => {
408
+ let {
409
+ name,
410
+ color,
411
+ data = [],
412
+ stack = columnOptions.stacked,
413
+ yAxisIndex = 0
414
+ } = _ref4;
415
+ return {
416
+ type: CHART_TYPE_BAR,
417
+ name,
418
+ data,
419
+ stack,
420
+ barMaxWidth: '50%',
421
+ yAxisIndex,
422
+ itemStyle: {
423
+ color: hexToRgba(color, 0.2),
424
+ borderColor: color,
425
+ borderWidth: 1
426
+ },
427
+ emphasis: {
428
+ itemStyle: {
429
+ color: hexToRgba(color, 0.4)
430
+ }
431
+ }
432
+ };
433
+ };
434
+
435
+ /**
436
+ * This method generates the data series and relevant defaults for a line chart
437
+ *
438
+ * @param {Object} options
439
+ * @param {string} options.name - xAxis name for the chart
440
+ * @param {string} options.color - color to render the data series
441
+ * @param {Array} options.data - data set to be rendered
442
+ * @param {number} [options.yAxisIndex] - specifies the yAxis to use (if there are multiple)
443
+ * @returns {Object} Line chart series
444
+ */
445
+ const generateLineSeries = _ref5 => {
446
+ let {
447
+ name,
448
+ color,
449
+ data = [],
450
+ yAxisIndex = 0
451
+ } = _ref5;
452
+ return {
453
+ name,
454
+ data,
455
+ type: CHART_TYPE_LINE,
456
+ yAxisIndex,
457
+ lineStyle: {
458
+ color
459
+ },
460
+ itemStyle: {
461
+ color
462
+ }
463
+ };
464
+ };
465
+ const getTooltipTitle = function () {
466
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
467
+ let titleAxisName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
468
+ if (!params) return '';
469
+ const title = params.seriesData.reduce((acc, _ref6) => {
470
+ let {
471
+ value
472
+ } = _ref6;
473
+ if (acc.includes(value[0])) {
474
+ return acc;
475
+ }
476
+ return [...acc, value[0]];
477
+ }, []).join(', ');
478
+ return titleAxisName ? `${title} (${titleAxisName})` : title;
479
+ };
480
+ const getTooltipContent = function () {
481
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
482
+ let valueAxisName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
483
+ if (!params) {
484
+ return {};
485
+ }
486
+ const {
487
+ seriesData
488
+ } = params;
489
+ if (seriesData.length === 1) {
490
+ const {
491
+ value: [, yValue],
492
+ seriesName
493
+ } = seriesData[0];
494
+ return {
495
+ [valueAxisName || seriesName]: {
496
+ value: yValue,
497
+ color: '' // ignore color when showing a single series
498
+ }
499
+ };
500
+ }
501
+ return seriesData.reduce((acc, _ref7) => {
502
+ let {
503
+ value: [, yValue],
504
+ seriesName,
505
+ color
506
+ } = _ref7;
507
+ acc[seriesName] = {
508
+ value: yValue,
509
+ color
510
+ };
511
+ return acc;
512
+ }, {});
513
+ };
514
+
515
+ /**
516
+ * The method works well if tooltip content should be against y-axis values.
517
+ * However, for bar charts, the tooltip should be against x-axis values.
518
+ * This method should be updated to work with all types of visualizations.
519
+ * https://gitlab.com/gitlab-org/gitlab-ui/-/issues/674
520
+ *
521
+ * @param {Object} params series data
522
+ * @param {String} yAxisTitle y-axis title
523
+ * @returns {Object} tooltip title and content
524
+ * @deprecated Use getTooltipContent and getTooltipContent to obtain the tooltip
525
+ */
526
+ const getDefaultTooltipContent = function (params) {
527
+ let yAxisTitle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
528
+ const seriesDataLength = params.seriesData.length;
529
+ const {
530
+ xLabels,
531
+ tooltipContent
532
+ } = params.seriesData.reduce((acc, chartItem) => {
533
+ const [title, value] = chartItem.value || [];
534
+ // Let's use the y axis title as series name when only one series exists
535
+ // This way, TooltipDefaultFormat will display the y axis title as label
536
+ const seriesName = seriesDataLength === 1 && yAxisTitle ? yAxisTitle : chartItem.seriesName;
537
+ const color = seriesDataLength === 1 ? '' : chartItem.color;
538
+ acc.tooltipContent[seriesName] = {
539
+ value,
540
+ color
541
+ };
542
+ if (!acc.xLabels.includes(title)) {
543
+ acc.xLabels.push(title);
544
+ }
545
+ return acc;
546
+ }, {
547
+ xLabels: [],
548
+ tooltipContent: {}
549
+ });
550
+ return {
551
+ xLabels,
552
+ tooltipContent
553
+ };
554
+ };
555
+
556
+ export { annotationsYAxisCoords, axes, dataZoomAdjustments, defaultAreaOpacity, defaultChartOptions, defaultFontSize, defaultHeight, defaultWidth, generateAnnotationSeries, generateBarSeries, generateLineSeries, getAnnotationsConfig, getDataZoomConfig, getDefaultTooltipContent, getThresholdConfig, getTooltipContent, getTooltipTitle, grid, gridWithSecondaryYAxis, lineStyle, mergeAnnotationAxisToOptions, mergeSeriesToOptions, parseAnnotations, symbolSize, toolboxHeight, validRenderers, xAxis, yAxis };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * As of %12.10 all annotations are added as a decorations
3
+ * by piggybacking a scatter series. The series should
4
+ * have 'annotations' as name for the annotation tooltips
5
+ * to work.
6
+ *
7
+ * More info here https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28825
8
+ *
9
+ */
10
+ const ANNOTATIONS_SERIES_NAME = 'annotations';
11
+ /**
12
+ * Annotations have a line (markLine) and an arrow (markPoint).
13
+ * When the markPoint is hovered, a tooltip is displayed to
14
+ * show the annotation description.
15
+ *
16
+ * All markPoints have this component type
17
+ */
18
+ const ANNOTATIONS_COMPONENT_TYPE = 'markPoint';
19
+
20
+ /**
21
+ * This is a slight offset that gets applied to the left
22
+ * of the chart tooltips to ensure a correct position.
23
+ */
24
+ const TOOLTIP_LEFT_OFFSET = 2;
25
+
26
+ /**
27
+ * This is a slight offset that gets applied to the left
28
+ * of the chart tooltips to ensure a correct position.
29
+ */
30
+ const TOOLTIP_TOP_OFFSET = 10;
31
+
32
+ /**
33
+ * These are the accepted values for the layout prop
34
+ * of the chart legend component
35
+ */
36
+ const LEGEND_LAYOUT_INLINE = 'inline';
37
+ const LEGEND_LAYOUT_TABLE = 'table';
38
+
39
+ /**
40
+ * Default values for the chart legend field labels
41
+ */
42
+ const LEGEND_AVERAGE_TEXT = 'Avg';
43
+ const LEGEND_CURRENT_TEXT = 'Current';
44
+ const LEGEND_MIN_TEXT = 'Min';
45
+ const LEGEND_MAX_TEXT = 'Max';
46
+
47
+ /**
48
+ * These arrow symbols are used as markPoints under the annotations lines
49
+ * within area and line charts. This icon doesn't exist in the svg
50
+ * library yet. The below issue is to track the progress of the svg icon
51
+ * https://gitlab.com/gitlab-org/gitlab-svgs/-/issues/118
52
+ */
53
+ const arrowSymbol = 'path://m5 229 5 8h-10z';
54
+
55
+ // Constants for the type property of charts
56
+ const CHART_TYPE_BAR = 'bar';
57
+ const CHART_TYPE_LINE = 'line';
58
+
59
+ // Constants for height "auto"
60
+ const HEIGHT_AUTO_CLASSES = 'gl-chart-h-auto gl-display-flex gl-flex-direction-column gl-h-full';
61
+ const HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES = 'gl-display-flex gl-h-full';
62
+
63
+ export { ANNOTATIONS_COMPONENT_TYPE, ANNOTATIONS_SERIES_NAME, CHART_TYPE_BAR, CHART_TYPE_LINE, HEIGHT_AUTO_CLASSES, HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES, LEGEND_AVERAGE_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, TOOLTIP_LEFT_OFFSET, TOOLTIP_TOP_OFFSET, arrowSymbol };