Skip to content

Commit

Permalink
VueUiQuadrant add plotLabels showAsTag option
Browse files Browse the repository at this point in the history
  • Loading branch information
graphieros committed Mar 4, 2024
1 parent 3b858c1 commit f37391d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-data-ui",
"private": false,
"version": "2.0.3",
"version": "2.0.4",
"type": "module",
"description": "A user-empowering data visualization Vue components library",
"keywords": [
Expand Down
74 changes: 45 additions & 29 deletions src/components/vue-ui-quadrant.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { ref, computed, onMounted, nextTick, watch } from "vue";
import { palette, createUid, giftWrap, shiftHue, opacity, convertColorToHex, createCsvContent, downloadCsv } from "../lib";
import { palette, createUid, giftWrap, shiftHue, opacity, convertColorToHex, createCsvContent, downloadCsv, adaptColorToBackground } from "../lib";
import pdf from "../pdf.js";
import img from "../img.js";
import mainConfig from "../default_configs.json";
Expand Down Expand Up @@ -818,36 +818,52 @@ defineExpose({
</g>

<!-- PLOTS -->
<g v-for="category in drawableDataset">
<Shape
v-for="plot in category.series"
:color="category.color"
:isSelected="hoveredPlotId && plot.uid === hoveredPlotId"
:plot="plot"
:radius="quadrantConfig.style.chart.layout.plots.radius"
:shape="category.shape"
:stroke="quadrantConfig.style.chart.layout.plots.outline ? quadrantConfig.style.chart.layout.plots.outlineColor : 'none'"
:strokeWidth="quadrantConfig.style.chart.layout.plots.outlineWidth"
@mouseover="hoverPlot(category, plot)"
@mouseleave="isTooltip = false; hoveredPlotId = null; hoveredPlot = null"
@click="selectPlot(category, plot)"
/>
</g>

<g v-if="mutableConfig.plotLabels.show">
<template v-if="!quadrantConfig.style.chart.layout.labels.plotLabels.showAsTag">
<g v-for="category in drawableDataset">
<text
v-for="plot in category.series"
:x="plot.x"
:y="plot.y + quadrantConfig.style.chart.layout.labels.plotLabels.offsetY + quadrantConfig.style.chart.layout.plots.radius"
text-anchor="middle"
:font-size="quadrantConfig.style.chart.layout.labels.plotLabels.fontSize"
:fill="quadrantConfig.style.chart.layout.labels.plotLabels.color"
>
{{ plot.name }}
</text>
<Shape
v-for="plot in category.series"
:color="category.color"
:isSelected="hoveredPlotId && plot.uid === hoveredPlotId"
:plot="plot"
:radius="quadrantConfig.style.chart.layout.plots.radius"
:shape="category.shape"
:stroke="quadrantConfig.style.chart.layout.plots.outline ? quadrantConfig.style.chart.layout.plots.outlineColor : 'none'"
:strokeWidth="quadrantConfig.style.chart.layout.plots.outlineWidth"
@mouseover="hoverPlot(category, plot)"
@mouseleave="isTooltip = false; hoveredPlotId = null; hoveredPlot = null"
@click="selectPlot(category, plot)"
/>
</g>
</g>

<g v-if="mutableConfig.plotLabels.show">
<g v-for="category in drawableDataset">
<text
v-for="plot in category.series"
:x="plot.x"
:y="plot.y + quadrantConfig.style.chart.layout.labels.plotLabels.offsetY + quadrantConfig.style.chart.layout.plots.radius"
text-anchor="middle"
:font-size="quadrantConfig.style.chart.layout.labels.plotLabels.fontSize"
:fill="quadrantConfig.style.chart.layout.labels.plotLabels.color"
>
{{ plot.name }}
</text>
</g>
</g>
</template>

<template v-else>
<g v-if="mutableConfig.plotLabels.show">
<template v-for="category in drawableDataset">
<foreignObject v-for="plot in category.series" style="overflow: visible;" height="10" width="100" :x="plot.x - 50" :y="plot.y - (quadrantConfig.style.chart.layout.labels.plotLabels.fontSize)" @mouseover="hoverPlot(category, plot)"
@mouseleave="isTooltip = false; hoveredPlotId = null; hoveredPlot = null"
@click="selectPlot(category, plot)">
<div :style="`color:${adaptColorToBackground(category.color)};margin: 0 auto; font-size:${quadrantConfig.style.chart.layout.labels.plotLabels.fontSize}px; text-align:center;background:${category.color}; padding: 2px 4px; border-radius: 12px; height: ${quadrantConfig.style.chart.layout.labels.plotLabels.fontSize*1.5}px`">
{{ plot.name }}
</div>
</foreignObject>
</template>
</g>
</template>

<!-- LEGEND AS G -->
<foreignObject
Expand Down
1 change: 1 addition & 0 deletions src/default_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@
}
},
"plotLabels": {
"showAsTag": false,
"show": true,
"fontSize": 10,
"color": "#2D353C",
Expand Down
1 change: 1 addition & 0 deletions types/vue-data-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,7 @@ declare module 'vue-data-ui' {
};
};
plotLabels?: {
showAsTag?: boolean;
show?: boolean;
fontSize?: number;
color?: string;
Expand Down

0 comments on commit f37391d

Please sign in to comment.