Skip to content

Commit f389e08

Browse files
committed
Improvement - VueUiXy - Add area-gradient and bar-gradient slots for gradient customization
1 parent d6623de commit f389e08

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

TestingArena/ArenaVueUiXy.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ const dates = [
284284
function createDs(n, m = 100) {
285285
const arr = [];
286286
for (let i = 0; i < n; i += 1) {
287-
arr.push(Math.random() * m * - 1)
287+
arr.push(Math.random() * m * 1)
288288
}
289289
return arr
290290
}
@@ -393,7 +393,8 @@ onMounted(() => {
393393
series: createDs(100),
394394
type: "line",
395395
dataLabels: false,
396-
smooth: false
396+
smooth: true,
397+
useArea: true,
397398
},
398399
// {
399400
// name: "Serie B",
@@ -1237,6 +1238,24 @@ onMounted(async () => {
12371238
responsive: true,
12381239
}" @selectTimeLabel="selectTimeLabel">
12391240

1241+
<template #area-gradient="{ series, id }">
1242+
<linearGradient :id="id" x1="0" x2="0" y1="0" y2="1">
1243+
<stop offset="0%" :stop-color="series.color"/>
1244+
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
1245+
</linearGradient>
1246+
</template>
1247+
1248+
<template #bar-gradient="{ series, positiveId, negativeId }">
1249+
<linearGradient :id="positiveId" x1="0" x2="0" y1="0" y2="1">
1250+
<stop offset="0%" :stop-color="series.color"/>
1251+
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
1252+
</linearGradient>
1253+
<linearGradient :id="negativeId" x1="0" x2="0" y1="0" y2="1">
1254+
<stop offset="0%" stop-color="#FFFFFF" stop-opacity="0"/>
1255+
<stop offset="100%" :stop-color="series.color"/>
1256+
</linearGradient>
1257+
</template>
1258+
12401259
<!-- <template #pattern="{ seriesIndex, patternId }">
12411260
<pattern v-if="seriesIndex === 0" :id="patternId" width="70" height="8" patternTransform="scale(2)"
12421261
patternUnits="userSpaceOnUse" opacity="0.5">

src/components/vue-ui-xy.vue

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,16 +3098,21 @@ defineExpose({
30983098
<!-- DEFS BARS -->
30993099
<template v-for="(serie, i) in barSet" :key="`def_rect_${i}`">
31003100
<defs :data-cy="`xy-def-bar-${i}`">
3101-
<linearGradient :id="`rectGradient_pos_${i}_${uniqueId}`" x2="0%" y2="100%">
3102-
<stop offset="0%" :stop-color="serie.color" />
3103-
<stop offset="62%" :stop-color="`${shiftHue(serie.color, 0.02)}`" />
3104-
<stop offset="100%" :stop-color="`${shiftHue(serie.color, 0.05)}`" />
3105-
</linearGradient>
3106-
<linearGradient :id="`rectGradient_neg_${i}_${uniqueId}`" x2="0%" y2="100%">
3107-
<stop offset="0%" :stop-color="`${shiftHue(serie.color, 0.05)}`" />
3108-
<stop offset="38%" :stop-color="`${shiftHue(serie.color, 0.02)}`" />
3109-
<stop offset="100%" :stop-color="serie.color" />
3110-
</linearGradient>
3101+
<template v-if="$slots['bar-gradient']">
3102+
<slot name="bar-gradient" v-bind="{ series: serie, positiveId: `rectGradient_pos_${i}_${uniqueId}`, negativeId: `rectGradient_neg_${i}_${uniqueId}` }"/>
3103+
</template>
3104+
<template v-else>
3105+
<linearGradient :id="`rectGradient_pos_${i}_${uniqueId}`" x2="0%" y2="100%">
3106+
<stop offset="0%" :stop-color="serie.color" />
3107+
<stop offset="62%" :stop-color="`${shiftHue(serie.color, 0.02)}`" />
3108+
<stop offset="100%" :stop-color="`${shiftHue(serie.color, 0.05)}`" />
3109+
</linearGradient>
3110+
<linearGradient :id="`rectGradient_neg_${i}_${uniqueId}`" x2="0%" y2="100%">
3111+
<stop offset="0%" :stop-color="`${shiftHue(serie.color, 0.05)}`" />
3112+
<stop offset="38%" :stop-color="`${shiftHue(serie.color, 0.02)}`" />
3113+
<stop offset="100%" :stop-color="serie.color" />
3114+
</linearGradient>
3115+
</template>
31113116
</defs>
31123117
</template>
31133118
@@ -3130,7 +3135,8 @@ defineExpose({
31303135
<stop offset="0%" :stop-color="`${shiftHue(serie.color, 0.05)}`" />
31313136
<stop offset="100%" :stop-color="serie.color" />
31323137
</radialGradient>
3133-
<linearGradient :id="`areaGradient_${i}_${uniqueId}`" x1="0%" x2="100%" y1="0%" y2="0%">
3138+
<slot v-if="$slots['area-gradient']" name="area-gradient" v-bind="{ series: serie, id: `areaGradient_${i}_${uniqueId}` }"/>
3139+
<linearGradient v-else :id="`areaGradient_${i}_${uniqueId}`" x1="0%" x2="100%" y1="0%" y2="0%">
31343140
<stop offset="0%"
31353141
:stop-color="`${setOpacity(shiftHue(serie.color, 0.03), FINAL_CONFIG.line.area.opacity)}`" />
31363142
<stop offset="100%"

0 commit comments

Comments
 (0)