Skip to content

Commit be8b053

Browse files
committed
VueUiScatter added marginal lines optional config
1 parent da2a438 commit be8b053

File tree

6 files changed

+99
-15
lines changed

6 files changed

+99
-15
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.1.31",
4+
"version": "2.1.32",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue 3 components library for eloquent data storytelling",
77
"keywords": [

src/App.vue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ const weeks = computed(() => {
10611061
10621062
const scat1 = computed(() => {
10631063
const arr = [];
1064-
for (let i = 0; i < 100; i += 1) {
1064+
for (let i = -100; i < 100; i += 1) {
10651065
arr.push({
10661066
x: Math.random() * i + 12,
10671067
y: (Math.random() * i) / 20,
@@ -1072,7 +1072,7 @@ const scat1 = computed(() => {
10721072
});
10731073
const scat2 = computed(() => {
10741074
const arr = [];
1075-
for (let i = 0; i < 50; i += 1) {
1075+
for (let i = -50; i < 50; i += 1) {
10761076
arr.push({
10771077
x: (Math.random() * i) / 2,
10781078
y: (Math.random() * i) / 10,
@@ -1143,12 +1143,14 @@ const scatterDataset = computed(() => {
11431143
{
11441144
name: "Cluster 1",
11451145
values: scat1.value,
1146-
shape: "star"
1146+
shape: "star",
1147+
color: '#FF0000'
11471148
},
11481149
{
11491150
name: "Cluster 2",
11501151
values: scat2.value,
1151-
shape: "diamond"
1152+
shape: "diamond",
1153+
color: "#00FF00"
11521154
},
11531155
];
11541156
});
@@ -2826,9 +2828,14 @@ const heatmapConfig = ref({
28262828
const scatterConfig = ref({
28272829
style: {
28282830
layout: {
2831+
marginalBars: {
2832+
show: true,
2833+
showLines: true,
2834+
linesStrokeWidth: 1
2835+
},
28292836
plots: {
28302837
giftWrap: {
2831-
show: true,
2838+
show: false,
28322839
strokeDasharray: 10
28332840
}
28342841
}
@@ -3801,7 +3808,7 @@ const pillConfig = ref({
38013808
</template>
38023809
</Box>
38033810

3804-
<Box open @copy="copyConfig(PROD_CONFIG.vue_ui_nested_donuts)">
3811+
<Box @copy="copyConfig(PROD_CONFIG.vue_ui_nested_donuts)">
38053812
<template #title>
38063813
<BaseIcon name="chartNestedDonuts"/>
38073814
VueUiNestedDonuts
@@ -4442,7 +4449,7 @@ const pillConfig = ref({
44424449
</template>
44434450
</Box>
44444451

4445-
<Box @copy="copyConfig(PROD_CONFIG.vue_ui_scatter)">
4452+
<Box open @copy="copyConfig(PROD_CONFIG.vue_ui_scatter)">
44464453
<template #title>
44474454
<BaseIcon name="chartScatter" />
44484455
VueUiScatter

src/components/vue-ui-scatter.vue

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
objectIsEmpty,
1313
opacity,
1414
palette,
15+
createSmoothPath,
1516
XMLNS
1617
} from '../lib';
1718
import pdf from "../pdf";
@@ -264,14 +265,19 @@ function getData() {
264265
}
265266
266267
function aggregateCoordinates(arr, scale) {
267-
const flattened = arr.flatMap(a => {
268+
const flattened = Array.isArray(arr) ? arr.flatMap(a => {
268269
return a.plots.map((p) => {
269270
return {
270271
x: p.x,
271272
y: p.y
272273
}
273274
})
274-
});
275+
}) : arr.plots.map(p => {
276+
return {
277+
x: p.x,
278+
y: p.y
279+
}
280+
})
275281
276282
let xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity;
277283
@@ -314,8 +320,35 @@ function aggregateCoordinates(arr, scale) {
314320
}
315321
316322
const scale = computed(() => scatterConfig.value.style.layout.marginalBars.tranches)
323+
317324
const marginalBars = computed(() => {
318325
return aggregateCoordinates(mutableDataset.value, scale.value)
326+
});
327+
328+
const marginalLines = computed(() => {
329+
const top = drawingArea.value.top - scatterConfig.value.style.layout.marginalBars.offset;
330+
const right = drawingArea.value.right + scatterConfig.value.style.layout.marginalBars.offset;
331+
return mutableDataset.value.map(ds => {
332+
const coords = aggregateCoordinates(ds, scale.value);
333+
334+
return {
335+
coords,
336+
dX: createSmoothPath(coords.avgX.map((el,i) => {
337+
return {
338+
x: el,
339+
y: top - coords.x[i] / coords.maxX * scatterConfig.value.style.layout.marginalBars.size
340+
}
341+
})),
342+
dY: createSmoothPath(coords.avgY.map((el, i) => {
343+
return {
344+
y: el,
345+
x: right + (scatterConfig.value.style.layout.marginalBars.size * coords.y[i] / coords.maxY)
346+
}
347+
})),
348+
color: ds.color,
349+
id: ds.id,
350+
}
351+
})
319352
})
320353
321354
const selectedPlotId = ref(undefined);
@@ -692,6 +725,46 @@ defineExpose({
692725
:rx="scatterConfig.style.layout.marginalBars.borderRadius"
693726
/>
694727
</g>
728+
<g v-if="scatterConfig.style.layout.marginalBars.showLines">
729+
<template v-for="line in marginalLines">
730+
<path
731+
v-if="!segregated.includes(line.id)"
732+
:d="`M ${line.dX}`"
733+
:stroke="scatterConfig.style.backgroundColor"
734+
:stroke-width="scatterConfig.style.layout.marginalBars.linesStrokeWidth + 1"
735+
stroke-linecap="round"
736+
stroke-linejoin="round"
737+
fill="none"
738+
/>
739+
<path
740+
v-if="!segregated.includes(line.id)"
741+
:d="`M ${line.dX}`"
742+
:stroke="line.color"
743+
:stroke-width="scatterConfig.style.layout.marginalBars.linesStrokeWidth"
744+
stroke-linecap="round"
745+
stroke-linejoin="round"
746+
fill="none"
747+
/>
748+
<path
749+
v-if="!segregated.includes(line.id)"
750+
:d="`M ${line.dY}`"
751+
:stroke="scatterConfig.style.backgroundColor"
752+
:stroke-width="scatterConfig.style.layout.marginalBars.linesStrokeWidth + 1"
753+
stroke-linecap="round"
754+
stroke-linejoin="round"
755+
fill="none"
756+
/>
757+
<path
758+
v-if="!segregated.includes(line.id)"
759+
:d="`M ${line.dY}`"
760+
:stroke="line.color"
761+
:stroke-width="scatterConfig.style.layout.marginalBars.linesStrokeWidth"
762+
stroke-linecap="round"
763+
stroke-linejoin="round"
764+
fill="none"
765+
/>
766+
</template>
767+
</g>
695768
</g>
696769
697770
<!-- AXIS LABELS -->
@@ -764,8 +837,8 @@ defineExpose({
764837
765838
<clipPath :id="`clip_path_${uid}`">
766839
<rect
767-
:x="scatterConfig.style.layout.padding.left"
768-
:y="scatterConfig.style.layout.padding.top"
840+
:x="drawingArea.left"
841+
:y="drawingArea.top"
769842
:width="drawingArea.width"
770843
:height="drawingArea.height"
771844
/>

src/default_configs.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,9 @@
19251925
"strokeWidth": 1,
19261926
"offset": 20,
19271927
"borderRadius": 2,
1928-
"useGradient": true
1928+
"useGradient": true,
1929+
"showLines": false,
1930+
"linesStrokeWidth": 1
19291931
},
19301932
"plots": {
19311933
"radius": 2,

types/vue-data-ui.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,8 @@ declare module 'vue-data-ui' {
20072007
offset?: number;
20082008
borderRadius?: number;
20092009
useGradient?: boolean;
2010+
showLines?: boolean;
2011+
linesStrokeWidth?: number;
20102012
};
20112013
correlation?: {
20122014
show?: boolean;

0 commit comments

Comments
 (0)