@gitlab/ui 56.3.0 → 56.4.0

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 (41) hide show
  1. package/CHANGELOG.md +7 -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/utils/charts/constants.js +5 -1
  13. package/package.json +5 -5
  14. package/src/components/charts/area/area.spec.js +9 -0
  15. package/src/components/charts/area/area.stories.js +3 -0
  16. package/src/components/charts/area/area.vue +22 -2
  17. package/src/components/charts/bar/bar.spec.js +11 -2
  18. package/src/components/charts/bar/bar.stories.js +21 -7
  19. package/src/components/charts/bar/bar.vue +22 -3
  20. package/src/components/charts/chart/chart.vue +3 -0
  21. package/src/components/charts/column/column.stories.js +3 -0
  22. package/src/components/charts/column/column.vue +26 -3
  23. package/src/components/charts/column/column_chart.spec.js +9 -0
  24. package/src/components/charts/discrete_scatter/discrete_scatter.spec.js +41 -0
  25. package/src/components/charts/discrete_scatter/discrete_scatter.stories.js +3 -0
  26. package/src/components/charts/discrete_scatter/discrete_scatter.vue +22 -2
  27. package/src/components/charts/gauge/gauge.stories.js +5 -2
  28. package/src/components/charts/gauge/gauge.vue +1 -3
  29. package/src/components/charts/heatmap/heatmap.spec.js +25 -5
  30. package/src/components/charts/heatmap/heatmap.stories.js +3 -0
  31. package/src/components/charts/heatmap/heatmap.vue +22 -3
  32. package/src/components/charts/line/line.spec.js +9 -0
  33. package/src/components/charts/line/line.stories.js +3 -0
  34. package/src/components/charts/line/line.vue +22 -2
  35. package/src/components/charts/sparkline/sparkline.spec.js +28 -1
  36. package/src/components/charts/sparkline/sparkline.stories.js +18 -10
  37. package/src/components/charts/sparkline/sparkline.vue +14 -3
  38. package/src/components/charts/stacked_column/stacked_column.spec.js +9 -0
  39. package/src/components/charts/stacked_column/stacked_column.stories.js +3 -0
  40. package/src/components/charts/stacked_column/stacked_column.vue +22 -2
  41. package/src/utils/charts/constants.js +4 -0
@@ -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
  });
@@ -24,6 +24,7 @@ const template = `
24
24
  :x-axis-name="xAxisName"
25
25
  :y-axis-name="yAxisName"
26
26
  :options="options"
27
+ :height="height"
27
28
  />
28
29
  `;
29
30
 
@@ -34,6 +35,7 @@ const generateProps = ({
34
35
  xAxisName = 'Hour',
35
36
  yAxisName = 'Day',
36
37
  options = {},
38
+ height = null,
37
39
  } = {}) => ({
38
40
  data,
39
41
  xAxisLabels,
@@ -41,6 +43,7 @@ const generateProps = ({
41
43
  xAxisName,
42
44
  yAxisName,
43
45
  options,
46
+ height,
44
47
  });
45
48
 
46
49
  const Template = (args, { argTypes }) => ({
@@ -3,7 +3,7 @@
3
3
  import merge from 'lodash/merge';
4
4
  import { white, gray100 } from '../../../../scss_to_js/scss_variables';
5
5
  import { getDefaultTooltipContent } 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 { heatmapHues } from '../../../utils/charts/theme';
8
8
  import { engineeringNotation } from '../../../utils/number_utils';
9
9
  import { debounceByAnimationFrame } from '../../../utils/utils';
@@ -98,6 +98,14 @@ export default {
98
98
  required: false,
99
99
  default: true,
100
100
  },
101
+ /**
102
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
103
+ */
104
+ height: {
105
+ type: [Number, String],
106
+ required: false,
107
+ default: null,
108
+ },
101
109
  },
102
110
  data() {
103
111
  return {
@@ -210,6 +218,9 @@ export default {
210
218
  };
211
219
  });
212
220
  },
221
+ autoHeight() {
222
+ return this.height === 'auto';
223
+ },
213
224
  },
214
225
  beforeDestroy() {
215
226
  this.chart.getDom().removeEventListener('mousemove', this.debouncedShowHideTooltip);
@@ -249,12 +260,20 @@ export default {
249
260
  }
250
261
  },
251
262
  },
263
+ HEIGHT_AUTO_CLASSES,
252
264
  };
253
265
  </script>
254
266
 
255
267
  <template>
256
- <div class="gl-heatmap">
257
- <chart v-bind="$attrs" :options="computedOptions" @created="onCreated" v-on="$listeners" />
268
+ <div class="gl-heatmap" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
269
+ <chart
270
+ v-bind="$attrs"
271
+ :class="{ 'gl-flex-grow-1': autoHeight }"
272
+ :height="height"
273
+ :options="computedOptions"
274
+ @created="onCreated"
275
+ v-on="$listeners"
276
+ />
258
277
  <chart-tooltip
259
278
  v-if="chart"
260
279
  :show="tooltip.show"
@@ -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 LineChart from './line.vue';
@@ -205,4 +206,12 @@ describe('line component', () => {
205
206
  expect(findLegend().exists()).toBe(false);
206
207
  });
207
208
  });
209
+
210
+ describe('height', () => {
211
+ expectHeightAutoClasses({
212
+ createComponent: createShallowWrapper,
213
+ findContainer: () => wrapper,
214
+ findChart,
215
+ });
216
+ });
208
217
  });
@@ -63,6 +63,7 @@ const template = `<gl-line-chart
63
63
  :annotations="annotations"
64
64
  :includeLegendAvgMax="includeLegendAvgMax"
65
65
  :showLegend="showLegend"
66
+ :height="height"
66
67
  />`;
67
68
 
68
69
  const generateProps = ({
@@ -72,6 +73,7 @@ const generateProps = ({
72
73
  annotations = [],
73
74
  includeLegendAvgMax = true,
74
75
  showLegend = true,
76
+ height = null,
75
77
  } = {}) => ({
76
78
  showLegend,
77
79
  includeLegendAvgMax,
@@ -79,6 +81,7 @@ const generateProps = ({
79
81
  thresholds,
80
82
  annotations,
81
83
  data,
84
+ height,
82
85
  });
83
86
 
84
87
  const Template = (_args, { argTypes }) => ({
@@ -41,6 +41,7 @@ import {
41
41
  LEGEND_CURRENT_TEXT,
42
42
  LEGEND_MIN_TEXT,
43
43
  LEGEND_MAX_TEXT,
44
+ HEIGHT_AUTO_CLASSES,
44
45
  } from '../../../utils/charts/constants';
45
46
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
46
47
  import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
@@ -121,6 +122,14 @@ export default {
121
122
  required: false,
122
123
  default: true,
123
124
  },
125
+ /**
126
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
127
+ */
128
+ height: {
129
+ type: [Number, String],
130
+ required: false,
131
+ default: null,
132
+ },
124
133
  },
125
134
  data() {
126
135
  // Part of the tooltip related data can be
@@ -249,6 +258,9 @@ export default {
249
258
  return acc;
250
259
  }, []);
251
260
  },
261
+ autoHeight() {
262
+ return this.height === 'auto';
263
+ },
252
264
  },
253
265
  beforeDestroy() {
254
266
  this.chart.getDom().removeEventListener('mousemove', this.debouncedShowHideTooltip);
@@ -330,12 +342,20 @@ export default {
330
342
  this.selectedFormatTooltipText(params);
331
343
  },
332
344
  },
345
+ HEIGHT_AUTO_CLASSES,
333
346
  };
334
347
  </script>
335
348
 
336
349
  <template>
337
- <div class="position-relative">
338
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
350
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
351
+ <chart
352
+ v-bind="$attrs"
353
+ :class="{ 'gl-flex-grow-1': autoHeight }"
354
+ :height="height"
355
+ :options="options"
356
+ v-on="$listeners"
357
+ @created="onCreated"
358
+ />
339
359
  <chart-tooltip
340
360
  v-if="shouldShowAnnotationsTooltip"
341
361
  id="annotationsTooltip"