Skip to content

Commit 0790909

Browse files
committed
Added tests
1 parent 41f07f3 commit 0790909

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "1.9.67",
4+
"version": "1.9.68",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,7 @@ const moodRadarConfig = ref({
42464246
</template>
42474247
</Box>
42484248

4249-
<Box @copy="copyConfig(PROD_CONFIG.vue_ui_candlestick)">
4249+
<Box open @copy="copyConfig(PROD_CONFIG.vue_ui_candlestick)">
42504250
<template #title>
42514251
<BaseIcon name="chartCandlestick" />
42524252
VueUiCandleStick

src/components/vue-ui-candlestick.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const slot = computed(() => {
129129
const extremes = computed(() => {
130130
return {
131131
max: Math.max(...datasetBreakdown.value.map(ds => ds.high)),
132-
min: Math.min(...datasetBreakdown.value.map(ds => ds.low))
132+
min: 0
133133
}
134134
});
135135

tests/lib.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
calcPercentageTrend,
88
calcPolygonPoints,
99
calcStarPoints,
10+
calculateNiceScale,
1011
checkArray,
1112
checkNaN,
1213
checkObj,
@@ -23,6 +24,7 @@ import {
2324
makeDonut,
2425
makePath,
2526
matrixTimes,
27+
niceNum,
2628
rotateMatrix,
2729
shiftHue,
2830
sumByAttribute,
@@ -616,4 +618,55 @@ describe('makePath', () => {
616618
test('creates a closed svg path from an array of plots', () => {
617619
expect(makePath(plots)).toBe('M1,2 2,3 3,4 4,5 5,6 Z')
618620
})
621+
})
622+
623+
describe('calculateNiceScale', () => {
624+
test('returns an object with nice scaling for y axis labels', () => {
625+
expect(calculateNiceScale(0, 118, 10)).toStrictEqual({
626+
max: 120,
627+
min: 0,
628+
tickSize: 20,
629+
ticks: [
630+
0,
631+
20,
632+
40,
633+
60,
634+
80,
635+
100,
636+
120,
637+
],
638+
})
639+
640+
expect(calculateNiceScale(0, 1, 10)).toStrictEqual({
641+
max: 1,
642+
min: 0,
643+
tickSize: 0.1,
644+
ticks: [
645+
0,
646+
0.1,
647+
0.2,
648+
0.30000000000000004,
649+
0.4,
650+
0.5,
651+
0.6,
652+
0.7,
653+
0.7999999999999999,
654+
0.8999999999999999,
655+
0.9999999999999999,
656+
],
657+
})
658+
})
659+
})
660+
661+
describe('niceNum', () => {
662+
test('returns a nice number', () => {
663+
expect(niceNum(1.18, false)).toBe(2)
664+
expect(niceNum(1.18, 1)).toBe(1)
665+
expect(niceNum(11.8, false)).toBe(20)
666+
expect(niceNum(11.8, 1)).toBe(10)
667+
expect(niceNum(118, false)).toBe(200)
668+
expect(niceNum(118, 1)).toBe(100)
669+
expect(niceNum(1118, false)).toBe(2000)
670+
expect(niceNum(1118, 1)).toBe(1000)
671+
})
619672
})

0 commit comments

Comments
 (0)