@gitlab/ui 56.3.0 → 56.4.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 (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/components/charts/area/area.js +17 -3
  3. package/dist/components/charts/bar/bar.js +17 -3
  4. package/dist/components/charts/chart/chart.js +3 -0
  5. package/dist/components/charts/column/column.js +17 -3
  6. package/dist/components/charts/discrete_scatter/discrete_scatter.js +17 -2
  7. package/dist/components/charts/gauge/gauge.js +1 -1
  8. package/dist/components/charts/heatmap/heatmap.js +17 -3
  9. package/dist/components/charts/line/line.js +17 -3
  10. package/dist/components/charts/sparkline/sparkline.js +11 -4
  11. package/dist/components/charts/stacked_column/stacked_column.js +17 -3
  12. package/dist/index.css +1 -1
  13. package/dist/index.css.map +1 -1
  14. package/dist/utils/charts/constants.js +5 -1
  15. package/package.json +5 -5
  16. package/src/components/base/drawer/drawer.scss +7 -6
  17. package/src/components/charts/area/area.spec.js +9 -0
  18. package/src/components/charts/area/area.stories.js +3 -0
  19. package/src/components/charts/area/area.vue +22 -2
  20. package/src/components/charts/bar/bar.spec.js +11 -2
  21. package/src/components/charts/bar/bar.stories.js +21 -7
  22. package/src/components/charts/bar/bar.vue +22 -3
  23. package/src/components/charts/chart/chart.vue +3 -0
  24. package/src/components/charts/column/column.stories.js +3 -0
  25. package/src/components/charts/column/column.vue +26 -3
  26. package/src/components/charts/column/column_chart.spec.js +9 -0
  27. package/src/components/charts/discrete_scatter/discrete_scatter.spec.js +41 -0
  28. package/src/components/charts/discrete_scatter/discrete_scatter.stories.js +3 -0
  29. package/src/components/charts/discrete_scatter/discrete_scatter.vue +22 -2
  30. package/src/components/charts/gauge/gauge.stories.js +5 -2
  31. package/src/components/charts/gauge/gauge.vue +1 -3
  32. package/src/components/charts/heatmap/heatmap.spec.js +25 -5
  33. package/src/components/charts/heatmap/heatmap.stories.js +3 -0
  34. package/src/components/charts/heatmap/heatmap.vue +22 -3
  35. package/src/components/charts/line/line.spec.js +9 -0
  36. package/src/components/charts/line/line.stories.js +3 -0
  37. package/src/components/charts/line/line.vue +22 -2
  38. package/src/components/charts/sparkline/sparkline.spec.js +28 -1
  39. package/src/components/charts/sparkline/sparkline.stories.js +18 -10
  40. package/src/components/charts/sparkline/sparkline.vue +14 -3
  41. package/src/components/charts/stacked_column/stacked_column.spec.js +9 -0
  42. package/src/components/charts/stacked_column/stacked_column.stories.js +3 -0
  43. package/src/components/charts/stacked_column/stacked_column.vue +22 -2
  44. package/src/utils/charts/constants.js +4 -0
@@ -64,4 +64,8 @@ const arrowSymbol = 'path://m5 229 5 8h-10z';
64
64
  const CHART_TYPE_BAR = 'bar';
65
65
  const CHART_TYPE_LINE = 'line';
66
66
 
67
- export { ANNOTATIONS_COMPONENT_TYPE, ANNOTATIONS_SERIES_NAME, ANNOTATION_TOOLTIP_TOP_OFFSET, CHART_TYPE_BAR, CHART_TYPE_LINE, DATA_TOOLTIP_LEFT_OFFSET, LEGEND_AVERAGE_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, TOOLTIP_LEFT_OFFSET, arrowSymbol };
67
+ // Constants for height "auto"
68
+ const HEIGHT_AUTO_CLASSES = 'gl-display-flex gl-flex-direction-column gl-h-full';
69
+ const HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES = 'gl-display-flex gl-h-full';
70
+
71
+ export { ANNOTATIONS_COMPONENT_TYPE, ANNOTATIONS_SERIES_NAME, ANNOTATION_TOOLTIP_TOP_OFFSET, CHART_TYPE_BAR, CHART_TYPE_LINE, DATA_TOOLTIP_LEFT_OFFSET, 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, arrowSymbol };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "56.3.0",
3
+ "version": "56.4.1",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -88,7 +88,7 @@
88
88
  "@gitlab/eslint-plugin": "18.2.0",
89
89
  "@gitlab/fonts": "^1.2.0",
90
90
  "@gitlab/stylelint-config": "4.1.0",
91
- "@gitlab/svgs": "3.22.0",
91
+ "@gitlab/svgs": "3.24.0",
92
92
  "@rollup/plugin-commonjs": "^11.1.0",
93
93
  "@rollup/plugin-node-resolve": "^7.1.3",
94
94
  "@rollup/plugin-replace": "^2.3.2",
@@ -125,9 +125,9 @@
125
125
  "glob": "^7.2.0",
126
126
  "identity-obj-proxy": "^3.0.0",
127
127
  "inquirer-select-directory": "^1.2.0",
128
- "jest": "^29.4.3",
129
- "jest-circus": "29.4.3",
130
- "jest-environment-jsdom": "29.4.3",
128
+ "jest": "^29.5.0",
129
+ "jest-circus": "29.5.0",
130
+ "jest-environment-jsdom": "29.5.0",
131
131
  "markdownlint-cli": "^0.29.0",
132
132
  "mockdate": "^2.0.5",
133
133
  "npm-run-all": "^4.1.5",
@@ -7,6 +7,7 @@ $gl-drawer-scrim-gradient: linear-gradient(to bottom, $transparent-rgba, $white)
7
7
  @include gl-transition-medium;
8
8
  @include gl-fixed;
9
9
  @include gl-h-full;
10
+ @include gl-w-full;
10
11
  @include gl-overflow-y-auto;
11
12
  @include gl-shadow-drawer;
12
13
  @include gl-font-base;
@@ -19,15 +20,13 @@ $gl-drawer-scrim-gradient: linear-gradient(to bottom, $transparent-rgba, $white)
19
20
  @include gl-top-0;
20
21
  @include gl-sticky;
21
22
  }
22
-
23
- @include media-breakpoint-down(sm) {
24
- @include gl-w-full;
25
- }
26
23
  }
27
24
 
28
25
  .gl-drawer-default {
29
26
  @include gl-bg-white;
30
- width: $gl-drawer-width;
27
+ @include media-breakpoint-up(md) {
28
+ width: $gl-drawer-width;
29
+ }
31
30
 
32
31
  .gl-drawer-header,
33
32
  .gl-drawer-body > * {
@@ -37,7 +36,9 @@ $gl-drawer-scrim-gradient: linear-gradient(to bottom, $transparent-rgba, $white)
37
36
 
38
37
  .gl-drawer-sidebar {
39
38
  @include gl-bg-gray-10;
40
- width: $gl-sidebar-width;
39
+ @include media-breakpoint-up(md) {
40
+ width: $gl-sidebar-width;
41
+ }
41
42
 
42
43
  .gl-drawer-header,
43
44
  .gl-drawer-body > * {
@@ -2,6 +2,7 @@ import { shallowMount } from '@vue/test-utils';
2
2
 
3
3
  import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
4
4
  import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
5
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
5
6
  import Chart from '../chart/chart.vue';
6
7
  import ChartLegend from '../legend/legend.vue';
7
8
  import AreaChart from './area.vue';
@@ -183,4 +184,12 @@ describe('area component', () => {
183
184
  expect(findLegend().props('layout')).toBe(LEGEND_LAYOUT_TABLE);
184
185
  });
185
186
  });
187
+
188
+ describe('height', () => {
189
+ expectHeightAutoClasses({
190
+ createComponent: createShallowWrapper,
191
+ findContainer: () => wrapper,
192
+ findChart,
193
+ });
194
+ });
186
195
  });
@@ -34,6 +34,7 @@ const template = `<gl-area-chart
34
34
  :thresholds="thresholds"
35
35
  :annotations="annotations"
36
36
  :includeLegendAvgMax="includeLegendAvgMax"
37
+ :height="height"
37
38
  />`;
38
39
 
39
40
  const generateProps = ({
@@ -42,12 +43,14 @@ const generateProps = ({
42
43
  thresholds = [],
43
44
  annotations = [],
44
45
  includeLegendAvgMax = true,
46
+ height = null,
45
47
  } = {}) => ({
46
48
  data,
47
49
  option,
48
50
  thresholds,
49
51
  annotations,
50
52
  includeLegendAvgMax,
53
+ height,
51
54
  });
52
55
 
53
56
  const Template = (args, { argTypes }) => ({
@@ -38,6 +38,7 @@ import {
38
38
  LEGEND_CURRENT_TEXT,
39
39
  LEGEND_MIN_TEXT,
40
40
  LEGEND_MAX_TEXT,
41
+ HEIGHT_AUTO_CLASSES,
41
42
  } from '../../../utils/charts/constants';
42
43
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
43
44
  import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
@@ -118,6 +119,14 @@ export default {
118
119
  return [LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE].indexOf(layout) !== -1;
119
120
  },
120
121
  },
122
+ /**
123
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
124
+ */
125
+ height: {
126
+ type: [Number, String],
127
+ required: false,
128
+ default: null,
129
+ },
121
130
  },
122
131
  data() {
123
132
  // Part of the tooltip related data can be
@@ -247,6 +256,9 @@ export default {
247
256
  return acc;
248
257
  }, []);
249
258
  },
259
+ autoHeight() {
260
+ return this.height === 'auto';
261
+ },
250
262
  },
251
263
  beforeDestroy() {
252
264
  this.chart.getDom().removeEventListener('mousemove', this.debouncedShowHideTooltip);
@@ -328,12 +340,20 @@ export default {
328
340
  this.selectedFormatTooltipText(params);
329
341
  },
330
342
  },
343
+ HEIGHT_AUTO_CLASSES,
331
344
  };
332
345
  </script>
333
346
 
334
347
  <template>
335
- <div class="position-relative">
336
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
348
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
349
+ <chart
350
+ v-bind="$attrs"
351
+ :class="{ 'gl-flex-grow-1': autoHeight }"
352
+ :height="height"
353
+ :options="options"
354
+ v-on="$listeners"
355
+ @created="onCreated"
356
+ />
337
357
  <chart-tooltip
338
358
  v-if="shouldShowAnnotationsTooltip"
339
359
  id="annotationsTooltip"
@@ -1,6 +1,7 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import TooltipDefaultFormat from '~/components/shared_components/charts/tooltip_default_format.vue';
3
3
  import { createMockChartInstance } from '~helpers/chart_stubs';
4
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
4
5
  import Chart from '../chart/chart.vue';
5
6
  import BarChart from './bar.vue';
6
7
 
@@ -29,9 +30,9 @@ describe('Bar chart component', () => {
29
30
  const getOptions = () => findChart().props('options');
30
31
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
31
32
 
32
- const createComponent = () => {
33
+ const createComponent = (props = {}) => {
33
34
  wrapper = shallowMount(BarChart, {
34
- propsData: defaultChartProps,
35
+ propsData: { ...defaultChartProps, ...props },
35
36
  stubs: {
36
37
  'tooltip-default-format': TooltipDefaultFormat,
37
38
  },
@@ -116,4 +117,12 @@ describe('Bar chart component', () => {
116
117
  });
117
118
  });
118
119
  });
120
+
121
+ describe('height', () => {
122
+ expectHeightAutoClasses({
123
+ createComponent,
124
+ findContainer: () => wrapper,
125
+ findChart,
126
+ });
127
+ });
119
128
  });
