Skip to content

Commit

Permalink
Gauges re-config logic fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhus committed Oct 2, 2016
1 parent 860d6e4 commit 4808b68
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/outrange.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
data-value="-20"
data-width="400"
data-height="400"
data-bar-width="20"
data-bar-width="10"
data-bar-shadow="5"
data-color-bar-progress="rgba(50,200,50,.75)"
></canvas>
Expand Down
4 changes: 2 additions & 2 deletions gauge.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gauge.min.js.map

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions lib/BaseGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class BaseGauge {
*
* @type {BaseGauge} type
*/
this.type = ns[className];
this.type = ns[className] || BaseGauge;

/**
* True if gauge has been drawn for the first time, false otherwise.
Expand Down Expand Up @@ -212,14 +212,25 @@ export default class BaseGauge {
this.options.value : this._value;
}

/**
* Updates gauge options
*
* @param {*} options
* @return {BaseGauge}
* @access protected
*/
static configure(options) {
return options;
}

/**
* Updates gauge configuration options at runtime and redraws the gauge
*
* @param {RadialGaugeOptions} options
* @returns {BaseGauge}
*/
update(options) {
Object.assign(this.options, options || {});
Object.assign(this.options, this.type.configure(options || {}));

this.canvas.width = this.options.width;
this.canvas.height = this.options.height;
Expand Down
12 changes: 11 additions & 1 deletion lib/LinearGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,17 @@ export default class LinearGauge extends BaseGauge {
*/
constructor(options) {
options = Object.assign({}, defaultLinearGaugeOptions, options || {});
super(LinearGauge.configure(options));
}

/**
* Checks and updates gauge options properly
*
* @param {*} options
* @return {*}
* @access protected
*/
static configure(options) {
/* istanbul ignore else */
if (options.barStrokeWidth >= options.barWidth) {
//noinspection JSUnresolvedFunction
Expand All @@ -1088,7 +1098,7 @@ export default class LinearGauge extends BaseGauge {
//noinspection JSUndefinedPropertyAssignment
options.hasRight = hasTicksBar('left', options);

super(options);
return options;
}

/* istanbul ignore next */
Expand Down
17 changes: 13 additions & 4 deletions lib/RadialGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,6 @@ function drawRadialProgressBar(context, options) {
let rMax = maxRadialRadius(context, options) - 5 * unit;
let sw = (parseFloat(options.barStrokeWidth) || 0);
let w = (parseFloat(options.barWidth) || 0) * unit;

if (w > context.max) w = 50 * unit;

let rMin = rMax - sw * 2 - w;
let half = (rMax- rMin) / 2;
let r = rMin + half;
Expand Down Expand Up @@ -692,6 +689,18 @@ export default class RadialGauge extends BaseGauge {
*/
constructor(options) {
options = Object.assign({}, defaultRadialGaugeOptions, options || {});
super(RadialGauge.configure(options));
}

/**
* Checks and updates gauge options properly
*
* @param {*} options
* @return {*}
* @access protected
*/
static configure(options) {
if (options.barWidth > 50) options.barWidth = 50;

/* istanbul ignore if */
if (isNaN(options.startAngle)) options.startAngle = 45;
Expand All @@ -708,7 +717,7 @@ export default class RadialGauge extends BaseGauge {
/* istanbul ignore if */
if (options.startAngle > 360) options.startAngle = 360;

super(options);
return options;
}

/* */
Expand Down
2 changes: 1 addition & 1 deletion test-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4808b68

Please sign in to comment.