Skip to content

Commit 8684ebc

Browse files
committed
VueUiSparkline layout fixes
1 parent 64d62fe commit 8684ebc

File tree

4 files changed

+90
-47
lines changed

4 files changed

+90
-47
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": "2.0.10",
4+
"version": "2.0.11",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -824,73 +824,96 @@ const ratingDataset = ref({
824824
825825
const ratingConfig = ref(getVueDataUiConfig('vue_ui_rating'));
826826
827-
const sparklineConfig = ref(getVueDataUiConfig('vue_ui_sparkline'));
827+
const sparklineConfig = ref({
828+
type: 'line',
829+
style: {
830+
backgroundColor: "#CCCCCC"
831+
}
832+
})
833+
const sparklineConfig2 = ref({
834+
type: 'bar',
835+
style: {
836+
backgroundColor: "#CCCCCC"
837+
}
838+
})
828839
829840
const sparklineDataset = ref([
830-
{
831-
period: "period1",
832-
value: 0,
833-
},
834841
{
835842
period: "period2",
836843
value: 1,
837844
},
838845
{
839-
period: "period3",
846+
period: "period2",
840847
value: 2,
841848
},
842849
{
843-
period: "period4",
850+
period: "period2",
844851
value: 3,
845852
},
846853
{
847-
period: "period5",
848-
value: 4,
854+
period: "period2",
855+
value: 8,
849856
},
850857
{
851-
period: "period6",
852-
value: 5,
858+
period: "period2",
859+
value: 13,
860+
},
861+
{
862+
period: "period2",
863+
value: 21,
853864
},
854865
{
855-
period: "period6",
856-
value: 6,
866+
period: "period2",
867+
value: 34,
857868
},
858869
{
859-
period: "period8",
860-
value: 7,
870+
period: "period2",
871+
value: 55,
861872
},
862873
{
863-
period: "period9",
864-
value: -7,
874+
period: "period2",
875+
value: 89,
865876
},
866877
{
867-
period: "period10",
868-
value: -6,
878+
period: "period2",
879+
value: 134,
869880
},
870881
{
871-
period: "period11",
872-
value: -5,
882+
period: "period2",
883+
value: 134,
873884
},
874885
{
875-
period: "period12",
876-
value: -4,
886+
period: "period2",
887+
value: 134,
877888
},
878889
{
879-
period: "period13",
880-
value: -3,
890+
period: "period2",
891+
value: 134,
881892
},
882893
{
883-
period: "period14",
884-
value: -2,
894+
period: "period2",
895+
value: 134,
885896
},
886897
{
887-
period: "period15",
888-
value: -1,
898+
period: "period2",
899+
value: 134,
889900
},
890901
{
891-
period: "period16",
892-
value: 0,
893-
}
902+
period: "period2",
903+
value: 134,
904+
},
905+
906+
]);
907+
const sparklineDataset2 = ref([
908+
{
909+
period: "period2",
910+
value: -2,
911+
},
912+
{
913+
period: "period2",
914+
value: 2,
915+
},
916+
894917
]);
895918
896919
const heatmapDataset = computed(() => {
@@ -2944,9 +2967,27 @@ function selectHistoDatapoint({ datapoint, index }) {
29442967
:dataset="sparklineDataset"
29452968
@selectDatapoint="selectSparklineDatapoint"
29462969
>
2947-
<template #svg="{ svg }">
2948-
<circle :cx="svg.width / 2" :cy="svg.height / 2" :r="30" fill="#FF000033"/>
2949-
</template>
2970+
</SparklineTest>
2971+
<SparklineTest
2972+
ref="sparkline"
2973+
:config="sparklineConfig"
2974+
:dataset="sparklineDataset2"
2975+
@selectDatapoint="selectSparklineDatapoint"
2976+
>
2977+
</SparklineTest>
2978+
<SparklineTest
2979+
ref="sparkline"
2980+
:config="sparklineConfig2"
2981+
:dataset="sparklineDataset"
2982+
@selectDatapoint="selectSparklineDatapoint"
2983+
>
2984+
</SparklineTest>
2985+
<SparklineTest
2986+
ref="sparkline"
2987+
:config="sparklineConfig2"
2988+
:dataset="sparklineDataset2"
2989+
@selectDatapoint="selectSparklineDatapoint"
2990+
>
29502991
</SparklineTest>
29512992
</template>
29522993
<template #prod>

src/components/vue-ui-sparkline.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const svg = ref({
5050
5151
const emits = defineEmits(['hoverIndex', 'selectDatapoint'])
5252
53+
const bottomPadding = ref(6)
54+
5355
const drawingArea = computed(() => {
5456
const topPadding = 12;
5557
return {
@@ -70,18 +72,18 @@ const max = computed(() => {
7072
return Math.max(...props.dataset.map(s => isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : s.value))
7173
});
7274
73-
const bottomPadding = ref(6)
7475
7576
const absoluteMin = computed(() => {
76-
return Math.abs(min.value);
77+
const num = min.value >= 0 ? 0 : min.value
78+
return Math.abs(num);
7779
});
7880
7981
const absoluteMax = computed(() => {
8082
return max.value + absoluteMin.value + bottomPadding.value;
8183
});
8284
8385
const absoluteZero = computed(() => {
84-
return drawingArea.value.bottom - (drawingArea.value.height * ratioToMax(absoluteMin.value + bottomPadding.value))
86+
return drawingArea.value.bottom - (drawingArea.value.height * ratioToMax(absoluteMin.value))
8587
})
8688
8789
function ratioToMax(v) {
@@ -98,11 +100,11 @@ const mutableDataset = computed(() => {
98100
period: s.period,
99101
plotValue: absoluteValue + absoluteMin.value,
100102
toMax: ratioToMax(absoluteValue + absoluteMin.value),
101-
x: drawingArea.value.start + (i * (drawingArea.value.width / len.value)),
102-
y: drawingArea.value.bottom - (drawingArea.value.height * ratioToMax(absoluteValue + bottomPadding.value + absoluteMin.value)),
103-
id: `plot_${uid}_${i}`,
103+
x: drawingArea.value.start + (i * ((drawingArea.value.width / (len.value + 1)) > 30 ? 30 : (drawingArea.value.width / (len.value + 1)))),
104+
y: drawingArea.value.bottom - (drawingArea.value.height * ratioToMax(absoluteValue + absoluteMin.value)),
105+
id: `plot_${uid.value}_${i}`,
104106
color: isBar.value ? sparklineConfig.value.style.bar.color : sparklineConfig.value.style.area.useGradient ? shiftHue(sparklineConfig.value.style.line.color, 0.05 * ( 1 - (i / len.value))) : sparklineConfig.value.style.line.color,
105-
width: drawingArea.value.width / len.value
107+
width: (drawingArea.value.width / (len.value + 1)) > 30 ? 30 : (drawingArea.value.width / (len.value + 1))
106108
}
107109
})
108110
});
@@ -282,10 +284,10 @@ function selectDatapoint(datapoint, index) {
282284
<rect
283285
v-for="(plot, i) in mutableDataset"
284286
:data-cy="`sparkline-mouse-trap-${i}`"
285-
:x="plot.x - (drawingArea.width / len / 2)"
287+
:x="plot.x - ((drawingArea.width / (len + 1) > 30 ? 30 : drawingArea.width / (len + 1)) / 2)"
286288
:y="drawingArea.top - 6"
287289
:height="drawingArea.height + 6"
288-
:width="(drawingArea.width / len)"
290+
:width="(drawingArea.width / (len + 1) > 30 ? 30: drawingArea.width / (len + 1))"
289291
fill="transparent"
290292
@mouseenter="selectPlot(plot, i)"
291293
@mouseleave="unselectPlot"

0 commit comments

Comments
 (0)