Fixed size() args

This commit is contained in:
Luis Leiva 2019-07-16 15:20:30 +03:00
parent 5e10d92ed2
commit 9c64bcaf4a
2 changed files with 13 additions and 10 deletions

2
dist/jsketch.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/*! /*!
* jSketch 1.0 | Luis A. Leiva | MIT license * jSketch 1.1 | Luis A. Leiva | MIT license
* A simple JavaScript library for drawing facilities on HTML5 canvas. * A simple JavaScript library for drawing facilities on HTML5 canvas.
*/ */
@ -9,7 +9,7 @@
* such as function chainability and old-school AS3-like notation. * such as function chainability and old-school AS3-like notation.
* @name jSketch * @name jSketch
* @class * @class
* @version 1.0 * @version 1.1
* @author Luis A. Leiva * @author Luis A. Leiva
* @license MIT license * @license MIT license
* @example * @example
@ -28,13 +28,13 @@
* @param {object} [options] - Configuration (default: {@link Sketchable#defaults}). * @param {object} [options] - Configuration (default: {@link Sketchable#defaults}).
*/ */
function jSketch(elem, options) { function jSketch(elem, options) {
if (!elem) throw new Error('Sketchable requires a DOM element.'); if (!elem) throw new Error('Sketchable requires a DOM element or selector.');
if (typeof elem === 'string') elem = document.querySelector(elem); if (typeof elem === 'string') elem = document.querySelector(elem);
// Set drawing context first. // Set drawing context first.
this.setContext(elem); this.setContext(elem);
// Scene defaults. // Scene defaults.
this.stageWidth = elem.width; this.stageWidth = elem.offsetWidth;
this.stageHeight = elem.height; this.stageHeight = elem.offsetHeight;
// Make room for storing some data such as line type, colors, etc. // Make room for storing some data such as line type, colors, etc.
this.data = options; this.data = options;
// Save abstract calls to low-level canvas methods, // Save abstract calls to low-level canvas methods,
@ -98,10 +98,13 @@
* @memberof jSketch * @memberof jSketch
*/ */
size: function(width, height) { size: function(width, height) {
this.stageWidth = width; // Allow grabbing values from CSS such as "100px".
this.stageHeight = height; var w = parseFloat(width);
this.canvas.width = width; var h = parseFloat(height);
this.canvas.height = height; this.stageWidth = w;
this.stageHeight = h;
this.canvas.width = w;
this.canvas.height = h;
// On resizing we lose drawing options, so restore them. // On resizing we lose drawing options, so restore them.
this.restoreGraphics(); this.restoreGraphics();
return this; return this;