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

Enable pointRotation for pointStyle: image #6159

Closed
nyammy opened this issue Mar 23, 2019 · 2 comments · Fixed by #6287
Closed

Enable pointRotation for pointStyle: image #6159

nyammy opened this issue Mar 23, 2019 · 2 comments · Fixed by #6287

Comments

@nyammy
Copy link

nyammy commented Mar 23, 2019

Feature Proposal

Adding ability to rotate points with image like other types of point.

Feature Use Case

It will be possible to ...

  • make multiple styles with single image file.
  • use different rotation for each point. It's good for the vector data (which has both of amplitude and direction).

Possible Implementation

In drawPoint, change

if (style && typeof style === 'object') {
	type = style.toString();
	if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
		ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
		return;
	}
}

to

if (style && typeof style === 'object') {
	type = style.toString();
	if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
		ctx.save();
		ctx.translate(x, y);
		ctx.rotate(rotation * Math.PI / 180);
		ctx.drawImage(style, -1 * style.width / 2, -1 * style.height / 2, style.width, style.height);
		ctx.restore();
		return;
	}
}
@nagix
Copy link
Contributor

nagix commented Apr 1, 2019

I think this is a good enhancement. Do you want to create a PR for this (including unit tests)?

@nyammy
Copy link
Author

nyammy commented Apr 5, 2019

Like this?
https://jsfiddle.net/nyammy/vx8cd9w4/3/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants