Skip to content

Commit 3189920

Browse files
authored
Merge pull request #101 from setaman/#100-fix-gradient-colors-handling
#100 fix gradient colors handling
2 parents 7c0a911 + f59442a commit 3189920

File tree

8 files changed

+52
-25
lines changed

8 files changed

+52
-25
lines changed

src/App.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@
4545
:thickness="10"
4646
:empty-thickness="10"
4747
line-mode="out"
48-
:loader="{ lineMode: 'in ', opacity: 1 }"
48+
:color="gradient"
49+
:loader="{
50+
lineMode: 'in ',
51+
opacity: 1,
52+
color: {
53+
colors: [
54+
{ color: 'yellow', offset: '0' },
55+
{ color: 'red', offset: '100' },
56+
],
57+
},
58+
}"
4959
>
5060
</ve-progress>
5161
</div>
@@ -58,7 +68,6 @@
5868
half
5969
:no-data="noData"
6070
:determinate="determinate"
61-
:loader="{ thickness: 40, color: 'red' }"
6271
>
6372
<template #legend>
6473
<span>/ hey</span>
@@ -138,6 +147,21 @@ export default {
138147
],
139148
radial: true,
140149
},
150+
gradient: {
151+
colors: [
152+
{
153+
color: "red",
154+
offset: "0",
155+
opacity: "1",
156+
},
157+
{
158+
color: "blue",
159+
offset: "100",
160+
opacity: "1",
161+
},
162+
],
163+
radial: false,
164+
},
141165
animation: "rs 1000 500",
142166
}),
143167
computed: {

src/components/Circle/CircleContainer.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
<svg class="ep-svg" :height="options.size" :width="options.size" xmlns="http://www.w3.org/2000/svg">
44
<g class="ep-circle--container">
55
<defs>
6-
<gradient v-if="isColorGradient" :color="options.color" type="progress" :id="options.id" />
7-
<gradient v-if="isColorFillGradient" :color="options.colorFill" type="progress-fill" :id="options.id" />
8-
<gradient v-if="isEmptyColorGradient" :color="options.emptyColor" type="empty" :id="options.id" />
9-
<gradient
10-
v-if="isEmptyColorFillGradient"
11-
:color="options.emptyColorFill"
12-
type="empty-fill"
13-
:id="options.id"
14-
/>
15-
<gradient v-if="isLoaderColorGradient" :color="options.loader.color" type="loader" :id="options.id" />
6+
<gradient v-if="isColorGradient" :color="options.color" type="progress" :uid="uid" />
7+
<gradient v-if="isColorFillGradient" :color="options.colorFill" type="progress-fill" :uid="uid" />
8+
<gradient v-if="isEmptyColorGradient" :color="options.emptyColor" type="empty" :uid="uid" />
9+
<gradient v-if="isEmptyColorFillGradient" :color="options.emptyColorFill" type="empty-fill" :uid="uid" />
10+
<gradient v-if="isLoaderColorGradient" :color="options.loader.color" type="loader" :uid="uid" />
1611
</defs>
17-
<component :is="circleType" :options="options" :id="options.id" />
12+
<component :is="circleType" :options="computedOptions" />
1813
</g>
1914
</svg>
20-
<circle-dot v-if="options.dot" :options="options" :id="options.id" />
15+
<circle-dot v-if="options.dot" :options="computedOptions" />
2116
</div>
2217
</template>
2318

@@ -37,6 +32,12 @@ export default {
3732
},
3833
},
3934
computed: {
35+
computedOptions() {
36+
return {
37+
...this.options,
38+
uid: this.uid,
39+
};
40+
},
4041
circleType() {
4142
return this.options.half ? "half-circle-progress" : "circle-progress";
4243
},
@@ -55,6 +56,9 @@ export default {
5556
isLoaderColorGradient() {
5657
return Array.isArray(this.options.loader.color.colors);
5758
},
59+
uid() {
60+
return this.$.uid;
61+
},
5862
},
5963
};
6064
</script>

