Skip to content

Commit

Permalink
VueUiAgePyramid added OffsetY to serie titles; refactored tooltip cus…
Browse files Browse the repository at this point in the history
…tomFormat handling
  • Loading branch information
graphieros committed Mar 11, 2024
1 parent f7c8dff commit 41e2a57
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 58 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.17",
"version": "2.0.18",
"type": "module",
"description": "A user-empowering data visualization Vue components library",
"keywords": [
Expand Down
26 changes: 15 additions & 11 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2410,8 +2410,8 @@ const donutConfig = ref({
tooltip: {
customFormat: ({ datapoint, seriesIndex, series , config}) => {
console.log({datapoint, seriesIndex, series, config});
return `<div style="color:${datapoint.color}">
${datapoint.name}
return `<div style="background:${datapoint.color}33;color:${datapoint.color};padding:12px">
${datapoint.name} : ${datapoint.value}
</div>`
}
}
Expand All @@ -2424,12 +2424,12 @@ const xyConfig = ref({
labels: {
fontSize: 30
},
// tooltip: {
// customFormat: ({ seriesIndex, datapoint, series, bars, lines, plots, config }) => {
// console.log({seriesIndex, datapoint, series, bars, lines, plots, config});
// return 'TEST'
// }
// }
tooltip: {
customFormat: ({ seriesIndex, datapoint, series, bars, lines, plots, config }) => {
console.log({seriesIndex, datapoint, series, bars, lines, plots, config});
return 'TEST'
}
}
},
bar: {
labels: {
Expand Down Expand Up @@ -2545,6 +2545,13 @@ const pyramidConfig = ref({
console.log({ seriesIndex, datapoint, series, config });
return "TEST"
}
},
layout: {
dataLabels: {
sideTitles: {
offsetY: -20
}
}
}
}
})
Expand Down Expand Up @@ -3948,8 +3955,5 @@ function selectHistoDatapoint({ datapoint, index }) {
</style>

<style>
.vue-data-ui-custom-tooltip {
background: red;
}
</style>
18 changes: 13 additions & 5 deletions src/components/vue-ui-age-pyramid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<script setup>
import { ref, computed, nextTick } from "vue";
import { opacity, shiftHue, createUid, createCsvContent, downloadCsv } from '../lib';
import {
createCsvContent,
createUid,
downloadCsv,
functionReturnsString,
isFunction,
opacity,
shiftHue,
} from '../lib';
import pdf from "../pdf";
import img from "../img";
import mainConfig from "../default_configs.json";
Expand Down Expand Up @@ -184,7 +192,7 @@ function useTooltip(index, datapoint) {
const customFormat = agePyramidConfig.value.style.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: index,
datapoint: {
segment: datapoint[0],
Expand All @@ -194,7 +202,7 @@ function useTooltip(index, datapoint) {
},
series: drawableDataset.value,
config: agePyramidConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: index,
datapoint: {
Expand Down Expand Up @@ -475,7 +483,7 @@ defineExpose({
<g v-if="agePyramidConfig.style.layout.dataLabels.sideTitles.show">
<text
:x="drawingArea.left"
:y="drawingArea.top"
:y="drawingArea.top + agePyramidConfig.style.layout.dataLabels.sideTitles.offsetY"
:fill="agePyramidConfig.style.layout.dataLabels.sideTitles.useSideColor ? agePyramidConfig.style.layout.bars.left.color : agePyramidConfig.style.layout.dataLabels.sideTitles.color"
:font-size="agePyramidConfig.style.layout.dataLabels.sideTitles.fontSize"
text-anchor="start"
Expand All @@ -485,7 +493,7 @@ defineExpose({
</text>
<text
:x="drawingArea.right"
:y="drawingArea.top"
:y="drawingArea.top + agePyramidConfig.style.layout.dataLabels.sideTitles.offsetY"
:fill="agePyramidConfig.style.layout.dataLabels.sideTitles.useSideColor ? agePyramidConfig.style.layout.bars.right.color : agePyramidConfig.style.layout.dataLabels.sideTitles.color"
:font-size="agePyramidConfig.style.layout.dataLabels.sideTitles.fontSize"
text-anchor="end"
Expand Down
17 changes: 14 additions & 3 deletions src/components/vue-ui-candlestick.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<script setup>
import { ref, computed, onMounted, nextTick } from "vue";
import { canShowValue, closestDecimal, shiftHue, opacity, createUid, createCsvContent, downloadCsv, calculateNiceScale } from "../lib";
import {
calculateNiceScale,
canShowValue,
closestDecimal,
createCsvContent,
createUid,
downloadCsv,
functionReturnsString,
isFunction,
opacity,
shiftHue,
} from "../lib";
import mainConfig from "../default_configs.json";
import pdf from "../pdf";
import img from "../img";
Expand Down Expand Up @@ -188,12 +199,12 @@ function useTooltip(index, datapoint) {
const customFormat = candlestickConfig.value.style.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: index,
datapoint,
series: drawableDataset.value,
config: candlestickConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: index,
datapoint,
Expand Down
18 changes: 15 additions & 3 deletions src/components/vue-ui-donut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
createCsvContent,
createUid,
dataLabel,
downloadCsv,
downloadCsv,
functionReturnsString,
isFunction,
makeDonut,
opacity,
palette,
Expand Down Expand Up @@ -192,8 +194,18 @@ function useTooltip({datapoint, relativeIndex, seriesIndex, show = false}) {
const customFormat = donutConfig.value.style.chart.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({ seriesIndex, datapoint, series: immutableSet.value, config: donutConfig.value }) === 'string') {
tooltipContent.value = customFormat({ seriesIndex, datapoint, series: immutableSet.value, config: donutConfig.value })
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex,
datapoint,
series: immutableSet.value,
config: donutConfig.value
}, () => tooltipContent))) {
tooltipContent.value = customFormat({
seriesIndex,
datapoint,
series: immutableSet.value,
config: donutConfig.value
})
} else {
html += `<div data-cy="donut-tooltip-name" style="width:100%;text-align:center;border-bottom:1px solid #ccc;padding-bottom:6px;margin-bottom:3px;">${datapoint.name}</div>`;
html += `<div style="display:flex;flex-direction:row;gap:6px;align-items:center;"><svg viewBox="0 0 12 12" height="14" width="14"><circle data-cy="donut-tooltip-marker" cx="6" cy="6" r="6" stroke="none" fill="${datapoint.color}"/></svg>`;
Expand Down
9 changes: 5 additions & 4 deletions src/components/vue-ui-heatmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
createCsvContent,
createUid,
dataLabel,
downloadCsv,
downloadCsv,
functionReturnsString,
isFunction,
interpolateColorHex,
opacity,
} from "../lib";
Expand Down Expand Up @@ -183,12 +185,12 @@ function useTooltip(datapoint, seriesIndex) {
const customFormat = heatmapConfig.value.style.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
datapoint,
seriesIndex,
series: mutableDataset.value,
config: heatmapConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
datapoint,
seriesIndex,
Expand All @@ -200,7 +202,6 @@ function useTooltip(datapoint, seriesIndex) {
html += `<div data-cy="heatmap-tooltip-value" style="margin-top:6px;padding-top:6px;border-top:1px solid #e1e5e8;font-weight:bold;display:flex;flex-direction:row;gap:12px;align-items:center;justify-content:center"><span style="color:${interpolateColorHex(heatmapConfig.value.style.layout.cells.colors.cold, heatmapConfig.value.style.layout.cells.colors.hot, minValue.value, maxValue.value, value)}">⬤</span><span>${isNaN(value) ? "-" : dataLabel({p:heatmapConfig.value.style.layout.dataLabels.prefix, v: value, s: heatmapConfig.value.style.layout.dataLabels.suffix, r:heatmapConfig.value.style.tooltip.roundingValue })}</span></div>`
tooltipContent.value = `<div style="font-size:${heatmapConfig.value.style.tooltip.fontSize}px">${html}</div>`;
}
}
const sideLegendIndicatorY = computed(() => {
Expand Down
15 changes: 12 additions & 3 deletions src/components/vue-ui-molecule.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<script setup>
import { ref, computed, nextTick } from "vue";
import { lightenHexColor, palette, createUid, createCsvContent, downloadCsv, createPolygonPath } from '../lib';
import {
createCsvContent,
createPolygonPath,
createUid,
downloadCsv,
functionReturnsString,
isFunction,
lightenHexColor,
palette,
} from '../lib';
import pdf from "../pdf";
import img from "../img";
import mainConfig from "../default_configs.json";
Expand Down Expand Up @@ -250,12 +259,12 @@ function createTooltipContent(node) {
const customFormat = moleculeConfig.value.style.chart.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: -1,
datapoint: node,
series: convertedDataset.value,
config: moleculeConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: -1, // well, ok
datapoint: node,
Expand Down
20 changes: 15 additions & 5 deletions src/components/vue-ui-quadrant.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<script setup>
import { ref, computed, onMounted, nextTick, watch } from "vue";
import { palette, createUid, giftWrap, shiftHue, opacity, convertColorToHex, createCsvContent, downloadCsv, adaptColorToBackground } from "../lib";
import {
adaptColorToBackground,
convertColorToHex,
createCsvContent,
createUid,
downloadCsv,
functionReturnsString,
isFunction,
giftWrap,
opacity,
palette,
shiftHue,
} from "../lib";
import pdf from "../pdf.js";
import img from "../img.js";
import mainConfig from "../default_configs.json";
Expand Down Expand Up @@ -426,20 +438,18 @@ function useTooltip(category, plot, categoryIndex) {
const customFormat = quadrantConfig.value.style.chart.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: categoryIndex,
datapoint: plot,
series: drawableDataset.value,
config: quadrantConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: categoryIndex,
datapoint: plot,
series: drawableDataset.value,
config: quadrantConfig.value
})
} else {
let html = "";
Expand Down
6 changes: 4 additions & 2 deletions src/components/vue-ui-radar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
createUid,
dataLabel,
downloadCsv,
functionReturnsString,
isFunction,
makePath,
opacity,
palette,
Expand Down Expand Up @@ -298,12 +300,12 @@ function useTooltip(apex, i) {
const customFormat = radarConfig.value.style.chart.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: i,
datapoint: apex,
series: { categories: datasetCopy.value, datapoints: seriesCopy.value, radar: radar.value },
config: radarConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: i,
datapoint: apex,
Expand Down
6 changes: 4 additions & 2 deletions src/components/vue-ui-rings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
createUid,
dataLabel,
downloadCsv,
functionReturnsString,
isFunction,
opacity,
palette,
shiftHue,
Expand Down Expand Up @@ -191,12 +193,12 @@ function useTooltip(index, datapoint) {
const selected = convertedDataset.value[index];
const customFormat = ringsConfig.value.style.chart.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
seriesIndex: index,
datapoint,
series: convertedDataset.value,
config: ringsConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
seriesIndex: index,
datapoint,
Expand Down
14 changes: 11 additions & 3 deletions src/components/vue-ui-scatter.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<script setup>
import { ref, computed, nextTick, onMounted } from "vue";
import { palette, opacity, createUid, createCsvContent, downloadCsv } from '../lib';
import {
createCsvContent,
createUid,
downloadCsv,
functionReturnsString,
isFunction,
opacity,
palette,
} from '../lib';
import pdf from "../pdf";
import img from "../img";
import mainConfig from "../default_configs.json";
Expand Down Expand Up @@ -210,12 +218,12 @@ function useTooltip(plot, seriesIndex) {
const customFormat = scatterConfig.value.style.tooltip.customFormat;
if (customFormat && typeof customFormat === 'function' && typeof customFormat({
if (isFunction(customFormat) && functionReturnsString(() => customFormat({
datapoint: plot,
seriesIndex,
series: drawableDataset.value,
config: scatterConfig.value
}) === 'string') {
}))) {
tooltipContent.value = customFormat({
datapoint: plot,
seriesIndex,
Expand Down
Loading

0 comments on commit 41e2a57

Please sign in to comment.