Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic and prop for changing direction of slider to counter-clockwise #23

Open
wants to merge 1 commit into
base: refactoring
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
:side="300"
:circleWidth="20"
:knobRadius="20"
:stepSize="10"
:stepSize="1"
:counterClockwise="true"
>
</circle-slider>
<div class="value"> {{ sliderValue }} </div>
Expand Down
21 changes: 17 additions & 4 deletions src/components/CircleSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export default {
type: Number,
required: false,
default: 10
},
counterClockwise: {
type: Boolean,
required: false,
default: false
}
// limitMin: {
// type: Number,
Expand Down Expand Up @@ -156,20 +161,24 @@ export default {
return this.side / 2
},
cpAngle () {
return this.angle + Math.PI / 2
if (this.counterClockwise) return this.angle
return this.angle + Math.PI / 2
},
cpMainCircleStrokeWidth () {
return this.circleWidth || (this.side / 2) / this.circleWidthRel
},
cpPathDirection () {
if (this.counterClockwise) return (this.cpAngle < Math.PI) ? 0 : 1
return (this.cpAngle < 3 / 2 * Math.PI) ? 0 : 1
},
cpPathX () {
if (this.counterClockwise) return this.cpCenter + this.radius * Math.sin(this.cpAngle)
return this.cpCenter + this.radius * Math.cos(this.cpAngle)
},
cpPathY () {
if (this.counterClockwise) return this.cpCenter + this.radius * Math.cos(this.cpAngle)
return this.cpCenter + this.radius * Math.sin(this.cpAngle)
},
},
cpPathStrokeWidth () {
return this.progressWidth || (this.side / 2) / this.progressWidthRel
},
Expand All @@ -185,9 +194,10 @@ export default {
parts.push(this.radius)
parts.push(0)
parts.push(this.cpPathDirection)
parts.push(1)
parts.push( this.counterClockwise ? 0 : 1 )
parts.push(this.cpPathX)
parts.push(this.cpPathY)

return parts.join(' ')
},
cpAngleUnit () {
Expand Down Expand Up @@ -325,7 +335,10 @@ export default {
},
setNewPosition (e) {
const dimensions = this.containerElement.getBoundingClientRect()
this.relativeX = e.clientX - dimensions.left
if (this.counterClockwise) {
this.relativeX = dimensions.right - e.clientX
} else this.relativeX = e.clientX - dimensions.left

this.relativeY = e.clientY - dimensions.top
}
},
Expand Down