Skip to content

Commit c4c24c9

Browse files
committed
Improvement - VueUiSparkline - Add scaleMin and scaleMax config attributes
1 parent e4c1382 commit c4c24c9

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/components/vue-ui-sparkline.vue

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
dataLabel as dl,
1010
error,
1111
getMissingDatasetAttributes,
12+
hasDeepProperty,
1213
largestTriangleThreeBucketsArrayObjects,
1314
objectIsEmpty,
1415
setOpacity,
@@ -79,16 +80,36 @@ function prepareConfig() {
7980
userConfig: props.config,
8081
defaultConfig: DEFAULT_CONFIG
8182
});
83+
let finalConfig = {};
84+
8285
if (mergedConfig.theme) {
83-
return {
86+
finalConfig = {
8487
...useNestedProp({
8588
userConfig: themes.vue_ui_sparkline[mergedConfig.theme] || props.config,
8689
defaultConfig: mergedConfig
8790
}),
8891
}
8992
} else {
90-
return mergedConfig;
93+
finalConfig = mergedConfig;
94+
}
95+
96+
// ------------------------------ OVERRIDES -----------------------------------
97+
98+
if (props.config && hasDeepProperty(props.config, 'style.scaleMin')) {
99+
finalConfig.style.scaleMin = props.config.style.scaleMin;
100+
} else {
101+
finalConfig.style.scaleMin = null;
102+
}
103+
104+
if (props.config && hasDeepProperty(props.config, 'style.scaleMax')) {
105+
finalConfig.style.scaleMax = props.config.style.scaleMax;
106+
} else {
107+
finalConfig.style.scaleMax = null;
91108
}
109+
110+
// ----------------------------------------------------------------------------
111+
112+
return finalConfig;
92113
}
93114
94115
const downsampled = computed(() => {
@@ -226,13 +247,21 @@ const drawingArea = computed(() => {
226247
});
227248
228249
const min = computed(() => {
229-
return Math.min(...safeDatasetCopy.value.map(s => isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : s.value || 0))
250+
if (![null, undefined].includes(FINAL_CONFIG.value.style.scaleMin)) {
251+
return FINAL_CONFIG.value.style.scaleMin;
252+
} else {
253+
return Math.min(...safeDatasetCopy.value.map(s => isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : s.value || 0))
254+
}
230255
});
256+
231257
const max = computed(() => {
232-
return Math.max(...safeDatasetCopy.value.map(s => isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : s.value || 0))
258+
if (![null, undefined].includes(FINAL_CONFIG.value.style.scaleMax)) {
259+
return FINAL_CONFIG.value.style.scaleMax;
260+
} else {
261+
return Math.max(...safeDatasetCopy.value.map(s => isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : s.value || 0))
262+
}
233263
});
234264
235-
236265
const absoluteMin = computed(() => {
237266
const num = min.value >= 0 ? 0 : min.value
238267
return Math.abs(num);
@@ -368,7 +397,7 @@ function selectDatapoint(datapoint, index) {
368397
</div>
369398

370399
<!-- CHART -->
371-
<svg :xmlns="XMLNS" v-if="isDataset" data-cy="sparkline-svg" :viewBox="`0 0 ${svg.width} ${svg.height}`" :style="`background:${FINAL_CONFIG.style.backgroundColor};overflow:visible`">
400+
<svg :xmlns="XMLNS" v-if="isDataset" data-cy="sparkline-svg" :viewBox="`0 0 ${svg.width} ${svg.height}`" :style="`background:${FINAL_CONFIG.style.backgroundColor};overflow:hidden`">
372401
<PackageVersion />
373402

374403
<!-- BACKGROUND SLOT -->

0 commit comments

Comments
 (0)