language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | chartjs | Chart.js | ce8ee02ccd992c062cfa734df713730c077cdb2e.json | Reduce indentation by reversing if check (#6497) | src/plugins/plugin.title.js | @@ -111,23 +111,20 @@ var Title = Element.extend({
fit: function() {
var me = this;
var opts = me.options;
- var display = opts.display;
- var minSize = me.minSize;
- var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
- var fontOpts = helpers.options._parseFont(opts);
- var textSize = display ? (lineCount * fontOpts.lineHeight) + (opts.padding * 2) : 0;
+ var minSize = me.minSize = {};
+ var isHorizontal = me.isHorizontal();
+ var lineCount, textSize;
- if (me.isHorizontal()) {
- minSize.width = me.maxWidth; // fill all the width
- minSize.height = textSize;
- } else {
- minSize.width = textSize;
- minSize.height = me.maxHeight; // fill all the height
+ if (!opts.display) {
+ me.width = minSize.width = me.height = minSize.height = 0;
+ return;
}
- me.width = minSize.width;
- me.height = minSize.height;
+ lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
+ textSize = lineCount * helpers.options._parseFont(opts).lineHeight + opts.padding * 2;
+ me.width = minSize.width = isHorizontal ? me.maxWidth : textSize;
+ me.height = minSize.height = isHorizontal ? textSize : me.maxHeight;
},
afterFit: noop,
@@ -143,51 +140,53 @@ var Title = Element.extend({
var ctx = me.ctx;
var opts = me.options;
- if (opts.display) {
- var fontOpts = helpers.options._parseFont(opts);
- var lineHeight = fontOpts.lineHeight;
- var offset = lineHeight / 2 + opts.padding;
- var rotation = 0;
- var top = me.top;
- var left = me.left;
- var bottom = me.bottom;
- var right = me.right;
- var maxWidth, titleX, titleY;
-
- ctx.fillStyle = helpers.valueOrDefault(opts.fontColor, defaults.global.defaultFontColor); // render in correct colour
- ctx.font = fontOpts.string;
-
- // Horizontal
- if (me.isHorizontal()) {
- titleX = left + ((right - left) / 2); // midpoint of the width
- titleY = top + offset;
- maxWidth = right - left;
- } else {
- titleX = opts.position === 'left' ? left + offset : right - offset;
- titleY = top + ((bottom - top) / 2);
- maxWidth = bottom - top;
- rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
- }
+ if (!opts.display) {
+ return;
+ }
- ctx.save();
- ctx.translate(titleX, titleY);
- ctx.rotate(rotation);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'middle';
-
- var text = opts.text;
- if (helpers.isArray(text)) {
- var y = 0;
- for (var i = 0; i < text.length; ++i) {
- ctx.fillText(text[i], 0, y, maxWidth);
- y += lineHeight;
- }
- } else {
- ctx.fillText(text, 0, 0, maxWidth);
- }
+ var fontOpts = helpers.options._parseFont(opts);
+ var lineHeight = fontOpts.lineHeight;
+ var offset = lineHeight / 2 + opts.padding;
+ var rotation = 0;
+ var top = me.top;
+ var left = me.left;
+ var bottom = me.bottom;
+ var right = me.right;
+ var maxWidth, titleX, titleY;
+
+ ctx.fillStyle = helpers.valueOrDefault(opts.fontColor, defaults.global.defaultFontColor); // render in correct colour
+ ctx.font = fontOpts.string;
+
+ // Horizontal
+ if (me.isHorizontal()) {
+ titleX = left + ((right - left) / 2); // midpoint of the width
+ titleY = top + offset;
+ maxWidth = right - left;
+ } else {
+ titleX = opts.position === 'left' ? left + offset : right - offset;
+ titleY = top + ((bottom - top) / 2);
+ maxWidth = bottom - top;
+ rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
+ }
- ctx.restore();
+ ctx.save();
+ ctx.translate(titleX, titleY);
+ ctx.rotate(rotation);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+
+ var text = opts.text;
+ if (helpers.isArray(text)) {
+ var y = 0;
+ for (var i = 0; i < text.length; ++i) {
+ ctx.fillText(text[i], 0, y, maxWidth);
+ y += lineHeight;
+ }
+ } else {
+ ctx.fillText(text, 0, 0, maxWidth);
}
+
+ ctx.restore();
}
});
| true |
Other | chartjs | Chart.js | ce8ee02ccd992c062cfa734df713730c077cdb2e.json | Reduce indentation by reversing if check (#6497) | test/specs/plugin.title.tests.js | @@ -27,7 +27,7 @@ describe('Title block tests', function() {
var minSize = title.update(400, 200);
expect(minSize).toEqual({
- width: 400,
+ width: 0,
height: 0
});
@@ -58,7 +58,7 @@ describe('Title block tests', function() {
expect(minSize).toEqual({
width: 0,
- height: 400
+ height: 0
});
// Now we have a height since we display | true |
Other | chartjs | Chart.js | 6e69a38305e532a36b8d8b1ed58a9c3655c58192.json | Add elements.arc.angle in documentation (#6491)
Add elements.arc.angle in documentation | docs/configuration/elements.md | @@ -82,6 +82,7 @@ Global arc options: `Chart.defaults.global.elements.arc`.
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
+| `angle` - for polar only | `number` | `circumference / (arc count)` | Arc angle to cover.
| `backgroundColor` | `Color` | `'rgba(0, 0, 0, 0.1)'` | Arc fill color.
| `borderAlign` | `string` | `'center'` | Arc stroke alignment.
| `borderColor` | `Color` | `'#fff'` | Arc stroke color. | false |
Other | chartjs | Chart.js | 053729ac44b6a16ce957142fdcacaa5bfd9d8d79.json | Add link back to home page from docs (#6435)
* Add link back to home page from docs #6433
* Modify link texts
* Edit homepage link | docs/SUMMARY.md | @@ -1,6 +1,7 @@
# Summary
-* [Chart.js](README.md)
+* [Chart.js](https://www.chartjs.org)
+* [Introduction](README.md)
* [Getting Started](getting-started/README.md)
* [Installation](getting-started/installation.md)
* [Integration](getting-started/integration.md) | false |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/controllers/controller.bar.js | @@ -32,7 +32,7 @@ defaults._set('bar', {
* @private
*/
function computeMinSampleSize(scale, pixels) {
- var min = scale.isHorizontal() ? scale.width : scale.height;
+ var min = scale._length;
var ticks = scale.getTicks();
var prev, curr, i, ilen;
@@ -42,7 +42,7 @@ function computeMinSampleSize(scale, pixels) {
for (i = 0, ilen = ticks.length; i < ilen; ++i) {
curr = scale.getPixelForTick(i);
- min = i > 0 ? Math.min(min, curr - prev) : min;
+ min = i > 0 ? Math.min(min, Math.abs(curr - prev)) : min;
prev = curr;
}
@@ -262,9 +262,6 @@ module.exports = DatasetController.extend({
var scale = me._getIndexScale();
var stackCount = me.getStackCount();
var datasetIndex = me.index;
- var isHorizontal = scale.isHorizontal();
- var start = isHorizontal ? scale.left : scale.top;
- var end = start + (isHorizontal ? scale.width : scale.height);
var pixels = [];
var i, ilen, min;
@@ -279,8 +276,8 @@ module.exports = DatasetController.extend({
return {
min: min,
pixels: pixels,
- start: start,
- end: end,
+ start: scale._startPixel,
+ end: scale._endPixel,
stackCount: stackCount,
scale: scale
}; | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/core/core.controller.js | @@ -546,6 +546,11 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
me._layers = [];
helpers.each(me.boxes, function(box) {
+ // _configure is called twice, once in core.scale.update and once here.
+ // Here the boxes are fully updated and at their final positions.
+ if (box._configure) {
+ box._configure();
+ }
me._layers.push.apply(me._layers, box._layers());
}, me);
| true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/core/core.helpers.js | @@ -100,19 +100,6 @@ module.exports = function() {
}
return x > 0 ? 1 : -1;
};
- helpers.log10 = Math.log10 ?
- function(x) {
- return Math.log10(x);
- } :
- function(x) {
- var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
- // Check for whole powers of 10,
- // which due to floating point rounding error should be corrected.
- var powerOf10 = Math.round(exponent);
- var isPowerOf10 = x === Math.pow(10, powerOf10);
-
- return isPowerOf10 ? powerOf10 : exponent;
- };
helpers.toRadians = function(degrees) {
return degrees * (Math.PI / 180);
}; | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/core/core.scale.js | @@ -70,9 +70,7 @@ function getPixelForGridLine(scale, index, offsetGridLines) {
if (offsetGridLines) {
if (scale.getTicks().length === 1) {
- lineValue -= scale.isHorizontal() ?
- Math.max(lineValue - scale.left, scale.right - lineValue) :
- Math.max(lineValue - scale.top, scale.bottom - lineValue);
+ lineValue -= Math.max(lineValue - scale._startPixel, scale._endPixel - lineValue);
} else if (index === 0) {
lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
} else {
@@ -318,6 +316,12 @@ var Scale = Element.extend({
me._ticks = ticks;
+ // _configure is called twice, once here, once from core.controller.updateLayout.
+ // Here we haven't been positioned yet, but dimensions are correct.
+ // Variables set in _configure are needed for calculateTickRotation, and
+ // it's ok that coordinates are not correct there, only dimensions matter.
+ me._configure();
+
// Tick Rotation
me.beforeCalculateTickRotation();
me.calculateTickRotation();
@@ -332,6 +336,30 @@ var Scale = Element.extend({
return me.minSize;
},
+
+ /**
+ * @private
+ */
+ _configure: function() {
+ var me = this;
+ var reversePixels = me.options.ticks.reverse;
+ var startPixel, endPixel;
+
+ if (me.isHorizontal()) {
+ startPixel = me.left;
+ endPixel = me.right;
+ } else {
+ startPixel = me.top;
+ endPixel = me.bottom;
+ // by default vertical scales are from bottom to top, so pixels are reversed
+ reversePixels = !reversePixels;
+ }
+ me._startPixel = startPixel;
+ me._endPixel = endPixel;
+ me._reversePixels = reversePixels;
+ me._length = endPixel - startPixel;
+ },
+
afterUpdate: function() {
helpers.callback(this.options.afterUpdate, [this]);
},
@@ -576,10 +604,11 @@ var Scale = Element.extend({
// Shared Methods
isHorizontal: function() {
- return this.options.position === 'top' || this.options.position === 'bottom';
+ var pos = this.options.position;
+ return pos === 'top' || pos === 'bottom';
},
isFullWidth: function() {
- return (this.options.fullWidth);
+ return this.options.fullWidth;
},
// Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
@@ -693,20 +722,11 @@ var Scale = Element.extend({
var me = this;
var offset = me.options.offset;
var numTicks = me._ticks.length;
- if (index < 0 || index > numTicks - 1) {
- return null;
- }
- if (me.isHorizontal()) {
- var tickWidth = me.width / Math.max((numTicks - (offset ? 0 : 1)), 1);
- var pixel = (tickWidth * index);
+ var tickWidth = 1 / Math.max(numTicks - (offset ? 0 : 1), 1);
- if (offset) {
- pixel += tickWidth / 2;
- }
-
- return me.left + pixel;
- }
- return me.top + (index * (me.height / (numTicks - 1)));
+ return index < 0 || index > numTicks - 1
+ ? null
+ : me.getPixelForDecimal(index * tickWidth + (offset ? tickWidth / 2 : 0));
},
/**
@@ -715,9 +735,17 @@ var Scale = Element.extend({
*/
getPixelForDecimal: function(decimal) {
var me = this;
- return me.isHorizontal()
- ? me.left + decimal * me.width
- : me.top + decimal * me.height;
+
+ if (me._reversePixels) {
+ decimal = 1 - decimal;
+ }
+
+ return me._startPixel + decimal * me._length;
+ },
+
+ getDecimalForPixel: function(pixel) {
+ var decimal = (pixel - this._startPixel) / this._length;
+ return Math.min(1, Math.max(0, this._reversePixels ? 1 - decimal : decimal));
},
/**
@@ -745,7 +773,6 @@ var Scale = Element.extend({
*/
_autoSkip: function(ticks) {
var me = this;
- var isHorizontal = me.isHorizontal();
var optionTicks = me.options.ticks;
var tickCount = ticks.length;
var skipRatio = false;
@@ -755,9 +782,7 @@ var Scale = Element.extend({
// drawn as their center at end of axis, so tickCount-1
var ticksLength = me._tickSize() * (tickCount - 1);
- // Axis length
- var axisLength = isHorizontal ? me.width : me.height;
-
+ var axisLength = me._length;
var result = [];
var i, tick;
@@ -788,7 +813,6 @@ var Scale = Element.extend({
*/
_tickSize: function() {
var me = this;
- var isHorizontal = me.isHorizontal();
var optionTicks = me.options.ticks;
// Calculate space needed by label in axis direction.
@@ -802,7 +826,7 @@ var Scale = Element.extend({
var h = labelSizes ? labelSizes.highest.height + padding : 0;
// Calculate space needed for 1 tick in axis direction.
- return isHorizontal
+ return me.isHorizontal()
? h * cos > w * sin ? w / cos : h / sin
: h * sin < w * cos ? h / cos : w / sin;
},
@@ -1130,7 +1154,7 @@ var Scale = Element.extend({
var scaleLabelX, scaleLabelY;
if (me.isHorizontal()) {
- scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
+ scaleLabelX = me.left + me.width / 2; // midpoint of the width
scaleLabelY = position === 'bottom'
? me.bottom - halfLineHeight - scaleLabelPadding.bottom
: me.top + halfLineHeight + scaleLabelPadding.top;
@@ -1139,7 +1163,7 @@ var Scale = Element.extend({
scaleLabelX = isLeft
? me.left + halfLineHeight + scaleLabelPadding.top
: me.right - halfLineHeight - scaleLabelPadding.top;
- scaleLabelY = me.top + ((me.bottom - me.top) / 2);
+ scaleLabelY = me.top + me.height / 2;
rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
}
| true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/helpers/helpers.math.js | @@ -1,5 +1,7 @@
'use strict';
+var helpers = require('./helpers.core');
+
/**
* @alias Chart.helpers.math
* @namespace
@@ -28,7 +30,28 @@ var exports = {
return a - b;
}).pop();
return result;
+ },
+
+ log10: Math.log10 || function(x) {
+ var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
+ // Check for whole powers of 10,
+ // which due to floating point rounding error should be corrected.
+ var powerOf10 = Math.round(exponent);
+ var isPowerOf10 = x === Math.pow(10, powerOf10);
+
+ return isPowerOf10 ? powerOf10 : exponent;
}
};
module.exports = exports;
+
+// DEPRECATIONS
+
+/**
+ * Provided for backward compatibility, use Chart.helpers.math.log10 instead.
+ * @namespace Chart.helpers.log10
+ * @deprecated since version 2.9.0
+ * @todo remove at version 3
+ * @private
+ */
+helpers.log10 = exports.log10; | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/scales/scale.category.js | @@ -63,17 +63,30 @@ module.exports = Scale.extend({
return me.ticks[index - me.minIndex];
},
- // Used to get data value locations. Value can either be an index or a numerical value
- getPixelForValue: function(value, index, datasetIndex) {
+ _configure: function() {
var me = this;
var offset = me.options.offset;
+ var ticks = me.ticks;
+
+ Scale.prototype._configure.call(me);
+
+ if (!me.isHorizontal()) {
+ // For backward compatibility, vertical category scale reverse is inverted.
+ me._reversePixels = !me._reversePixels;
+ }
+
+ if (!ticks) {
+ return;
+ }
- // 1 is added because we need the length but we have the indexes
- var offsetAmt = Math.max(me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1), 1);
+ me._startValue = me.minIndex - (offset ? 0.5 : 0);
+ me._valueRange = Math.max(ticks.length - (offset ? 0 : 1), 1);
+ },
- var isHorizontal = me.isHorizontal();
- var valueDimension = (isHorizontal ? me.width : me.height) / offsetAmt;
- var valueCategory, labels, idx, pixel;
+ // Used to get data value locations. Value can either be an index or a numerical value
+ getPixelForValue: function(value, index, datasetIndex) {
+ var me = this;
+ var valueCategory, labels, idx;
if (!isNullOrUndef(index) && !isNullOrUndef(datasetIndex)) {
value = me.chart.data.datasets[datasetIndex].data[index];
@@ -82,53 +95,31 @@ module.exports = Scale.extend({
// If value is a data object, then index is the index in the data array,
// not the index of the scale. We need to change that.
if (!isNullOrUndef(value)) {
- valueCategory = isHorizontal ? value.x : value.y;
+ valueCategory = me.isHorizontal() ? value.x : value.y;
}
if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
labels = me._getLabels();
value = helpers.valueOrDefault(valueCategory, value);
idx = labels.indexOf(value);
index = idx !== -1 ? idx : index;
+ if (isNaN(index)) {
+ index = value;
+ }
}
-
- pixel = valueDimension * (index - me.minIndex);
-
- if (offset) {
- pixel += valueDimension / 2;
- }
-
- return (isHorizontal ? me.left : me.top) + pixel;
+ return me.getPixelForDecimal((index - me._startValue) / me._valueRange);
},
getPixelForTick: function(index) {
var ticks = this.ticks;
- if (index < 0 || index > ticks.length - 1) {
- return null;
- }
- return this.getPixelForValue(ticks[index], index + this.minIndex);
+ return index < 0 || index > ticks.length - 1
+ ? null
+ : this.getPixelForValue(ticks[index], index + this.minIndex);
},
getValueForPixel: function(pixel) {
var me = this;
- var offset = me.options.offset;
- var offsetAmt = Math.max(me._ticks.length - (offset ? 0 : 1), 1);
- var isHorizontal = me.isHorizontal();
- var valueDimension = (isHorizontal ? me.width : me.height) / offsetAmt;
- var value;
-
- pixel -= isHorizontal ? me.left : me.top;
-
- if (offset) {
- pixel -= valueDimension / 2;
- }
-
- if (pixel <= 0) {
- value = 0;
- } else {
- value = Math.round(pixel / valueDimension);
- }
-
- return value + me.minIndex;
+ var value = Math.round(me._startValue + me.getDecimalForPixel(pixel) * me._valueRange);
+ return Math.min(Math.max(value, 0), me.ticks.length - 1);
},
getBasePixel: function() { | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/scales/scale.linear.js | @@ -149,29 +149,12 @@ module.exports = LinearScaleBase.extend({
// Utils
getPixelForValue: function(value) {
- // This must be called after fit has been run so that
- // this.left, this.top, this.right, and this.bottom have been defined
var me = this;
- var start = me.start;
-
- var rightValue = +me.getRightValue(value);
- var pixel;
- var range = me.end - start;
-
- if (me.isHorizontal()) {
- pixel = me.left + (me.width / range * (rightValue - start));
- } else {
- pixel = me.bottom - (me.height / range * (rightValue - start));
- }
- return pixel;
+ return me.getPixelForDecimal((+me.getRightValue(value) - me._startValue) / me._valueRange);
},
getValueForPixel: function(pixel) {
- var me = this;
- var isHorizontal = me.isHorizontal();
- var innerDimension = isHorizontal ? me.width : me.height;
- var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
- return me.start + ((me.end - me.start) * offset);
+ return this._startValue + this.getDecimalForPixel(pixel) * this._valueRange;
},
getPixelForTick: function(index) { | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/scales/scale.linearbase.js | @@ -231,5 +231,24 @@ module.exports = Scale.extend({
me.zeroLineIndex = me.ticks.indexOf(0);
Scale.prototype.convertTicksToLabels.call(me);
+ },
+
+ _configure: function() {
+ var me = this;
+ var ticks = me.getTicks();
+ var start = me.min;
+ var end = me.max;
+ var offset;
+
+ Scale.prototype._configure.call(me);
+
+ if (me.options.offset && ticks.length) {
+ offset = (end - start) / Math.max(ticks.length - 1, 1) / 2;
+ start -= offset;
+ end += offset;
+ }
+ me._startValue = start;
+ me._endValue = end;
+ me._valueRange = end - start;
}
}); | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/scales/scale.logarithmic.js | @@ -6,6 +6,7 @@ var Scale = require('../core/core.scale');
var Ticks = require('../core/core.ticks');
var valueOrDefault = helpers.valueOrDefault;
+var log10 = helpers.math.log10;
/**
* Generate a set of logarithmic ticks
@@ -16,20 +17,20 @@ var valueOrDefault = helpers.valueOrDefault;
function generateTicks(generationOptions, dataRange) {
var ticks = [];
- var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
+ var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(log10(dataRange.min))));
- var endExp = Math.floor(helpers.log10(dataRange.max));
+ var endExp = Math.floor(log10(dataRange.max));
var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
var exp, significand;
if (tickVal === 0) {
- exp = Math.floor(helpers.log10(dataRange.minNotZero));
+ exp = Math.floor(log10(dataRange.minNotZero));
significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
ticks.push(tickVal);
tickVal = significand * Math.pow(10, exp);
} else {
- exp = Math.floor(helpers.log10(tickVal));
+ exp = Math.floor(log10(tickVal));
significand = Math.floor(tickVal / Math.pow(10, exp));
}
var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
@@ -178,26 +179,26 @@ module.exports = Scale.extend({
if (me.min === me.max) {
if (me.min !== 0 && me.min !== null) {
- me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
- me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
+ me.min = Math.pow(10, Math.floor(log10(me.min)) - 1);
+ me.max = Math.pow(10, Math.floor(log10(me.max)) + 1);
} else {
me.min = DEFAULT_MIN;
me.max = DEFAULT_MAX;
}
}
if (me.min === null) {
- me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
+ me.min = Math.pow(10, Math.floor(log10(me.max)) - 1);
}
if (me.max === null) {
me.max = me.min !== 0
- ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
+ ? Math.pow(10, Math.floor(log10(me.min)) + 1)
: DEFAULT_MAX;
}
if (me.minNotZero === null) {
if (me.min > 0) {
me.minNotZero = me.min;
} else if (me.max < 1) {
- me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
+ me.minNotZero = Math.pow(10, Math.floor(log10(me.max)));
} else {
me.minNotZero = DEFAULT_MIN;
}
@@ -259,87 +260,47 @@ module.exports = Scale.extend({
* @private
*/
_getFirstTickValue: function(value) {
- var exp = Math.floor(helpers.log10(value));
+ var exp = Math.floor(log10(value));
var significand = Math.floor(value / Math.pow(10, exp));
return significand * Math.pow(10, exp);
},
- getPixelForValue: function(value) {
+ _configure: function() {
var me = this;
- var tickOpts = me.options.ticks;
- var reverse = tickOpts.reverse;
- var log10 = helpers.log10;
- var firstTickValue = me._getFirstTickValue(me.minNotZero);
+ var start = me.min;
var offset = 0;
- var innerDimension, pixel, start, end, sign;
- value = +me.getRightValue(value);
- if (reverse) {
- start = me.end;
- end = me.start;
- sign = -1;
- } else {
- start = me.start;
- end = me.end;
- sign = 1;
- }
- if (me.isHorizontal()) {
- innerDimension = me.width;
- pixel = reverse ? me.right : me.left;
- } else {
- innerDimension = me.height;
- sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
- pixel = reverse ? me.top : me.bottom;
- }
- if (value !== start) {
- if (start === 0) { // include zero tick
- offset = valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
- innerDimension -= offset;
- start = firstTickValue;
- }
- if (value !== 0) {
- offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
- }
- pixel += sign * offset;
+ Scale.prototype._configure.call(me);
+
+ if (start === 0) {
+ start = me._getFirstTickValue(me.minNotZero);
+ offset = valueOrDefault(me.options.ticks.fontSize, defaults.global.defaultFontSize) / me._length;
}
- return pixel;
+
+ me._startValue = log10(start);
+ me._valueOffset = offset;
+ me._valueRange = (log10(me.max) - log10(start)) / (1 - offset);
},
- getValueForPixel: function(pixel) {
+ getPixelForValue: function(value) {
var me = this;
- var tickOpts = me.options.ticks;
- var reverse = tickOpts.reverse;
- var log10 = helpers.log10;
- var firstTickValue = me._getFirstTickValue(me.minNotZero);
- var innerDimension, start, end, value;
+ var decimal = 0;
- if (reverse) {
- start = me.end;
- end = me.start;
- } else {
- start = me.start;
- end = me.end;
- }
- if (me.isHorizontal()) {
- innerDimension = me.width;
- value = reverse ? me.right - pixel : pixel - me.left;
- } else {
- innerDimension = me.height;
- value = reverse ? pixel - me.top : me.bottom - pixel;
- }
- if (value !== start) {
- if (start === 0) { // include zero tick
- var offset = valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
- value -= offset;
- innerDimension -= offset;
- start = firstTickValue;
- }
- value *= log10(end) - log10(start);
- value /= innerDimension;
- value = Math.pow(10, log10(start) + value);
+ value = +me.getRightValue(value);
+
+ if (value > me.min && value > 0) {
+ decimal = (log10(value) - me._startValue) / me._valueRange + me._valueOffset;
}
- return value;
+ return me.getPixelForDecimal(decimal);
+ },
+
+ getValueForPixel: function(pixel) {
+ var me = this;
+ var decimal = me.getDecimalForPixel(pixel);
+ return decimal === 0 && me.min === 0
+ ? 0
+ : Math.pow(10, me._startValue + (decimal - me._valueOffset) * me._valueRange);
}
});
| true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | src/scales/scale.time.js | @@ -596,7 +596,6 @@ module.exports = Scale.extend({
me.max = Math.max(min + 1, max);
// PRIVATE
- me._horizontal = me.isHorizontal();
me._table = [];
me._timestamps = {
data: timestamps,
@@ -611,16 +610,16 @@ module.exports = Scale.extend({
var max = me.max;
var options = me.options;
var timeOpts = options.time;
- var timestamps = [];
+ var timestamps = me._timestamps;
var ticks = [];
var i, ilen, timestamp;
switch (options.ticks.source) {
case 'data':
- timestamps = me._timestamps.data;
+ timestamps = timestamps.data;
break;
case 'labels':
- timestamps = me._timestamps.labels;
+ timestamps = timestamps.labels;
break;
case 'auto':
default:
@@ -725,13 +724,8 @@ module.exports = Scale.extend({
getPixelForOffset: function(time) {
var me = this;
var offsets = me._offsets;
- var size = me._horizontal ? me.width : me.height;
var pos = interpolate(me._table, 'time', time, 'pos');
- var offset = size * (offsets.start + pos) * offsets.factor;
-
- return me.options.ticks.reverse ?
- (me._horizontal ? me.right : me.bottom) - offset :
- (me._horizontal ? me.left : me.top) + offset;
+ return me.getPixelForDecimal((offsets.start + pos) * offsets.factor);
},
getPixelForValue: function(value, index, datasetIndex) {
@@ -761,11 +755,7 @@ module.exports = Scale.extend({
getValueForPixel: function(pixel) {
var me = this;
var offsets = me._offsets;
- var size = me._horizontal ? me.width : me.height;
- var offset = me.options.ticks.reverse ?
- (me._horizontal ? me.right : me.bottom) - pixel :
- pixel - (me._horizontal ? me.left : me.top);
- var pos = offset / size / offsets.factor - offsets.start;
+ var pos = me.getDecimalForPixel(pixel) / offsets.factor - offsets.end;
var time = interpolate(me._table, 'pos', pos, 'time');
// DEPRECATION, we should return time directly | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/core.helpers.tests.js | @@ -26,16 +26,6 @@ describe('Core helper tests', function() {
expect(helpers.sign(-5)).toBe(-1);
});
- it('should do a log10 operation', function() {
- expect(helpers.log10(0)).toBe(-Infinity);
-
- // Check all allowed powers of 10, which should return integer values
- var maxPowerOf10 = Math.floor(helpers.log10(Number.MAX_VALUE));
- for (var i = 0; i < maxPowerOf10; i += 1) {
- expect(helpers.log10(Math.pow(10, i))).toBe(i);
- }
- });
-
it('should correctly determine if two numbers are essentially equal', function() {
expect(helpers.almostEquals(0, Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
expect(helpers.almostEquals(1, 1.1, 0.0001)).toBe(false); | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/core.scale.tests.js | @@ -94,7 +94,7 @@ describe('Core.scale', function() {
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5'],
offsetGridLines: true,
offset: true,
- expected: [-0.5, 102.5, 204.5, 307.5, 409.5]
+ expected: [0.5, 102.5, 204.5, 307.5, 409.5]
}, {
labels: ['tick1'],
offsetGridLines: false, | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/helpers.math.tests.js | @@ -1,7 +1,9 @@
'use strict';
+
describe('Chart.helpers.math', function() {
- var factorize = Chart.helpers.math._factorize;
+ var math = Chart.helpers.math;
+ var factorize = math._factorize;
it('should factorize', function() {
expect(factorize(1000)).toEqual([1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500]);
@@ -13,4 +15,14 @@ describe('Chart.helpers.math', function() {
expect(factorize(-1)).toEqual([]);
expect(factorize(2.76)).toEqual([]);
});
+
+ it('should do a log10 operation', function() {
+ expect(math.log10(0)).toBe(-Infinity);
+
+ // Check all allowed powers of 10, which should return integer values
+ var maxPowerOf10 = Math.floor(math.log10(Number.MAX_VALUE));
+ for (var i = 0; i < maxPowerOf10; i += 1) {
+ expect(math.log10(Math.pow(10, i))).toBe(i);
+ }
+ });
}); | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/scale.linear.tests.js | @@ -1196,4 +1196,86 @@ describe('Linear Scale', function() {
expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
expect(chart.scales.yScale0.max).toBeGreaterThan(chart.scales.yScale0.min);
});
+
+ it('Should get correct pixel values when horizontal', function() {
+ var chart = window.acquireChart({
+ type: 'horizontalBar',
+ data: {
+ datasets: [{
+ data: [0.05, -25, 10, 15, 20, 25, 30, 35]
+ }]
+ },
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'x',
+ type: 'linear',
+ }]
+ }
+ }
+ });
+
+ var start = chart.chartArea.left;
+ var end = chart.chartArea.right;
+ var min = -30;
+ var max = 40;
+ var scale = chart.scales.x;
+
+ expect(scale.getPixelForValue(max)).toBeCloseToPixel(end);
+ expect(scale.getPixelForValue(min)).toBeCloseToPixel(start);
+ expect(scale.getValueForPixel(end)).toBeCloseTo(max, 4);
+ expect(scale.getValueForPixel(start)).toBeCloseTo(min, 4);
+
+ scale.options.ticks.reverse = true;
+ chart.update();
+
+ start = chart.chartArea.left;
+ end = chart.chartArea.right;
+
+ expect(scale.getPixelForValue(max)).toBeCloseToPixel(start);
+ expect(scale.getPixelForValue(min)).toBeCloseToPixel(end);
+ expect(scale.getValueForPixel(end)).toBeCloseTo(min, 4);
+ expect(scale.getValueForPixel(start)).toBeCloseTo(max, 4);
+ });
+
+ it('Should get correct pixel values when vertical', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [0.05, -25, 10, 15, 20, 25, 30, 35]
+ }]
+ },
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'y',
+ type: 'linear',
+ }]
+ }
+ }
+ });
+
+ var start = chart.chartArea.bottom;
+ var end = chart.chartArea.top;
+ var min = -30;
+ var max = 40;
+ var scale = chart.scales.y;
+
+ expect(scale.getPixelForValue(max)).toBeCloseToPixel(end);
+ expect(scale.getPixelForValue(min)).toBeCloseToPixel(start);
+ expect(scale.getValueForPixel(end)).toBeCloseTo(max, 4);
+ expect(scale.getValueForPixel(start)).toBeCloseTo(min, 4);
+
+ scale.options.ticks.reverse = true;
+ chart.update();
+
+ start = chart.chartArea.bottom;
+ end = chart.chartArea.top;
+
+ expect(scale.getPixelForValue(max)).toBeCloseToPixel(start);
+ expect(scale.getPixelForValue(min)).toBeCloseToPixel(end);
+ expect(scale.getValueForPixel(end)).toBeCloseTo(min, 4);
+ expect(scale.getValueForPixel(start)).toBeCloseTo(max, 4);
+ });
}); | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/scale.logarithmic.tests.js | @@ -862,6 +862,8 @@ describe('Logarithmic Scale tests', function() {
type: 'logarithmic'
}];
Chart.helpers.extend(scaleConfig, setup.scale);
+ scaleConfig[setup.axis + 'Axes'][0].type = 'logarithmic';
+
var description = 'dataset has stack option and ' + setup.describe
+ ' and axis is "' + setup.axis + '";';
describe(description, function() { | true |
Other | chartjs | Chart.js | cbace1cfe2c1b70ac26d1ee798eb5841fcd978c5.json | Handle reverse support in core.scale (#6343)
* Move log10 from core.helpers to helpers.math
* Refactor scales | test/specs/scale.time.tests.js | @@ -1551,11 +1551,11 @@ describe('Time scale tests', function() {
var firstTickInterval = scale.getPixelForTick(1) - scale.getPixelForTick(0);
var lastTickInterval = scale.getPixelForTick(numTicks - 1) - scale.getPixelForTick(numTicks - 2);
- expect(scale.getValueForPixel(scale.left + firstTickInterval / 2)).toBeCloseToTime({
+ expect(scale.getValueForPixel(scale.left + lastTickInterval / 2)).toBeCloseToTime({
value: moment('2042-01-01T00:00:00'),
unit: 'hour',
});
- expect(scale.getValueForPixel(scale.left + scale.width - lastTickInterval / 2)).toBeCloseToTime({
+ expect(scale.getValueForPixel(scale.left + scale.width - firstTickInterval / 2)).toBeCloseToTime({
value: moment('2017-01-01T00:00:00'),
unit: 'hour',
}); | true |
Other | chartjs | Chart.js | 454f519b6ddc2d60dba0ae2257e0252c6555374c.json | Fix jshint warnings | src/Chart.Scale.js | @@ -73,7 +73,7 @@
});
// Adjust the padding to take into account displaying labels
- if (topScales.length == 0 || bottomScales.length == 0) {
+ if (topScales.length === 0 || bottomScales.length === 0) {
var maxFontHeight = 0;
var maxFontHeightFunction = function(scaleInstance) {
@@ -86,12 +86,12 @@
helpers.each(leftScales, maxFontHeightFunction);
helpers.each(rightScales, maxFontHeightFunction);
- if (topScales.length == 0) {
+ if (topScales.length === 0) {
// Add padding so that we can handle drawing the top nicely
yPadding += 0.75 * maxFontHeight; // 0.75 since padding added on both sides
}
- if (bottomScales.length == 0) {
+ if (bottomScales.length === 0) {
// Add padding so that we can handle drawing the bottom nicely
yPadding += 1.5 * maxFontHeight;
} | false |
Other | chartjs | Chart.js | d7ad5b6340d1200570b904cce09a1960c8088e55.json | Add a scatter chart sample | samples/scatter.html | @@ -0,0 +1,145 @@
+<!doctype html>
+<html>
+
+<head>
+ <title>Scatter Chart</title>
+ <script src="../Chart.js"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
+</head>
+
+<body>
+ <div style="width:50%">
+ <div>
+ <canvas id="canvas" height="450" width="600"></canvas>
+ </div>
+ </div>
+ <button id="randomizeData">Randomize Data</button>
+ <script>
+ var randomScalingFactor = function() {
+ return Math.round(Math.random() * 100);
+ };
+ var randomColor = function(opacity) {
+ return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
+ };
+
+ var scatterChartData = {
+ datasets: [{
+ label: "My First dataset",
+ data: [{
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }]
+ }, {
+ label: "My Second dataset",
+ data: [{
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }]
+ }]
+ };
+
+ $.each(scatterChartData.datasets, function(i, dataset) {
+ dataset.borderColor = randomColor(0.4);
+ dataset.backgroundColor = randomColor(0.1);
+ dataset.pointBorderColor = randomColor(0.7);
+ dataset.pointBackgroundColor = randomColor(0.5);
+ dataset.pointBorderWidth = 1;
+ });
+
+ console.log(scatterChartData);
+
+ window.onload = function() {
+ var ctx = document.getElementById("canvas").getContext("2d");
+ window.myScatter = new Chart(ctx).Scatter(scatterChartData, {
+ responsive: true,
+ hoverMode: 'single'
+ });
+ };
+
+ $('#randomizeData').click(function() {
+ scatterChartData.datasets[0].data = [{
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }];
+ scatterChartData.datasets[1].data = [{
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }, {
+ x: randomScalingFactor(),
+ y: randomScalingFactor(),
+ }]
+ window.myScatter.update();
+ });
+ </script>
+</body>
+
+</html> | false |
Other | chartjs | Chart.js | d26f37236dcd64472b91ed03f90b27e571ef469f.json | Update package.json for color lib location | package.json | @@ -10,7 +10,7 @@
},
"dependences": {},
"devDependencies": {
- "color": "file:../../../../var/folders/rv/vd7mrb5j0hnbrr_2f3q2p6m00000gn/T/npm-53789-2bfe35a6/git-cache-40335d988a8e/54fd04acedef6ccdc54a9929be298945a8093496",
+ "color": "git://github.com/chartjs/color",
"gulp": "3.5.x",
"gulp-concat": "~2.1.x",
"gulp-connect": "~2.0.5", | false |
Other | chartjs | Chart.js | 62b29282fd57dd40654e3867350132a245fa4cd5.json | Fix a minor bug | src/Chart.Bar.js | @@ -146,7 +146,7 @@
calculateBarBase: function() {
var base = this.scale.endPoint;
- if (this.scale.beginAtZero || ((this.scale.min < 0 && this.scale.max > 0) || (this.scale.min > 0 && this.scale.max < 0)))
+ if (this.scale.beginAtZero || ((this.scale.min <= 0 && this.scale.max >= 0) || (this.scale.min >= 0 && this.scale.max <= 0)))
{
base = this.scale.calculateY(0);
} | false |
Other | chartjs | Chart.js | 66f7f96d4b0f8a03b67a45c43f20c1155935f792.json | stop animations when destroying a chart
otherwise the animation keeps updating the chart for some time after it
was supposed to be destroyed, and when the canvas might have been
already reused for a new chart | src/Chart.Core.js | @@ -952,6 +952,7 @@
return template(this.options.legendTemplate,this);
},
destroy : function(){
+ this.stop();
this.clear();
unbindEvents(this, this.events);
var canvas = this.chart.canvas; | false |
Other | chartjs | Chart.js | e69aa04918f0603555ee1b19a82516047a4ac6fc.json | Add StackedArea chart type to community extensions | docs/06-Advanced.md | @@ -159,6 +159,7 @@ new Chart(ctx).LineAlt(data);
### Community extensions
- <a href="https://github.com/Regaddi/Chart.StackedBar.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/Regaddi" target="_blank">@Regaddi</a>
+- <a href="https://github.com/tannerlinsley/Chart.StackedArea.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/tannerlinsley" target="_blank">@tannerlinsley</a>
- <a href="https://github.com/CAYdenberg/Chart.js" target="_blank">Error bars (bar and line charts)</a> by <a href="https://twitter.com/CAYdenberg" target="_blank">@CAYdenberg</a>
- <a href="http://dima117.github.io/Chart.Scatter/" target="_blank">Scatter chart (number & date scales are supported)</a> by <a href="https://github.com/dima117" target="_blank">@dima117</a>
| false |
Other | chartjs | Chart.js | c476db0dd7269ef47e36162b3f9ab2323f409d2e.json | Use findNextWhere correctly. | src/Chart.Core.js | @@ -2098,7 +2098,7 @@
return animationWrapper.chartInstance === chartInstance;
});
- if (index != -1)
+ if (index)
{
this.animations.splice(index, 1);
} | false |
Other | chartjs | Chart.js | b0bddce017c1e8fa0094e69213a096a98377907d.json | Remove some unused scale code | src/core/core.scale.js | @@ -40,44 +40,6 @@
return scaleInstance.options.position == "bottom";
});
- var visibleLeftScales = helpers.where(chartInstance.scales, function(scaleInstance) {
- return scaleInstance.options.position == "left";
- });
- var visibleRightScales = helpers.where(chartInstance.scales, function(scaleInstance) {
- return scaleInstance.options.position == "right";
- });
- var visibleTopScales = helpers.where(chartInstance.scales, function(scaleInstance) {
- return scaleInstance.options.position == "top";
- });
- var visibleBottomScales = helpers.where(chartInstance.scales, function(scaleInstance) {
- return scaleInstance.options.position == "bottom";
- });
-
- // // Adjust the padding to take into account displaying labels
- // if (topScales.length === 0 || bottomScales.length === 0) {
- // var maxFontHeight = 0;
-
- // var maxFontHeightFunction = function(scaleInstance) {
- // if (scaleInstance.options.labels.show) {
- // // Only consider font sizes for axes that actually show labels
- // maxFontHeight = Math.max(maxFontHeight, scaleInstance.options.labels.fontSize);
- // }
- // };
-
- // helpers.each(leftScales, maxFontHeightFunction);
- // helpers.each(rightScales, maxFontHeightFunction);
-
- // if (topScales.length === 0) {
- // // Add padding so that we can handle drawing the top nicely
- // yPadding += 0.75 * maxFontHeight; // 0.75 since padding added on both sides
- // }
-
- // if (bottomScales.length === 0) {
- // // Add padding so that we can handle drawing the bottom nicely
- // yPadding += 1.5 * maxFontHeight;
- // }
- // }
-
// Essentially we now have any number of scales on each of the 4 sides.
// Our canvas looks like the following.
// The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and | false |
Other | chartjs | Chart.js | d37e65c58cf4253e33d732c56f8862458de84597.json | Convert line chart to tabs from spaces | src/charts/chart.line.js | @@ -1,547 +1,547 @@
(function() {
- "use strict";
-
- var root = this,
- Chart = root.Chart,
- helpers = Chart.helpers;
-
- var defaultConfig = {
- hover: {
- mode: "label"
- },
-
- scales: {
- xAxes: [{
- type: "category", // scatter should not use a dataset axis
- display: true,
- position: "bottom",
- id: "x-axis-1", // need an ID so datasets can reference the scale
-
- // grid line settings
- gridLines: {
- show: true,
- color: "rgba(0, 0, 0, 0.05)",
- lineWidth: 1,
- drawOnChartArea: true,
- drawTicks: true,
- zeroLineWidth: 1,
- zeroLineColor: "rgba(0,0,0,0.25)",
- offsetGridLines: false,
- },
-
- // label settings
- labels: {
- show: true,
- template: "<%=value%>",
- fontSize: 12,
- fontStyle: "normal",
- fontColor: "#666",
- fontFamily: "Helvetica Neue",
- },
- }],
- yAxes: [{
- type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
- display: true,
- position: "left",
- id: "y-axis-1",
-
- // grid line settings
- gridLines: {
- show: true,
- color: "rgba(0, 0, 0, 0.05)",
- lineWidth: 1,
- drawOnChartArea: true,
- drawTicks: true, // draw ticks extending towards the label
- zeroLineWidth: 1,
- zeroLineColor: "rgba(0,0,0,0.25)",
- },
-
- // scale numbers
- beginAtZero: false,
- override: null,
-
- // label settings
- labels: {
- show: true,
- template: "<%=value.toLocaleString()%>",
- fontSize: 12,
- fontStyle: "normal",
- fontColor: "#666",
- fontFamily: "Helvetica Neue",
- }
- }],
- },
- };
-
-
- Chart.Type.extend({
- name: "Line",
- defaults: defaultConfig,
- initialize: function() {
-
- var _this = this;
-
- // Events
- helpers.bindEvents(this, this.options.events, this.events);
-
- // Create a new line and its points for each dataset and piece of data
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
-
- dataset.metaDataset = new Chart.Line({
- _chart: this.chart,
- _datasetIndex: datasetIndex,
- _points: dataset.metaData,
- });
-
- dataset.metaData = [];
-
- helpers.each(dataset.data, function(dataPoint, index) {
- dataset.metaData.push(new Chart.Point({
- _datasetIndex: datasetIndex,
- _index: index,
- _chart: this.chart,
- _model: {
- x: 0, //xScale.getPixelForValue(null, index, true),
- y: 0, //this.chartArea.bottom,
- },
- }));
-
- }, this);
-
- // The line chart onlty supports a single x axis because the x axis is always a dataset axis
- dataset.xAxisID = this.options.scales.xAxes[0].id;
-
- if (!dataset.yAxisID) {
- dataset.yAxisID = this.options.scales.yAxes[0].id;
- }
-
- }, this);
-
- // Build and fit the scale. Needs to happen after the axis IDs have been set
- this.buildScale();
-
- // Create tooltip instance exclusively for this chart with some defaults.
- this.tooltip = new Chart.Tooltip({
- _chart: this.chart,
- _data: this.data,
- _options: this.options,
- }, this);
-
- // Need to fit scales before we reset elements.
- Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
-
- // Reset so that we animation from the baseline
- this.resetElements();
-
- // Update that shiz
- this.update();
- },
- nextPoint: function(collection, index) {
- return collection[index + 1] || collection[index];
- },
- previousPoint: function(collection, index) {
- return collection[index - 1] || collection[index];
- },
- resetElements: function() {
- // Update the points
- this.eachElement(function(point, index, dataset, datasetIndex) {
- var xScale = this.scales[this.data.datasets[datasetIndex].xAxisID];
- var yScale = this.scales[this.data.datasets[datasetIndex].yAxisID];
-
- var yScalePoint;
-
- if (yScale.min < 0 && yScale.max < 0) {
- // all less than 0. use the top
- yScalePoint = yScale.getPixelForValue(yScale.max);
- } else if (yScale.min > 0 && yScale.max > 0) {
- yScalePoint = yScale.getPixelForValue(yScale.min);
- } else {
- yScalePoint = yScale.getPixelForValue(0);
- }
-
- helpers.extend(point, {
- // Utility
- _chart: this.chart,
- _xScale: xScale,
- _yScale: yScale,
- _datasetIndex: datasetIndex,
- _index: index,
-
- // Desired view properties
- _model: {
- x: xScale.getPixelForValue(null, index, true), // value not used in dataset scale, but we want a consistent API between scales
- y: yScalePoint,
-
- // Appearance
- tension: point.custom && point.custom.tension ? point.custom.tension : this.options.elements.line.tension,
- radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].radius, index, this.options.elements.point.radius),
- backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBackgroundColor, index, this.options.elements.point.backgroundColor),
- borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderColor, index, this.options.elements.point.borderColor),
- borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderWidth, index, this.options.elements.point.borderWidth),
- skip: this.data.datasets[datasetIndex].data[index] === null,
-
- // Tooltip
- hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].hitRadius, index, this.options.elements.point.hitRadius),
- },
- });
- }, this);
-
- // Update control points for the bezier curve
- this.eachElement(function(point, index, dataset, datasetIndex) {
- var controlPoints = helpers.splineCurve(
- this.previousPoint(dataset, index)._model,
- point._model,
- this.nextPoint(dataset, index)._model,
- point._model.tension
- );
-
- point._model.controlPointPreviousX = controlPoints.previous.x;
- point._model.controlPointNextX = controlPoints.next.x;
-
- // Prevent the bezier going outside of the bounds of the graph
-
- // Cap puter bezier handles to the upper/lower scale bounds
- if (controlPoints.next.y > this.chartArea.bottom) {
- point._model.controlPointNextY = this.chartArea.bottom;
- } else if (controlPoints.next.y < this.chartArea.top) {
- point._model.controlPointNextY = this.chartArea.top;
- } else {
- point._model.controlPointNextY = controlPoints.next.y;
- }
-
- // Cap inner bezier handles to the upper/lower scale bounds
- if (controlPoints.previous.y > this.chartArea.bottom) {
- point._model.controlPointPreviousY = this.chartArea.bottom;
- } else if (controlPoints.previous.y < this.chartArea.top) {
- point._model.controlPointPreviousY = this.chartArea.top;
- } else {
- point._model.controlPointPreviousY = controlPoints.previous.y;
- }
-
- // Now pivot the point for animation
- point.pivot();
- }, this);
- },
- update: function(animationDuration) {
-
- Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
-
- // Update the lines
- this.eachDataset(function(dataset, datasetIndex) {
- var yScale = this.scales[dataset.yAxisID];
- var scaleBase;
-
- if (yScale.min < 0 && yScale.max < 0) {
- scaleBase = yScale.getPixelForValue(yScale.max);
- } else if (yScale.min > 0 && yScale.max > 0) {
- scaleBase = yScale.getPixelForValue(yScale.min);
- } else {
- scaleBase = yScale.getPixelForValue(0);
- }
-
- helpers.extend(dataset.metaDataset, {
- // Utility
- _scale: yScale,
- _datasetIndex: datasetIndex,
- // Data
- _children: dataset.metaData,
- // Model
- _model: {
- // Appearance
- tension: dataset.metaDataset.custom && dataset.metaDataset.custom.tension ? dataset.metaDataset.custom.tension : (dataset.tension || this.options.elements.line.tension),
- backgroundColor: dataset.metaDataset.custom && dataset.metaDataset.custom.backgroundColor ? dataset.metaDataset.custom.backgroundColor : (dataset.backgroundColor || this.options.elements.line.backgroundColor),
- borderWidth: dataset.metaDataset.custom && dataset.metaDataset.custom.borderWidth ? dataset.metaDataset.custom.borderWidth : (dataset.borderWidth || this.options.elements.line.borderWidth),
- borderColor: dataset.metaDataset.custom && dataset.metaDataset.custom.borderColor ? dataset.metaDataset.custom.borderColor : (dataset.borderColor || this.options.elements.line.borderColor),
- fill: dataset.metaDataset.custom && dataset.metaDataset.custom.fill ? dataset.metaDataset.custom.fill : (dataset.fill !== undefined ? dataset.fill : this.options.elements.line.fill),
- skipNull: dataset.skipNull !== undefined ? dataset.skipNull : this.options.elements.line.skipNull,
- drawNull: dataset.drawNull !== undefined ? dataset.drawNull : this.options.elements.line.drawNull,
- // Scale
- scaleTop: yScale.top,
- scaleBottom: yScale.bottom,
- scaleZero: scaleBase,
- },
- });
-
- dataset.metaDataset.pivot();
- });
-
- // Update the points
- this.eachElement(function(point, index, dataset, datasetIndex) {
- var xScale = this.scales[this.data.datasets[datasetIndex].xAxisID];
- var yScale = this.scales[this.data.datasets[datasetIndex].yAxisID];
-
- helpers.extend(point, {
- // Utility
- _chart: this.chart,
- _xScale: xScale,
- _yScale: yScale,
- _datasetIndex: datasetIndex,
- _index: index,
-
- // Desired view properties
- _model: {
- x: xScale.getPixelForValue(null, index, true), // value not used in dataset scale, but we want a consistent API between scales
- y: yScale.getPointPixelForValue(this.data.datasets[datasetIndex].data[index], index, datasetIndex),
-
- // Appearance
- tension: point.custom && point.custom.tension ? point.custom.tension : this.options.elements.line.tension,
- radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].radius, index, this.options.elements.point.radius),
- backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBackgroundColor, index, this.options.elements.point.backgroundColor),
- borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderColor, index, this.options.elements.point.borderColor),
- borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderWidth, index, this.options.elements.point.borderWidth),
- skip: this.data.datasets[datasetIndex].data[index] === null,
-
- // Tooltip
- hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].hitRadius, index, this.options.elements.point.hitRadius),
- },
- });
- }, this);
-
-
- // Update control points for the bezier curve
- this.eachElement(function(point, index, dataset, datasetIndex) {
- var controlPoints = helpers.splineCurve(
- this.previousPoint(dataset, index)._model,
- point._model,
- this.nextPoint(dataset, index)._model,
- point._model.tension
- );
-
- point._model.controlPointPreviousX = controlPoints.previous.x;
- point._model.controlPointNextX = controlPoints.next.x;
-
- // Prevent the bezier going outside of the bounds of the graph
-
- // Cap puter bezier handles to the upper/lower scale bounds
- if (controlPoints.next.y > this.chartArea.bottom) {
- point._model.controlPointNextY = this.chartArea.bottom;
- } else if (controlPoints.next.y < this.chartArea.top) {
- point._model.controlPointNextY = this.chartArea.top;
- } else {
- point._model.controlPointNextY = controlPoints.next.y;
- }
-
- // Cap inner bezier handles to the upper/lower scale bounds
- if (controlPoints.previous.y > this.chartArea.bottom) {
- point._model.controlPointPreviousY = this.chartArea.bottom;
- } else if (controlPoints.previous.y < this.chartArea.top) {
- point._model.controlPointPreviousY = this.chartArea.top;
- } else {
- point._model.controlPointPreviousY = controlPoints.previous.y;
- }
-
- // Now pivot the point for animation
- point.pivot();
- }, this);
-
- this.render(animationDuration);
- },
- buildScale: function() {
- var self = this;
-
- // Map of scale ID to scale object so we can lookup later
- this.scales = {};
-
- // Build the x axis. The line chart only supports a single x axis
- var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].type);
- var xScale = new ScaleClass({
- ctx: this.chart.ctx,
- options: this.options.scales.xAxes[0],
- data: this.data,
- id: this.options.scales.xAxes[0].id,
- });
- this.scales[xScale.id] = xScale;
-
- // Build up all the y scales
- helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
- var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
- var scale = new ScaleClass({
- ctx: this.chart.ctx,
- options: yAxisOptions,
- data: this.data,
- id: yAxisOptions.id,
- });
-
- this.scales[scale.id] = scale;
- }, this);
- },
- draw: function(ease) {
-
- var easingDecimal = ease || 1;
- this.clear();
-
- // Draw all the scales
- helpers.each(this.scales, function(scale) {
- scale.draw(this.chartArea);
- }, this);
-
- // reverse for-loop for proper stacking
- for (var i = this.data.datasets.length - 1; i >= 0; i--) {
-
- var dataset = this.data.datasets[i];
-
- // Transition Point Locations
- helpers.each(dataset.metaData, function(point, index) {
- point.transition(easingDecimal);
- }, this);
-
- // Transition and Draw the line
- dataset.metaDataset.transition(easingDecimal).draw();
-
- // Draw the points
- helpers.each(dataset.metaData, function(point) {
- point.draw();
- });
- }
-
- // Finally draw the tooltip
- this.tooltip.transition(easingDecimal).draw();
- },
- events: function(e) {
-
- this.lastActive = this.lastActive || [];
-
- // Find Active Elements
- if (e.type == 'mouseout') {
- this.active = [];
- } else {
- this.active = function() {
- switch (this.options.hover.mode) {
- case 'single':
- return this.getElementAtEvent(e);
- case 'label':
- return this.getElementsAtEvent(e);
- case 'dataset':
- return this.getDatasetAtEvent(e);
- default:
- return e;
- }
- }.call(this);
- }
-
- // On Hover hook
- if (this.options.hover.onHover) {
- this.options.hover.onHover.call(this, this.active);
- }
-
- if (e.type == 'mouseup' || e.type == 'click') {
- if (this.options.onClick) {
- this.options.onClick.call(this, e, this.active);
- }
- }
-
- var dataset;
- var index;
- // Remove styling for last active (even if it may still be active)
- if (this.lastActive.length) {
- switch (this.options.hover.mode) {
- case 'single':
- dataset = this.data.datasets[this.lastActive[0]._datasetIndex];
- index = this.lastActive[0]._index;
-
- this.lastActive[0]._model.radius = this.lastActive[0].custom && this.lastActive[0].custom.radius ? this.lastActive[0].custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, this.options.elements.point.radius);
- this.lastActive[0]._model.backgroundColor = this.lastActive[0].custom && this.lastActive[0].custom.backgroundColor ? this.lastActive[0].custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, this.options.elements.point.backgroundColor);
- this.lastActive[0]._model.borderColor = this.lastActive[0].custom && this.lastActive[0].custom.borderColor ? this.lastActive[0].custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, this.options.elements.point.borderColor);
- this.lastActive[0]._model.borderWidth = this.lastActive[0].custom && this.lastActive[0].custom.borderWidth ? this.lastActive[0].custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.options.elements.point.borderWidth);
- break;
- case 'label':
- for (var i = 0; i < this.lastActive.length; i++) {
- dataset = this.data.datasets[this.lastActive[i]._datasetIndex];
- index = this.lastActive[i]._index;
-
- this.lastActive[i]._model.radius = this.lastActive[i].custom && this.lastActive[i].custom.radius ? this.lastActive[i].custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, this.options.elements.point.radius);
- this.lastActive[i]._model.backgroundColor = this.lastActive[i].custom && this.lastActive[i].custom.backgroundColor ? this.lastActive[i].custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, this.options.elements.point.backgroundColor);
- this.lastActive[i]._model.borderColor = this.lastActive[i].custom && this.lastActive[i].custom.borderColor ? this.lastActive[i].custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, this.options.elements.point.borderColor);
- this.lastActive[i]._model.borderWidth = this.lastActive[i].custom && this.lastActive[i].custom.borderWidth ? this.lastActive[i].custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.options.elements.point.borderWidth);
- }
- break;
- case 'dataset':
- break;
- default:
- // Don't change anything
- }
- }
-
- // Built in hover styling
- if (this.active.length && this.options.hover.mode) {
- switch (this.options.hover.mode) {
- case 'single':
- dataset = this.data.datasets[this.active[0]._datasetIndex];
- index = this.active[0]._index;
-
- this.active[0]._model.radius = this.active[0].custom && this.active[0].custom.radius ? this.active[0].custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.options.elements.point.hoverRadius);
- this.active[0]._model.backgroundColor = this.active[0].custom && this.active[0].custom.hoverBackgroundColor ? this.active[0].custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(this.active[0]._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
- this.active[0]._model.borderColor = this.active[0].custom && this.active[0].custom.hoverBorderColor ? this.active[0].custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(this.active[0]._model.borderColor).saturate(0.5).darken(0.1).rgbString());
- this.active[0]._model.borderWidth = this.active[0].custom && this.active[0].custom.hoverBorderWidth ? this.active[0].custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.active[0]._model.borderWidth);
- break;
- case 'label':
- for (var i = 0; i < this.active.length; i++) {
- dataset = this.data.datasets[this.active[i]._datasetIndex];
- index = this.active[i]._index;
-
- this.active[i]._model.radius = this.active[i].custom && this.active[i].custom.radius ? this.active[i].custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.options.elements.point.hoverRadius);
- this.active[i]._model.backgroundColor = this.active[i].custom && this.active[i].custom.hoverBackgroundColor ? this.active[i].custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(this.active[i]._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
- this.active[i]._model.borderColor = this.active[i].custom && this.active[i].custom.hoverBorderColor ? this.active[i].custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(this.active[i]._model.borderColor).saturate(0.5).darken(0.1).rgbString());
- this.active[i]._model.borderWidth = this.active[i].custom && this.active[i].custom.hoverBorderWidth ? this.active[i].custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.active[i]._model.borderWidth);
- }
- break;
- case 'dataset':
- break;
- default:
- // Don't change anything
- }
- }
-
-
- // Built in Tooltips
- if (this.options.tooltips.enabled) {
-
- // The usual updates
- this.tooltip.initialize();
-
- // Active
- if (this.active.length) {
- this.tooltip._model.opacity = 1;
-
- helpers.extend(this.tooltip, {
- _active: this.active,
- });
-
- this.tooltip.update();
- } else {
- // Inactive
- this.tooltip._model.opacity = 0;
- }
- }
-
-
- // Hover animations
- this.tooltip.pivot();
-
- if (!this.animating) {
- var changed;
-
- helpers.each(this.active, function(element, index) {
- if (element !== this.lastActive[index]) {
- changed = true;
- }
- }, this);
-
- // If entering, leaving, or changing elements, animate the change via pivot
- if ((!this.lastActive.length && this.active.length) ||
- (this.lastActive.length && !this.active.length) ||
- (this.lastActive.length && this.active.length && changed)) {
-
- this.stop();
- this.render(this.options.hover.animationDuration);
- }
- }
-
- // Remember Last Active
- this.lastActive = this.active;
- return this;
- },
- });
+ "use strict";
+
+ var root = this,
+ Chart = root.Chart,
+ helpers = Chart.helpers;
+
+ var defaultConfig = {
+ hover: {
+ mode: "label"
+ },
+
+ scales: {
+ xAxes: [{
+ type: "category", // scatter should not use a dataset axis
+ display: true,
+ position: "bottom",
+ id: "x-axis-1", // need an ID so datasets can reference the scale
+
+ // grid line settings
+ gridLines: {
+ show: true,
+ color: "rgba(0, 0, 0, 0.05)",
+ lineWidth: 1,
+ drawOnChartArea: true,
+ drawTicks: true,
+ zeroLineWidth: 1,
+ zeroLineColor: "rgba(0,0,0,0.25)",
+ offsetGridLines: false,
+ },
+
+ // label settings
+ labels: {
+ show: true,
+ template: "<%=value%>",
+ fontSize: 12,
+ fontStyle: "normal",
+ fontColor: "#666",
+ fontFamily: "Helvetica Neue",
+ },
+ }],
+ yAxes: [{
+ type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
+ display: true,
+ position: "left",
+ id: "y-axis-1",
+
+ // grid line settings
+ gridLines: {
+ show: true,
+ color: "rgba(0, 0, 0, 0.05)",
+ lineWidth: 1,
+ drawOnChartArea: true,
+ drawTicks: true, // draw ticks extending towards the label
+ zeroLineWidth: 1,
+ zeroLineColor: "rgba(0,0,0,0.25)",
+ },
+
+ // scale numbers
+ beginAtZero: false,
+ override: null,
+
+ // label settings
+ labels: {
+ show: true,
+ template: "<%=value.toLocaleString()%>",
+ fontSize: 12,
+ fontStyle: "normal",
+ fontColor: "#666",
+ fontFamily: "Helvetica Neue",
+ }
+ }],
+ },
+ };
+
+
+ Chart.Type.extend({
+ name: "Line",
+ defaults: defaultConfig,
+ initialize: function() {
+
+ var _this = this;
+
+ // Events
+ helpers.bindEvents(this, this.options.events, this.events);
+
+ // Create a new line and its points for each dataset and piece of data
+ helpers.each(this.data.datasets, function(dataset, datasetIndex) {
+
+ dataset.metaDataset = new Chart.Line({
+ _chart: this.chart,
+ _datasetIndex: datasetIndex,
+ _points: dataset.metaData,
+ });
+
+ dataset.metaData = [];
+
+ helpers.each(dataset.data, function(dataPoint, index) {
+ dataset.metaData.push(new Chart.Point({
+ _datasetIndex: datasetIndex,
+ _index: index,
+ _chart: this.chart,
+ _model: {
+ x: 0, //xScale.getPixelForValue(null, index, true),
+ y: 0, //this.chartArea.bottom,
+ },
+ }));
+
+ }, this);
+
+ // The line chart onlty supports a single x axis because the x axis is always a dataset axis
+ dataset.xAxisID = this.options.scales.xAxes[0].id;
+
+ if (!dataset.yAxisID) {
+ dataset.yAxisID = this.options.scales.yAxes[0].id;
+ }
+
+ }, this);
+
+ // Build and fit the scale. Needs to happen after the axis IDs have been set
+ this.buildScale();
+
+ // Create tooltip instance exclusively for this chart with some defaults.
+ this.tooltip = new Chart.Tooltip({
+ _chart: this.chart,
+ _data: this.data,
+ _options: this.options,
+ }, this);
+
+ // Need to fit scales before we reset elements.
+ Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
+
+ // Reset so that we animation from the baseline
+ this.resetElements();
+
+ // Update that shiz
+ this.update();
+ },
+ nextPoint: function(collection, index) {
+ return collection[index + 1] || collection[index];
+ },
+ previousPoint: function(collection, index) {
+ return collection[index - 1] || collection[index];
+ },
+ resetElements: function() {
+ // Update the points
+ this.eachElement(function(point, index, dataset, datasetIndex) {
+ var xScale = this.scales[this.data.datasets[datasetIndex].xAxisID];
+ var yScale = this.scales[this.data.datasets[datasetIndex].yAxisID];
+
+ var yScalePoint;
+
+ if (yScale.min < 0 && yScale.max < 0) {
+ // all less than 0. use the top
+ yScalePoint = yScale.getPixelForValue(yScale.max);
+ } else if (yScale.min > 0 && yScale.max > 0) {
+ yScalePoint = yScale.getPixelForValue(yScale.min);
+ } else {
+ yScalePoint = yScale.getPixelForValue(0);
+ }
+
+ helpers.extend(point, {
+ // Utility
+ _chart: this.chart,
+ _xScale: xScale,
+ _yScale: yScale,
+ _datasetIndex: datasetIndex,
+ _index: index,
+
+ // Desired view properties
+ _model: {
+ x: xScale.getPixelForValue(null, index, true), // value not used in dataset scale, but we want a consistent API between scales
+ y: yScalePoint,
+
+ // Appearance
+ tension: point.custom && point.custom.tension ? point.custom.tension : this.options.elements.line.tension,
+ radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].radius, index, this.options.elements.point.radius),
+ backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBackgroundColor, index, this.options.elements.point.backgroundColor),
+ borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderColor, index, this.options.elements.point.borderColor),
+ borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderWidth, index, this.options.elements.point.borderWidth),
+ skip: this.data.datasets[datasetIndex].data[index] === null,
+
+ // Tooltip
+ hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].hitRadius, index, this.options.elements.point.hitRadius),
+ },
+ });
+ }, this);
+
+ // Update control points for the bezier curve
+ this.eachElement(function(point, index, dataset, datasetIndex) {
+ var controlPoints = helpers.splineCurve(
+ this.previousPoint(dataset, index)._model,
+ point._model,
+ this.nextPoint(dataset, index)._model,
+ point._model.tension
+ );
+
+ point._model.controlPointPreviousX = controlPoints.previous.x;
+ point._model.controlPointNextX = controlPoints.next.x;
+
+ // Prevent the bezier going outside of the bounds of the graph
+
+ // Cap puter bezier handles to the upper/lower scale bounds
+ if (controlPoints.next.y > this.chartArea.bottom) {
+ point._model.controlPointNextY = this.chartArea.bottom;
+ } else if (controlPoints.next.y < this.chartArea.top) {
+ point._model.controlPointNextY = this.chartArea.top;
+ } else {
+ point._model.controlPointNextY = controlPoints.next.y;
+ }
+
+ // Cap inner bezier handles to the upper/lower scale bounds
+ if (controlPoints.previous.y > this.chartArea.bottom) {
+ point._model.controlPointPreviousY = this.chartArea.bottom;
+ } else if (controlPoints.previous.y < this.chartArea.top) {
+ point._model.controlPointPreviousY = this.chartArea.top;
+ } else {
+ point._model.controlPointPreviousY = controlPoints.previous.y;
+ }
+
+ // Now pivot the point for animation
+ point.pivot();
+ }, this);
+ },
+ update: function(animationDuration) {
+
+ Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
+
+ // Update the lines
+ this.eachDataset(function(dataset, datasetIndex) {
+ var yScale = this.scales[dataset.yAxisID];
+ var scaleBase;
+
+ if (yScale.min < 0 && yScale.max < 0) {
+ scaleBase = yScale.getPixelForValue(yScale.max);
+ } else if (yScale.min > 0 && yScale.max > 0) {
+ scaleBase = yScale.getPixelForValue(yScale.min);
+ } else {
+ scaleBase = yScale.getPixelForValue(0);
+ }
+
+ helpers.extend(dataset.metaDataset, {
+ // Utility
+ _scale: yScale,
+ _datasetIndex: datasetIndex,
+ // Data
+ _children: dataset.metaData,
+ // Model
+ _model: {
+ // Appearance
+ tension: dataset.metaDataset.custom && dataset.metaDataset.custom.tension ? dataset.metaDataset.custom.tension : (dataset.tension || this.options.elements.line.tension),
+ backgroundColor: dataset.metaDataset.custom && dataset.metaDataset.custom.backgroundColor ? dataset.metaDataset.custom.backgroundColor : (dataset.backgroundColor || this.options.elements.line.backgroundColor),
+ borderWidth: dataset.metaDataset.custom && dataset.metaDataset.custom.borderWidth ? dataset.metaDataset.custom.borderWidth : (dataset.borderWidth || this.options.elements.line.borderWidth),
+ borderColor: dataset.metaDataset.custom && dataset.metaDataset.custom.borderColor ? dataset.metaDataset.custom.borderColor : (dataset.borderColor || this.options.elements.line.borderColor),
+ fill: dataset.metaDataset.custom && dataset.metaDataset.custom.fill ? dataset.metaDataset.custom.fill : (dataset.fill !== undefined ? dataset.fill : this.options.elements.line.fill),
+ skipNull: dataset.skipNull !== undefined ? dataset.skipNull : this.options.elements.line.skipNull,
+ drawNull: dataset.drawNull !== undefined ? dataset.drawNull : this.options.elements.line.drawNull,
+ // Scale
+ scaleTop: yScale.top,
+ scaleBottom: yScale.bottom,
+ scaleZero: scaleBase,
+ },
+ });
+
+ dataset.metaDataset.pivot();
+ });
+
+ // Update the points
+ this.eachElement(function(point, index, dataset, datasetIndex) {
+ var xScale = this.scales[this.data.datasets[datasetIndex].xAxisID];
+ var yScale = this.scales[this.data.datasets[datasetIndex].yAxisID];
+
+ helpers.extend(point, {
+ // Utility
+ _chart: this.chart,
+ _xScale: xScale,
+ _yScale: yScale,
+ _datasetIndex: datasetIndex,
+ _index: index,
+
+ // Desired view properties
+ _model: {
+ x: xScale.getPixelForValue(null, index, true), // value not used in dataset scale, but we want a consistent API between scales
+ y: yScale.getPointPixelForValue(this.data.datasets[datasetIndex].data[index], index, datasetIndex),
+
+ // Appearance
+ tension: point.custom && point.custom.tension ? point.custom.tension : this.options.elements.line.tension,
+ radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].radius, index, this.options.elements.point.radius),
+ backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBackgroundColor, index, this.options.elements.point.backgroundColor),
+ borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderColor, index, this.options.elements.point.borderColor),
+ borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].pointBorderWidth, index, this.options.elements.point.borderWidth),
+ skip: this.data.datasets[datasetIndex].data[index] === null,
+
+ // Tooltip
+ hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.data.datasets[datasetIndex].hitRadius, index, this.options.elements.point.hitRadius),
+ },
+ });
+ }, this);
+
+
+ // Update control points for the bezier curve
+ this.eachElement(function(point, index, dataset, datasetIndex) {
+ var controlPoints = helpers.splineCurve(
+ this.previousPoint(dataset, index)._model,
+ point._model,
+ this.nextPoint(dataset, index)._model,
+ point._model.tension
+ );
+
+ point._model.controlPointPreviousX = controlPoints.previous.x;
+ point._model.controlPointNextX = controlPoints.next.x;
+
+ // Prevent the bezier going outside of the bounds of the graph
+
+ // Cap puter bezier handles to the upper/lower scale bounds
+ if (controlPoints.next.y > this.chartArea.bottom) {
+ point._model.controlPointNextY = this.chartArea.bottom;
+ } else if (controlPoints.next.y < this.chartArea.top) {
+ point._model.controlPointNextY = this.chartArea.top;
+ } else {
+ point._model.controlPointNextY = controlPoints.next.y;
+ }
+
+ // Cap inner bezier handles to the upper/lower scale bounds
+ if (controlPoints.previous.y > this.chartArea.bottom) {
+ point._model.controlPointPreviousY = this.chartArea.bottom;
+ } else if (controlPoints.previous.y < this.chartArea.top) {
+ point._model.controlPointPreviousY = this.chartArea.top;
+ } else {
+ point._model.controlPointPreviousY = controlPoints.previous.y;
+ }
+
+ // Now pivot the point for animation
+ point.pivot();
+ }, this);
+
+ this.render(animationDuration);
+ },
+ buildScale: function() {
+ var self = this;
+
+ // Map of scale ID to scale object so we can lookup later
+ this.scales = {};
+
+ // Build the x axis. The line chart only supports a single x axis
+ var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].type);
+ var xScale = new ScaleClass({
+ ctx: this.chart.ctx,
+ options: this.options.scales.xAxes[0],
+ data: this.data,
+ id: this.options.scales.xAxes[0].id,
+ });
+ this.scales[xScale.id] = xScale;
+
+ // Build up all the y scales
+ helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
+ var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
+ var scale = new ScaleClass({
+ ctx: this.chart.ctx,
+ options: yAxisOptions,
+ data: this.data,
+ id: yAxisOptions.id,
+ });
+
+ this.scales[scale.id] = scale;
+ }, this);
+ },
+ draw: function(ease) {
+
+ var easingDecimal = ease || 1;
+ this.clear();
+
+ // Draw all the scales
+ helpers.each(this.scales, function(scale) {
+ scale.draw(this.chartArea);
+ }, this);
+
+ // reverse for-loop for proper stacking
+ for (var i = this.data.datasets.length - 1; i >= 0; i--) {
+
+ var dataset = this.data.datasets[i];
+
+ // Transition Point Locations
+ helpers.each(dataset.metaData, function(point, index) {
+ point.transition(easingDecimal);
+ }, this);
+
+ // Transition and Draw the line
+ dataset.metaDataset.transition(easingDecimal).draw();
+
+ // Draw the points
+ helpers.each(dataset.metaData, function(point) {
+ point.draw();
+ });
+ }
+
+ // Finally draw the tooltip
+ this.tooltip.transition(easingDecimal).draw();
+ },
+ events: function(e) {
+
+ this.lastActive = this.lastActive || [];
+
+ // Find Active Elements
+ if (e.type == 'mouseout') {
+ this.active = [];
+ } else {
+ this.active = function() {
+ switch (this.options.hover.mode) {
+ case 'single':
+ return this.getElementAtEvent(e);
+ case 'label':
+ return this.getElementsAtEvent(e);
+ case 'dataset':
+ return this.getDatasetAtEvent(e);
+ default:
+ return e;
+ }
+ }.call(this);
+ }
+
+ // On Hover hook
+ if (this.options.hover.onHover) {
+ this.options.hover.onHover.call(this, this.active);
+ }
+
+ if (e.type == 'mouseup' || e.type == 'click') {
+ if (this.options.onClick) {
+ this.options.onClick.call(this, e, this.active);
+ }
+ }
+
+ var dataset;
+ var index;
+ // Remove styling for last active (even if it may still be active)
+ if (this.lastActive.length) {
+ switch (this.options.hover.mode) {
+ case 'single':
+ dataset = this.data.datasets[this.lastActive[0]._datasetIndex];
+ index = this.lastActive[0]._index;
+
+ this.lastActive[0]._model.radius = this.lastActive[0].custom && this.lastActive[0].custom.radius ? this.lastActive[0].custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, this.options.elements.point.radius);
+ this.lastActive[0]._model.backgroundColor = this.lastActive[0].custom && this.lastActive[0].custom.backgroundColor ? this.lastActive[0].custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, this.options.elements.point.backgroundColor);
+ this.lastActive[0]._model.borderColor = this.lastActive[0].custom && this.lastActive[0].custom.borderColor ? this.lastActive[0].custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, this.options.elements.point.borderColor);
+ this.lastActive[0]._model.borderWidth = this.lastActive[0].custom && this.lastActive[0].custom.borderWidth ? this.lastActive[0].custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.options.elements.point.borderWidth);
+ break;
+ case 'label':
+ for (var i = 0; i < this.lastActive.length; i++) {
+ dataset = this.data.datasets[this.lastActive[i]._datasetIndex];
+ index = this.lastActive[i]._index;
+
+ this.lastActive[i]._model.radius = this.lastActive[i].custom && this.lastActive[i].custom.radius ? this.lastActive[i].custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, this.options.elements.point.radius);
+ this.lastActive[i]._model.backgroundColor = this.lastActive[i].custom && this.lastActive[i].custom.backgroundColor ? this.lastActive[i].custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, this.options.elements.point.backgroundColor);
+ this.lastActive[i]._model.borderColor = this.lastActive[i].custom && this.lastActive[i].custom.borderColor ? this.lastActive[i].custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, this.options.elements.point.borderColor);
+ this.lastActive[i]._model.borderWidth = this.lastActive[i].custom && this.lastActive[i].custom.borderWidth ? this.lastActive[i].custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.options.elements.point.borderWidth);
+ }
+ break;
+ case 'dataset':
+ break;
+ default:
+ // Don't change anything
+ }
+ }
+
+ // Built in hover styling
+ if (this.active.length && this.options.hover.mode) {
+ switch (this.options.hover.mode) {
+ case 'single':
+ dataset = this.data.datasets[this.active[0]._datasetIndex];
+ index = this.active[0]._index;
+
+ this.active[0]._model.radius = this.active[0].custom && this.active[0].custom.radius ? this.active[0].custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.options.elements.point.hoverRadius);
+ this.active[0]._model.backgroundColor = this.active[0].custom && this.active[0].custom.hoverBackgroundColor ? this.active[0].custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(this.active[0]._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
+ this.active[0]._model.borderColor = this.active[0].custom && this.active[0].custom.hoverBorderColor ? this.active[0].custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(this.active[0]._model.borderColor).saturate(0.5).darken(0.1).rgbString());
+ this.active[0]._model.borderWidth = this.active[0].custom && this.active[0].custom.hoverBorderWidth ? this.active[0].custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.active[0]._model.borderWidth);
+ break;
+ case 'label':
+ for (var i = 0; i < this.active.length; i++) {
+ dataset = this.data.datasets[this.active[i]._datasetIndex];
+ index = this.active[i]._index;
+
+ this.active[i]._model.radius = this.active[i].custom && this.active[i].custom.radius ? this.active[i].custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.options.elements.point.hoverRadius);
+ this.active[i]._model.backgroundColor = this.active[i].custom && this.active[i].custom.hoverBackgroundColor ? this.active[i].custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(this.active[i]._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
+ this.active[i]._model.borderColor = this.active[i].custom && this.active[i].custom.hoverBorderColor ? this.active[i].custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(this.active[i]._model.borderColor).saturate(0.5).darken(0.1).rgbString());
+ this.active[i]._model.borderWidth = this.active[i].custom && this.active[i].custom.hoverBorderWidth ? this.active[i].custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, this.active[i]._model.borderWidth);
+ }
+ break;
+ case 'dataset':
+ break;
+ default:
+ // Don't change anything
+ }
+ }
+
+
+ // Built in Tooltips
+ if (this.options.tooltips.enabled) {
+
+ // The usual updates
+ this.tooltip.initialize();
+
+ // Active
+ if (this.active.length) {
+ this.tooltip._model.opacity = 1;
+
+ helpers.extend(this.tooltip, {
+ _active: this.active,
+ });
+
+ this.tooltip.update();
+ } else {
+ // Inactive
+ this.tooltip._model.opacity = 0;
+ }
+ }
+
+
+ // Hover animations
+ this.tooltip.pivot();
+
+ if (!this.animating) {
+ var changed;
+
+ helpers.each(this.active, function(element, index) {
+ if (element !== this.lastActive[index]) {
+ changed = true;
+ }
+ }, this);
+
+ // If entering, leaving, or changing elements, animate the change via pivot
+ if ((!this.lastActive.length && this.active.length) ||
+ (this.lastActive.length && !this.active.length) ||
+ (this.lastActive.length && this.active.length && changed)) {
+
+ this.stop();
+ this.render(this.options.hover.animationDuration);
+ }
+ }
+
+ // Remember Last Active
+ this.lastActive = this.active;
+ return this;
+ },
+ });
}).call(this); | false |
Other | chartjs | Chart.js | 29743e1d63353008d53276cce6db962c636d6c39.json | Use a polyfill when Math.log10 does not exist | src/Chart.Core.js | @@ -329,6 +329,13 @@
return x > 0 ? 1 : -1;
}
},
+ log10 = helpers.log10 = function(x) {
+ if (Math.log10) {
+ return Math.log10(x)
+ } else {
+ return Math.log(x) / Math.LN10;
+ }
+ },
cap = helpers.cap = function(valueToCap, maxValue, minValue) {
if (isNumber(maxValue)) {
if (valueToCap > maxValue) {
@@ -484,7 +491,7 @@
},
// Implementation of the nice number algorithm used in determining where axis labels will go
niceNum = helpers.niceNum = function(range, round) {
- var exponent = Math.floor(Math.log10(range));
+ var exponent = Math.floor(helpers.log10(range));
var fraction = range / Math.pow(10, exponent);
var niceFraction;
| false |
Other | chartjs | Chart.js | d1cccd354639cfc65b5f82ecd5d58666eda2a0a8.json | Update CDN link | docs/00-Getting-Started.md | @@ -33,7 +33,7 @@ bower install Chart.js --save
Also, Chart.js is available from CDN:
-https://cdnjs.com/libraries/chart.js
+https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js
###Creating a chart
| false |
Other | chartjs | Chart.js | 051f5b015bc9d1fb07cd23ec3bfc78e6e3914360.json | Fix bug with pie/doughnut chart legends
Fixes a rendering issue when there are multiple datasets on a pie chart and they do not all contain the same number of data in their datasets
Fixes #3309 | src/controllers/controller.doughnut.js | @@ -76,7 +76,10 @@ module.exports = function(Chart) {
for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
meta = chart.getDatasetMeta(i);
- meta.data[index].hidden = !meta.data[index].hidden;
+ // toggle visibility of index if exists
+ if (meta.data[index]) {
+ meta.data[index].hidden = !meta.data[index].hidden;
+ }
}
chart.update(); | false |
Other | chartjs | Chart.js | 8bc280e1856c4ab09a8a529347f2ef1e5292807e.json | Allow variable use before define with warning | .eslintrc | @@ -112,7 +112,7 @@ rules:
no-undef: 2
no-undefined: 0
no-unused-vars: 2
- no-use-before-define: 2
+ no-use-before-define: 1
# Node.js and CommonJS
callback-return: 2 | false |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/core/core.helpers.js | @@ -45,7 +45,9 @@ module.exports = function(Chart) {
return objClone;
};
helpers.extend = function(base) {
- var setFn = function(value, key) { base[key] = value; };
+ var setFn = function(value, key) {
+ base[key] = value;
+ };
for (var i = 1, ilen = arguments.length; i < ilen; i++) {
helpers.each(arguments[i], setFn);
}
@@ -150,7 +152,9 @@ module.exports = function(Chart) {
return value === undefined ? defaultValue : value;
};
helpers.indexOf = Array.prototype.indexOf?
- function(array, item) { return array.indexOf(item); } :
+ function(array, item) {
+ return array.indexOf(item);
+ }:
function(array, item) {
for (var i = 0, ilen = array.length; i < ilen; ++i) {
if (array[i] === item) {
@@ -162,20 +166,21 @@ module.exports = function(Chart) {
helpers.where = function(collection, filterCallback) {
if (helpers.isArray(collection) && Array.prototype.filter) {
return collection.filter(filterCallback);
- } else {
- var filtered = [];
+ }
+ var filtered = [];
- helpers.each(collection, function(item) {
- if (filterCallback(item)) {
- filtered.push(item);
- }
- });
+ helpers.each(collection, function(item) {
+ if (filterCallback(item)) {
+ filtered.push(item);
+ }
+ });
- return filtered;
- }
+ return filtered;
};
helpers.findIndex = Array.prototype.findIndex?
- function(array, callback, scope) { return array.findIndex(callback, scope); } :
+ function(array, callback, scope) {
+ return array.findIndex(callback, scope);
+ } :
function(array, callback, scope) {
scope = scope === undefined? array : scope;
for (var i = 0, ilen = array.length; i < ilen; ++i) {
@@ -211,15 +216,15 @@ module.exports = function(Chart) {
};
helpers.inherits = function(extensions) {
// Basic javascript inheritance based on the model created in Backbone.js
- var parent = this;
+ var me = this;
var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
- return parent.apply(this, arguments);
+ return me.apply(this, arguments);
};
var Surrogate = function() {
this.constructor = ChartElement;
};
- Surrogate.prototype = parent.prototype;
+ Surrogate.prototype = me.prototype;
ChartElement.prototype = new Surrogate();
ChartElement.extend = helpers.inherits;
@@ -228,7 +233,7 @@ module.exports = function(Chart) {
helpers.extend(ChartElement.prototype, extensions);
}
- ChartElement.__super__ = parent.prototype;
+ ChartElement.__super__ = me.prototype;
return ChartElement;
};
@@ -250,22 +255,22 @@ module.exports = function(Chart) {
return array.reduce(function(max, value) {
if (!isNaN(value)) {
return Math.max(max, value);
- } else {
- return max;
}
+ return max;
}, Number.NEGATIVE_INFINITY);
};
helpers.min = function(array) {
return array.reduce(function(min, value) {
if (!isNaN(value)) {
return Math.min(min, value);
- } else {
- return min;
}
+ return min;
}, Number.POSITIVE_INFINITY);
};
helpers.sign = Math.sign?
- function(x) { return Math.sign(x); } :
+ function(x) {
+ return Math.sign(x);
+ } :
function(x) {
x = +x; // convert to a number
if (x === 0 || isNaN(x)) {
@@ -274,7 +279,9 @@ module.exports = function(Chart) {
return x > 0 ? 1 : -1;
};
helpers.log10 = Math.log10?
- function(x) { return Math.log10(x); } :
+ function(x) {
+ return Math.log10(x);
+ } :
function(x) {
return Math.log(x) / Math.LN10;
};
@@ -455,16 +462,14 @@ module.exports = function(Chart) {
} else {
niceFraction = 10;
}
+ } else if (fraction <= 1.0) {
+ niceFraction = 1;
+ } else if (fraction <= 2) {
+ niceFraction = 2;
+ } else if (fraction <= 5) {
+ niceFraction = 5;
} else {
- if (fraction <= 1.0) {
- niceFraction = 1;
- } else if (fraction <= 2) {
- niceFraction = 2;
- } else if (fraction <= 5) {
- niceFraction = 5;
- } else {
- niceFraction = 10;
- }
+ niceFraction = 10;
}
return niceFraction * Math.pow(10, exponent);
@@ -656,9 +661,8 @@ module.exports = function(Chart) {
return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
} else if (t < (2.5 / 2.75)) {
return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
- } else {
- return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
}
+ return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
},
easeInOutBounce: function(t) {
if (t < 1 / 2) {
@@ -996,7 +1000,9 @@ module.exports = function(Chart) {
}
};
helpers.isArray = Array.isArray?
- function(obj) { return Array.isArray(obj); } :
+ function(obj) {
+ return Array.isArray(obj);
+ } :
function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
@@ -1029,10 +1035,10 @@ module.exports = function(Chart) {
fn.apply(_tArg, args);
}
};
- helpers.getHoverColor = function(color) {
+ helpers.getHoverColor = function(colorValue) {
/* global CanvasPattern */
- return (color instanceof CanvasPattern) ?
- color :
- helpers.color(color).saturate(0.5).darken(0.1).rgbString();
+ return (colorValue instanceof CanvasPattern) ?
+ colorValue :
+ helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
};
}; | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/core/core.layoutService.js | @@ -161,8 +161,8 @@ module.exports = function(Chart) {
// Function to fit a box
function fitBox(box) {
- var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
- return minBoxSize.box === box;
+ var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
+ return minBox.box === box;
});
if (minBoxSize) {
@@ -196,8 +196,8 @@ module.exports = function(Chart) {
helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
function finalFitVerticalBox(box) {
- var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
- return minBoxSize.box === box;
+ var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
+ return minSize.box === box;
});
var scaleMargin = { | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/core/core.legend.js | @@ -397,12 +397,10 @@ module.exports = function(Chart) {
cursor.line++;
x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
}
- } else {
- if (y + itemHeight > me.bottom) {
- x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
- y = cursor.y = me.top;
- cursor.line++;
- }
+ } else if (y + itemHeight > me.bottom) {
+ x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
+ y = cursor.y = me.top;
+ cursor.line++;
}
drawLegendBox(x, y, legendItem); | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/core/core.scale.js | @@ -406,9 +406,8 @@ module.exports = function(Chart) {
if (typeof(rawValue) === 'object') {
if ((rawValue instanceof Date) || (rawValue.isValid)) {
return rawValue;
- } else {
- return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
+ return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
// Value is good, return it
@@ -440,10 +439,9 @@ module.exports = function(Chart) {
var finalVal = me.left + Math.round(pixel);
finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
- } else {
- var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
- return me.top + (index * (innerHeight / (me.ticks.length - 1)));
}
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ return me.top + (index * (innerHeight / (me.ticks.length - 1)));
},
// Utility for getting the pixel location of a percentage of scale
@@ -456,9 +454,8 @@ module.exports = function(Chart) {
var finalVal = me.left + Math.round(valueOffset);
finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
- } else {
- return me.top + (decimal * me.height);
}
+ return me.top + (decimal * me.height);
},
getBasePixel: function() {
@@ -584,7 +581,8 @@ module.exports = function(Chart) {
// Common properties
var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
- var textAlign, textBaseline = 'middle';
+ var textAlign = 'middle';
+ var textBaseline = 'middle';
if (isHorizontal) {
if (!isRotated) {
@@ -611,15 +609,13 @@ module.exports = function(Chart) {
labelX = me.right - optionTicks.padding;
textAlign = 'right';
}
+ // right side
+ } else if (optionTicks.mirror) {
+ labelX = me.left - optionTicks.padding;
+ textAlign = 'right';
} else {
- // right side
- if (optionTicks.mirror) {
- labelX = me.left - optionTicks.padding;
- textAlign = 'right';
- } else {
- labelX = me.left + optionTicks.padding;
- textAlign = 'left';
- }
+ labelX = me.left + optionTicks.padding;
+ textAlign = 'left';
}
var yLineValue = me.getPixelForTick(index); // xvalues for grid lines | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/core/core.tooltip.js | @@ -492,12 +492,10 @@ module.exports = function(Chart) {
} else if (xAlign === 'right') {
pt.x -= paddingAndSize;
}
- } else {
- if (xAlign === 'left') {
- pt.x -= radiusAndPadding;
- } else if (xAlign === 'right') {
- pt.x += radiusAndPadding;
- }
+ } else if (xAlign === 'left') {
+ pt.x -= radiusAndPadding;
+ } else if (xAlign === 'right') {
+ pt.x += radiusAndPadding;
}
return pt; | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/scales/scale.category.js | @@ -56,9 +56,8 @@ module.exports = function(Chart) {
if ((data.xLabels && isHorizontal) || (data.yLabels && !isHorizontal)) {
return me.getRightValue(data.datasets[datasetIndex].data[index]);
- } else {
- return me.ticks[index];
}
+ return me.ticks[index];
},
// Used to get data value locations. Value can either be an index or a numerical value
@@ -83,17 +82,16 @@ module.exports = function(Chart) {
}
return me.left + Math.round(widthOffset);
- } else {
- var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
- var valueHeight = innerHeight / offsetAmt;
- var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
-
- if (me.options.gridLines.offsetGridLines && includeOffset) {
- heightOffset += (valueHeight / 2);
- }
+ }
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ var valueHeight = innerHeight / offsetAmt;
+ var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
- return me.top + Math.round(heightOffset);
+ if (me.options.gridLines.offsetGridLines && includeOffset) {
+ heightOffset += (valueHeight / 2);
}
+
+ return me.top + Math.round(heightOffset);
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset); | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/scales/scale.linear.js | @@ -54,8 +54,6 @@ module.exports = function(Chart) {
if (opts.stacked) {
var valuesPerType = {};
- var hasPositiveValues = false;
- var hasNegativeValues = false;
helpers.each(datasets, function(dataset, datasetIndex) {
var meta = chart.getDatasetMeta(datasetIndex);
@@ -82,14 +80,10 @@ module.exports = function(Chart) {
if (opts.relativePoints) {
positiveValues[index] = 100;
+ } else if (value < 0) {
+ negativeValues[index] += value;
} else {
- if (value < 0) {
- hasNegativeValues = true;
- negativeValues[index] += value;
- } else {
- hasPositiveValues = true;
- positiveValues[index] += value;
- }
+ positiveValues[index] += value;
}
});
}
@@ -175,11 +169,10 @@ module.exports = function(Chart) {
innerDimension = me.width - (paddingLeft + me.paddingRight);
pixel = me.left + (innerDimension / range * (rightValue - start));
return Math.round(pixel + paddingLeft);
- } else {
- innerDimension = me.height - (me.paddingTop + paddingBottom);
- pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
- return Math.round(pixel);
}
+ innerDimension = me.height - (me.paddingTop + paddingBottom);
+ pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
+ return Math.round(pixel);
},
getValueForPixel: function(pixel) {
var me = this; | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/scales/scale.logarithmic.js | @@ -16,9 +16,8 @@ module.exports = function(Chart) {
return '0';
} else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
return value.toExponential();
- } else {
- return '';
}
+ return '';
}
}
}; | true |
Other | chartjs | Chart.js | bddd4cd94bbb2fa40d36029433069fa7950fd3ef.json | Fix style issues in core and scales | src/scales/scale.radialLinear.js | @@ -195,12 +195,10 @@ module.exports = function(Chart) {
furthestRight = pointPosition.x + textWidth;
furthestRightIndex = i;
}
- } else {
- // More than half the values means we'll right align the text
- if (pointPosition.x - textWidth < furthestLeft) {
- furthestLeft = pointPosition.x - textWidth;
- furthestLeftIndex = i;
- }
+ // More than half the values means we'll right align the text
+ } else if (pointPosition.x - textWidth < furthestLeft) {
+ furthestLeft = pointPosition.x - textWidth;
+ furthestLeftIndex = i;
}
}
@@ -252,9 +250,8 @@ module.exports = function(Chart) {
var scalingFactor = me.drawingArea / (me.max - me.min);
if (me.options.reverse) {
return (me.max - value) * scalingFactor;
- } else {
- return (value - me.min) * scalingFactor;
}
+ return (value - me.min) * scalingFactor;
},
getPointPosition: function(index, distanceFromCenter) {
var me = this; | true |
Other | chartjs | Chart.js | 11739234a4b218d65a008c1afcb72c8ee42556a9.json | Add keyword spacing to eslint and update code | .eslintrc | @@ -136,13 +136,15 @@ rules:
computed-property-spacing: [2, never]
consistent-this: [2, me]
eol-last: 2
+ func-call-spacing: [2, never]
func-names: [2, never]
func-style: 0
id-length: 0
id-match: 0
indent: [2, tab]
jsx-quotes: 0
key-spacing: 2
+ keyword-spacing: 2
linebreak-style: [2, unix]
lines-around-comment: 0
max-depth: 0 | true |
Other | chartjs | Chart.js | 11739234a4b218d65a008c1afcb72c8ee42556a9.json | Add keyword spacing to eslint and update code | src/core/core.controller.js | @@ -415,7 +415,7 @@ module.exports = function(Chart) {
if (me.isDatasetVisible(datasetIndex)) {
var meta = me.getDatasetMeta(datasetIndex),
element = meta.data[found._index];
- if(element && !element._view.skip) {
+ if (element && !element._view.skip) {
elementsArray.push(element);
}
}
@@ -454,7 +454,7 @@ module.exports = function(Chart) {
var index = helpers.findIndex(meta.data, function(it) {
return found._model.x === it._model.x;
});
- if(index !== -1 && !meta.data[index]._view.skip) {
+ if (index !== -1 && !meta.data[index]._view.skip) {
elementsArray.push(meta.data[index]);
}
} | true |
Other | chartjs | Chart.js | 11739234a4b218d65a008c1afcb72c8ee42556a9.json | Add keyword spacing to eslint and update code | src/core/core.legend.js | @@ -151,7 +151,7 @@ module.exports = function(Chart) {
buildLabels: function() {
var me = this;
me.legendItems = me.options.labels.generateLabels.call(me, me.chart);
- if(me.options.reverse) {
+ if (me.options.reverse) {
me.legendItems.reverse();
}
}, | true |
Other | chartjs | Chart.js | 11739234a4b218d65a008c1afcb72c8ee42556a9.json | Add keyword spacing to eslint and update code | src/scales/scale.logarithmic.js | @@ -100,7 +100,7 @@ module.exports = function(Chart) {
me.max = value;
}
- if(value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
+ if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
me.minNotZero = value;
}
});
@@ -144,7 +144,7 @@ module.exports = function(Chart) {
var exp;
var significand;
- if(tickVal === 0) {
+ if (tickVal === 0) {
exp = Math.floor(helpers.log10(me.minNotZero));
significand = Math.round(me.minNotZero / Math.pow(10, exp));
} else {
@@ -221,11 +221,11 @@ module.exports = function(Chart) {
} else {
// Bottom - top since pixels increase downard on a screen
innerDimension = me.height - (paddingTop + paddingBottom);
- if(start === 0 && !tickOpts.reverse) {
+ if (start === 0 && !tickOpts.reverse) {
range = helpers.log10(me.end) - helpers.log10(me.minNotZero);
if (newVal === start) {
pixel = me.bottom - paddingBottom;
- } else if(newVal === me.minNotZero) {
+ } else if (newVal === me.minNotZero) {
pixel = me.bottom - paddingBottom - innerDimension * 0.02;
} else {
pixel = me.bottom - paddingBottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
@@ -234,7 +234,7 @@ module.exports = function(Chart) {
range = helpers.log10(me.start) - helpers.log10(me.minNotZero);
if (newVal === me.end) {
pixel = me.top + paddingTop;
- } else if(newVal === me.minNotZero) {
+ } else if (newVal === me.minNotZero) {
pixel = me.top + paddingTop + innerDimension * 0.02;
} else {
pixel = me.top + paddingTop + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero))); | true |
Other | chartjs | Chart.js | f6eb675470485c487c4e8c88f0e4cad265264456.json | Update new eslint rules | .eslintrc | @@ -12,9 +12,8 @@ env:
# http://eslint.org/docs/rules/
rules:
# Possible Errors
- comma-dangle: [2, never]
no-cond-assign: 2
- no-console: 0
+ no-console: 1
no-constant-condition: 2
no-control-regex: 2
no-debugger: 2
@@ -25,7 +24,7 @@ rules:
no-empty-character-class: 2
no-ex-assign: 2
no-extra-boolean-cast: 2
- no-extra-parens: 0
+ no-extra-parens: [2, functions]
no-extra-semi: 2
no-func-assign: 2
no-inner-declarations: [2, functions]
@@ -43,37 +42,38 @@ rules:
# Best Practices
accessor-pairs: 2
+ array-callback-return: 0
block-scoped-var: 0
complexity: [2, 6]
consistent-return: 0
curly: [2, all]
- default-case: 0
+ default-case: 2
dot-location: 0
- dot-notation: 0
+ dot-notation: 2
eqeqeq: 2
guard-for-in: 2
no-alert: 2
no-caller: 2
no-case-declarations: 2
no-div-regex: 2
- no-else-return: 0
+ no-else-return: 2
no-empty-pattern: 2
no-eq-null: 2
no-eval: 2
no-extend-native: 2
no-extra-bind: 2
no-fallthrough: 2
- no-floating-decimal: 0
+ no-floating-decimal: 2
no-implicit-coercion: 0
no-implied-eval: 2
no-invalid-this: 0
no-iterator: 2
- no-labels: 0
+ no-labels: 2
no-lone-blocks: 2
no-loop-func: 2
no-magic-number: 0
- no-multi-spaces: 0
- no-multi-str: 0
+ no-multi-spaces: 2
+ no-multi-str: 2
no-native-reassign: 2
no-new-func: 2
no-new-wrappers: 2
@@ -85,7 +85,7 @@ rules:
no-return-assign: 2
no-script-url: 2
no-self-compare: 2
- no-sequences: 0
+ no-sequences: 2
no-throw-literal: 0
no-unused-expressions: 2
no-useless-call: 2
@@ -96,7 +96,7 @@ rules:
radix: 2
vars-on-top: 0
wrap-iife: 2
- yoda: 0
+ yoda: [2, never]
# Strict
strict: 0
@@ -107,12 +107,12 @@ rules:
no-delete-var: 2
no-label-var: 2
no-shadow-restricted-names: 2
- no-shadow: 0
+ no-shadow: 2
no-undef-init: 2
- no-undef: 0
+ no-undef: 2
no-undefined: 0
- no-unused-vars: 0
- no-use-before-define: 0
+ no-unused-vars: 2
+ no-use-before-define: 2
# Node.js and CommonJS
callback-return: 2
@@ -126,70 +126,80 @@ rules:
no-sync: 0
# Stylistic Issues
- array-bracket-spacing: 0
+ array-bracket-spacing: [2, never]
block-spacing: 0
- brace-style: 0
- camelcase: 0
- comma-spacing: 0
- comma-style: 0
- computed-property-spacing: 0
- consistent-this: 0
- eol-last: 0
- func-names: 0
+ brace-style: [2, 1tbs]
+ camelcase: 2
+ comma-dangle: [2, never]
+ comma-spacing: 2
+ comma-style: [2, last]
+ computed-property-spacing: [2, never]
+ consistent-this: [2, me]
+ eol-last: 2
+ func-names: [2, never]
func-style: 0
id-length: 0
id-match: 0
indent: [2, tab]
jsx-quotes: 0
- key-spacing: 0
- linebreak-style: 0
+ key-spacing: 2
+ linebreak-style: [2, unix]
lines-around-comment: 0
max-depth: 0
max-len: 0
+ max-lines: 0
max-nested-callbacks: 0
max-params: 0
+ max-statements-per-line: 0
max-statements: [2, 30]
+ multiline-ternary: 0
new-cap: 0
- new-parens: 0
+ new-parens: 2
newline-after-var: 0
+ newline-before-return: 0
+ newline-per-chained-call: 0
no-array-constructor: 0
no-bitwise: 0
no-continue: 0
no-inline-comments: 0
- no-lonely-if: 0
- no-mixed-spaces-and-tabs: 0
- no-multiple-empty-lines: 0
+ no-lonely-if: 2
+ no-mixed-operators: 0
+ no-mixed-spaces-and-tabs: 2
+ no-multiple-empty-lines: [2, {max: 2}]
no-negated-condition: 0
no-nested-ternary: 0
no-new-object: 0
no-plusplus: 0
no-restricted-syntax: 0
no-spaced-func: 0
no-ternary: 0
- no-trailing-spaces: 0
+ no-trailing-spaces: 2
no-underscore-dangle: 0
no-unneeded-ternary: 0
- object-curly-spacing: 0
+ no-whitespace-before-property: 2
+ object-curly-newline: 0
+ object-curly-spacing: [2, never]
+ object-property-newline: 0
+ one-var-declaration-per-line: 2
one-var: 0
operator-assignment: 0
operator-linebreak: 0
padded-blocks: 0
- quote-props: 0
- quotes: 0
+ quote-props: [2, as-needed]
+ quotes: [2, single]
require-jsdoc: 0
- semi-spacing: 0
- semi: 0
+ semi-spacing: 2
+ semi: [2, always]
+ sort-keys: 0
sort-vars: 0
- space-after-keywords: 0
- space-before-blocks: 0
- space-before-function-paren: 0
- space-before-keywords: 0
- space-in-parens: 0
+ space-before-blocks: [2, always]
+ space-before-function-paren: [2, never]
+ space-in-parens: [2, never]
space-infix-ops: 0
- space-return-throw-case: 0
space-unary-ops: 0
- spaced-comment: 0
- wrap-regex: 0
+ spaced-comment: [2, always]
+ unicode-bom: 0
+ wrap-regex: 2
# ECMAScript 6
arrow-body-style: 0 | false |
Other | chartjs | Chart.js | 894b9928e77f97dba02181e1f9258a44692dc290.json | Fix broken links in Maintaining.md | MAINTAINING.md | @@ -31,6 +31,6 @@ Finally, [cdnjs](https://cdnjs.com/libraries/Chart.js) is automatically updated
### Further Reading
-* [Travis GitHub releases](/chartjs/Chart.js/pull/2555)
-* [Bower support and dist/* files](/chartjs/Chart.js/issues/3033)
-* [cdnjs npm auto update](/cdnjs/cdnjs/pull/8401)
+* [Travis GitHub releases](https://github.com/chartjs/Chart.js/pull/2555)
+* [Bower support and dist/* files](https://github.com/chartjs/Chart.js/issues/3033)
+* [cdnjs npm auto update](https://github.com/cdnjs/cdnjs/pull/8401) | false |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | .eslintrc | @@ -46,7 +46,7 @@ rules:
block-scoped-var: 0
complexity: [2, 6]
consistent-return: 0
- curly: 0
+ curly: [2, all]
default-case: 0
dot-location: 0
dot-notation: 0 | true |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | src/controllers/controller.bar.js | @@ -405,17 +405,19 @@ module.exports = function(Chart) {
// Find first (starting) corner with fallback to 'bottom'
var borders = ['bottom', 'left', 'top', 'right'];
var startCorner = borders.indexOf(vm.borderSkipped, 0);
- if (startCorner === -1)
+ if (startCorner === -1) {
startCorner = 0;
+ }
function cornerAt(index) {
return corners[(startCorner + index) % 4];
}
// Draw rectangle from 'startCorner'
ctx.moveTo.apply(ctx, cornerAt(0));
- for (var i = 1; i < 4; i++)
+ for (var i = 1; i < 4; i++) {
ctx.lineTo.apply(ctx, cornerAt(i));
+ }
ctx.fill();
if (vm.borderWidth) { | true |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | src/controllers/controller.line.js | @@ -250,20 +250,23 @@ module.exports = function(Chart) {
var me = this;
var meta = me.getMeta();
var area = me.chart.chartArea;
-
- // Only consider points that are drawn in case the spanGaps option is used
var points = (meta.data || []);
- if (meta.dataset._model.spanGaps) points = points.filter(function(pt) { return !pt._model.skip; });
var i, ilen, point, model, controlPoints;
+ // Only consider points that are drawn in case the spanGaps option is used
+ if (meta.dataset._model.spanGaps) {
+ points = points.filter(function(pt) {
+ return !pt._model.skip;
+ });
+ }
+
function capControlPoint(pt, min, max) {
return Math.max(Math.min(pt, max), min);
}
if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
helpers.splineCurveMonotone(points);
- }
- else {
+ } else {
for (i = 0, ilen = points.length; i < ilen; ++i) {
point = points[i];
model = point._model;
@@ -289,7 +292,6 @@ module.exports = function(Chart) {
model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
}
}
-
},
draw: function(ease) { | true |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | src/core/core.helpers.js | @@ -358,32 +358,48 @@ module.exports = function(Chart) {
var i, pointBefore, pointCurrent, pointAfter;
for (i = 0; i < pointsLen; ++i) {
pointCurrent = pointsWithTangents[i];
- if (pointCurrent.model.skip) continue;
+ if (pointCurrent.model.skip) {
+ continue;
+ }
+
pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
if (pointAfter && !pointAfter.model.skip) {
pointCurrent.deltaK = (pointAfter.model.y - pointCurrent.model.y) / (pointAfter.model.x - pointCurrent.model.x);
}
- if (!pointBefore || pointBefore.model.skip) pointCurrent.mK = pointCurrent.deltaK;
- else if (!pointAfter || pointAfter.model.skip) pointCurrent.mK = pointBefore.deltaK;
- else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) pointCurrent.mK = 0;
- else pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
+
+ if (!pointBefore || pointBefore.model.skip) {
+ pointCurrent.mK = pointCurrent.deltaK;
+ } else if (!pointAfter || pointAfter.model.skip) {
+ pointCurrent.mK = pointBefore.deltaK;
+ } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
+ pointCurrent.mK = 0;
+ } else {
+ pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
+ }
}
// Adjust tangents to ensure monotonic properties
var alphaK, betaK, tauK, squaredMagnitude;
for (i = 0; i < pointsLen - 1; ++i) {
pointCurrent = pointsWithTangents[i];
pointAfter = pointsWithTangents[i + 1];
- if (pointCurrent.model.skip || pointAfter.model.skip) continue;
+ if (pointCurrent.model.skip || pointAfter.model.skip) {
+ continue;
+ }
+
if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
pointCurrent.mK = pointAfter.mK = 0;
continue;
}
+
alphaK = pointCurrent.mK / pointCurrent.deltaK;
betaK = pointAfter.mK / pointCurrent.deltaK;
squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
- if (squaredMagnitude <= 9) continue;
+ if (squaredMagnitude <= 9) {
+ continue;
+ }
+
tauK = 3 / Math.sqrt(squaredMagnitude);
pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
@@ -393,7 +409,10 @@ module.exports = function(Chart) {
var deltaX;
for (i = 0; i < pointsLen; ++i) {
pointCurrent = pointsWithTangents[i];
- if (pointCurrent.model.skip) continue;
+ if (pointCurrent.model.skip) {
+ continue;
+ }
+
pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
if (pointBefore && !pointBefore.model.skip) {
@@ -412,7 +431,6 @@ module.exports = function(Chart) {
if (loop) {
return index >= collection.length - 1 ? collection[0] : collection[index + 1];
}
-
return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
};
helpers.previousItem = function(collection, index, loop) { | true |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | src/core/core.legend.js | @@ -341,11 +341,9 @@ module.exports = function(Chart) {
// Draw pointStyle as legend symbol
Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
- }
- else {
+ } else {
// Draw box as legend symbol
- if (!isLineWidthZero)
- {
+ if (!isLineWidthZero) {
ctx.strokeRect(x, y, boxWidth, fontSize);
}
ctx.fillRect(x, y, boxWidth, fontSize); | true |
Other | chartjs | Chart.js | 7c93255b16868c4f23249670e998b6c9ce92b9fd.json | Enforce curly braces for single statement block
curly: [error, all] (http://eslint.org/docs/rules/curly) | src/elements/element.rectangle.js | @@ -48,17 +48,19 @@ module.exports = function(Chart) {
// Find first (starting) corner with fallback to 'bottom'
var borders = ['bottom', 'left', 'top', 'right'];
var startCorner = borders.indexOf(vm.borderSkipped, 0);
- if (startCorner === -1)
+ if (startCorner === -1) {
startCorner = 0;
+ }
function cornerAt(index) {
return corners[(startCorner + index) % 4];
}
// Draw rectangle from 'startCorner'
ctx.moveTo.apply(ctx, cornerAt(0));
- for (var i = 1; i < 4; i++)
+ for (var i = 1; i < 4; i++) {
ctx.lineTo.apply(ctx, cornerAt(i));
+ }
ctx.fill();
if (vm.borderWidth) { | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | .eslintrc | @@ -139,7 +139,7 @@ rules:
func-style: 0
id-length: 0
id-match: 0
- indent: 0
+ indent: [2, tab]
jsx-quotes: 0
key-spacing: 0
linebreak-style: 0 | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/controllers/controller.bar.js | @@ -142,8 +142,8 @@ module.exports = function(Chart) {
var fullBarWidth = categoryWidth / datasetCount;
if (xScale.ticks.length !== me.chart.data.labels.length) {
- var perc = xScale.ticks.length / me.chart.data.labels.length;
- fullBarWidth = fullBarWidth * perc;
+ var perc = xScale.ticks.length / me.chart.data.labels.length;
+ fullBarWidth = fullBarWidth * perc;
}
var barWidth = fullBarWidth * xScale.options.barPercentage;
@@ -326,7 +326,7 @@ module.exports = function(Chart) {
},
label: function(tooltipItem, data) {
var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
- return datasetLabel + ': ' + tooltipItem.xLabel;
+ return datasetLabel + ': ' + tooltipItem.xLabel;
}
}
} | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/controllers/controller.doughnut.js | @@ -166,8 +166,8 @@ module.exports = function(Chart) {
minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
}
- chart.borderWidth = me.getMaxBorderWidth(meta.data);
+ chart.borderWidth = me.getMaxBorderWidth(meta.data);
chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 1, 0);
chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
@@ -268,23 +268,23 @@ module.exports = function(Chart) {
return 0;
}
},
-
+
//gets the max border or hover width to properly scale pie charts
- getMaxBorderWidth: function (elements) {
- var max = 0,
+ getMaxBorderWidth: function (elements) {
+ var max = 0,
index = this.index,
length = elements.length,
borderWidth,
hoverWidth;
- for (var i = 0; i < length; i++) {
- borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
- hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
-
- max = borderWidth > max ? borderWidth : max;
- max = hoverWidth > max ? hoverWidth : max;
- }
- return max;
- }
+ for (var i = 0; i < length; i++) {
+ borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
+ hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
+
+ max = borderWidth > max ? borderWidth : max;
+ max = hoverWidth > max ? hoverWidth : max;
+ }
+ return max;
+ }
});
}; | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/core/core.controller.js | @@ -461,7 +461,7 @@ module.exports = function(Chart) {
}, me);
return elementsArray;
- },
+ },
getElementsAtEventForMode: function(e, mode) {
var me = this;
@@ -472,8 +472,8 @@ module.exports = function(Chart) {
return me.getElementsAtEvent(e);
case 'dataset':
return me.getDatasetAtEvent(e);
- case 'x-axis':
- return me.getElementsAtXAxis(e);
+ case 'x-axis':
+ return me.getElementsAtXAxis(e);
default:
return e;
}
@@ -499,14 +499,14 @@ module.exports = function(Chart) {
var meta = dataset._meta[me.id];
if (!meta) {
meta = dataset._meta[me.id] = {
- type: null,
- data: [],
- dataset: null,
- controller: null,
- hidden: null, // See isDatasetVisible() comment
- xAxisID: null,
- yAxisID: null
- };
+ type: null,
+ data: [],
+ dataset: null,
+ controller: null,
+ hidden: null, // See isDatasetVisible() comment
+ xAxisID: null,
+ yAxisID: null
+ };
}
return meta;
@@ -591,7 +591,7 @@ module.exports = function(Chart) {
break;
case 'label':
case 'dataset':
- case 'x-axis':
+ case 'x-axis':
// elements = elements;
break;
default: | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/core/core.datasetController.js | @@ -158,8 +158,7 @@ module.exports = function(Chart) {
model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
}
- });
-
+ });
Chart.DatasetController.extend = helpers.inherits;
};
\ No newline at end of file | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/core/core.element.js | @@ -2,103 +2,103 @@
module.exports = function(Chart) {
- var helpers = Chart.helpers;
-
- Chart.elements = {};
-
- Chart.Element = function(configuration) {
- helpers.extend(this, configuration);
- this.initialize.apply(this, arguments);
- };
-
- helpers.extend(Chart.Element.prototype, {
-
- initialize: function() {
- this.hidden = false;
- },
-
- pivot: function() {
- var me = this;
- if (!me._view) {
- me._view = helpers.clone(me._model);
- }
- me._start = helpers.clone(me._view);
- return me;
- },
-
- transition: function(ease) {
- var me = this;
-
- if (!me._view) {
- me._view = helpers.clone(me._model);
- }
-
- // No animation -> No Transition
- if (ease === 1) {
- me._view = me._model;
- me._start = null;
- return me;
- }
-
- if (!me._start) {
- me.pivot();
- }
-
- helpers.each(me._model, function(value, key) {
-
- if (key[0] === '_') {
- // Only non-underscored properties
- }
-
- // Init if doesn't exist
- else if (!me._view.hasOwnProperty(key)) {
- if (typeof value === 'number' && !isNaN(me._view[key])) {
- me._view[key] = value * ease;
- } else {
- me._view[key] = value;
- }
- }
-
- // No unnecessary computations
- else if (value === me._view[key]) {
- // It's the same! Woohoo!
- }
-
- // Color transitions if possible
- else if (typeof value === 'string') {
- try {
- var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
- me._view[key] = color.rgbString();
- } catch (err) {
- me._view[key] = value;
- }
- }
- // Number transitions
- else if (typeof value === 'number') {
- var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
- me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
- }
- // Everything else
- else {
- me._view[key] = value;
- }
- }, me);
-
- return me;
- },
-
- tooltipPosition: function() {
- return {
- x: this._model.x,
- y: this._model.y
- };
- },
-
- hasValue: function() {
- return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
- }
- });
-
- Chart.Element.extend = helpers.inherits;
+ var helpers = Chart.helpers;
+
+ Chart.elements = {};
+
+ Chart.Element = function(configuration) {
+ helpers.extend(this, configuration);
+ this.initialize.apply(this, arguments);
+ };
+
+ helpers.extend(Chart.Element.prototype, {
+
+ initialize: function() {
+ this.hidden = false;
+ },
+
+ pivot: function() {
+ var me = this;
+ if (!me._view) {
+ me._view = helpers.clone(me._model);
+ }
+ me._start = helpers.clone(me._view);
+ return me;
+ },
+
+ transition: function(ease) {
+ var me = this;
+
+ if (!me._view) {
+ me._view = helpers.clone(me._model);
+ }
+
+ // No animation -> No Transition
+ if (ease === 1) {
+ me._view = me._model;
+ me._start = null;
+ return me;
+ }
+
+ if (!me._start) {
+ me.pivot();
+ }
+
+ helpers.each(me._model, function(value, key) {
+
+ if (key[0] === '_') {
+ // Only non-underscored properties
+ }
+
+ // Init if doesn't exist
+ else if (!me._view.hasOwnProperty(key)) {
+ if (typeof value === 'number' && !isNaN(me._view[key])) {
+ me._view[key] = value * ease;
+ } else {
+ me._view[key] = value;
+ }
+ }
+
+ // No unnecessary computations
+ else if (value === me._view[key]) {
+ // It's the same! Woohoo!
+ }
+
+ // Color transitions if possible
+ else if (typeof value === 'string') {
+ try {
+ var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
+ me._view[key] = color.rgbString();
+ } catch (err) {
+ me._view[key] = value;
+ }
+ }
+ // Number transitions
+ else if (typeof value === 'number') {
+ var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
+ me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
+ }
+ // Everything else
+ else {
+ me._view[key] = value;
+ }
+ }, me);
+
+ return me;
+ },
+
+ tooltipPosition: function() {
+ return {
+ x: this._model.x,
+ y: this._model.y
+ };
+ },
+
+ hasValue: function() {
+ return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
+ }
+ });
+
+ Chart.Element.extend = helpers.inherits;
}; | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/core/core.legend.js | @@ -346,7 +346,7 @@ module.exports = function(Chart) {
// Draw box as legend symbol
if (!isLineWidthZero)
{
- ctx.strokeRect(x, y, boxWidth, fontSize);
+ ctx.strokeRect(x, y, boxWidth, fontSize);
}
ctx.fillRect(x, y, boxWidth, fontSize);
} | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/core/core.scale.js | @@ -170,12 +170,12 @@ module.exports = function(Chart) {
var me = this;
// Convert ticks to strings
me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
- if (me.options.ticks.userCallback) {
- return me.options.ticks.userCallback(numericalTick, index, ticks);
- }
- return me.options.ticks.callback(numericalTick, index, ticks);
- },
- me);
+ if (me.options.ticks.userCallback) {
+ return me.options.ticks.userCallback(numericalTick, index, ticks);
+ }
+ return me.options.ticks.callback(numericalTick, index, ticks);
+ },
+ me);
},
afterTickToLabelConversion: function() {
helpers.callCallback(this.options.afterTickToLabelConversion, [this]); | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/elements/element.arc.js | @@ -2,92 +2,92 @@
module.exports = function(Chart) {
- var helpers = Chart.helpers,
- globalOpts = Chart.defaults.global;
-
- globalOpts.elements.arc = {
- backgroundColor: globalOpts.defaultColor,
- borderColor: "#fff",
- borderWidth: 2
- };
-
- Chart.elements.Arc = Chart.Element.extend({
- inLabelRange: function(mouseX) {
- var vm = this._view;
-
- if (vm) {
- return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
- } else {
- return false;
- }
- },
- inRange: function(chartX, chartY) {
- var vm = this._view;
-
- if (vm) {
- var pointRelativePosition = helpers.getAngleFromPoint(vm, {
- x: chartX,
- y: chartY
- }),
- angle = pointRelativePosition.angle,
- distance = pointRelativePosition.distance;
-
- //Sanitise angle range
- var startAngle = vm.startAngle;
- var endAngle = vm.endAngle;
- while (endAngle < startAngle) {
- endAngle += 2.0 * Math.PI;
- }
- while (angle > endAngle) {
- angle -= 2.0 * Math.PI;
- }
- while (angle < startAngle) {
- angle += 2.0 * Math.PI;
- }
-
- //Check if within the range of the open/close angle
- var betweenAngles = (angle >= startAngle && angle <= endAngle),
- withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
-
- return (betweenAngles && withinRadius);
- } else {
- return false;
- }
- },
- tooltipPosition: function() {
- var vm = this._view;
-
- var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
- rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
- return {
- x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
- y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
- };
- },
- draw: function() {
-
- var ctx = this._chart.ctx,
- vm = this._view,
- sA = vm.startAngle,
- eA = vm.endAngle;
-
- ctx.beginPath();
-
- ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
- ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
-
- ctx.closePath();
- ctx.strokeStyle = vm.borderColor;
- ctx.lineWidth = vm.borderWidth;
-
- ctx.fillStyle = vm.backgroundColor;
-
- ctx.fill();
- ctx.lineJoin = 'bevel';
-
- if (vm.borderWidth) {
- ctx.stroke();
- }
- }
- });
+ var helpers = Chart.helpers,
+ globalOpts = Chart.defaults.global;
+
+ globalOpts.elements.arc = {
+ backgroundColor: globalOpts.defaultColor,
+ borderColor: "#fff",
+ borderWidth: 2
+ };
+
+ Chart.elements.Arc = Chart.Element.extend({
+ inLabelRange: function(mouseX) {
+ var vm = this._view;
+
+ if (vm) {
+ return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
+ } else {
+ return false;
+ }
+ },
+ inRange: function(chartX, chartY) {
+ var vm = this._view;
+
+ if (vm) {
+ var pointRelativePosition = helpers.getAngleFromPoint(vm, {
+ x: chartX,
+ y: chartY
+ }),
+ angle = pointRelativePosition.angle,
+ distance = pointRelativePosition.distance;
+
+ //Sanitise angle range
+ var startAngle = vm.startAngle;
+ var endAngle = vm.endAngle;
+ while (endAngle < startAngle) {
+ endAngle += 2.0 * Math.PI;
+ }
+ while (angle > endAngle) {
+ angle -= 2.0 * Math.PI;
+ }
+ while (angle < startAngle) {
+ angle += 2.0 * Math.PI;
+ }
+
+ //Check if within the range of the open/close angle
+ var betweenAngles = (angle >= startAngle && angle <= endAngle),
+ withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
+
+ return (betweenAngles && withinRadius);
+ } else {
+ return false;
+ }
+ },
+ tooltipPosition: function() {
+ var vm = this._view;
+
+ var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
+ rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
+ return {
+ x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
+ y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
+ };
+ },
+ draw: function() {
+
+ var ctx = this._chart.ctx,
+ vm = this._view,
+ sA = vm.startAngle,
+ eA = vm.endAngle;
+
+ ctx.beginPath();
+
+ ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
+ ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
+
+ ctx.closePath();
+ ctx.strokeStyle = vm.borderColor;
+ ctx.lineWidth = vm.borderWidth;
+
+ ctx.fillStyle = vm.backgroundColor;
+
+ ctx.fill();
+ ctx.lineJoin = 'bevel';
+
+ if (vm.borderWidth) {
+ ctx.stroke();
+ }
+ }
+ });
}; | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/scales/scale.category.js | @@ -70,9 +70,9 @@ module.exports = function(Chart) {
var valueWidth = innerWidth / offsetAmt;
var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft;
- if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
+ if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
widthOffset += (valueWidth / 2);
- }
+ }
return me.left + Math.round(widthOffset);
} else { | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/scales/scale.logarithmic.js | @@ -243,7 +243,7 @@ module.exports = function(Chart) {
range = helpers.log10(me.end) - helpers.log10(start);
innerDimension = me.height - (paddingTop + paddingBottom);
pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
- }
+ }
}
return pixel;
}, | true |
Other | chartjs | Chart.js | 3d40774c7d835b738227d13dbca365ea50ba7a85.json | Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent) | src/scales/scale.time.js | @@ -78,8 +78,8 @@ module.exports = function(Chart) {
getLabelMoment: function(datasetIndex, index) {
if (datasetIndex === null || index === null) {
return null;
- }
-
+ }
+
if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
return this.labelMoments[datasetIndex][index];
} | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | .eslintrc | @@ -57,7 +57,6 @@ rules:
no-case-declarations: 2
no-div-regex: 2
no-else-return: 0
- no-empty-label: 2
no-empty-pattern: 2
no-eq-null: 2
no-eval: 2 | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | README.md | @@ -34,7 +34,7 @@ To build, run `gulp build`.
To test, run `gulp test`.
-To test against code standards, run `gulp jshint`.
+To test against code standards, run `gulp lint`.
More information on building and testing can be found in [gulpfile.js](gulpfile.js).
| true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | docs/10-Notes.md | @@ -34,7 +34,7 @@ New contributions to the library are welcome, but we ask that you please follow
- Use tabs for indentation, not spaces.
- Only change the individual files in `/src`.
-- Check that your code will pass `jshint` code standards, `gulp jshint` will run this for you.
+- Check that your code will pass `eslint` code standards, `gulp lint` will run this for you.
- Check that your code will pass tests, `gulp test` will run tests for you.
- Keep pull requests concise, and document new functionality in the relevant `.md` file.
- Consider whether your changes are useful for all users, or if creating a Chart.js plugin would be more appropriate. | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | gulpfile.js | @@ -1,23 +1,23 @@
-var gulp = require('gulp'),
- concat = require('gulp-concat'),
- file = require('gulp-file'),
- uglify = require('gulp-uglify'),
- util = require('gulp-util'),
- jshint = require('gulp-jshint'),
- size = require('gulp-size'),
- connect = require('gulp-connect'),
- replace = require('gulp-replace'),
- htmlv = require('gulp-html-validator'),
- insert = require('gulp-insert'),
- zip = require('gulp-zip'),
- exec = require('child_process').exec,
- package = require('./package.json'),
- karma = require('gulp-karma'),
- browserify = require('browserify'),
- streamify = require('gulp-streamify'),
- source = require('vinyl-source-stream'),
- merge = require('merge-stream'),
- collapse = require('bundle-collapser/plugin');
+var gulp = require('gulp');
+var concat = require('gulp-concat');
+var connect = require('gulp-connect');
+var eslint = require('gulp-eslint');
+var file = require('gulp-file');
+var htmlv = require('gulp-html-validator');
+var insert = require('gulp-insert');
+var replace = require('gulp-replace');
+var size = require('gulp-size');
+var streamify = require('gulp-streamify');
+var uglify = require('gulp-uglify');
+var util = require('gulp-util');
+var zip = require('gulp-zip');
+var exec = require('child_process').exec;
+var karma = require('gulp-karma');
+var browserify = require('browserify');
+var source = require('vinyl-source-stream');
+var merge = require('merge-stream');
+var collapse = require('bundle-collapser/plugin');
+var package = require('./package.json');
var srcDir = './src/';
var outDir = './dist/';
@@ -43,16 +43,16 @@ var testFiles = [
// Disable tests which need to be rewritten based on changes introduced by
// the following changes: https://github.com/chartjs/Chart.js/pull/2346
'!./test/core.layoutService.tests.js',
- '!./test/defaultConfig.tests.js',
+ '!./test/defaultConfig.tests.js'
];
gulp.task('bower', bowerTask);
gulp.task('build', buildTask);
gulp.task('package', packageTask);
gulp.task('coverage', coverageTask);
gulp.task('watch', watchTask);
-gulp.task('jshint', jshintTask);
-gulp.task('test', ['jshint', 'validHTML', 'unittest']);
+gulp.task('lint', lintTask);
+gulp.task('test', ['lint', 'validHTML', 'unittest']);
gulp.task('size', ['library-size', 'module-sizes']);
gulp.task('server', serverTask);
gulp.task('validHTML', validHTMLTask);
@@ -130,11 +130,25 @@ function packageTask() {
.pipe(gulp.dest(outDir));
}
-function jshintTask() {
- return gulp.src(srcDir + '**/*.js')
- .pipe(jshint('config.jshintrc'))
- .pipe(jshint.reporter('jshint-stylish'))
- .pipe(jshint.reporter('fail'));
+function lintTask() {
+ var files = [
+ srcDir + '**/*.js',
+ ];
+
+ // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
+ // compare to what the current codebase can support, and since it's not straightforward
+ // to fix, let's turn them as warnings and rewrite code later progressively.
+ var options = {
+ rules: {
+ 'complexity': [1, 6],
+ 'max-statements': [1, 30]
+ }
+ };
+
+ return gulp.src(files)
+ .pipe(eslint(options))
+ .pipe(eslint.format())
+ .pipe(eslint.failAfterError());
}
function validHTMLTask() { | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | package.json | @@ -17,10 +17,10 @@
"gulp": "3.9.x",
"gulp-concat": "~2.1.x",
"gulp-connect": "~2.0.5",
+ "gulp-eslint": "^2.0.0",
"gulp-file": "^0.3.0",
"gulp-html-validator": "^0.0.2",
"gulp-insert": "~0.5.0",
- "gulp-jshint": "~1.5.1",
"gulp-karma": "0.0.4",
"gulp-replace": "^0.5.4",
"gulp-size": "~0.4.0",
@@ -30,7 +30,6 @@
"gulp-zip": "~3.2.0",
"jasmine": "^2.3.2",
"jasmine-core": "^2.3.4",
- "jshint-stylish": "~2.1.0",
"karma": "^0.12.37",
"karma-browserify": "^5.0.1",
"karma-chrome-launcher": "^0.2.0", | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | src/controllers/controller.line.js | @@ -260,7 +260,7 @@ module.exports = function(Chart) {
return Math.max(Math.min(pt, max), min);
}
- if (meta.dataset._model.cubicInterpolationMode == 'monotone') {
+ if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
helpers.splineCurveMonotone(points);
}
else { | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | src/core/core.datasetController.js | @@ -7,7 +7,7 @@ module.exports = function(Chart) {
// Base class for all dataset controllers (line, bar, etc)
Chart.DatasetController = function(chart, datasetIndex) {
- this.initialize.call(this, chart, datasetIndex);
+ this.initialize(chart, datasetIndex);
};
helpers.extend(Chart.DatasetController.prototype, {
@@ -157,9 +157,9 @@ module.exports = function(Chart) {
model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
}
-
+
});
-
+
Chart.DatasetController.extend = helpers.inherits;
};
\ No newline at end of file | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | src/core/core.helpers.js | @@ -238,7 +238,7 @@ module.exports = function(Chart) {
return function() {
return id++;
};
- })();
+ }());
//-- Math methods
helpers.isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
@@ -366,7 +366,7 @@ module.exports = function(Chart) {
}
if (!pointBefore || pointBefore.model.skip) pointCurrent.mK = pointCurrent.deltaK;
else if (!pointAfter || pointAfter.model.skip) pointCurrent.mK = pointBefore.deltaK;
- else if (this.sign(pointBefore.deltaK) != this.sign(pointCurrent.deltaK)) pointCurrent.mK = 0;
+ else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) pointCurrent.mK = 0;
else pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
}
@@ -376,8 +376,7 @@ module.exports = function(Chart) {
pointCurrent = pointsWithTangents[i];
pointAfter = pointsWithTangents[i + 1];
if (pointCurrent.model.skip || pointAfter.model.skip) continue;
- if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON))
- {
+ if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
pointCurrent.mK = pointAfter.mK = 0;
continue;
}
@@ -660,7 +659,7 @@ module.exports = function(Chart) {
function(callback) {
return window.setTimeout(callback, 1000 / 60);
};
- })();
+ }());
helpers.cancelAnimFrame = (function() {
return window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
@@ -670,7 +669,7 @@ module.exports = function(Chart) {
function(callback) {
return window.clearTimeout(callback, 1000 / 60);
};
- })();
+ }());
//-- DOM methods
helpers.getRelativePosition = function(evt, chart) {
var mouseX, mouseY;
@@ -751,7 +750,7 @@ module.exports = function(Chart) {
if (typeof(styleValue) === 'string') {
valueInPixels = parseInt(styleValue, 10);
- if (styleValue.indexOf('%') != -1) {
+ if (styleValue.indexOf('%') !== -1) {
// percentage * size in dimension
valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
}
@@ -802,15 +801,17 @@ module.exports = function(Chart) {
};
helpers.getMaximumWidth = function(domNode) {
var container = domNode.parentNode;
- var padding = parseInt(helpers.getStyle(container, 'padding-left')) + parseInt(helpers.getStyle(container, 'padding-right'));
- var w = container.clientWidth - padding;
+ var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
+ var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
+ var w = container.clientWidth - paddingLeft - paddingRight;
var cw = helpers.getConstraintWidth(domNode);
return isNaN(cw)? w : Math.min(w, cw);
};
helpers.getMaximumHeight = function(domNode) {
var container = domNode.parentNode;
- var padding = parseInt(helpers.getStyle(container, 'padding-top')) + parseInt(helpers.getStyle(container, 'padding-bottom'));
- var h = container.clientHeight - padding;
+ var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
+ var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
+ var h = container.clientHeight - paddingTop - paddingBottom;
var ch = helpers.getConstraintHeight(domNode);
return isNaN(ch)? h : Math.min(h, ch);
};
@@ -964,7 +965,7 @@ module.exports = function(Chart) {
(hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
if (callback) {
- callback();
+ return callback();
}
};
};
@@ -985,7 +986,7 @@ module.exports = function(Chart) {
helpers.arrayEquals = function(a0, a1) {
var i, ilen, v0, v1;
- if (!a0 || !a1 || a0.length != a1.length) {
+ if (!a0 || !a1 || a0.length !== a1.length) {
return false;
}
@@ -997,7 +998,7 @@ module.exports = function(Chart) {
if (!helpers.arrayEquals(v0, v1)) {
return false;
}
- } else if (v0 != v1) {
+ } else if (v0 !== v1) {
// NOTE: two different object instances will never be equal: {x:20} != {x:20}
return false;
} | true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | src/scales/scale.time.js | @@ -80,7 +80,7 @@ module.exports = function(Chart) {
return null;
}
- if (typeof this.labelMoments[datasetIndex] != 'undefined') {
+ if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
return this.labelMoments[datasetIndex][index];
}
| true |
Other | chartjs | Chart.js | 69ab0d3e238206fa90b06fcc87054b0a7dc97298.json | Use gulp-eslint instead of gulp-jshint
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`. | test/core.layoutService.tests.js | @@ -230,10 +230,10 @@ describe('Test the layout service', function() {
expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
expect(chart.scales.xScale1.top).toBeCloseToPixel(484);
- expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
+ expect(chart.scales.xScale2.bottom).toBeCloseToPixel(60);
expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
- expect(chart.scales.xScale2.top).toBeCloseToPixel(0);
+ expect(chart.scales.xScale2.top).toBeCloseToPixel(32);
// Is yScale at the right spot
expect(chart.scales.yScale.bottom).toBeCloseToPixel(484); | true |
Other | chartjs | Chart.js | 1f67e54d79625575c854e5352bae3d048902bcbc.json | Remove unused npm packages | package.json | @@ -26,12 +26,10 @@
"gulp-size": "~0.4.0",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "~0.2.x",
- "gulp-umd": "~0.2.0",
"gulp-util": "~2.2.x",
"gulp-zip": "~3.2.0",
"jasmine": "^2.3.2",
"jasmine-core": "^2.3.4",
- "jquery": "^2.1.4",
"jshint-stylish": "~2.1.0",
"karma": "^0.12.37",
"karma-browserify": "^5.0.1",
@@ -41,8 +39,7 @@
"karma-jasmine": "^0.3.6",
"karma-jasmine-html-reporter": "^0.1.8",
"merge-stream": "^1.0.0",
- "vinyl-source-stream": "^1.1.0",
- "watchify": "^3.7.0"
+ "vinyl-source-stream": "^1.1.0"
},
"spm": {
"main": "Chart.js" | false |
Other | chartjs | Chart.js | 6d5638e4152bd16916309c2e625a489d7a8f5951.json | Describe the release process | MAINTAINING.md | @@ -0,0 +1,36 @@
+# Maintaining
+## Release Process
+Chart.js relies on [Travis CI](https://travis-ci.org/) to automate the library [releases](https://github.com/chartjs/Chart.js/releases).
+
+### Releasing a New Version
+
+1. draft release notes on [GitHub](https://github.com/chartjs/Chart.js/releases/new) for the upcoming tag
+1. update `master` `package.json` version using [semver](http://semver.org/) semantic
+1. merge `master` into the `release` branch
+1. follow the build process on [Travis CI](https://travis-ci.org/chartjs/Chart.js)
+
+> **Note:** if `master` is merged in `release` with a `package.json` version that already exists, the tag
+creation fails and the release process is aborted.
+
+### Automated Tasks
+Merging into the `release` branch kicks off the automated release process:
+
+* build of the `dist/*.js` files
+* `bower.json` is generated from `package.json`
+* `dist/*.js` and `bower.json` are added to a detached branch
+* a tag is created from the `package.json` version
+* tag (with dist files) is pushed to GitHub
+
+Creation of this tag triggers a new build:
+
+* `Chart.js.zip` package is generated, containing dist files and examples
+* `dist/*.js` and `Chart.js.zip` are attached to the GitHub release (downloads)
+* a new npm package is published on [npmjs](https://www.npmjs.com/package/chart.js)
+
+Finally, [cdnjs](https://cdnjs.com/libraries/Chart.js) is automatically updated from the npm release.
+
+### Further Reading
+
+* [Travis GitHub releases](/chartjs/Chart.js/pull/2555)
+* [Bower support and dist/* files](/chartjs/Chart.js/issues/3033)
+* [cdnjs npm auto update](/cdnjs/cdnjs/pull/8401) | false |
Other | chartjs | Chart.js | f12fbbc6ccdd07cb3780ce647723a5994e59ab27.json | Remove encrypted data from .travis.yml
Secure values are now read from environment variables defined in the repository settings: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings | .travis.yml | @@ -43,8 +43,7 @@ deploy:
on:
branch: release
- provider: releases
- api_key:
- secure: E6JiZzA/Qy+UD1so/rVfqYnMhgU4m0cUsljxyrKIiYKlt/ZXo1XJabNkpEIYLvckrNx+g/4cmidNcuLfrnAZJtUg53qHLxyqMTXa9zAqmxxJ6aIpQpNK25FIEk9Xwm2XZdbI5rrm0ZciP5rcgg0X8/j5+RtnU3ZpTOCVkp0P73A=
+ api_key: $GITHUB_AUTH_TOKEN
file:
- "./dist/Chart.bundle.js"
- "./dist/Chart.bundle.min.js"
@@ -55,10 +54,8 @@ deploy:
on:
tags: true
- provider: npm
- email:
- secure: f6jQXdqhoKtEZ3WBvnNM9PB2l9yg8SGmnUwQzeuLpW731opmv1ngPcMA+CotDAavIRs2BvAgVoLJOVGxMRXRSi5pgahfR0O2LetFoT/Px+q4MMqtn3zMgV/OuYL/fIyKXjyoYwSRfjuaIIGX7VTCOpqOEe29UQJAb7XcG9jhgIo=
- api_key:
- secure: O5lgPeX5ofkMSiUeijs+0hrK9Dejmpki/UABd+rgx3Cmjlxvi5DVugHpcn/6C0if0CoHv5/TqwQHVgL43kwR5ZKcspl7bzK2vD2YBpingF42Oz91YVNZwQIJyWNVSSWzzFYzG9xOXO26ZD1gTZ26Z3X+xfZVtugWkzbBa/c8NmQ=
+ email: $NPM_AUTH_EMAIL
+ api_key: $NPM_AUTH_TOKEN
skip_cleanup: true
on:
tags: true | false |
Other | chartjs | Chart.js | e8a51d80c809a26c1365070e8570f7a883248831.json | #3033 Deploy dist files and bower.json (tags)
Add a new Travis deploy task to push dist/*.js and bower.json files into tag sources:
- requires Travis GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
- skipped if not built from the "release" branch
- release.sh must be executable (see comment)
- reads tag version from package.json
- fails if tag already exists | .travis.yml | @@ -33,6 +33,15 @@ addons:
- google-chrome-stable
deploy:
+# Creates a tag containing dist files and bower.json
+# Requires GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
+# IMPORTANT: the script has to be set executable in the Git repository (error 127)
+# https://github.com/travis-ci/travis-ci/issues/5538#issuecomment-225025939
+- provider: script
+ script: ./scripts/release.sh
+ skip_cleanup: true
+ on:
+ branch: release
- provider: releases
api_key:
secure: E6JiZzA/Qy+UD1so/rVfqYnMhgU4m0cUsljxyrKIiYKlt/ZXo1XJabNkpEIYLvckrNx+g/4cmidNcuLfrnAZJtUg53qHLxyqMTXa9zAqmxxJ6aIpQpNK25FIEk9Xwm2XZdbI5rrm0ZciP5rcgg0X8/j5+RtnU3ZpTOCVkp0P73A= | true |
Other | chartjs | Chart.js | e8a51d80c809a26c1365070e8570f7a883248831.json | #3033 Deploy dist files and bower.json (tags)
Add a new Travis deploy task to push dist/*.js and bower.json files into tag sources:
- requires Travis GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
- skipped if not built from the "release" branch
- release.sh must be executable (see comment)
- reads tag version from package.json
- fails if tag already exists | scripts/release.sh | @@ -0,0 +1,29 @@
+#!/bin/bash
+
+set -e
+
+if [ "$TRAVIS_BRANCH" != "release" ]; then
+ echo "Skipping release because this is not the 'release' branch"
+ exit 0
+fi
+
+# Travis executes this script from the repository root, so at the same level than package.json
+VERSION=$(node -p -e "require('./package.json').version")
+
+# Make sure that the associated tag doesn't already exist
+GITTAG=$(git ls-remote origin refs/tags/v$VERSION)
+if [ "$GITTAG" != "" ]; then
+ echo "Tag for package.json version already exists, aborting release"
+ exit 1
+fi
+
+git remote add auth-origin https://$GITHUB_AUTH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git
+git config --global user.email "$GITHUB_AUTH_EMAIL"
+git config --global user.name "Chart.js"
+git checkout --detach --quiet
+git add -f dist/*.js bower.json
+git commit -m "Release $VERSION"
+git tag -a "v$VERSION" -m "Version $VERSION"
+git push -q auth-origin refs/tags/v$VERSION 2>/dev/null
+git remote rm auth-origin
+git checkout -f @{-1} | true |
Other | chartjs | Chart.js | 0ebe388611a8d394750aa6dba5634db26e378742.json | Update version for v2.2.2 release | package.json | @@ -2,7 +2,7 @@
"name": "chart.js",
"homepage": "http://www.chartjs.org",
"description": "Simple HTML5 charts using the canvas element.",
- "version": "2.2.1",
+ "version": "2.2.2",
"license": "MIT",
"main": "src/chart.js",
"repository": {
@@ -52,4 +52,4 @@
"chartjs-color": "^2.0.0",
"moment": "^2.10.6"
}
-}
\ No newline at end of file
+} | false |
Other | chartjs | Chart.js | c283867f73a5caea271304dd42480383ccd515ba.json | Remove smallestLabelSeparation from TimeScale (#3186)
In case of charts with over 4000 points, smallestLabelSeparation
calculation contributes significantly to total cpu usage (about 25% according
to built-in Chrome profiler). Important thing to note is that result
of this calculation is not used at all.
Related commits:
* 677c249b613bf1a4ebccb1bebda9f04f7346b866
introduced smallestLabelSeparation. It was used in calculateBaseWidth
function.
* d198157fb8ea479ec9286bcf0ffb72e2e62e9661
removed last use of smallestLabelSeparation. Since then the calculated
value was never used. | src/scales/scale.time.js | @@ -255,14 +255,6 @@ module.exports = function(Chart) {
me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
}
- me.smallestLabelSeparation = me.width;
-
- helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
- for (var i = 1; i < me.labelMoments[datasetIndex].length; i++) {
- me.smallestLabelSeparation = Math.min(me.smallestLabelSeparation, me.labelMoments[datasetIndex][i].diff(me.labelMoments[datasetIndex][i - 1], me.tickUnit, true));
- }
- }, me);
-
// Tick displayFormat override
if (me.options.time.displayFormat) {
me.displayFormat = me.options.time.displayFormat; | false |
Other | chartjs | Chart.js | abfbdd5f312bc3be7add68f356fcaf097ca938f9.json | Remove unneeded trailing commas | src/controllers/controller.bar.js | @@ -500,7 +500,7 @@ module.exports = function(Chart) {
categorySpacing: categorySpacing,
fullBarHeight: fullBarHeight,
barHeight: barHeight,
- barSpacing: barSpacing,
+ barSpacing: barSpacing
};
},
| true |
Other | chartjs | Chart.js | abfbdd5f312bc3be7add68f356fcaf097ca938f9.json | Remove unneeded trailing commas | src/scales/scale.linearbase.js | @@ -120,6 +120,6 @@ module.exports = function(Chart) {
me.zeroLineIndex = me.ticks.indexOf(0);
Chart.Scale.prototype.convertTicksToLabels.call(me);
- },
+ }
});
};
\ No newline at end of file | true |
Other | chartjs | Chart.js | e2dd4483c79956b76fa3a7bddf0e379e48b3877e.json | Add an Ember.js Integration in the Documentation (#4984) | docs/notes/extensions.md | @@ -50,3 +50,6 @@ In addition, many plugins can be found on the [npm registry](https://www.npmjs.c
### Java
- <a href="https://github.com/mdewilde/chart/" target="_blank">Chart.java</a>
+
+### Ember.js
+ - <a href="https://github.com/aomran/ember-cli-chart" target="_blank">ember-cli-chart</a> | false |
Other | chartjs | Chart.js | 6b824d933451243a4fc57d973da6a8ebe6175b8f.json | add check on overwriting canvas height/width (#4874)
* add check on overwriting canvas height/width
* unit test for this | src/core/core.helpers.js | @@ -512,8 +512,10 @@ module.exports = function(Chart) {
// If no style has been set on the canvas, the render size is used as display size,
// making the chart visually bigger, so let's enforce it to the "correct" values.
// See https://github.com/chartjs/Chart.js/issues/3575
- canvas.style.height = height + 'px';
- canvas.style.width = width + 'px';
+ if (!canvas.style.height && !canvas.style.width) {
+ canvas.style.height = height + 'px';
+ canvas.style.width = width + 'px';
+ }
};
// -- Canvas methods
helpers.fontString = function(pixelSize, fontStyle, fontFamily) { | true |
Other | chartjs | Chart.js | 6b824d933451243a4fc57d973da6a8ebe6175b8f.json | add check on overwriting canvas height/width (#4874)
* add check on overwriting canvas height/width
* unit test for this | test/specs/core.helpers.tests.js | @@ -725,6 +725,23 @@ describe('Core helper tests', function() {
document.body.removeChild(div);
});
+ it ('should leave styled height and width on canvas if explicitly set', function() {
+ var chart = window.acquireChart({}, {
+ canvas: {
+ height: 200,
+ width: 200,
+ style: 'height: 400px; width: 400px;'
+ }
+ });
+
+ helpers.retinaScale(chart, true);
+
+ var canvas = chart.canvas;
+
+ expect(canvas.style.height).toBe('400px');
+ expect(canvas.style.width).toBe('400px');
+ });
+
describe('Color helper', function() {
function isColorInstance(obj) {
return typeof obj === 'object' && obj.hasOwnProperty('values') && obj.values.hasOwnProperty('rgb'); | true |
Other | chartjs | Chart.js | e080e782ab44f34d2bcd63ad6255f48bac2292ea.json | Fix bumpy line on smooth data set (#4944)
Linear scale getPixelForValue() method doesn't round the returned value anymore. | src/scales/scale.linear.js | @@ -170,11 +170,10 @@ module.exports = function(Chart) {
if (me.isHorizontal()) {
pixel = me.left + (me.width / range * (rightValue - start));
- return Math.round(pixel);
+ } else {
+ pixel = me.bottom - (me.height / range * (rightValue - start));
}
-
- pixel = me.bottom - (me.height / range * (rightValue - start));
- return Math.round(pixel);
+ return pixel;
},
getValueForPixel: function(pixel) {
var me = this; | true |
Other | chartjs | Chart.js | e080e782ab44f34d2bcd63ad6255f48bac2292ea.json | Fix bumpy line on smooth data set (#4944)
Linear scale getPixelForValue() method doesn't round the returned value anymore. | test/specs/core.controller.tests.js | @@ -759,8 +759,8 @@ describe('Chart', function() {
// Verify that points are at their initial correct location,
// then we will reset and see that they moved
- expect(meta.data[0]._model.y).toBe(333);
- expect(meta.data[1]._model.y).toBe(183);
+ expect(meta.data[0]._model.y).toBeCloseToPixel(333);
+ expect(meta.data[1]._model.y).toBeCloseToPixel(183);
expect(meta.data[2]._model.y).toBe(32);
expect(meta.data[3]._model.y).toBe(484);
| true |
Other | chartjs | Chart.js | e080e782ab44f34d2bcd63ad6255f48bac2292ea.json | Fix bumpy line on smooth data set (#4944)
Linear scale getPixelForValue() method doesn't round the returned value anymore. | test/specs/core.tooltip.tests.js | @@ -764,7 +764,7 @@ describe('Core.Tooltip', function() {
it('Should not update if active element has not changed', function() {
var chart = window.acquireChart({
- type: 'bar',
+ type: 'line',
data: {
datasets: [{
label: 'Dataset 1', | true |
Other | chartjs | Chart.js | 939756c26083d5fbd7c8ae2ed7981696566684eb.json | Fix log scale when value is 0 (#4913) | src/scales/scale.logarithmic.js | @@ -177,64 +177,94 @@ module.exports = function(Chart) {
getPixelForTick: function(index) {
return this.getPixelForValue(this.tickValues[index]);
},
+ /**
+ * Returns the value of the first tick.
+ * @param {Number} value - The minimum not zero value.
+ * @return {Number} The first tick value.
+ * @private
+ */
+ _getFirstTickValue: function(value) {
+ var exp = Math.floor(helpers.log10(value));
+ var significand = Math.floor(value / Math.pow(10, exp));
+
+ return significand * Math.pow(10, exp);
+ },
getPixelForValue: function(value) {
var me = this;
- var start = me.start;
- var newVal = +me.getRightValue(value);
- var opts = me.options;
- var tickOpts = opts.ticks;
- var innerDimension, pixel, range;
+ var reverse = me.options.ticks.reverse;
+ var log10 = helpers.log10;
+ var firstTickValue = me._getFirstTickValue(me.minNotZero);
+ var offset = 0;
+ var innerDimension, pixel, start, end, sign;
+ value = +me.getRightValue(value);
+ if (reverse) {
+ start = me.end;
+ end = me.start;
+ sign = -1;
+ } else {
+ start = me.start;
+ end = me.end;
+ sign = 1;
+ }
if (me.isHorizontal()) {
- range = helpers.log10(me.end) - helpers.log10(start); // todo: if start === 0
- if (newVal === 0) {
- pixel = me.left;
- } else {
- innerDimension = me.width;
- pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
- }
+ innerDimension = me.width;
+ pixel = reverse ? me.right : me.left;
} else {
- // Bottom - top since pixels increase downward on a screen
innerDimension = me.height;
- if (start === 0 && !tickOpts.reverse) {
- range = helpers.log10(me.end) - helpers.log10(me.minNotZero);
- if (newVal === start) {
- pixel = me.bottom;
- } else if (newVal === me.minNotZero) {
- pixel = me.bottom - innerDimension * 0.02;
- } else {
- pixel = me.bottom - innerDimension * 0.02 - (innerDimension * 0.98 / range * (helpers.log10(newVal) - helpers.log10(me.minNotZero)));
- }
- } else if (me.end === 0 && tickOpts.reverse) {
- range = helpers.log10(me.start) - helpers.log10(me.minNotZero);
- if (newVal === me.end) {
- pixel = me.top;
- } else if (newVal === me.minNotZero) {
- pixel = me.top + innerDimension * 0.02;
- } else {
- pixel = me.top + innerDimension * 0.02 + (innerDimension * 0.98 / range * (helpers.log10(newVal) - helpers.log10(me.minNotZero)));
- }
- } else if (newVal === 0) {
- pixel = tickOpts.reverse ? me.top : me.bottom;
- } else {
- range = helpers.log10(me.end) - helpers.log10(start);
- innerDimension = me.height;
- pixel = me.bottom - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
+ sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
+ pixel = reverse ? me.top : me.bottom;
+ }
+ if (value !== start) {
+ if (start === 0) { // include zero tick
+ offset = helpers.getValueOrDefault(
+ me.options.ticks.fontSize,
+ Chart.defaults.global.defaultFontSize
+ );
+ innerDimension -= offset;
+ start = firstTickValue;
}
+ if (value !== 0) {
+ offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
+ }
+ pixel += sign * offset;
}
return pixel;
},
getValueForPixel: function(pixel) {
var me = this;
- var range = helpers.log10(me.end) - helpers.log10(me.start);
- var value, innerDimension;
+ var reverse = me.options.ticks.reverse;
+ var log10 = helpers.log10;
+ var firstTickValue = me._getFirstTickValue(me.minNotZero);
+ var innerDimension, start, end, value;
+ if (reverse) {
+ start = me.end;
+ end = me.start;
+ } else {
+ start = me.start;
+ end = me.end;
+ }
if (me.isHorizontal()) {
innerDimension = me.width;
- value = me.start * Math.pow(10, (pixel - me.left) * range / innerDimension);
- } else { // todo: if start === 0
+ value = reverse ? me.right - pixel : pixel - me.left;
+ } else {
innerDimension = me.height;
- value = Math.pow(10, (me.bottom - pixel) * range / innerDimension) / me.start;
+ value = reverse ? pixel - me.top : me.bottom - pixel;
+ }
+ if (value !== start) {
+ if (start === 0) { // include zero tick
+ var offset = helpers.getValueOrDefault(
+ me.options.ticks.fontSize,
+ Chart.defaults.global.defaultFontSize
+ );
+ value -= offset;
+ innerDimension -= offset;
+ start = firstTickValue;
+ }
+ value *= log10(end) - log10(start);
+ value /= innerDimension;
+ value = Math.pow(10, log10(start) + value);
}
return value;
} | true |
Other | chartjs | Chart.js | 939756c26083d5fbd7c8ae2ed7981696566684eb.json | Fix log scale when value is 0 (#4913) | test/specs/scale.logarithmic.tests.js | @@ -735,47 +735,99 @@ describe('Logarithmic Scale tests', function() {
expect(yScale.getValueForPixel(246)).toBeCloseTo(10, 1e-4);
});
- it('should get the correct pixel value for a point when 0 values are present', function() {
- var chart = window.acquireChart({
- type: 'bar',
- data: {
- datasets: [{
- yAxisID: 'yScale',
- data: [0.063, 4, 0, 63, 10, 0.5]
- }],
- labels: []
+ it('should get the correct pixel value for a point when 0 values are present or min: 0', function() {
+ var config = [
+ {
+ dataset: [{x: 0, y: 0}, {x: 10, y: 10}, {x: 1.2, y: 1.2}, {x: 25, y: 25}, {x: 78, y: 78}],
+ firstTick: 1, // value of the first tick
+ lastTick: 80
},
- options: {
- scales: {
- yAxes: [{
- id: 'yScale',
- type: 'logarithmic',
- ticks: {
- reverse: false
- }
- }]
+ {
+ dataset: [{x: 0, y: 0}, {x: 10, y: 10}, {x: 6.3, y: 6.3}, {x: 25, y: 25}, {x: 78, y: 78}],
+ firstTick: 6,
+ lastTick: 80
+ },
+ {
+ dataset: [{x: 10, y: 10}, {x: 1.2, y: 1.2}, {x: 25, y: 25}, {x: 78, y: 78}],
+ scale: {ticks: {min: 0}},
+ firstTick: 1,
+ lastTick: 80
+ },
+ {
+ dataset: [{x: 10, y: 10}, {x: 6.3, y: 6.3}, {x: 25, y: 25}, {x: 78, y: 78}],
+ scale: {ticks: {min: 0}},
+ firstTick: 6,
+ lastTick: 80
+ },
+ ];
+ Chart.helpers.each(config, function(setup) {
+ var xScaleConfig = {
+ type: 'logarithmic'
+ };
+ var yScaleConfig = {
+ type: 'logarithmic'
+ };
+ Chart.helpers.extend(xScaleConfig, setup.scale);
+ Chart.helpers.extend(yScaleConfig, setup.scale);
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: setup.dataset
+ }],
+ },
+ options: {
+ scales: {
+ xAxes: [xScaleConfig],
+ yAxes: [yScaleConfig]
+ }
}
- }
+ });
+
+ var chartArea = chart.chartArea;
+ var expectations = [
+ {
+ id: 'x-axis-0', // horizontal scale
+ axis: 'xAxes',
+ start: chartArea.left,
+ end: chartArea.right
+ },
+ {
+ id: 'y-axis-0', // vertical scale
+ axis: 'yAxes',
+ start: chartArea.bottom,
+ end: chartArea.top
+ }
+ ];
+ Chart.helpers.each(expectations, function(expectation) {
+ var scale = chart.scales[expectation.id];
+ var firstTick = setup.firstTick;
+ var lastTick = setup.lastTick;
+ var fontSize = chart.options.defaultFontSize;
+ var start = expectation.start;
+ var end = expectation.end;
+ var sign = scale.isHorizontal() ? 1 : -1;
+
+ expect(scale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(start);
+ expect(scale.getPixelForValue(lastTick, 0, 0)).toBeCloseToPixel(end);
+ expect(scale.getPixelForValue(firstTick, 0, 0)).toBeCloseToPixel(start + sign * fontSize);
+
+ expect(scale.getValueForPixel(start)).toBeCloseTo(0);
+ expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick);
+ expect(scale.getValueForPixel(start + sign * fontSize)).toBeCloseTo(firstTick);
+
+ chart.options.scales[expectation.axis][0].ticks.reverse = true; // Reverse mode
+ chart.update();
+
+ expect(scale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(end);
+ expect(scale.getPixelForValue(lastTick, 0, 0)).toBeCloseToPixel(start);
+ expect(scale.getPixelForValue(firstTick, 0, 0)).toBeCloseToPixel(end - sign * fontSize);
+
+ expect(scale.getValueForPixel(end)).toBeCloseTo(0);
+ expect(scale.getValueForPixel(start)).toBeCloseTo(lastTick);
+ expect(scale.getValueForPixel(end - sign * fontSize)).toBeCloseTo(firstTick);
+ });
});
-
- var yScale = chart.scales.yScale;
- expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
- expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
- expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(475); // minNotZero 2% from range
- expect(yScale.getPixelForValue(0.5, 0, 0)).toBeCloseToPixel(344);
- expect(yScale.getPixelForValue(4, 0, 0)).toBeCloseToPixel(213);
- expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(155);
- expect(yScale.getPixelForValue(63, 0, 0)).toBeCloseToPixel(38.5);
-
- chart.options.scales.yAxes[0].ticks.reverse = true; // Reverse mode
- chart.update();
-
- expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
- expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
- expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(41); // minNotZero 2% from range
- expect(yScale.getPixelForValue(0.5, 0, 0)).toBeCloseToPixel(172);
- expect(yScale.getPixelForValue(4, 0, 0)).toBeCloseToPixel(303);
- expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(361);
- expect(yScale.getPixelForValue(63, 0, 0)).toBeCloseToPixel(477);
});
+
}); | true |
Other | chartjs | Chart.js | 95d7d8c20df4377c238224654037e2f4886823a8.json | Add link to chartjs-plugin-waterfall (#4921) | docs/notes/extensions.md | @@ -18,6 +18,7 @@ In addition, many charts can be found on the [npm registry](https://www.npmjs.co
- <a href="https://github.com/chartjs/chartjs-plugin-deferred" target="_blank">chartjs-plugin-deferred</a> - Defers initial chart update until chart scrolls into viewport.
- <a href="https://github.com/compwright/chartjs-plugin-draggable" target="_blank">chartjs-plugin-draggable</a> - Makes select chart elements draggable with the mouse.
- <a href="https://github.com/y-takey/chartjs-plugin-stacked100" target="_blank">chartjs-plugin-stacked100</a> - Draws 100% stacked bar chart.
+ - <a href="https://github.com/everestate/chartjs-plugin-waterfall" target="_blank">chartjs-plugin-waterfall</a> - Enables easy use of waterfall charts.
- <a href="https://github.com/chartjs/chartjs-plugin-zoom" target="_blank">chartjs-plugin-zoom</a> - Enables zooming and panning on charts.
In addition, many plugins can be found on the [npm registry](https://www.npmjs.com/search?q=chartjs-plugin-). | false |
Other | chartjs | Chart.js | ffbdb483105c750c836fde32501f65d9577ddc83.json | Upgrade dependencies (incl. ESLint 4) (#4738) | .codeclimate.yml | @@ -6,7 +6,7 @@ engines:
- javascript
eslint:
enabled: true
- channel: "eslint-3"
+ channel: "eslint-4"
fixme:
enabled: true
ratings: | true |
Other | chartjs | Chart.js | ffbdb483105c750c836fde32501f65d9577ddc83.json | Upgrade dependencies (incl. ESLint 4) (#4738) | .eslintrc | @@ -1,7 +1,3 @@
-ecmaFeatures:
- modules: true
- jsx: true
-
env:
amd: true
browser: true
@@ -72,7 +68,7 @@ rules:
no-lone-blocks: 2
no-loop-func: 2
no-magic-number: 0
- no-multi-spaces: 2
+ no-multi-spaces: [2, {ignoreEOLComments: true}]
no-multi-str: 2
no-native-reassign: 2
no-new-func: 2
@@ -141,7 +137,7 @@ rules:
func-style: 0
id-length: 0
id-match: 0
- indent: [2, tab]
+ indent: [2, tab, {flatTernaryExpressions: true}]
jsx-quotes: 0
key-spacing: 2
keyword-spacing: 2 | true |
Other | chartjs | Chart.js | ffbdb483105c750c836fde32501f65d9577ddc83.json | Upgrade dependencies (incl. ESLint 4) (#4738) | package.json | @@ -10,30 +10,31 @@
"url": "https://github.com/chartjs/Chart.js.git"
},
"devDependencies": {
- "browserify": "^14.3.0",
- "browserify-istanbul": "^2.0.0",
- "bundle-collapser": "^1.2.1",
+ "browserify": "^14.5.0",
+ "browserify-istanbul": "^3.0.1",
+ "bundle-collapser": "^1.3.0",
"child-process-promise": "^2.2.1",
- "coveralls": "^2.13.1",
- "gitbook-cli": "^2.3.0",
+ "coveralls": "^3.0.0",
+ "eslint": "^4.9.0",
+ "gitbook-cli": "^2.3.2",
"gulp": "3.9.x",
"gulp-concat": "~2.6.x",
"gulp-connect": "~5.0.0",
- "gulp-eslint": "^3.0.1",
+ "gulp-eslint": "^4.0.0",
"gulp-file": "^0.3.0",
"gulp-html-validator": "^0.0.5",
"gulp-insert": "~0.5.0",
- "gulp-replace": "^0.5.4",
+ "gulp-replace": "^0.6.1",
"gulp-size": "~2.1.0",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "~3.0.x",
"gulp-util": "~3.0.x",
"gulp-zip": "~4.0.0",
- "jasmine": "^2.6.0",
- "jasmine-core": "^2.6.2",
- "karma": "^1.7.0",
+ "jasmine": "^2.8.0",
+ "jasmine-core": "^2.8.0",
+ "karma": "^1.7.1",
"karma-browserify": "^5.1.1",
- "karma-chrome-launcher": "^2.1.1",
+ "karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
@@ -42,13 +43,13 @@
"pixelmatch": "^4.0.2",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.9.0",
- "yargs": "^8.0.1"
+ "yargs": "^9.0.1"
},
"spm": {
"main": "Chart.js"
},
"dependencies": {
"chartjs-color": "~2.2.0",
- "moment": "~2.18.0"
+ "moment": "~2.19.1"
}
} | true |
Other | chartjs | Chart.js | 13e9676625723a4c6d4e8232b2fe3fa02421d38b.json | Reset tooltip when calling Chart.update (#4840) | src/core/core.controller.js | @@ -371,6 +371,14 @@ module.exports = function(Chart) {
me.updateDatasets();
+ // Need to reset tooltip in case it is displayed with elements that are removed
+ // after update.
+ me.tooltip.initialize();
+
+ // Last active contains items that were previously in the tooltip.
+ // When we reset the tooltip, we need to clear it
+ me.lastActive = [];
+
// Do this before render so that any plugins that need final scale updates can use it
plugins.notify(me, 'afterUpdate');
| true |
Other | chartjs | Chart.js | 13e9676625723a4c6d4e8232b2fe3fa02421d38b.json | Reset tooltip when calling Chart.update (#4840) | src/core/core.tooltip.js | @@ -384,6 +384,7 @@ module.exports = function(Chart) {
Chart.Tooltip = Element.extend({
initialize: function() {
this._model = getBaseModel(this._options);
+ this._lastActive = [];
},
// Get the title | true |
Other | chartjs | Chart.js | 13e9676625723a4c6d4e8232b2fe3fa02421d38b.json | Reset tooltip when calling Chart.update (#4840) | test/specs/core.controller.tests.js | @@ -822,6 +822,54 @@ describe('Chart', function() {
expect(chart.tooltip._options).toEqual(jasmine.objectContaining(newTooltipConfig));
});
+ it ('should reset the tooltip on update', function() {
+ var chart = acquireChart({
+ type: 'line',
+ data: {
+ labels: ['A', 'B', 'C', 'D'],
+ datasets: [{
+ data: [10, 20, 30, 100]
+ }]
+ },
+ options: {
+ responsive: true,
+ tooltip: {
+ mode: 'nearest'
+ }
+ }
+ });
+
+ // Trigger an event over top of a point to
+ // put an item into the tooltip
+ var meta = chart.getDatasetMeta(0);
+ var point = meta.data[1];
+
+ var node = chart.canvas;
+ var rect = node.getBoundingClientRect();
+
+ var evt = new MouseEvent('mousemove', {
+ view: window,
+ bubbles: true,
+ cancelable: true,
+ clientX: rect.left + point._model.x,
+ clientY: 0
+ });
+
+ // Manually trigger rather than having an async test
+ node.dispatchEvent(evt);
+
+ // Check and see if tooltip was displayed
+ var tooltip = chart.tooltip;
+
+ expect(chart.lastActive).toEqual([point]);
+ expect(tooltip._lastActive).toEqual([]);
+
+ // Update and confirm tooltip is reset
+ chart.update();
+ expect(chart.lastActive).toEqual([]);
+ expect(tooltip._lastActive).toEqual([]);
+ });
+
it ('should update the metadata', function() {
var cfg = {
data: { | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.