Skip to content

Commit 3de836f

Browse files
committed
Improvement - Sanitize datasets to process charts with unprocessable values
1 parent e18d8a6 commit 3de836f

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/components/vue-ui-dumbbell.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ref, computed, nextTick, onMounted, onBeforeUnmount } from "vue";
33
import {
44
applyDataLabel,
55
calculateNiceScale,
6+
checkNaN,
67
createCsvContent,
78
createUid,
89
darkenHexColor,
@@ -12,7 +13,6 @@ import {
1213
getMissingDatasetAttributes,
1314
lightenHexColor,
1415
objectIsEmpty,
15-
sanitizeArray,
1616
XMLNS,
1717
} from "../lib";
1818
import { throttle } from "../canvas-lib";
@@ -135,9 +135,11 @@ const mutableConfig = ref({
135135
});
136136
137137
const immutableDataset = computed(() => {
138-
return sanitizeArray(props.dataset, ['start', 'end']).map((ds, i) => {
138+
return props.dataset.map((ds, i) => {
139139
return {
140140
...ds,
141+
start: checkNaN(ds.start),
142+
end: checkNaN(ds.end),
141143
id: createUid()
142144
}
143145
})

src/components/vue-ui-quick-chart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const fd = computed(() => {
9797
'data',
9898
'value',
9999
'values',
100-
'num'
100+
'num',
101101
]), barLineSwitch: FINAL_CONFIG.value.chartIsBarUnderDatasetLength });
102102
console.log(f)
103103
if(!f) {

src/components/vue-ui-strip-plot.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ref, computed, nextTick, onMounted, onBeforeUnmount } from "vue";
33
import {
44
applyDataLabel,
55
calculateNiceScale,
6+
checkNaN,
67
convertColorToHex,
78
convertCustomPalette,
89
createCsvContent,
@@ -17,7 +18,6 @@ import {
1718
lightenHexColor,
1819
objectIsEmpty,
1920
palette,
20-
sanitizeArray,
2121
themePalettes,
2222
translateSize,
2323
XMLNS,
@@ -228,9 +228,10 @@ const immutableDataset = computed(() => {
228228
...ds,
229229
id,
230230
color: ds.color ? convertColorToHex(ds.color) : customPalette.value[i] || palette[i] || palette[i % palette.length],
231-
plots: sanitizeArray(ds.plots, ['value']).map(p => {
231+
plots: ds.plots.map(p => {
232232
return {
233233
...p,
234+
value: checkNaN(p.value),
234235
parentId: id,
235236
color: ds.color ? convertColorToHex(ds.color) : customPalette.value[i] || palette[i] || palette[i % palette.length],
236237
id: createUid(),

src/lib.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,36 @@ export function sanitizeArray(arr, keys = []) {
17821782

17831783
let sanitizedObject = { ...data };
17841784
keys.forEach(key => {
1785-
if (sanitizedObject.hasOwnProperty(key) && Array.isArray(sanitizedObject[key])) {
1785+
if (sanitizedObject.hasOwnProperty(key) && ![
1786+
'NAME',
1787+
'name',
1788+
'TITLE',
1789+
'title',
1790+
'DESCRIPTION',
1791+
'description',
1792+
'LABEL',
1793+
'label',
1794+
'TIME',
1795+
'time',
1796+
'PERIOD',
1797+
'period',
1798+
'MONTH',
1799+
'month',
1800+
'YEAR',
1801+
'year',
1802+
'MONTHS',
1803+
'months',
1804+
'YEARS',
1805+
'years',
1806+
'DAY',
1807+
'day',
1808+
'DAYS',
1809+
'days',
1810+
'HOUR',
1811+
'hour',
1812+
'HOURS',
1813+
'hours'
1814+
].includes(key) && Array.isArray(sanitizedObject[key])) {
17861815
sanitizedObject[key] = sanitize(sanitizedObject[key]);
17871816
}
17881817
});

0 commit comments

Comments
 (0)