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

Support for high resolution devices #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Support for high resolution devices #76

wants to merge 1 commit into from

Conversation

khenderick
Copy link

Added support for devices with a devicePixelRatio > 1, like all devices with so called "retina" screens. For example, the most recent iPad.

@gwatts
Copy link
Owner

gwatts commented May 4, 2013

@khenderick
Copy link
Author

Well, to all my own canvas controls I made for the project I'm working on, I was indeed working with context.scale(ratio, ratio).

However, if I do exactly the same to sparklines, without the scaling, the sparkline renders 100% crisp, but scaled down with the device's pixel ratio (so the sparkline looks too small). The same effect I get when I comment out the scaling in my own canvas controls. However, as soon as I enable the scaling in my own controls, the scaling is good on all devices, but if I enable the context.scale inside sparklines, (and I'm using the normal line style with light blue fill and blue topline) the fill is drawing scaled up with the device's pixel ratio (so, it's twice too big on the iPad) and the blue topline isn't displaying at all. Additionally, as soon as I hover the mouse over the sparkline, it completely disappears.

I think I somehow miss something in sparklines, but the code above gives at least a more crisp image on the iPad while it's not yet pixel perfect. It might be a start for you to work on?

A snipped of the code I use in my canvas controls:

var draw_width = 480;
var draw_height = 320;
var ratio = window.hasOwnProperty('devicePixelRatio') ? window.devicePixelRatio : 1;
var canvas_element = document.getElementById(id_offset + 'canvas');
canvas_element.style.width = draw_width + 'px';
canvas_element.style.height = draw_height + 'px';
canvas_element.width = draw_width * ratio;
canvas_element.height = draw_height * ratio;
var canvas = $('#' + id_offset + 'canvas');
var context = canvas[0].getContext('2d');
context.scale(ratio, ratio);
context.strokeStyle = background_color;
context.fillStyle = background_color;
context.fillRect(0, 0, draw_width, draw_height);
context.stroke();

@gwatts
Copy link
Owner

gwatts commented May 10, 2013

Hrm.. Well, my ideal solution would be to add an svg renderer to complement the canvas & vml renderers.

Had a severe lack of time recently though to work on it :-(

@hartator
Copy link

Any update on that?

Will love to use this plugin in our project but I've a retina as a dev. screen and that doesn't look really good...

Anyway thanks for great work!

@introvert
Copy link

Any updates on this? Sparklines on retina look awful..

@jfkahn
Copy link

jfkahn commented Aug 27, 2014

+1 to retina viewable sparklines

@avand
Copy link

avand commented Mar 26, 2015

+1 for 👀

@hartator
Copy link

+1 <3

@atuttle
Copy link

atuttle commented Oct 15, 2015

I would very much like to have retina sparkline charts!

I tried retrofitting this into my minified version and the displayed pie charts look great... but the hover effect is off. No matter where I hover, I seem to highlight whichever piece is on the left side of the chart. Seems like the hover-calculations also need to take the ratio into account.

... Unless I did something wrong? :)

@atuttle
Copy link

atuttle commented Oct 15, 2015

Also worth noting I also tried a slightly lower tech solution: I set my size to 2x what I want and added style="zoom: 50%" to the container. This made it appear high-resolution on retina screens, but the hover effect doesn't work at all, then.

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

Successfully merging this pull request may close these issues.

7 participants