Skip to content

Commit 0242a3f

Browse files
committed
Improvement - VueUiSparkHistogram - Add color dataset option for individual datapoint coloring
1 parent a3d8f6f commit 0242a3f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/vue-ui-sparkhistogram.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ const computedDataset = computed(() => {
120120
const x = drawingArea.value.left + (gap / 2 + (i * unitWidth));
121121
const trapX = drawingArea.value.left + (i * unitWidth);
122122
const intensity = typeof dp.intensity === 'undefined' ? 100 : Math.round(dp.intensity * 100);
123-
const color = dp.value >= 0 ? `${FINAL_CONFIG.value.style.bars.colors.positive}${opacity[intensity]}` : `${FINAL_CONFIG.value.style.bars.colors.negative}${opacity[intensity]}`;
124-
const stroke = dp.value >= 0 ? FINAL_CONFIG.value.style.bars.colors.positive : FINAL_CONFIG.value.style.bars.colors.negative;
125-
const gradient = dp.value >= 0 ? `url(#gradient_positive_${i}_${uid.value})` : `url(#gradient_negative_${i}_${uid.value})`;
123+
const color = dp.color ? dp.color : dp.value >= 0 ? `${FINAL_CONFIG.value.style.bars.colors.positive}${opacity[intensity]}` : `${FINAL_CONFIG.value.style.bars.colors.negative}${opacity[intensity]}`;
124+
const stroke = dp.color ? dp.color : dp.value >= 0 ? FINAL_CONFIG.value.style.bars.colors.positive : FINAL_CONFIG.value.style.bars.colors.negative;
125+
const gradient = dp.color ? `url(#gradient_datapoint_${i}_${uid.value})` : dp.value >= 0 ? `url(#gradient_positive_${i}_${uid.value})` : `url(#gradient_negative_${i}_${uid.value})`;
126126
const textAnchor = x + width / 2;
127127
return {
128128
...dp,
@@ -179,6 +179,11 @@ const animation = computed(() => {
179179
<stop offset="0%" :stop-color="`${shiftHue(FINAL_CONFIG.style.bars.colors.negative, 0.05)}${opacity[negGrad.intensity]}`"/>
180180
<stop offset="100%" :stop-color="`${FINAL_CONFIG.style.bars.colors.negative}${opacity[negGrad.intensity]}`"/>
181181
</radialGradient>
182+
183+
<radialGradient v-for="(dp, i) in computedDataset" :id="`gradient_datapoint_${i}_${uid}`" cy="50%" cx="50%" r="50%" fx="50%" fy="50%">
184+
<stop offset="0%" :stop-color="`${shiftHue(dp.color, 0.05)}${opacity[dp.intensity]}`"/>
185+
<stop offset="100%" :stop-color="`${dp.color}${opacity[dp.intensity]}`"/>
186+
</radialGradient>
182187
</defs>
183188

184189
<g v-if="!FINAL_CONFIG.style.bars.shape || FINAL_CONFIG.style.bars.shape === 'square'">

0 commit comments

Comments
 (0)