-
Notifications
You must be signed in to change notification settings - Fork 303
Introduce emptyThickness parameter
#167
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
Open
monovertex
wants to merge
12
commits into
kottenator:master
Choose a base branch
from
monovertex:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a0c71a6
Test was failing on Firefox 55 / Linux Mint
monovertex ce9500b
Initial implementation for empty thickness parameter
monovertex 12d0992
Make sure that thicker empty arcs don't break the circle aspect
monovertex db508b7
Update docs
monovertex 28b7a53
Add different thicknesses example
monovertex bd1baa0
Add tests for the `emptyThickness` parameter
monovertex fe16684
Wrap up changes
monovertex 1d057a4
Replace `this.radius` with `this.size / 2`
monovertex a03e481
Rename `getArcRadius` to `getRadius`
monovertex 3be50dc
Remove unnecessary `if` block
monovertex a9838eb
Fix failing tests because of renaming
monovertex b46a9ba
Build minified distribution file
monovertex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,14 @@ | |
| */ | ||
| thickness: 'auto', | ||
|
|
||
| /** | ||
| * Width of the empty arc (under the filled one) in pixels. | ||
| * If it's `'auto'`, it falls back to the value of the `thickness` property. | ||
| * @type {number|string} | ||
| * @default 'auto' | ||
| */ | ||
| emptyThickness: 'auto', | ||
|
|
||
| /** | ||
| * Fill of the arc. You may set it to: | ||
| * | ||
|
|
@@ -342,16 +350,17 @@ | |
|
|
||
| var ctx = this.ctx, | ||
| r = this.radius, | ||
| arcR = this.getArcRadius(), | ||
| t = this.getThickness(), | ||
| a = this.startAngle; | ||
|
|
||
| ctx.save(); | ||
| ctx.beginPath(); | ||
|
|
||
| if (!this.reverse) { | ||
| ctx.arc(r, r, r - t / 2, a, a + Math.PI * 2 * v); | ||
| ctx.arc(r, r, arcR, a, a + Math.PI * 2 * v); | ||
| } else { | ||
| ctx.arc(r, r, r - t / 2, a - Math.PI * 2 * v, a); | ||
| ctx.arc(r, r, arcR, a - Math.PI * 2 * v, a); | ||
| } | ||
|
|
||
| ctx.lineWidth = t; | ||
|
|
@@ -369,21 +378,17 @@ | |
| drawEmptyArc: function(v) { | ||
| var ctx = this.ctx, | ||
| r = this.radius, | ||
| t = this.getThickness(), | ||
| a = this.startAngle; | ||
| arcR = this.getArcRadius(), | ||
| t = this.getEmptyThickness(); | ||
|
|
||
| if (v < 1) { | ||
| ctx.save(); | ||
| ctx.beginPath(); | ||
|
|
||
| if (v <= 0) { | ||
| ctx.arc(r, r, r - t / 2, 0, Math.PI * 2); | ||
| if (this.reverse) { | ||
| ctx.arc(r, r, arcR, 0, Math.PI * 2); | ||
| } else { | ||
| if (!this.reverse) { | ||
| ctx.arc(r, r, r - t / 2, a + Math.PI * 2 * v, a); | ||
| } else { | ||
| ctx.arc(r, r, r - t / 2, a, a - Math.PI * 2 * v); | ||
| } | ||
| ctx.arc(r, r, arcR, Math.PI * 2, 0); | ||
|
||
| } | ||
|
|
||
| ctx.lineWidth = t; | ||
|
|
@@ -441,6 +446,25 @@ | |
| return $.isNumeric(this.thickness) ? this.thickness : this.size / 14; | ||
| }, | ||
|
|
||
| /** | ||
| * Get the empty arc thickness. | ||
| * @see CircleProgress#emptyThickness | ||
| * @protected | ||
| * @returns {number} | ||
| */ | ||
| getEmptyThickness: function() { | ||
| return $.isNumeric(this.emptyThickness) ? this.emptyThickness : this.getThickness(); | ||
| }, | ||
|
|
||
| /** | ||
| * Returns the real arc radius, after the thickness has been accounted for. | ||
| * @private | ||
| * @returns {number} | ||
| */ | ||
| getArcRadius: function() { | ||
| return this.radius - Math.max(this.getThickness(), this.getEmptyThickness()) / 2; | ||
| }, | ||
|
|
||
| /** | ||
| * Get current value. | ||
| * @protected | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that there're
this.radiusandthis.getArcRadious()at the same time.this.size / 2anymore - I'd get rid ofthis.radius.this.getRadius(), because it affects both arc & BG circle.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I left
this.radiusjust to have easy access tothis.size / 2, as I need that in order to calculate the actual radius and the x, y coords for the circle.I could either calculate the half coords everytime in
drawArcanddrawEmptyArc, as well asgetArcRadius, or renamethis.radiusto something likethis.halfSize, and use that instead ofthis.radius, just to avoid unnecessary math operations.What do you think?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable needs to be updated when
this.sizeis changed. I'd rather drop it. There are only 2 places where it'd get replaced withthis.size / 2.Also, I still think it's reasonable to rename your
getArcRadiusmethod intogetRadius.I suggest the following naming: