@gitlab/ui 52.4.0 → 52.5.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.
- package/CHANGELOG.md +7 -0
- package/dist/components/charts/sparkline/sparkline.js +28 -1
- package/package.json +3 -3
- package/src/components/charts/sparkline/sparkline.spec.js +11 -0
- package/src/components/charts/sparkline/sparkline.stories.js +13 -0
- package/src/components/charts/sparkline/sparkline.vue +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [52.5.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v52.4.0...v52.5.0) (2022-12-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlSparklineChart:** Add gradient prop ([eb28329](https://gitlab.com/gitlab-org/gitlab-ui/commit/eb283290d82a506c2a9732d3b86ad328f4be0385))
|
|
7
|
+
|
|
1
8
|
# [52.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v52.3.1...v52.4.0) (2022-12-12)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import merge from 'lodash/merge';
|
|
2
|
+
import { graphic } from 'echarts';
|
|
2
3
|
import { GlResizeObserverDirective } from '../../../directives/resize_observer/resize_observer';
|
|
3
4
|
import { defaultChartOptions, mergeSeriesToOptions, symbolSize } from '../../../utils/charts/config';
|
|
4
5
|
import Chart from '../chart/chart';
|
|
@@ -9,6 +10,15 @@ import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
|
9
10
|
|
|
10
11
|
// the padding is needed so the mark points don't overflow when visible
|
|
11
12
|
const gridPadding = symbolSize / 2;
|
|
13
|
+
const generateGradient = colors => {
|
|
14
|
+
return new graphic.LinearGradient(0, 0, 0, 1, colors.map((color, index) => {
|
|
15
|
+
const offset = index / (colors.length - 1);
|
|
16
|
+
return {
|
|
17
|
+
offset,
|
|
18
|
+
color
|
|
19
|
+
};
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
12
22
|
var script = {
|
|
13
23
|
components: {
|
|
14
24
|
Chart,
|
|
@@ -48,6 +58,14 @@ var script = {
|
|
|
48
58
|
type: Boolean,
|
|
49
59
|
required: false,
|
|
50
60
|
default: true
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Sets a colour gradient for the sparkline
|
|
64
|
+
*/
|
|
65
|
+
gradient: {
|
|
66
|
+
type: Array,
|
|
67
|
+
required: false,
|
|
68
|
+
default: () => []
|
|
51
69
|
}
|
|
52
70
|
},
|
|
53
71
|
data() {
|
|
@@ -117,9 +135,18 @@ var script = {
|
|
|
117
135
|
yAxis: data[data.length - 1][1]
|
|
118
136
|
}]
|
|
119
137
|
},
|
|
120
|
-
data
|
|
138
|
+
data,
|
|
139
|
+
itemStyle: this.itemStyle
|
|
121
140
|
};
|
|
122
141
|
},
|
|
142
|
+
itemStyle() {
|
|
143
|
+
if (this.gradient.length) {
|
|
144
|
+
return {
|
|
145
|
+
color: generateGradient(this.gradient)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {};
|
|
149
|
+
},
|
|
123
150
|
lastYValue() {
|
|
124
151
|
const latestEntry = this.data.slice(-1)[0];
|
|
125
152
|
return latestEntry[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitlab/ui",
|
|
3
|
-
"version": "52.
|
|
3
|
+
"version": "52.5.0",
|
|
4
4
|
"description": "GitLab UI Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -115,10 +115,10 @@
|
|
|
115
115
|
"bootstrap-vue-vue3": "npm:bootstrap-vue@2.23.1",
|
|
116
116
|
"cypress": "^11.2.0",
|
|
117
117
|
"emoji-regex": "^10.0.0",
|
|
118
|
-
"eslint": "8.
|
|
118
|
+
"eslint": "8.29.0",
|
|
119
119
|
"eslint-import-resolver-jest": "3.0.2",
|
|
120
120
|
"eslint-plugin-cypress": "2.12.1",
|
|
121
|
-
"eslint-plugin-storybook": "0.6.
|
|
121
|
+
"eslint-plugin-storybook": "0.6.8",
|
|
122
122
|
"file-loader": "^4.2.0",
|
|
123
123
|
"glob": "^7.2.0",
|
|
124
124
|
"identity-obj-proxy": "^3.0.0",
|
|
@@ -8,6 +8,9 @@ let mockChartInstance;
|
|
|
8
8
|
|
|
9
9
|
jest.mock('echarts', () => ({
|
|
10
10
|
getInstanceByDom: () => mockChartInstance,
|
|
11
|
+
graphic: {
|
|
12
|
+
LinearGradient: jest.fn(),
|
|
13
|
+
},
|
|
11
14
|
}));
|
|
12
15
|
|
|
13
16
|
let triggerResize = () => {};
|
|
@@ -176,4 +179,12 @@ describe('sparkline chart component', () => {
|
|
|
176
179
|
await wrapper.vm.$nextTick();
|
|
177
180
|
expect(getLastYValue().exists()).toBe(false);
|
|
178
181
|
});
|
|
182
|
+
|
|
183
|
+
it('gradient will set the series itemStyle color', async () => {
|
|
184
|
+
wrapper.setProps({ gradient: ['red', 'green'] });
|
|
185
|
+
|
|
186
|
+
await wrapper.vm.$nextTick();
|
|
187
|
+
|
|
188
|
+
expect(getChartOptions().series[0].itemStyle.color).toBeDefined();
|
|
189
|
+
});
|
|
179
190
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GlSparklineChart } from '../../../charts';
|
|
2
|
+
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
2
3
|
import readme from './sparkline.md';
|
|
3
4
|
|
|
4
5
|
const chartData = [
|
|
@@ -11,16 +12,24 @@ const chartData = [
|
|
|
11
12
|
['Sun', 18],
|
|
12
13
|
];
|
|
13
14
|
|
|
15
|
+
const customGradient = [
|
|
16
|
+
colorFromDefaultPalette(0),
|
|
17
|
+
colorFromDefaultPalette(1),
|
|
18
|
+
colorFromDefaultPalette(2),
|
|
19
|
+
];
|
|
20
|
+
|
|
14
21
|
const generateProps = ({
|
|
15
22
|
data = chartData,
|
|
16
23
|
height = 50,
|
|
17
24
|
tooltipLabel = 'tooltipLabel',
|
|
18
25
|
showLastYValue = true,
|
|
26
|
+
gradient,
|
|
19
27
|
} = {}) => ({
|
|
20
28
|
data,
|
|
21
29
|
height,
|
|
22
30
|
tooltipLabel,
|
|
23
31
|
showLastYValue,
|
|
32
|
+
gradient,
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
const Template = (args) => ({
|
|
@@ -33,6 +42,7 @@ const Template = (args) => ({
|
|
|
33
42
|
:height="height"
|
|
34
43
|
:tooltip-label="tooltipLabel"
|
|
35
44
|
:show-last-y-value="showLastYValue"
|
|
45
|
+
:gradient="gradient"
|
|
36
46
|
/>
|
|
37
47
|
</div>`,
|
|
38
48
|
});
|
|
@@ -40,6 +50,9 @@ const Template = (args) => ({
|
|
|
40
50
|
export const Default = Template.bind({});
|
|
41
51
|
Default.args = generateProps();
|
|
42
52
|
|
|
53
|
+
export const WithChartColorGradient = Template.bind({});
|
|
54
|
+
WithChartColorGradient.args = generateProps({ gradient: customGradient });
|
|
55
|
+
|
|
43
56
|
export default {
|
|
44
57
|
title: 'charts/sparkline-chart',
|
|
45
58
|
component: GlSparklineChart,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<!-- eslint-disable vue/multi-word-component-names -->
|
|
2
2
|
<script>
|
|
3
3
|
import merge from 'lodash/merge';
|
|
4
|
+
import { graphic } from 'echarts';
|
|
4
5
|
import { GlResizeObserverDirective } from '../../../directives/resize_observer/resize_observer';
|
|
5
6
|
import {
|
|
6
7
|
defaultChartOptions,
|
|
@@ -13,6 +14,19 @@ import ChartTooltip from '../tooltip/tooltip.vue';
|
|
|
13
14
|
// the padding is needed so the mark points don't overflow when visible
|
|
14
15
|
const gridPadding = symbolSize / 2;
|
|
15
16
|
|
|
17
|
+
const generateGradient = (colors) => {
|
|
18
|
+
return new graphic.LinearGradient(
|
|
19
|
+
0,
|
|
20
|
+
0,
|
|
21
|
+
0,
|
|
22
|
+
1,
|
|
23
|
+
colors.map((color, index) => {
|
|
24
|
+
const offset = index / (colors.length - 1);
|
|
25
|
+
return { offset, color };
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
16
30
|
export default {
|
|
17
31
|
components: { Chart, ChartTooltip },
|
|
18
32
|
directives: {
|
|
@@ -50,6 +64,14 @@ export default {
|
|
|
50
64
|
required: false,
|
|
51
65
|
default: true,
|
|
52
66
|
},
|
|
67
|
+
/**
|
|
68
|
+
* Sets a colour gradient for the sparkline
|
|
69
|
+
*/
|
|
70
|
+
gradient: {
|
|
71
|
+
type: Array,
|
|
72
|
+
required: false,
|
|
73
|
+
default: () => [],
|
|
74
|
+
},
|
|
53
75
|
},
|
|
54
76
|
data() {
|
|
55
77
|
return {
|
|
@@ -119,8 +141,15 @@ export default {
|
|
|
119
141
|
],
|
|
120
142
|
},
|
|
121
143
|
data,
|
|
144
|
+
itemStyle: this.itemStyle,
|
|
122
145
|
};
|
|
123
146
|
},
|
|
147
|
+
itemStyle() {
|
|
148
|
+
if (this.gradient.length) {
|
|
149
|
+
return { color: generateGradient(this.gradient) };
|
|
150
|
+
}
|
|
151
|
+
return {};
|
|
152
|
+
},
|
|
124
153
|
lastYValue() {
|
|
125
154
|
const latestEntry = this.data.slice(-1)[0];
|
|
126
155
|
|