src/components/Circle/CircleLoader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
},
4040
loaderColor() {
4141
return Array.isArray(this.options.loader.color.colors)
42-
? `url(#ep-loader-gradient-${this.options.id})`
42+
? `url(#ep-loader-gradient-${this.options.uid})`
4343
: this.options.color;
4444
},
4545
},

src/components/Circle/HalfCircleLoader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
},
4141
halfLoaderColor() {
4242
return Array.isArray(this.options.loader.color.colors)
43-
? `url(#ep-loader-gradient-${this.options.id})`
43+
? `url(#ep-loader-gradient-${this.options.uid})`
4444
: this.options.color;
4545
},
4646
},

src/components/Circle/circleMixin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ export default {
5555

5656
color() {
5757
return Array.isArray(this.options.color.colors)
58-
? `url(#ep-progress-gradient-${this.options.id})`
58+
? `url(#ep-progress-gradient-${this.options.uid})`
5959
: this.options.color;
6060
},
6161
emptyColor() {
6262
return Array.isArray(this.options.emptyColor.colors)
63-
? `url(#ep-empty-gradient-${this.options.id})`
63+
? `url(#ep-empty-gradient-${this.options.uid})`
6464
: this.options.emptyColor;
6565
},
6666
colorFill() {
6767
return Array.isArray(this.options.colorFill.colors)
68-
? `url(#ep-progress-fill-gradient-${this.options.id})`
68+
? `url(#ep-progress-fill-gradient-${this.options.uid})`
6969
: this.options.colorFill;
7070
},
7171
emptyColorFill() {
7272
return Array.isArray(this.options.emptyColorFill.colors)
73-
? `url(#ep-empty-fill-gradient-${this.options.id})`
73+
? `url(#ep-empty-fill-gradient-${this.options.uid})`
7474
: this.options.emptyColorFill;
7575
},
7676

src/components/Gradient.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<component
33
:is="gradientComponent"
4-
:id="`ep-${type}-gradient-${id}`"
4+
:id="`ep-${type}-gradient-${uid}`"
55
x1="0%"
66
y1="100%"
77
x2="0%"
@@ -31,7 +31,7 @@ export default {
3131
type: String,
3232
required: true,
3333
},
34-
id: {
34+
uid: {
3535
type: Number,
3636
required: true,
3737
},

src/components/VueEllipseProgress.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export default {
8383
const options = this.circlesData[i];
8484
const parsedOptions = parseOptions({
8585
index: i,
86-
id: i,
8786
...options,
8887
globalDot: this.dot,
8988
globalGap: this.gap,

tests/unit/circle/circle-colors.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const colorAsStringTests = (colorProp, color, selector, fill = false, half) => {
4545
const gradientColorTests = (colorProp, selector, gradientURLPrefix, fill = false, half) => {
4646
describe("applies gradient color correctly", () => {
4747
const wrapper = localFactory({ ...colorProp, half });
48+
const { uid } = wrapper.componentVM;
4849
const circleWrapper = wrapper.find(selector);
49-
const id = 0;
5050
const stopColorWrappers = wrapper.findAll("stop");
5151

5252
it("recognizes gradient colors", () => {
@@ -59,7 +59,7 @@ const gradientColorTests = (colorProp, selector, gradientURLPrefix, fill = false
5959
});
6060
it(`applies gradient URL to SVG ${fill ? "fill" : "stroke"}`, () => {
6161
expect(circleWrapper.element.getAttribute(`${fill ? "fill" : "stroke"}`)).to.equal(
62-
`url(#${gradientURLPrefix}-gradient-${id})`
62+
`url(#${gradientURLPrefix}-gradient-${uid})`
6363
);
6464
});
6565
it("renders corresponding amount of stop colors SVG elements", () => {

0 commit comments

Comments
 (0)