Skip to content

Commit bd17d62

Browse files
authored
Merge pull request #93 from setaman/v2-stroke-alignment
V2 stroke alignment
2 parents 389943d + 6b2fc86 commit bd17d62

File tree

10 files changed

+115
-36
lines changed

10 files changed

+115
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-ellipse-progress",
3-
"version": "2.0.0-alpha.5",
3+
"version": "2.0.0-alpha.6",
44
"private": false,
55
"description": "A Vue.js component to create beautiful animated circular progress bars",
66
"main": "./dist/veprogress.umd.min.js",

src/App.vue

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,15 @@
3939
</div>-->
4040
<div style="border: 1px solid red; display: inline-block">
4141
<ve-progress
42-
:size="200"
42+
:size="600"
43+
:angle="0"
44+
line-position="out 26"
45+
empty-line-position="out 20"
46+
empty-color-fill="transparent"
47+
color-fill="red"
4348
:progress="progress"
44-
:legendValue="1315.56"
45-
animation="rs 2000 500"
46-
:loading="loading"
47-
:reverse="true"
48-
:thickness="20"
49-
:empty-thickness="10"
50-
dot="10 red"
51-
:loader="{ thickness: 40, color: 'red' }"
52-
line-mode="bottom"
5349
:no-data="noData"
54-
:determinate="determinate"
5550
>
56-
<template v-slot:default="{ counterTick }">
57-
<span
58-
:style="` transition: 0.5s; font-weight: bold; font-size: 1.6rem; color: ${
59-
counterTick.currentValue < 600 ? 'red' : 'yellow'
60-
};`"
61-
>
62-
{{ formattedPrice(counterTick.currentValue) }}
63-
</span>
64-
</template>
6551
</ve-progress>
6652
</div>
6753
<ve-progress

src/components/Circle/Circle.vue

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@
77
transform: `rotate(${angle}deg)`,
88
}"
99
>
10+
<circle
11+
class="ep-circle--empty__fill"
12+
:r="emptyFillRadius"
13+
:cx="position"
14+
:cy="position"
15+
:fill="computedEmptyColorFill"
16+
:class="{ 'ep-circle--nodata': !dataIsAvailable }"
17+
:style="{
18+
transitionDuration: animationDuration,
19+
transitionTimingFunction: styles.transitionTimingFunction,
20+
}"
21+
>
22+
</circle>
1023
<circle
1124
class="ep-circle--empty"
1225
:r="emptyRadius"
1326
:cx="position"
1427
:cy="position"
1528
:stroke="computedEmptyColor"
1629
:stroke-dasharray="emptyDasharray"
17-
:fill="computedEmptyColorFill"
30+
fill="transparent"
1831
:class="{ 'ep-circle--nodata': !dataIsAvailable }"
1932
:style="{
2033
transitionDuration: animationDuration,
@@ -28,13 +41,23 @@
2841
<circle-loader :options="options.loader" />
2942
</g>
3043
</fade-in-transition>
44+
<circle
45+
class="ep-circle--progress__fill"
46+
:r="fillRadius"
47+
:cx="position"
48+
:cy="position"
49+
:fill="computedColorFill"
50+
:class="{ 'ep-circle--nodata': !dataIsAvailable }"
51+
:style="{ transition: styles.transition }"
52+
>
53+
</circle>
3154
<circle
3255
class="ep-circle--progress"
3356
:class="animationClass"
3457
:r="radius"
3558
:cx="position"
3659
:cy="position"
37-
:fill="computedColorFill"
60+
fill="transparent"
3861
:stroke="computedColor"
3962
:stroke-width="thickness"
4063
:stroke-linecap="options.line"

src/components/Circle/HalfCircle.vue

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77
transform: `rotate(${angle}deg)`,
88
}"
99
>
10+
<path
11+
:fill="computedEmptyColorFill"
12+
:d="emptyFillPath"
13+
:style="{
14+
transition: styles.transition,
15+
}"
16+
:class="{ 'ep-circle--nodata': !dataIsAvailable }"
17+
>
18+
</path>
1019
<path
1120
:stroke-width="emptyThickness"
12-
:fill="computedColorFill"
21+
fill="transparent"
1322
:stroke="computedEmptyColor"
1423
class="ep-half-circle--empty"
1524
:d="emptyPath"
@@ -28,12 +37,19 @@
2837
</g>
2938
</fade-in-transition>
3039

40+
<path
41+
class="ep-half-circle--progress__fill"
42+
:d="fillPath"
43+
:fill="computedColorFill"
44+
:style="{ transition: styles.transition }"
45+
>
46+
</path>
3147
<path
3248
:stroke-width="thickness"
3349
class="ep-half-circle--progress ep-circle--progress"
3450
:class="animationClass"
3551
:d="path"
36-
:fill="computedColorFill"
52+
fill="transparent"
3753
:stroke="computedColor"
3854
:stroke-dasharray="circumference"
3955
:stroke-linecap="options.line"
@@ -56,18 +72,24 @@ export default {
5672
return (this.radius * 2 * Math.PI) / 2;
5773
},
5874
path() {
59-
return ` M ${this.position}, ${this.options.size / 2} a ${this.radius},${this.radius} 0 1,1 ${this.radius * 2},0`;
75+
return this.getPath(this.radius);
76+
},
77+
fillPath() {
78+
return this.getPath(this.fillRadius);
6079
},
6180
emptyPath() {
62-
return ` M ${this.emptyPosition}, ${this.options.size / 2} a ${this.emptyRadius},${this.emptyRadius} 0 1,1 ${
63-
this.emptyRadius * 2
64-
},0`;
81+
return this.getPath(this.emptyRadius);
82+
},
83+
emptyFillPath() {
84+
return this.getPath(this.emptyFillRadius);
6585
},
66-
position() {
67-
return this.options.size / 2 - this.radius;
86+
},
87+
methods: {
88+
getPosition(radius) {
89+
return this.options.size / 2 - radius;
6890
},
69-
emptyPosition() {
70-
return this.options.size / 2 - this.emptyRadius;
91+
getPath(radius) {
92+
return ` M ${this.getPosition(radius)}, ${this.options.size / 2} a ${radius},${radius} 0 1,1 ${radius * 2},0`;
7193
},
7294
},
7395
};

src/components/Circle/circleMixin.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { emptyRadius, radius } from "@/components/Circle/radiusCalculation";
1+
import { emptyRadius, fillRadius, radius } from "@/components/Circle/radiusCalculation";
22
import { isValidNumber } from "../../utils";
33

44
const wait = (ms = 400) => new Promise((resolve) => setTimeout(() => resolve(), ms));
@@ -32,9 +32,15 @@ export default {
3232
radius() {
3333
return radius(this.options);
3434
},
35+
fillRadius() {
36+
return fillRadius(this.options.linePosition, this.thickness, this.radius);
37+
},
3538
emptyRadius() {
3639
return emptyRadius(this.options);
3740
},
41+
emptyFillRadius() {
42+
return fillRadius(this.options.emptyLinePosition, this.emptyThickness, this.emptyRadius);
43+
},
3844

3945
dataIsAvailable() {
4046
return isValidNumber(this.computedProgress) && !this.options.noData;

src/components/Circle/radiusCalculation.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ export const emptyRadius = (options) => {
105105
const modeHandler = modes[options.lineMode.mode];
106106
return modeHandler ? modeHandler() : emptyBaseRadius(options);
107107
};
108+
109+
export const fillRadius = (linePosition, thickness, lineCircleRadius) => {
110+
const { position, offset } = linePosition;
111+
if (position === "center") {
112+
return lineCircleRadius;
113+
}
114+
return position === "out" ? lineCircleRadius - offset - thickness / 2 : lineCircleRadius + thickness / 2;
115+
};

src/components/interface.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ const colorConfig = (defaultColor = "transparent") => ({
1414
});
1515

1616
const validateLoaderProps = (loaderOptions) =>
17-
Object.keys(loaderOptions).every((p) => options[p].validator(loaderOptions[p]));
17+
Object.keys(loaderOptions).every((option) => options[option].validator(loaderOptions[option]));
18+
19+
const linePosition = {
20+
type: String,
21+
required: false,
22+
default: "center",
23+
validator: (value) => {
24+
const [position, offset] = value.toString().split(" ");
25+
const isValidOffset = offset ? !Number.isNaN(parseFloat(offset)) : true;
26+
return ["center", "out", "in"].includes(position) && isValidOffset;
27+
},
28+
};
1829

1930
const options = {
2031
data: {
@@ -68,6 +79,8 @@ const options = {
6879
return isValidType && isValidOffset;
6980
},
7081
},
82+
linePosition,
83+
emptyLinePosition: linePosition,
7184
color: colorConfig("#3f79ff"),
7285
emptyColor: colorConfig("#e6e9f0"),
7386
colorFill: colorConfig(),

src/components/optionsParser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ export const calcThickness = (thickness, size) => {
5454
return thickness.toString().includes("%") ? (value * size) / 100 : value;
5555
};
5656

57+
const parseLinePosition = (linePosition) => {
58+
const [position, offset] = linePosition.toString().split(" ");
59+
return {
60+
position,
61+
offset: offset || 0,
62+
};
63+
};
64+
5765
export const parseOptions = (options) => {
5866
const dot = dotParser(options.dot);
5967
const globalDot = dotParser(options.globalDot);
@@ -66,6 +74,8 @@ export const parseOptions = (options) => {
6674
globalDot: { ...globalDot, size: calcThickness(globalDot.size, options.size) },
6775
dash: dashParser(options.dash),
6876
lineMode: lineModeParser(options),
77+
linePosition: parseLinePosition(options.linePosition),
78+
emptyLinePosition: parseLinePosition(options.emptyLinePosition),
6979
animation: animationParser(options.animation),
7080
};
7181
};

src/styles/animationsUsage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636
}
3737

38-
.ep-half-circle--empty, .ep-circle--empty {
38+
.ep-half-circle--empty, .ep-half-circle--empty__fill, .ep-circle--empty, .ep-circle--empty__fill {
3939
&.ep-circle--nodata {
4040
opacity: 0.5;
4141
}

vue.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,15 @@ module.exports = {
33
extract: false,
44
},
55
productionSourceMap: false,
6+
// see issue https://github.com/vuejs/vue-loader/issues/1734
7+
chainWebpack: (config) => {
8+
config.module
9+
.rule("vue")
10+
.use("vue-loader")
11+
.loader("vue-loader")
12+
.tap((options) => {
13+
options.isServerBuild = false;
14+
return options;
15+
});
16+
},
617
};

0 commit comments

Comments
 (0)