@@ -1,16 +1,20 @@
1
1
  import { GlBarChart } from '../../../charts';
2
+ import { makeContainer } from '../../../utils/story_decorators/container';
2
3
  import readme from './bar.md';
3
4
 
4
5
  const Template = (args, { argTypes }) => ({
5
6
  components: { GlBarChart },
6
7
  props: Object.keys(argTypes),
7
- template: `<gl-bar-chart
8
- :data="data"
9
- :option="option"
10
- :y-axis-title="yAxisTitle"
11
- :x-axis-title="xAxisTitle"
12
- :x-axis-type="xAxisType"
13
- />`,
8
+ template: `
9
+ <gl-bar-chart
10
+ :data="data"
11
+ :option="option"
12
+ :y-axis-title="yAxisTitle"
13
+ :x-axis-title="xAxisTitle"
14
+ :x-axis-type="xAxisType"
15
+ :height="height"
16
+ />
17
+ `,
14
18
  });
15
19
 
16
20
  const mockData = {
@@ -34,17 +38,27 @@ const generateProps = ({
34
38
  xAxisTitle = 'Pushes per day',
35
39
  yAxisTitle = 'User',
36
40
  xAxisType = 'value',
41
+ height = null,
37
42
  } = {}) => ({
38
43
  data,
39
44
  option,
40
45
  xAxisTitle,
41
46
  yAxisTitle,
42
47
  xAxisType,
48
+ height,
43
49
  });
44
50
 
45
51
  export const Default = Template.bind({});
46
52
  Default.args = generateProps();
47
53
 
54
+ export const AutoHeight = Template.bind({});
55
+ Object.assign(AutoHeight, {
56
+ args: generateProps({
57
+ height: 'auto',
58
+ }),
59
+ decorators: [makeContainer({ height: '600px' })],
60
+ });
61
+
48
62
  export default {
49
63
  title: 'charts/bar-chart',
50
64
  component: GlBarChart,
@@ -3,7 +3,7 @@
3
3
  import merge from 'lodash/merge';
4
4
  import truncate from 'lodash/truncate';
5
5
  import { grid, dataZoomAdjustments, mergeSeriesToOptions } from '../../../utils/charts/config';
6
- import { TOOLTIP_LEFT_OFFSET } from '../../../utils/charts/constants';
6
+ import { TOOLTIP_LEFT_OFFSET, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
7
7
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
8
8
  import { engineeringNotation } from '../../../utils/number_utils';
9
9
  import { hexToRgba, debounceByAnimationFrame } from '../../../utils/utils';
@@ -85,6 +85,14 @@ export default {
85
85
  required: false,
86
86
  default: 'value',
87
87
  },
88
+ /**
89
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
90
+ */
91
+ height: {
92
+ type: [Number, String],
93
+ required: false,
94
+ default: null,
95
+ },
88
96
  },
89
97
  data() {
90
98
  return {
@@ -160,6 +168,9 @@ export default {
160
168
  // needs to be handled specially
161
169
  return mergeSeriesToOptions(mergedOptions, this.series);
162
170
  },
171
+ autoHeight() {
172
+ return this.height === 'auto';
173
+ },
163
174
  },
164
175
  beforeDestroy() {
165
176
  if (this.chart) {
@@ -223,12 +234,20 @@ export default {
223
234
  return { yLabels, tooltipContent };
224
235
  },
225
236
  },
237
+ HEIGHT_AUTO_CLASSES,
226
238
  };
227
239
  </script>
228
240
 
229
241
  <template>
230
- <div class="position-relative">
231
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
242
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
243
+ <chart
244
+ v-bind="$attrs"
245
+ :class="{ 'gl-flex-grow-1': autoHeight }"
246
+ :height="height"
247
+ :options="options"
248
+ v-on="$listeners"
249
+ @created="onCreated"
250
+ />
232
251
  <chart-tooltip
233
252
  v-if="chart"
234
253
  :show="showTooltip"
@@ -55,6 +55,9 @@ export default {
55
55
  default: null,
56
56
  validator: sizeValidator,
57
57
  },
58
+ /**
59
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
60
+ */
58
61
  height: {
59
62
  type: [Number, String],
60
63
  required: false,
@@ -17,6 +17,7 @@ const template = `
17
17
  :secondary-data-title="secondaryDataTitle"
18
18
  :x-axis-title="xAxisTitle"
19
19
  :x-axis-type="xAxisType"
20
+ :height="height"
20
21
  />
21
22
  `;
22
23
 
@@ -29,6 +30,7 @@ const generateProps = ({
29
30
  xAxisType = 'category',
30
31
  secondaryData = [],
31
32
  secondaryDataTitle = '',
33
+ height = null,
32
34
  } = {}) => ({
33
35
  bars,
34
36
  lines,
@@ -38,6 +40,7 @@ const generateProps = ({
38
40
  xAxisType,
39
41
  secondaryData,
40
42
  secondaryDataTitle,
43
+ height,
41
44
  });
42
45
 
43
46
  const Template = (args, { argTypes }) => ({
@@ -12,7 +12,11 @@ import {
12
12
  generateBarSeries,
13
13
  generateLineSeries,
14
14
  } from '../../../utils/charts/config';
15
- import { TOOLTIP_LEFT_OFFSET, CHART_TYPE_LINE } from '../../../utils/charts/constants';
15
+ import {
16
+ TOOLTIP_LEFT_OFFSET,
17
+ CHART_TYPE_LINE,
18
+ HEIGHT_AUTO_CLASSES,
19
+ } from '../../../utils/charts/constants';
16
20
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
17
21
  import { columnOptions } from '../../../utils/constants';
18
22
  import { debounceByAnimationFrame } from '../../../utils/utils';
@@ -74,6 +78,14 @@ export default {
74
78
  required: true,
75
79
  validator: (value) => ['value', 'category', 'time', 'log'].indexOf(value) !== -1,
76
80
  },
81
+ /**
82
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
83
+ */
84
+ height: {
85
+ type: [Number, String],
86
+ required: false,
87
+ default: null,
88
+ },
77
89
  },
78
90
  data() {
79
91
  return {
@@ -168,6 +180,9 @@ export default {
168
180
  // needs to be handled specially
169
181
  return mergeSeriesToOptions(mergedOptions, this.series);
170
182
  },
183
+ autoHeight() {
184
+ return this.height === 'auto';
185
+ },
171
186
  },
172
187
  beforeDestroy() {
173
188
  this.chart.getDom().removeEventListener('mousemove', this.debouncedMoveShowTooltip);
@@ -194,11 +209,19 @@ export default {
194
209
  this.tooltipTitle = xLabels.join(', ');
195
210
  },
196
211
  },
212
+ HEIGHT_AUTO_CLASSES,
197
213
  };
198
214
  </script>
199
215
  <template>
200
- <div class="position-relative">
201
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
216
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
217
+ <chart
218
+ v-bind="$attrs"
219
+ :class="{ 'gl-flex-grow-1': autoHeight }"
220
+ :height="height"
221
+ :options="options"
222
+ v-on="$listeners"
223
+ @created="onCreated"
224
+ />
202
225
  <chart-tooltip
203
226
  v-if="chart"
204
227
  :show="showTooltip"
@@ -1,5 +1,6 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
3
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
3
4
  import {
4
5
  mockDefaultLineData,
5
6
  mockDefaultBarData,
@@ -120,4 +121,12 @@ describe('column chart component', () => {
120
121
  expect(findTooltip().text()).toContain(expectedTooltipTitle);
121
122
  });
122
123
  });
124
+
125
+ describe('height', () => {
126
+ expectHeightAutoClasses({
127
+ createComponent: (props) => factory({ ...defaultChartProps, ...props }),
128
+ findContainer: () => wrapper,
129
+ findChart,
130
+ });
131
+ });
123
132
  });
@@ -0,0 +1,41 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { createMockChartInstance } from '~helpers/chart_stubs';
3
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
4
+ import Chart from '../chart/chart.vue';
5
+ import DiscreteScatterChart from './discrete_scatter.vue';
6
+
7
+ let mockChartInstance;
8
+
9
+ jest.mock('echarts', () => ({
10
+ getInstanceByDom: () => mockChartInstance,
11
+ }));
12
+
13
+ describe('column chart component', () => {
14
+ const defaultChartProps = {
15
+ xAxisTitle: 'x axis',
16
+ yAxisTitle: 'y axis',
17
+ xAxisType: 'category',
18
+ data: [['19 May', 6.95]],
19
+ };
20
+ let wrapper;
21
+
22
+ const findChart = () => wrapper.findComponent(Chart);
23
+
24
+ const createComponent = (props = {}) => {
25
+ wrapper = shallowMount(DiscreteScatterChart, {
26
+ propsData: { ...defaultChartProps, ...props },
27
+ });
28
+ };
29
+
30
+ beforeEach(() => {
31
+ mockChartInstance = createMockChartInstance();
32
+ });
33
+
34
+ describe('height', () => {
35
+ expectHeightAutoClasses({
36
+ createComponent,
37
+ findContainer: () => wrapper,
38
+ findChart,
39
+ });
40
+ });
41
+ });
@@ -10,6 +10,7 @@ const Template = (args, { argTypes }) => ({
10
10
  :y-axis-title="yAxisTitle"
11
11
  :x-axis-title="xAxisTitle"
12
12
  data-testid="discrete-scatter-chart"
13
+ :height="height"
13
14
  />
14
15
  `,
15
16
  });
@@ -32,11 +33,13 @@ const generateProps = ({
32
33
  option = {},
33
34
  yAxisTitle = 'Pushes per day',
34
35
  xAxisTitle = 'Date',
36
+ height = null,
35
37
  } = {}) => ({
36
38
  data,
37
39
  option,
38
40
  yAxisTitle,
39
41
  xAxisTitle,
42
+ height,
40
43
  });
41
44
 
42
45
  export const Default = Template.bind({});
@@ -8,6 +8,7 @@ import {
8
8
  } from '../../../utils/charts/config';
9
9
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
10
10
  import { debounceByAnimationFrame } from '../../../utils/utils';
11
+ import { HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
11
12
  import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
12
13
  import Chart from '../chart/chart.vue';
13
14
  import ChartTooltip from '../tooltip/tooltip.vue';
@@ -47,6 +48,14 @@ export default {
47
48
  required: false,
48
49
  default: null,
49
50
  },
51
+ /**
52
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
53
+ */
54
+ height: {
55
+ type: [Number, String],
56
+ required: false,
57
+ default: null,
58
+ },
50
59
  },
51
60
  data() {
52
61
  return {
@@ -121,6 +130,9 @@ export default {
121
130
  // needs to be handled specially
122
131
  return mergeSeriesToOptions(mergedOptions, this.series);
123
132
  },
133
+ autoHeight() {
134
+ return this.height === 'auto';
135
+ },
124
136
  },
125
137
  methods: {
126
138
  defaultFormatTooltipText(params) {
@@ -160,11 +172,19 @@ export default {
160
172
  }
161
173
  },
162
174
  },
175
+ HEIGHT_AUTO_CLASSES,
163
176
  };
164
177
  </script>
165
178
  <template>
166
- <div class="position-relative">
167
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
179
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
180
+ <chart
181
+ v-bind="$attrs"
182
+ :class="{ 'gl-flex-grow-1': autoHeight }"
183
+ :height="height"
184
+ :options="options"
185
+ v-on="$listeners"
186
+ @created="onCreated"
187
+ />
168
188
  <chart-tooltip
169
189
  v-if="chart"
170
190
  :show="showTooltip"
@@ -3,14 +3,15 @@ import readme from './gauge.md';
3
3
  import GlGauge from './gauge.vue';
4
4
 
5
5
  const template = `
6
- <gl-gauge
6
+ <gl-gauge
7
7
  :value="value"
8
8
  :min="min"
9
9
  :max="max"
10
10
  :thresholds="thresholds"
11
11
  :text="text"
12
12
  :splitNumber="splitNumber"
13
- :option="option"
13
+ :option="option"
14
+ :height="height"
14
15
  />
15
16
  `;
16
17
 
@@ -22,6 +23,7 @@ const generateProps = ({
22
23
  option = {},
23
24
  thresholds = [38, 82],
24
25
  splitNumber = 10,
26
+ height = null,
25
27
  } = {}) => ({
26
28
  option,
27
29
  value,
@@ -30,6 +32,7 @@ const generateProps = ({
30
32
  thresholds,
31
33
  text,
32
34
  splitNumber,
35
+ height,
33
36
  });
34
37
 
35
38
  const Template = (args, { argTypes }) => ({
@@ -173,7 +173,5 @@ export default {
173
173
  </script>
174
174
 
175
175
  <template>
176
- <div>
177
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
178
- </div>
176
+ <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
179
177
  </template>
@@ -2,6 +2,7 @@ import { shallowMount } from '@vue/test-utils';
2
2
 
3
3
  import { TOOLTIP_LEFT_OFFSET } from '~/utils/charts/constants';
4
4
  import { createMockChartInstance } from '~helpers/chart_stubs';
5
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
5
6
  import Chart from '../chart/chart.vue';
6
7
  import ChartTooltip from '../tooltip/tooltip.vue';
7
8
  import HeatMapChart from './heatmap.vue';
@@ -21,23 +22,34 @@ describe('heatmap component', () => {
21
22
 
22
23
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
23
24
 
24
- beforeEach(() => {
25
- mockChartInstance = createMockChartInstance();
26
-
25
+ const createComponent = (props = {}) => {
27
26
  wrapper = shallowMount(HeatMapChart, {
28
- propsData: { options: { series: [] }, dataSeries: [] },
27
+ propsData: {
28
+ options: { series: [] },
29
+ dataSeries: [],
30
+ ...props,
31
+ },
29
32
  });
33
+
30
34
  emitChartCreated();
35
+ };
31
36
 
32
- return wrapper.vm.$nextTick();
37
+ beforeEach(async () => {
38
+ mockChartInstance = createMockChartInstance();
33
39
  });
34
40
 
35
41
  it('emits `created`, with the chart instance', () => {
42
+ createComponent();
43
+
36
44
  expect(wrapper.emitted('created').length).toBe(1);
37
45
  expect(wrapper.emitted('created')[0][0]).toBe(mockChartInstance);
38
46
  });
39
47
 
40
48
  describe('tooltip position', () => {
49
+ beforeEach(() => {
50
+ createComponent();
51
+ });
52
+
41
53
  it('is initialized', () => {
42
54
  expect(findChartTooltip().props('left')).toBe('0');
43
55
  expect(findChartTooltip().props('top')).toBe('0');
@@ -64,4 +76,12 @@ describe('heatmap component', () => {
64
76
  });
65
77
  });
66
78
  });
79
+
80
+ describe('height', () => {
81
+ expectHeightAutoClasses({
82
+ createComponent,
83
+ findContainer: () => wrapper,
84
+ findChart,
85
+ });
86
+ });
67
87
  });