-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Enable arbitrary rotation of datapoints #5319
Changes from all commits
fd0ea21
8cf7910
d47c278
b2cb8b1
d22d7ce
d182d34
da23599
6b9dfaf
71ae83a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,9 @@ var exports = module.exports = { | |
} | ||
}, | ||
|
||
drawPoint: function(ctx, style, radius, x, y) { | ||
drawPoint: function(ctx, style, radius, x, y, rotation) { | ||
var type, edgeLength, xOffset, yOffset, height, size; | ||
rotation = rotation || 0; | ||
|
||
if (style && typeof style === 'object') { | ||
type = style.toString(); | ||
|
@@ -59,34 +60,38 @@ var exports = module.exports = { | |
return; | ||
} | ||
|
||
ctx.save(); | ||
ctx.translate(x, y); | ||
ctx.rotate(rotation * Math.PI / 180); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how we can do differently right now but I'm a bit worry of these extra save / translate / rotate / restore because drawing point is already pretty slow. Anyway, if we are translating we should remove the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! |
||
|
||
switch (style) { | ||
// Default includes circle | ||
default: | ||
ctx.beginPath(); | ||
ctx.arc(x, y, radius, 0, Math.PI * 2); | ||
ctx.arc(0, 0, radius, 0, Math.PI * 2); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
break; | ||
case 'triangle': | ||
ctx.beginPath(); | ||
edgeLength = 3 * radius / Math.sqrt(3); | ||
height = edgeLength * Math.sqrt(3) / 2; | ||
ctx.moveTo(x - edgeLength / 2, y + height / 3); | ||
ctx.lineTo(x + edgeLength / 2, y + height / 3); | ||
ctx.lineTo(x, y - 2 * height / 3); | ||
ctx.moveTo(-edgeLength / 2, height / 3); | ||
ctx.lineTo(edgeLength / 2, height / 3); | ||
ctx.lineTo(0, -2 * height / 3); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
break; | ||
case 'rect': | ||
size = 1 / Math.SQRT2 * radius; | ||
ctx.beginPath(); | ||
ctx.fillRect(x - size, y - size, 2 * size, 2 * size); | ||
ctx.strokeRect(x - size, y - size, 2 * size, 2 * size); | ||
ctx.fillRect(-size, -size, 2 * size, 2 * size); | ||
ctx.strokeRect(-size, -size, 2 * size, 2 * size); | ||
break; | ||
case 'rectRounded': | ||
var offset = radius / Math.SQRT2; | ||
var leftX = x - offset; | ||
var topY = y - offset; | ||
var leftX = -offset; | ||
var topY = -offset; | ||
var sideSize = Math.SQRT2 * radius; | ||
ctx.beginPath(); | ||
this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius / 2); | ||
|
@@ -96,60 +101,61 @@ var exports = module.exports = { | |
case 'rectRot': | ||
size = 1 / Math.SQRT2 * radius; | ||
ctx.beginPath(); | ||
ctx.moveTo(x - size, y); | ||
ctx.lineTo(x, y + size); | ||
ctx.lineTo(x + size, y); | ||
ctx.lineTo(x, y - size); | ||
ctx.moveTo(-size, 0); | ||
ctx.lineTo(0, size); | ||
ctx.lineTo(size, 0); | ||
ctx.lineTo(0, -size); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
break; | ||
case 'cross': | ||
ctx.beginPath(); | ||
ctx.moveTo(x, y + radius); | ||
ctx.lineTo(x, y - radius); | ||
ctx.moveTo(x - radius, y); | ||
ctx.lineTo(x + radius, y); | ||
ctx.moveTo(0, radius); | ||
ctx.lineTo(0, -radius); | ||
ctx.moveTo(-radius, 0); | ||
ctx.lineTo(radius, 0); | ||
ctx.closePath(); | ||
break; | ||
case 'crossRot': | ||
ctx.beginPath(); | ||
xOffset = Math.cos(Math.PI / 4) * radius; | ||
yOffset = Math.sin(Math.PI / 4) * radius; | ||
ctx.moveTo(x - xOffset, y - yOffset); | ||
ctx.lineTo(x + xOffset, y + yOffset); | ||
ctx.moveTo(x - xOffset, y + yOffset); | ||
ctx.lineTo(x + xOffset, y - yOffset); | ||
ctx.moveTo(-xOffset, -yOffset); | ||
ctx.lineTo(xOffset, yOffset); | ||
ctx.moveTo(-xOffset, yOffset); | ||
ctx.lineTo(xOffset, -yOffset); | ||
ctx.closePath(); | ||
break; | ||
case 'star': | ||
ctx.beginPath(); | ||
ctx.moveTo(x, y + radius); | ||
ctx.lineTo(x, y - radius); | ||
ctx.moveTo(x - radius, y); | ||
ctx.lineTo(x + radius, y); | ||
ctx.moveTo(0, radius); | ||
ctx.lineTo(0, -radius); | ||
ctx.moveTo(-radius, 0); | ||
ctx.lineTo(radius, 0); | ||
xOffset = Math.cos(Math.PI / 4) * radius; | ||
yOffset = Math.sin(Math.PI / 4) * radius; | ||
ctx.moveTo(x - xOffset, y - yOffset); | ||
ctx.lineTo(x + xOffset, y + yOffset); | ||
ctx.moveTo(x - xOffset, y + yOffset); | ||
ctx.lineTo(x + xOffset, y - yOffset); | ||
ctx.moveTo(-xOffset, -yOffset); | ||
ctx.lineTo(xOffset, yOffset); | ||
ctx.moveTo(-xOffset, yOffset); | ||
ctx.lineTo(xOffset, -yOffset); | ||
ctx.closePath(); | ||
break; | ||
case 'line': | ||
ctx.beginPath(); | ||
ctx.moveTo(x - radius, y); | ||
ctx.lineTo(x + radius, y); | ||
ctx.moveTo(-radius, 0); | ||
ctx.lineTo(radius, 0); | ||
ctx.closePath(); | ||
break; | ||
case 'dash': | ||
ctx.beginPath(); | ||
ctx.moveTo(x, y); | ||
ctx.lineTo(x + radius, y); | ||
ctx.moveTo(0, 0); | ||
ctx.lineTo(radius, 0); | ||
ctx.closePath(); | ||
break; | ||
} | ||
|
||
ctx.stroke(); | ||
ctx.restore(); | ||
}, | ||
|
||
clipArea: function(ctx, area) { | ||
|
This comment was marked as outdated.
Sorry, something went wrong.