|
5 | 5 | calcLinearProgression,
|
6 | 6 | calcMedian,
|
7 | 7 | createSmoothPath,
|
| 8 | + createStraightPath, |
8 | 9 | createUid,
|
9 | 10 | dataLabel as dl,
|
10 | 11 | error,
|
@@ -59,7 +60,7 @@ const props = defineProps({
|
59 | 60 | });
|
60 | 61 |
|
61 | 62 | const isDataset = computed(() => {
|
62 |
| - return !!props.dataset && props.dataset.length; |
| 63 | + return Array.isArray(props.dataset) && props.dataset.length > 0; |
63 | 64 | });
|
64 | 65 |
|
65 | 66 | const uid = ref(createUid());
|
@@ -143,7 +144,7 @@ const safeDatasetCopy = ref(prepareDsCopy());
|
143 | 144 | function prepareDsCopy() {
|
144 | 145 | return largestTriangleThreeBucketsArrayObjects({
|
145 | 146 | data: props.dataset.map(d => {
|
146 |
| - if (FINAL_CONFIG.value.style.animation.show) { |
| 147 | + if (FINAL_CONFIG.value.style.animation.show && props.dataset.length > 1) { |
147 | 148 | return {
|
148 | 149 | ...d,
|
149 | 150 | value: null
|
@@ -278,24 +279,25 @@ const absoluteZero = computed(() => {
|
278 | 279 | })
|
279 | 280 |
|
280 | 281 | function ratioToMax(v) {
|
281 |
| - return v / absoluteMax.value; |
| 282 | + return isNaN(v / absoluteMax.value) ? 0 : v / absoluteMax.value; |
282 | 283 | }
|
283 | 284 |
|
284 | 285 | const len = computed(() => downsampled.value.length - 1);
|
285 | 286 |
|
286 | 287 | const mutableDataset = computed(() => {
|
287 | 288 | return safeDatasetCopy.value.map((s, i) => {
|
288 | 289 | const absoluteValue = isNaN(s.value) || [undefined, null, 'NaN', NaN, Infinity, -Infinity].includes(s.value) ? 0 : (s.value || 0);
|
| 290 | + const width = (drawingArea.value.width / (len.value + 1)) > svg.padding ? svg.padding : (drawingArea.value.width / (len.value + 1)); |
289 | 291 | return {
|
290 | 292 | absoluteValue,
|
291 | 293 | period: s.period,
|
292 | 294 | plotValue: absoluteValue + absoluteMin.value,
|
293 | 295 | toMax: ratioToMax(absoluteValue + absoluteMin.value),
|
294 |
| - x: drawingArea.value.start + (i * ((drawingArea.value.width / (len.value + 1)) > svg.padding ? svg.padding : (drawingArea.value.width / (len.value + 1)))), |
| 296 | + x: drawingArea.value.start + (i * (width > drawingArea.value.width / 12 ? drawingArea.value.width / 12 : width)), |
295 | 297 | y: drawingArea.value.bottom - (drawingArea.value.height * ratioToMax(absoluteValue + absoluteMin.value)),
|
296 | 298 | id: `plot_${uid.value}_${i}`,
|
297 | 299 | color: isBar.value ? FINAL_CONFIG.value.style.bar.color : FINAL_CONFIG.value.style.area.useGradient ? shiftHue(FINAL_CONFIG.value.style.line.color, 0.05 * ( 1 - (i / len.value))) : FINAL_CONFIG.value.style.line.color,
|
298 |
| - width: (drawingArea.value.width / (len.value + 1)) > svg.padding ? svg.padding : (drawingArea.value.width / (len.value + 1)) |
| 300 | + width: width > drawingArea.value.width / 12 ? drawingArea.value.width / 12 : width |
299 | 301 | }
|
300 | 302 | })
|
301 | 303 | });
|
@@ -451,21 +453,10 @@ function selectDatapoint(datapoint, index) {
|
451 | 453 | </g>
|
452 | 454 |
|
453 | 455 | <path data-cy="sparkline-smooth-path" v-if="FINAL_CONFIG.style.line.smooth && !isBar" :d="`M ${createSmoothPath(mutableDataset)}`" :stroke="FINAL_CONFIG.style.line.color" fill="none" :stroke-width="FINAL_CONFIG.style.line.strokeWidth" stroke-linecap="round"/>
|
| 456 | + |
| 457 | + <path data-cy="sparkline-straight-line" v-if="!FINAL_CONFIG.style.line.smooth && !isBar" :d="`M ${createStraightPath(mutableDataset)}`" :stroke="FINAL_CONFIG.style.line.color" fill="none" :stroke-width="FINAL_CONFIG.style.line.strokeWidth" stroke-linecap="round"/> |
454 | 458 |
|
455 | 459 | <g v-for="(plot, i) in mutableDataset">
|
456 |
| - <line |
457 |
| - v-if="i < mutableDataset.length - 1 && !FINAL_CONFIG.style.line.smooth && !isBar" |
458 |
| - data-cy="segment-line" |
459 |
| - :x1="plot.x" |
460 |
| - :x2="mutableDataset[i + 1].x" |
461 |
| - :y1="plot.y || 0" |
462 |
| - :y2="mutableDataset[i + 1].y || 0" |
463 |
| - :stroke="plot.color" |
464 |
| - :stroke-width="FINAL_CONFIG.style.line.strokeWidth" |
465 |
| - stroke-linecap="round" |
466 |
| - stroke-linejoin="round" |
467 |
| - shape-rendering="geometricPrecision" |
468 |
| - /> |
469 | 460 | <rect
|
470 | 461 | data-cy="datapoint-bar"
|
471 | 462 | v-if="isBar"
|
@@ -509,7 +500,7 @@ function selectDatapoint(datapoint, index) {
|
509 | 500 | <g v-if="FINAL_CONFIG.style.plot.show" v-for="(plot, i) in mutableDataset">
|
510 | 501 | <circle
|
511 | 502 | data-cy="selection-plot"
|
512 |
| - v-if="(selectedPlot && plot.id === selectedPlot.id) || selectedIndex === i" |
| 503 | + v-if="(selectedPlot && plot.id === selectedPlot.id) || selectedIndex === i || dataset.length === 1" |
513 | 504 | :cx="plot.x"
|
514 | 505 | :cy="plot.y"
|
515 | 506 | :r="FINAL_CONFIG.style.plot.radius"
|
|
0 commit comments