Skip to content

Commit cfe8315

Browse files
committed
fix: rewrite props parsing strategy
1 parent d7e2594 commit cfe8315

9 files changed

+195
-201
lines changed

src/App.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<input type="checkbox" v-model="circles[3].loading" />
3939
</div>-->
4040
<div style="border: 1px solid red; display: inline-block">
41-
<!--<vue-ellipse-progress
41+
<vue-ellipse-progress
4242
:size="200"
4343
:progress="progress"
4444
:legendValue="1315.56"
@@ -49,6 +49,7 @@
4949
line-mode="out 10"
5050
:no-data="noData"
5151
:determinate="determinate"
52+
:data="circles"
5253
>
5354
<template v-slot:default="{ counterTick }">
5455
<span
@@ -59,7 +60,7 @@
5960
{{ formattedPrice(counterTick.currentValue) }}
6061
</span>
6162
</template>
62-
</vue-ellipse-progress>-->
63+
</vue-ellipse-progress>
6364
</div>
6465
<vue-ellipse-progress
6566
dot="20 green"

src/components/Circle/Circle.vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:style="{
55
transitionDuration: styles.transitionDuration,
66
transitionTimingFunction: styles.transitionTimingFunction,
7-
transform: `rotate(${computedAngle}deg)`,
7+
transform: `rotate(${angle}deg)`,
88
}"
99
>
1010
<circle
@@ -20,21 +20,21 @@
2020
transitionDuration: animationDuration,
2121
transitionTimingFunction: styles.transitionTimingFunction,
2222
}"
23-
:stroke-width="computedEmptyThickness"
23+
:stroke-width="emptyThickness"
2424
>
2525
</circle>
2626
<fade-in-transition>
2727
<g v-if="isLoading">
28-
<g class="ep-circle--loading__container" :style="{ opacity: `${loading ? 1 : 0.45}` }">
28+
<g class="ep-circle--loading__container" :style="{ opacity: `${options.loading ? 1 : 0.45}` }">
2929
<circle
3030
class="ep-circle--loading animation__loading"
3131
:r="radius"
3232
:cx="position"
3333
:cy="position"
3434
fill="transparent"
3535
:stroke="computedColor"
36-
:stroke-width="computedThickness"
37-
:stroke-linecap="line"
36+
:stroke-width="thickness"
37+
:stroke-linecap="options.line"
3838
:stroke-dasharray="circumference"
3939
:style="{
4040
transitionTimingFunction: styles.transitionTimingFunction,
@@ -55,8 +55,8 @@
5555
:cy="position"
5656
:fill="computedColorFill"
5757
:stroke="computedColor"
58-
:stroke-width="computedThickness"
59-
:stroke-linecap="line"
58+
:stroke-width="thickness"
59+
:stroke-linecap="options.line"
6060
:stroke-dasharray="circumference"
6161
:style="styles"
6262
>
@@ -74,7 +74,7 @@ export default {
7474
mixins: [CircleMixin],
7575
computed: {
7676
position() {
77-
return this.size / 2;
77+
return this.options.size / 2;
7878
},
7979
circumference() {
8080
return this.radius * 2 * Math.PI;

src/components/Circle/CircleContainer.vue

+20-36
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,55 @@
11
<template>
2-
<div class="ep-svg-container" :class="{ 'ep-reverse': reverse }">
3-
<svg class="ep-svg" :height="size" :width="size" xmlns="http://www.w3.org/2000/svg">
2+
<div class="ep-svg-container" :class="{ 'ep-reverse': options.reverse }">
3+
<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="color" type="progress" :id="id" />
7-
<gradient v-if="isColorFillGradient" :color="colorFill" type="progress-fill" :id="id" />
8-
<gradient v-if="isEmptyColorGradient" :color="emptyColor" type="empty" :id="id" />
9-
<gradient v-if="isEmptyColorFillGradient" :color="emptyColorFill" type="empty-fill" :id="id" />
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+
/>
1015
</defs>
11-
<component :is="circleType" v-bind="$props" :id="id" />
16+
<component :is="circleType" :options="options" :id="options.id" />
1217
</g>
1318
</svg>
14-
<circle-dot v-if="dot" v-bind="$props" :id="id" />
19+
<circle-dot v-if="options.dot" :options="options" :id="options.id" />
1520
</div>
1621
</template>
1722

1823
<script>
1924
import Gradient from "../Gradient.vue";
2025
import HalfCircleProgress from "./HalfCircle.vue";
2126
import CircleProgress from "./Circle.vue";
22-
import { simplifiedProps } from "../interface";
2327
import CircleDot from "./CircleDot.vue";
2428
2529
export default {
2630
name: "EpCircleContainer",
2731
components: { CircleDot, CircleProgress, HalfCircleProgress, Gradient },
2832
props: {
29-
...simplifiedProps,
30-
index: {
31-
type: Number,
33+
options: {
34+
type: Object,
3235
required: true,
3336
},
34-
multiple: {
35-
type: Boolean,
36-
required: true,
37-
},
38-
globalThickness: {
39-
type: [Number, String],
40-
required: false,
41-
default: "5%",
42-
},
43-
globalGap: {
44-
type: Number,
45-
required: false,
46-
},
47-
globalDot: {
48-
type: [Number, String, Object],
49-
required: false,
50-
},
51-
// Temp Fix
52-
id: Number,
5337
},
5438
computed: {
5539
circleType() {
56-
return this.half ? "half-circle-progress" : "circle-progress";
40+
return this.options.half ? "half-circle-progress" : "circle-progress";
5741
},
5842
isColorGradient() {
59-
return Array.isArray(this.color.colors);
43+
return Array.isArray(this.options.color.colors);
6044
},
6145
isColorFillGradient() {
62-
return Array.isArray(this.colorFill.colors);
46+
return Array.isArray(this.options.colorFill.colors);
6347
},
6448
isEmptyColorGradient() {
65-
return Array.isArray(this.emptyColor.colors);
49+
return Array.isArray(this.options.emptyColor.colors);
6650
},
6751
isEmptyColorFillGradient() {
68-
return Array.isArray(this.emptyColorFill.colors);
52+
return Array.isArray(this.options.emptyColorFill.colors);
6953
},
7054
},
7155
};

src/components/Circle/CircleDot.vue

+12-16
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,30 @@
77
</template>
88

99
<script>
10-
import { simplifiedProps } from "../interface";
1110
import CircleMixin from "./circleMixin";
1211
1312
export default {
14-
props: { ...simplifiedProps },
1513
name: "CircleDot",
1614
mixins: [CircleMixin],
1715
computed: {
1816
dotContainerSize() {
1917
return this.radius * 2 + this.dotSize;
2018
},
2119
dotContainerRotation() {
22-
if (this.isInitialized && !this.loading && this.dataIsAvailable) {
20+
if (this.isInitialized && !this.options.loading && this.dataIsAvailable) {
2321
return this.dotEnd;
2422
}
2523
return this.dotStart;
2624
},
2725
dotContainerFullRotationDeg() {
28-
return this.half ? 180 : 360;
26+
return this.options.half ? 180 : 360;
2927
},
3028
dotContainerStyle() {
3129
return {
3230
width: `${this.dotContainerSize}px`,
3331
height: `${this.dotContainerSize}px`,
3432
transform: `rotate(${this.dotContainerRotation}deg)`,
35-
transitionDuration: this.loading || !this.dataIsAvailable ? "0s" : this.animationDuration,
33+
transitionDuration: this.options.loading || !this.dataIsAvailable ? "0s" : this.animationDuration,
3634
transitionTimingFunction: "ease-in-out",
3735
"animation-duration": this.animationDuration,
3836
"--ep-dot-start": `${this.dotStart}deg`,
@@ -42,47 +40,45 @@ export default {
4240
};
4341
},
4442
dotContainerClasses() {
45-
return [this.animationClass, !this.half || "ep-half-circle-progress__dot"];
43+
return [this.animationClass, !this.options.half || "ep-half-circle-progress__dot"];
4644
},
4745
dotContainerAnimationStyle() {
4846
const styles = {
4947
loop: {
50-
opacity: this.half ? 0 : 1,
48+
opacity: this.options.half ? 0 : 1,
5149
"--ep-dot-loop-end": `${this.dotStart + this.dotContainerFullRotationDeg + this.dotEnd}deg`,
5250
},
5351
bounce: {
5452
opacity: 0,
55-
"animation-duration": `${this.parsedAnimation.duration + 500}ms`,
53+
"animation-duration": `${this.animationDuration + 500}ms`,
5654
},
5755
};
58-
return styles[this.parsedAnimation.type];
56+
return styles[this.animation.type];
5957
},
6058
dotStyle() {
6159
return {
6260
borderRadius: `${this.dotSize / 2}px`,
6361
width: `${this.dotSize}px`,
6462
backgroundColor: this.dotColor,
65-
// eslint-disable-next-line max-len
66-
// FIXME: this is passed as String (e.g "20 green") and destructed ({0:2, 0:0...}), causing CSSStyleDeclaration Error
67-
// ...this.dot,
68-
transitionDuration: this.loading || !this.dataIsAvailable ? "0s" : this.animationDuration,
63+
...this.options.dot,
64+
transitionDuration: this.options.loading || !this.dataIsAvailable ? "0s" : this.animationDuration,
6965
height: `${this.dotSize}px`,
7066
};
7167
},
7268
dotStart() {
73-
return this.half ? this.angle - 90 : this.angle + 90;
69+
return this.options.half ? this.angle - 90 : this.angle + 90;
7470
},
7571
dotEnd() {
7672
const progress = this.calculateProgress();
7773
return this.dotStart + (progress * this.dotContainerFullRotationDeg) / 100;
7874
},
7975
isHidden() {
80-
return !this.isInitialized || this.loading || !this.dataIsAvailable;
76+
return !this.isInitialized || this.options.loading || !this.dataIsAvailable;
8177
},
8278
},
8379
methods: {
8480
calculateProgress() {
85-
if (this.half) {
81+
if (this.options.half) {
8682
return this.computedProgress < 0 ? this.computedProgress - 100 : this.computedProgress;
8783
}
8884
return this.computedProgress;

src/components/Circle/HalfCircle.vue

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
:style="{
55
transitionDuration: styles.transitionDuration,
66
transitionTimingFunction: styles.transitionTimingFunction,
7-
transform: `rotate(${computedAngle}deg)`,
7+
transform: `rotate(${angle}deg)`,
88
}"
99
>
1010
<path
11-
:stroke-width="computedEmptyThickness"
11+
:stroke-width="emptyThickness"
1212
:fill="computedColorFill"
1313
:stroke="computedEmptyColor"
1414
class="ep-half-circle--empty"
1515
:d="emptyPath"
16-
:stroke-linecap="line"
16+
:stroke-linecap="options.line"
1717
:stroke-dasharray="emptyDasharray"
1818
:style="{
1919
transitionDuration: animationDuration,
@@ -24,15 +24,15 @@
2424
</path>
2525
<fade-in-transition>
2626
<g v-if="isLoading">
27-
<g :style="{ opacity: `${loading ? 1 : 0.45}` }">
27+
<g :style="{ opacity: `${options.loading ? 1 : 0.45}` }">
2828
<path
29-
:stroke-width="computedThickness"
29+
:stroke-width="thickness"
3030
class="ep-half-circle--loading animation__loading"
3131
:d="path"
3232
:fill="computedColorFill"
3333
:stroke="computedColor"
3434
:stroke-dasharray="circumference"
35-
:stroke-linecap="line"
35+
:stroke-linecap="options.line"
3636
:style="{
3737
transitionTimingFunction: styles.transitionTimingFunction,
3838
transformOrigin: styles.transformOrigin,
@@ -47,14 +47,14 @@
4747
</fade-in-transition>
4848

4949
<path
50-
:stroke-width="computedThickness"
50+
:stroke-width="thickness"
5151
class="ep-half-circle--progress ep-circle--progress"
5252
:class="animationClass"
5353
:d="path"
5454
:fill="computedColorFill"
5555
:stroke="computedColor"
5656
:stroke-dasharray="circumference"
57-
:stroke-linecap="line"
57+
:stroke-linecap="options.line"
5858
:style="styles"
5959
>
6060
</path>
@@ -73,18 +73,18 @@ export default {
7373
return (this.radius * 2 * Math.PI) / 2;
7474
},
7575
path() {
76-
return ` M ${this.position}, ${this.size / 2} a ${this.radius},${this.radius} 0 1,1 ${this.radius * 2},0`;
76+
return ` M ${this.position}, ${this.options.size / 2} a ${this.radius},${this.radius} 0 1,1 ${this.radius * 2},0`;
7777
},
7878
emptyPath() {
79-
return ` M ${this.emptyPosition}, ${this.size / 2} a ${this.emptyRadius},${this.emptyRadius} 0 1,1 ${
79+
return ` M ${this.emptyPosition}, ${this.options.size / 2} a ${this.emptyRadius},${this.emptyRadius} 0 1,1 ${
8080
this.emptyRadius * 2
8181
},0`;
8282
},
8383
position() {
84-
return this.size / 2 - this.radius;
84+
return this.options.size / 2 - this.radius;
8585
},
8686
emptyPosition() {
87-
return this.size / 2 - this.emptyRadius;
87+
return this.options.size / 2 - this.emptyRadius;
8888
},
8989
},
9090
};

0 commit comments

Comments
 (0)