Skip to content
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
2 changes: 1 addition & 1 deletion src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

var UNSET_OPTION = {},
getDefaults, createClass, SPFormat, clipval, quartile, normalizeValue, normalizeValues,
remove, isNumber, all, sum, addCSS, ensureArray, formatNumber, RangeMap,
remove, isNumber, all, sum, addCSS, getDevicePixelRatio, ensureArray, formatNumber, RangeMap,
MouseHandler, Tooltip, barHighlightMixin,
line, bar, tristate, discrete, bullet, pie, box, defaultStyles, initStyles,
VShape, VCanvas_base, VCanvas_canvas, VCanvas_vml, pending, shapeCount = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,11 @@
}
};

getDevicePixelRatio = function() {
if (window.devicePixelRatio) return window.devicePixelRatio;
if (window.matchMedia) {
const mediaStr = '(min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 1.5),(-moz-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5)';
return window.matchMedia(mediaStr).matches ? 2 : 1;
}
return 1;
};
13 changes: 9 additions & 4 deletions src/vcanvas-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
if (target[0]) {
target = target[0];
}
var dpi = this.dpi = getDevicePixelRatio();
$.data(target, '_jqs_vcanvas', this);
$(this.canvas).css({ display: 'inline-block', width: width, height: height, verticalAlign: 'top' });
this._insert(this.canvas, target);
this._calculatePixelDims(width, height, this.canvas);
this.canvas.width = this.pixelWidth;
this.canvas.height = this.pixelHeight;
this.canvas.width = this.pixelWidth * dpi;
this.canvas.height = this.pixelHeight * dpi;
this.interact = interact;
this.shapes = {};
this.shapeseq = [];
Expand All @@ -32,7 +33,7 @@

reset: function () {
var context = this._getContext();
context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
context.clearRect(0, 0, this.pixelWidth * this.dpi, this.pixelHeight * this.dpi);
this.shapes = {};
this.shapeseq = [];
this.currentTargetShapeId = undefined;
Expand Down Expand Up @@ -176,7 +177,10 @@
shapeCount = shapeseq.length,
context = this._getContext(),
shapeid, shape, i;
context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
var dpi = this.dpi;
context.clearRect(0, 0, this.pixelWidth * dpi, this.pixelHeight * dpi);
context.save();
context.scale(dpi, dpi);
for (i = 0; i < shapeCount; i++) {
shapeid = shapeseq[i];
shape = shapes[shapeid];
Expand All @@ -187,6 +191,7 @@
this.shapes = {};
this.shapeseq = [];
}
context.restore();
}

});
Expand Down