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
88308c600cbbd38458bc94549ca6139698508c58.json
Enhance the rounded rectangle implementation (#5597) Use `arcTo` instead of `quadraticCurveTo` (both methods have the same compatibility level) because it generates better results when the final rect is a circle but also when it's actually a rectangle and not a square. This change is needed by the datalabels plugin where the user can configure the `borderRadius` and thus generate circle from a rounded rectangle.
src/helpers/helpers.canvas.js
@@ -27,18 +27,20 @@ var exports = module.exports = { */ roundedRect: function(ctx, x, y, width, height, radius) { if (radius) { - var rx = Math.min(radius, width / 2); - var ry = Math.min(radius, height / 2); - - ctx.moveTo(x + rx, y); - ctx.lineTo(x + width - rx, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + ry); - ctx.lineTo(x + width, y + height - ry); - ctx.quadraticCurveTo(x + width, y + height, x + width - rx, y + height); - ctx.lineTo(x + rx, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - ry); - ctx.lineTo(x, y + ry); - ctx.quadraticCurveTo(x, y, x + rx, y); + // NOTE(SB) `epsilon` helps to prevent minor artifacts appearing + // on Chrome when `r` is exactly half the height or the width. + var epsilon = 0.0000001; + var r = Math.min(radius, (height / 2) - epsilon, (width / 2) - epsilon); + + ctx.moveTo(x + r, y); + ctx.lineTo(x + width - r, y); + ctx.arcTo(x + width, y, x + width, y + r, r); + ctx.lineTo(x + width, y + height - r); + ctx.arcTo(x + width, y + height, x + width - r, y + height, r); + ctx.lineTo(x + r, y + height); + ctx.arcTo(x, y + height, x, y + height - r, r); + ctx.lineTo(x, y + r); + ctx.arcTo(x, y, x + r, y, r); } else { ctx.rect(x, y, width, height); } @@ -89,7 +91,13 @@ var exports = module.exports = { var topY = y - offset; var sideSize = Math.SQRT2 * radius; ctx.beginPath(); - this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius / 2); + + // NOTE(SB) the rounded rect implementation changed to use `arcTo` + // instead of `quadraticCurveTo` since it generates better results + // when rect is almost a circle. 0.425 (instead of 0.5) produces + // results visually closer to the previous impl. + this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius * 0.425); + ctx.closePath(); ctx.fill(); break;
true
Other
chartjs
Chart.js
88308c600cbbd38458bc94549ca6139698508c58.json
Enhance the rounded rectangle implementation (#5597) Use `arcTo` instead of `quadraticCurveTo` (both methods have the same compatibility level) because it generates better results when the final rect is a circle but also when it's actually a rectangle and not a square. This change is needed by the datalabels plugin where the user can configure the `borderRadius` and thus generate circle from a rounded rectangle.
test/jasmine.context.js
@@ -75,6 +75,7 @@ Context.prototype._initMethods = function() { var me = this; var methods = { arc: function() {}, + arcTo: function() {}, beginPath: function() {}, bezierCurveTo: function() {}, clearRect: function() {},
true
Other
chartjs
Chart.js
88308c600cbbd38458bc94549ca6139698508c58.json
Enhance the rounded rectangle implementation (#5597) Use `arcTo` instead of `quadraticCurveTo` (both methods have the same compatibility level) because it generates better results when the final rect is a circle but also when it's actually a rectangle and not a square. This change is needed by the datalabels plugin where the user can configure the `borderRadius` and thus generate circle from a rounded rectangle.
test/specs/element.point.tests.js
@@ -222,7 +222,7 @@ describe('Point element tests', function() { 15 - offset, Math.SQRT2 * 2, Math.SQRT2 * 2, - 2 / 2 + 2 * 0.425 ); expect(mockContext.getCalls()).toContain( jasmine.objectContaining({
true
Other
chartjs
Chart.js
88308c600cbbd38458bc94549ca6139698508c58.json
Enhance the rounded rectangle implementation (#5597) Use `arcTo` instead of `quadraticCurveTo` (both methods have the same compatibility level) because it generates better results when the final rect is a circle but also when it's actually a rectangle and not a square. This change is needed by the datalabels plugin where the user can configure the `borderRadius` and thus generate circle from a rounded rectangle.
test/specs/helpers.canvas.tests.js
@@ -30,13 +30,13 @@ describe('Chart.helpers.canvas', function() { expect(context.getCalls()).toEqual([ {name: 'moveTo', args: [15, 20]}, {name: 'lineTo', args: [35, 20]}, - {name: 'quadraticCurveTo', args: [40, 20, 40, 25]}, + {name: 'arcTo', args: [40, 20, 40, 25, 5]}, {name: 'lineTo', args: [40, 55]}, - {name: 'quadraticCurveTo', args: [40, 60, 35, 60]}, + {name: 'arcTo', args: [40, 60, 35, 60, 5]}, {name: 'lineTo', args: [15, 60]}, - {name: 'quadraticCurveTo', args: [10, 60, 10, 55]}, + {name: 'arcTo', args: [10, 60, 10, 55, 5]}, {name: 'lineTo', args: [10, 25]}, - {name: 'quadraticCurveTo', args: [10, 20, 15, 20]} + {name: 'arcTo', args: [10, 20, 15, 20, 5]} ]); }); it('should optimize path if radius is 0', function() {
true
Other
chartjs
Chart.js
6f90e0799e7a8a080f5ecc76928bebb76c672946.json
Use comment for pull request template (#5595)
.github/PULL_REQUEST_TEMPLATE.md
@@ -1,3 +1,4 @@ +<!-- Please consider the following before submitting a pull request: Guidelines for contributing: https://github.com/chartjs/Chart.js/blob/master/docs/developers/contributing.md @@ -6,4 +7,5 @@ Example of changes on an interactive website such as the following: - http://jsbin.com/ - http://jsfiddle.net/ - http://codepen.io/pen/ -- Premade template: http://codepen.io/pen?template=JXVYzq \ No newline at end of file +- Premade template: http://codepen.io/pen?template=JXVYzq +-->
false
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
karma.conf.js
@@ -19,7 +19,6 @@ module.exports = function(karma) { // These settings deal with browser disconnects. We had seen test flakiness from Firefox // [Firefox 56.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms. // https://github.com/jasmine/jasmine/issues/1327#issuecomment-332939551 - browserNoActivityTimeout: 60000, browserDisconnectTolerance: 3 };
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.bar.js
@@ -461,29 +461,6 @@ module.exports = function(Chart) { helpers.canvas.unclipArea(chart.ctx); }, - - setHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; - var index = rectangle._index; - var custom = rectangle.custom || {}; - var model = rectangle._model; - - model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); - model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor)); - model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); - }, - - removeHoverStyle: function(rectangle) { - var dataset = this.chart.data.datasets[rectangle._datasetIndex]; - var index = rectangle._index; - var custom = rectangle.custom || {}; - var model = rectangle._model; - var rectangleElementOptions = this.chart.options.elements.rectangle; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth); - } }); Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.bubble.js
@@ -102,26 +102,18 @@ module.exports = function(Chart) { setHoverStyle: function(point) { var model = point._model; var options = point._options; - + point.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor)); model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor)); model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth); model.radius = options.radius + options.hoverRadius; }, - /** - * @protected - */ - removeHoverStyle: function(point) { - var model = point._model; - var options = point._options; - - model.backgroundColor = options.backgroundColor; - model.borderColor = options.borderColor; - model.borderWidth = options.borderWidth; - model.radius = options.radius; - }, - /** * @private */
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.doughnut.js
@@ -229,8 +229,14 @@ module.exports = function(Chart) { }); var model = arc._model; + // Resets the visual styles - this.removeHoverStyle(arc); + var custom = arc.custom || {}; + var valueOrDefault = helpers.valueAtIndexOrDefault; + var elementOpts = this.chart.options.elements.arc; + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); // Set correct angles if not resetting if (!reset || !animationOpts.animateRotate) { @@ -246,10 +252,6 @@ module.exports = function(Chart) { arc.pivot(); }, - removeHoverStyle: function(arc) { - Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc); - }, - calculateTotal: function() { var dataset = this.getDataset(); var meta = this.getMeta();
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.line.js
@@ -307,35 +307,24 @@ module.exports = function(Chart) { } }, - setHoverStyle: function(point) { + setHoverStyle: function(element) { // Point - var dataset = this.chart.data.datasets[point._datasetIndex]; - var index = point._index; - var custom = point.custom || {}; - var model = point._model; + var dataset = this.chart.data.datasets[element._datasetIndex]; + var index = element._index; + var custom = element.custom || {}; + var model = element._model; + + element.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; - model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); + model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); }, - - removeHoverStyle: function(point) { - var me = this; - var dataset = me.chart.data.datasets[point._datasetIndex]; - var index = point._index; - var custom = point.custom || {}; - var model = point._model; - - // Compatibility: If the properties are defined with only the old name, use those values - if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) { - dataset.pointRadius = dataset.radius; - } - - model.radius = custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius); - model.backgroundColor = me.getPointBackgroundColor(point, index); - model.borderColor = me.getPointBorderColor(point, index); - model.borderWidth = me.getPointBorderWidth(point, index); - } }); };
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.polarArea.js
@@ -199,13 +199,16 @@ module.exports = function(Chart) { }); // Apply border and fill style - me.removeHoverStyle(arc); + var elementOpts = this.chart.options.elements.arc; + var custom = arc.custom || {}; + var valueOrDefault = helpers.valueAtIndexOrDefault; + var model = arc._model; - arc.pivot(); - }, + model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); + model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); + model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); - removeHoverStyle: function(arc) { - Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc); + arc.pivot(); }, countVisibleElements: function() {
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/controllers/controller.radar.js
@@ -146,23 +146,17 @@ module.exports = function(Chart) { var index = point._index; var model = point._model; + point.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth, + radius: model.radius + }; + model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius); model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor)); model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor)); model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth); }, - - removeHoverStyle: function(point) { - var dataset = this.chart.data.datasets[point._datasetIndex]; - var custom = point.custom || {}; - var index = point._index; - var model = point._model; - var pointElementOptions = this.chart.options.elements.point; - - model.radius = custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius); - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth); - } }); };
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
src/core/core.datasetController.js
@@ -238,16 +238,9 @@ module.exports = function(Chart) { } }, - removeHoverStyle: function(element, elementOpts) { - var dataset = this.chart.data.datasets[element._datasetIndex]; - var index = element._index; - var custom = element.custom || {}; - var valueOrDefault = helpers.valueAtIndexOrDefault; - var model = element._model; - - model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor); - model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor); - model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth); + removeHoverStyle: function(element) { + helpers.merge(element._model, element.$previousStyle || {}); + delete element.$previousStyle; }, setHoverStyle: function(element) { @@ -258,6 +251,12 @@ module.exports = function(Chart) { var getHoverColor = helpers.getHoverColor; var model = element._model; + element.$previousStyle = { + backgroundColor: model.backgroundColor, + borderColor: model.borderColor, + borderWidth: model.borderWidth + }; + model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor)); 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);
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
test/specs/controller.bar.tests.js
@@ -1372,13 +1372,21 @@ describe('Chart.controllers.bar', function() { var meta = chart.getDatasetMeta(1); var bar = meta.data[0]; + var helpers = window.Chart.helpers; // Change default chart.options.elements.rectangle.backgroundColor = 'rgb(128, 128, 128)'; chart.options.elements.rectangle.borderColor = 'rgb(15, 15, 15)'; chart.options.elements.rectangle.borderWidth = 3.14; - // Remove to defaults + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); + expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); + expect(bar._model.borderWidth).toBe(3.14); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(128, 128, 128)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(15, 15, 15)')); + expect(bar._model.borderWidth).toBe(3.14); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); @@ -1389,6 +1397,14 @@ describe('Chart.controllers.bar', function() { chart.data.datasets[1].borderColor = ['rgb(9, 9, 9)', 'rgb(0, 0, 0)']; chart.data.datasets[1].borderWidth = [2.5, 5]; + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); + expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); + expect(bar._model.borderWidth).toBe(2.5); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 255, 255)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(9, 9, 9)')); + expect(bar._model.borderWidth).toBe(2.5); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); @@ -1401,6 +1417,14 @@ describe('Chart.controllers.bar', function() { borderWidth: 1.5 }; + chart.update(); + expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)'); + expect(bar._model.borderColor).toBe('rgb(0, 255, 0)'); + expect(bar._model.borderWidth).toBe(1.5); + meta.controller.setHoverStyle(bar); + expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 0, 0)')); + expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(0, 255, 0)')); + expect(bar._model.borderWidth).toBe(1.5); meta.controller.removeHoverStyle(bar); expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)'); expect(bar._model.borderColor).toBe('rgb(0, 255, 0)');
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
test/specs/controller.doughnut.tests.js
@@ -355,6 +355,8 @@ describe('Chart.controllers.doughnut', function() { var meta = chart.getDatasetMeta(0); var arc = meta.data[0]; + chart.update(); + meta.controller.setHoverStyle(arc); meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(255, 0, 0)'); expect(arc._model.borderColor).toBe('rgb(0, 0, 255)'); @@ -365,6 +367,8 @@ describe('Chart.controllers.doughnut', function() { chart.data.datasets[0].borderColor = 'rgb(18, 18, 18)'; chart.data.datasets[0].borderWidth = 1.56; + chart.update(); + meta.controller.setHoverStyle(arc); meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(9, 9, 9)'); expect(arc._model.borderColor).toBe('rgb(18, 18, 18)'); @@ -375,6 +379,8 @@ describe('Chart.controllers.doughnut', function() { chart.data.datasets[0].borderColor = ['rgb(18, 18, 18)']; chart.data.datasets[0].borderWidth = [0.1, 1.56]; + chart.update(); + meta.controller.setHoverStyle(arc); meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(arc._model.borderColor).toBe('rgb(18, 18, 18)'); @@ -387,6 +393,8 @@ describe('Chart.controllers.doughnut', function() { borderWidth: 3.14159, }; + chart.update(); + meta.controller.setHoverStyle(arc); meta.controller.removeHoverStyle(arc); expect(arc._model.backgroundColor).toBe('rgb(7, 7, 7)'); expect(arc._model.borderColor).toBe('rgb(17, 17, 17)');
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
test/specs/controller.line.tests.js
@@ -703,6 +703,7 @@ describe('Chart.controllers.line', function() { chart.options.elements.point.radius = 1.01; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(point._model.borderColor).toBe('rgb(50, 51, 52)'); expect(point._model.borderWidth).toBe(10.1); @@ -715,6 +716,7 @@ describe('Chart.controllers.line', function() { chart.data.datasets[0].pointBorderWidth = 2.1; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -726,6 +728,7 @@ describe('Chart.controllers.line', function() { chart.data.datasets[0].radius = 20; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -740,6 +743,7 @@ describe('Chart.controllers.line', function() { }; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(point._model.borderColor).toBe('rgb(10, 10, 10)'); expect(point._model.borderWidth).toBe(5.5);
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
test/specs/controller.polarArea.tests.js
@@ -332,7 +332,14 @@ describe('Chart.controllers.polarArea', function() { chart.options.elements.arc.borderColor = 'rgb(50, 51, 52)'; chart.options.elements.arc.borderWidth = 10.1; + meta.controller.setHoverStyle(arc); + chart.update(); + expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); + expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); + expect(arc._model.borderWidth).toBe(10.1); + meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(arc._model.borderColor).toBe('rgb(50, 51, 52)'); expect(arc._model.borderWidth).toBe(10.1); @@ -343,6 +350,7 @@ describe('Chart.controllers.polarArea', function() { chart.data.datasets[0].borderWidth = 2.1; meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(arc._model.borderColor).toBe('rgb(123, 125, 127)'); expect(arc._model.borderWidth).toBe(2.1); @@ -355,6 +363,7 @@ describe('Chart.controllers.polarArea', function() { }; meta.controller.removeHoverStyle(arc); + chart.update(); expect(arc._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(arc._model.borderColor).toBe('rgb(10, 10, 10)'); expect(arc._model.borderWidth).toBe(5.5);
true
Other
chartjs
Chart.js
da3aa68f38b9db25156c3b32c56098f9ca70f4d8.json
Restore original styles when removing hover (#5570) Refactor `updateElement` and `removeHoverStyle` and fix tests.
test/specs/controller.radar.tests.js
@@ -410,6 +410,7 @@ describe('Chart.controllers.radar', function() { chart.options.elements.point.radius = 1.01; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(45, 46, 47)'); expect(point._model.borderColor).toBe('rgb(50, 51, 52)'); expect(point._model.borderWidth).toBe(10.1); @@ -422,6 +423,7 @@ describe('Chart.controllers.radar', function() { chart.data.datasets[0].pointBorderWidth = 2.1; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(77, 79, 81)'); expect(point._model.borderColor).toBe('rgb(123, 125, 127)'); expect(point._model.borderWidth).toBe(2.1); @@ -436,6 +438,7 @@ describe('Chart.controllers.radar', function() { }; meta.controller.removeHoverStyle(point); + chart.update(); expect(point._model.backgroundColor).toBe('rgb(0, 0, 0)'); expect(point._model.borderColor).toBe('rgb(10, 10, 10)'); expect(point._model.borderWidth).toBe(5.5);
true
Other
chartjs
Chart.js
ca9d3175c5fa9da69434cf7ed40b299fd221b667.json
Fix time documentation (#5507)
docs/axes/cartesian/time.md
@@ -6,7 +6,7 @@ The time scale is used to display times and dates. When building its ticks, it w ### Input Data -The x-axis data points may additionally be specified via the `t` attribute when using the time scale. +The x-axis data points may additionally be specified via the `t` or `x` attribute when using the time scale. data: [{ x: new Date(), @@ -64,6 +64,7 @@ var chart = new Chart(ctx, { options: { scales: { xAxes: [{ + type: 'time', time: { unit: 'month' }
false
Other
chartjs
Chart.js
1072ed9238ac48b6be5a7db8546103ec50a92c0d.json
Fix typo in README.md (#5504)
README.md
@@ -35,7 +35,7 @@ Files: * `dist/Chart.bundle.js` * `dist/Chart.bundle.min.js` -The bundled build includes Moment.js in a single file. You should use this version if you require time axes and want to include a single file. You should not use this build if your application already included Moment.js. Otherwise, Moment.js will be included twice which results in increasing page load time and possible version compatability issues. +The bundled build includes Moment.js in a single file. You should use this version if you require time axes and want to include a single file. You should not use this build if your application already included Moment.js. Otherwise, Moment.js will be included twice which results in increasing page load time and possible version compatibility issues. ## Documentation
false
Other
chartjs
Chart.js
14399ffe372ebabcb66bab20827b45594e7fc204.json
Update gulpfile.js to use in strict mode (#5478)
gulpfile.js
@@ -20,7 +20,7 @@ var yargs = require('yargs'); var path = require('path'); var fs = require('fs'); var htmllint = require('gulp-htmllint'); -var package = require('./package.json'); +var pkg = require('./package.json'); var argv = yargs .option('force-output', {default: false}) @@ -69,11 +69,11 @@ gulp.task('default', ['build', 'watch']); */ function bowerTask() { var json = JSON.stringify({ - name: package.name, - description: package.description, - homepage: package.homepage, - license: package.license, - version: package.version, + name: pkg.name, + description: pkg.description, + homepage: pkg.homepage, + license: pkg.license, + version: pkg.version, main: outDir + "Chart.js", ignore: [ '.github', @@ -112,11 +112,11 @@ function buildTask() { .on('error', errorHandler) .pipe(source('Chart.bundle.js')) .pipe(insert.prepend(header)) - .pipe(streamify(replace('{{ version }}', package.version))) + .pipe(streamify(replace('{{ version }}', pkg.version))) .pipe(gulp.dest(outDir)) .pipe(streamify(uglify())) .pipe(insert.prepend(header)) - .pipe(streamify(replace('{{ version }}', package.version))) + .pipe(streamify(replace('{{ version }}', pkg.version))) .pipe(streamify(concat('Chart.bundle.min.js'))) .pipe(gulp.dest(outDir)); @@ -127,11 +127,11 @@ function buildTask() { .on('error', errorHandler) .pipe(source('Chart.js')) .pipe(insert.prepend(header)) - .pipe(streamify(replace('{{ version }}', package.version))) + .pipe(streamify(replace('{{ version }}', pkg.version))) .pipe(gulp.dest(outDir)) .pipe(streamify(uglify())) .pipe(insert.prepend(header)) - .pipe(streamify(replace('{{ version }}', package.version))) + .pipe(streamify(replace('{{ version }}', pkg.version))) .pipe(streamify(concat('Chart.min.js'))) .pipe(gulp.dest(outDir));
false
Other
chartjs
Chart.js
9fbac8893865fc6f7efdab7f49d480e6a730c669.json
Add `ticks.precision` option to linear scale. (#4841) If defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
docs/axes/cartesian/linear.md
@@ -12,6 +12,7 @@ The following options are provided by the linear scale. They are all located in | `min` | `Number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings) | `max` | `Number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings) | `maxTicksLimit` | `Number` | `11` | Maximum number of ticks and gridlines to show. +| `precision` | `Number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places. | `stepSize` | `Number` | | User defined fixed step size for the scale. [more...](#step-size) | `suggestedMax` | `Number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings) | `suggestedMin` | `Number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
true
Other
chartjs
Chart.js
9fbac8893865fc6f7efdab7f49d480e6a730c669.json
Add `ticks.precision` option to linear scale. (#4841) If defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
docs/axes/radial/linear.md
@@ -27,6 +27,7 @@ The following options are provided by the linear scale. They are all located in | `min` | `Number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings) | `max` | `Number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings) | `maxTicksLimit` | `Number` | `11` | Maximum number of ticks and gridlines to show. +| `precision` | `Number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places. | `stepSize` | `Number` | | User defined fixed step size for the scale. [more...](#step-size) | `suggestedMax` | `Number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings) | `suggestedMin` | `Number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
true
Other
chartjs
Chart.js
9fbac8893865fc6f7efdab7f49d480e6a730c669.json
Add `ticks.precision` option to linear scale. (#4841) If defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
src/scales/scale.linearbase.js
@@ -14,12 +14,22 @@ function generateTicks(generationOptions, dataRange) { // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks // for details. + var factor; + var precision; var spacing; + if (generationOptions.stepSize && generationOptions.stepSize > 0) { spacing = generationOptions.stepSize; } else { var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); + + precision = generationOptions.precision; + if (precision !== undefined) { + // If the user specified a precision, round to that number of decimal places + factor = Math.pow(10, precision); + spacing = Math.ceil(spacing * factor) / factor; + } } var niceMin = Math.floor(dataRange.min / spacing) * spacing; var niceMax = Math.ceil(dataRange.max / spacing) * spacing; @@ -41,7 +51,7 @@ function generateTicks(generationOptions, dataRange) { numSpaces = Math.ceil(numSpaces); } - var precision = 1; + precision = 1; if (spacing < 1) { precision = Math.pow(10, spacing.toString().length - 2); niceMin = Math.round(niceMin * precision) / precision; @@ -154,6 +164,7 @@ module.exports = function(Chart) { maxTicks: maxTicks, min: tickOpts.min, max: tickOpts.max, + precision: tickOpts.precision, stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize) }; var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
true
Other
chartjs
Chart.js
9fbac8893865fc6f7efdab7f49d480e6a730c669.json
Add `ticks.precision` option to linear scale. (#4841) If defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
test/specs/scale.linear.tests.js
@@ -548,6 +548,66 @@ describe('Linear Scale', function() { expect(chart.scales.yScale0.ticks).toEqual(['11', '9', '7', '5', '3', '1']); }); + describe('precision', function() { + it('Should create integer steps if precision is 0', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [{ + yAxisID: 'yScale0', + data: [0, 1, 2, 1, 0, 1] + }], + labels: ['a', 'b', 'c', 'd', 'e', 'f'] + }, + options: { + scales: { + yAxes: [{ + id: 'yScale0', + type: 'linear', + ticks: { + precision: 0 + } + }] + } + } + }); + + expect(chart.scales.yScale0).not.toEqual(undefined); // must construct + expect(chart.scales.yScale0.min).toBe(0); + expect(chart.scales.yScale0.max).toBe(2); + expect(chart.scales.yScale0.ticks).toEqual(['2', '1', '0']); + }); + + it('Should round the step size to the given number of decimal places', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [{ + yAxisID: 'yScale0', + data: [0, 0.001, 0.002, 0.003, 0, 0.001] + }], + labels: ['a', 'b', 'c', 'd', 'e', 'f'] + }, + options: { + scales: { + yAxes: [{ + id: 'yScale0', + type: 'linear', + ticks: { + precision: 2 + } + }] + } + } + }); + + expect(chart.scales.yScale0).not.toEqual(undefined); // must construct + expect(chart.scales.yScale0.min).toBe(0); + expect(chart.scales.yScale0.max).toBe(0.01); + expect(chart.scales.yScale0.ticks).toEqual(['0.01', '0']); + }); + }); + it('should forcibly include 0 in the range if the beginAtZero option is used', function() { var chart = window.acquireChart({
true
Other
chartjs
Chart.js
a191921b1553d0af05dbb6ee621f171aeabf9baa.json
Fix typo in the legend documentation (#5348)
docs/configuration/legend.md
@@ -1,6 +1,6 @@ # Legend Configuration -The chart legend displays data about the datasets that area appearing on the chart. +The chart legend displays data about the datasets that are appearing on the chart. ## Configuration options The legend configuration is passed into the `options.legend` namespace. The global options for the chart legend is defined in `Chart.defaults.global.legend`.
false
Other
chartjs
Chart.js
7f4b1d9715f3da507893cf145009c729fad3606b.json
Add undefined guard for window.devicePixelRatio (#5324)
src/core/core.helpers.js
@@ -502,7 +502,7 @@ module.exports = function(Chart) { document.defaultView.getComputedStyle(el, null).getPropertyValue(property); }; helpers.retinaScale = function(chart, forceRatio) { - var pixelRatio = chart.currentDevicePixelRatio = forceRatio || window.devicePixelRatio || 1; + var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1; if (pixelRatio === 1) { return; }
false
Other
chartjs
Chart.js
be6660c63d10b54f4972170c4f3364b61bb9b9b3.json
Improve title of generated documentation (#5256)
book.json
@@ -1,5 +1,6 @@ { "root": "./docs", + "title": "Chart.js documentation", "author": "chartjs", "gitbook": "3.2.2", "plugins": ["-lunr", "-search", "search-plus", "anchorjs", "chartjs", "ga"],
false
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/axes/README.md
@@ -26,18 +26,18 @@ There are a number of config callbacks that can be used to change parameters in | Name | Arguments | Description | ---- | --------- | ----------- | `beforeUpdate` | `axis` | Callback called before the update process starts. -| `beforeSetDimensions` | `axis` | Callback that runs before dimensions are set. +| `beforeSetDimensions` | `axis` | Callback that runs before dimensions are set. | `afterSetDimensions` | `axis` | Callback that runs after dimensions are set. | `beforeDataLimits` | `axis` | Callback that runs before data limits are determined. | `afterDataLimits` | `axis` | Callback that runs after data limits are determined. | `beforeBuildTicks` | `axis` | Callback that runs before ticks are created. | `afterBuildTicks` | `axis` | Callback that runs after ticks are created. Useful for filtering ticks. | `beforeTickToLabelConversion` | `axis` | Callback that runs before ticks are converted into strings. -| `afterTickToLabelConversion` | `axis` | Callback that runs after ticks are converted into strings. +| `afterTickToLabelConversion` | `axis` | Callback that runs after ticks are converted into strings. | `beforeCalculateTickRotation` | `axis` | Callback that runs before tick rotation is determined. | `afterCalculateTickRotation` | `axis` | Callback that runs after tick rotation is determined. -| `beforeFit` | `axis` | Callback that runs before the scale fits to the canvas. -| `afterFit` | `axis` | Callback that runs after the scale fits to the canvas. +| `beforeFit` | `axis` | Callback that runs before the scale fits to the canvas. +| `afterFit` | `axis` | Callback that runs after the scale fits to the canvas. | `afterUpdate` | `axis` | Callback that runs at the end of the update process. ## Updating Axis Defaults
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/axes/cartesian/time.md
@@ -147,6 +147,6 @@ The `ticks.source` property controls the ticks generation * `'labels'`: generates ticks from user given `data.labels` values ONLY ### Parser -If this property is defined as a string, it is interpreted as a custom format to be used by moment to parse the date. +If this property is defined as a string, it is interpreted as a custom format to be used by moment to parse the date. If this is a function, it must return a moment.js object given the appropriate data value.
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/charts/bar.md
@@ -6,12 +6,12 @@ A bar chart provides a way of showing data values represented as vertical bars. "type": "bar", "data": { "labels": [ - "January", - "February", - "March", - "April", - "May", - "June", + "January", + "February", + "March", + "April", + "May", + "June", "July" ], "datasets": [{
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/charts/mixed.md
@@ -41,9 +41,9 @@ At this point we have a chart rendering how we'd like. It's important to note th "type": "bar", "data": { "labels": [ - "January", - "February", - "March", + "January", + "February", + "March", "April" ], "datasets": [{
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/charts/radar.md
@@ -8,9 +8,9 @@ They are often useful for comparing the points of two or more different data set "type": "radar", "data": { "labels": [ - "Eating", - "Drinking", - "Sleeping", + "Eating", + "Drinking", + "Sleeping", "Designing", "Coding", "Cycling", @@ -94,7 +94,7 @@ The style of point. Options are: * 'circle' * 'cross' * 'crossRot' -* 'dash'. +* 'dash'. * 'line' * 'rect' * 'rectRounded' @@ -127,7 +127,7 @@ It is common to want to apply a configuration setting to all created radar chart ## Data Structure -The `data` property of a dataset for a radar chart is specified as a an array of numbers. Each point in the data array corresponds to the label at the same index on the x axis. +The `data` property of a dataset for a radar chart is specified as a an array of numbers. Each point in the data array corresponds to the label at the same index on the x axis. ```javascript data: [20, 10]
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/configuration/legend.md
@@ -10,7 +10,7 @@ The legend configuration is passed into the `options.legend` namespace. The glob | `display` | `Boolean` | `true` | is the legend shown | `position` | `String` | `'top'` | Position of the legend. [more...](#position) | `fullWidth` | `Boolean` | `true` | Marks that this box should take the full width of the canvas (pushing down other boxes). This is unlikely to need to be changed in day-to-day use. -| `onClick` | `Function` | | A callback that is called when a click event is registered on a label item +| `onClick` | `Function` | | A callback that is called when a click event is registered on a label item | `onHover` | `Function` | | A callback that is called when a 'mousemove' event is registered on top of a label item | `reverse` | `Boolean` | `false` | Legend will show datasets in reverse order. | `labels` | `Object` | | See the [Legend Label Configuration](#legend-label-configuration) section below.
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/configuration/tooltip.md
@@ -63,9 +63,9 @@ Example: Chart.Tooltip.positioners.custom = function(elements, eventPosition) { /** @type {Chart.Tooltip} */ var tooltip = this; - + /* ... */ - + return { x: 0, y: 0
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/developers/charts.md
@@ -75,7 +75,7 @@ The built in controller types are: For example, to derive a new chart type that extends from a bubble chart, you would do the following. ```javascript -// Sets the default config for 'derivedBubble' to be the same as the bubble defaults. +// Sets the default config for 'derivedBubble' to be the same as the bubble defaults. // We look for the defaults by doing Chart.defaults[chartType] // It looks like a bug exists when the defaults don't exist Chart.defaults.derivedBubble = Chart.defaults.bubble; @@ -102,7 +102,7 @@ var custom = Chart.controllers.bubble.extend({ // Stores the controller so that the chart initialization routine can look it up with // Chart.controllers[type] -Chart.controllers.derivedBubble = custom; +Chart.controllers.derivedBubble = custom; // Now we can create and use our new chart type new Chart(ctx, {
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/general/colors.md
@@ -6,7 +6,7 @@ You can also pass a [CanvasGradient](https://developer.mozilla.org/en-US/docs/We ## Patterns and Gradients -An alternative option is to pass a [CanvasPattern](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern) or [CanvasGradient](https://developer.mozilla.org/en/docs/Web/API/CanvasGradient) object instead of a string colour. +An alternative option is to pass a [CanvasPattern](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern) or [CanvasGradient](https://developer.mozilla.org/en/docs/Web/API/CanvasGradient) object instead of a string colour. For example, if you wanted to fill a dataset with a pattern from an image you could do the following.
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/general/interactions/README.md
@@ -1,6 +1,6 @@ # Interactions -The hover configuration is passed into the `options.hover` namespace. The global hover configuration is at `Chart.defaults.global.hover`. To configure which events trigger chart interactions, see [events](./events.md#events). +The hover configuration is passed into the `options.hover` namespace. The global hover configuration is at `Chart.defaults.global.hover`. To configure which events trigger chart interactions, see [events](./events.md#events). | Name | Type | Default | Description | ---- | ---- | ------- | -----------
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/general/interactions/events.md
@@ -7,7 +7,7 @@ The following properties define how the chart interacts with events. | `onHover` | `Function` | `null` | Called when any of the events fire. Called in the context of the chart and passed the event and an array of active elements (bars, points, etc). | `onClick` | `Function` | `null` | Called if the event is of type 'mouseup' or 'click'. Called in the context of the chart and passed the event and an array of active elements -## Event Option +## Event Option For example, to have the chart only respond to click events, you could do ```javascript var chart = new Chart(ctx, {
true
Other
chartjs
Chart.js
bba29e591604fed8c1e3bc4cf911273d4c5e0f42.json
Remove trailing spaces from docs (#5227)
docs/general/interactions/modes.md
@@ -41,7 +41,7 @@ Finds the first item that intersects the point and returns it. Behaves like 'nea See `'index'` mode ## index -Finds item at the same index. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item, in the x direction, is used to determine the index. +Finds item at the same index. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item, in the x direction, is used to determine the index. ```javascript var chart = new Chart(ctx, {
true
Other
chartjs
Chart.js
c2681859531977fb83fee782f8aec6b50196d644.json
Fix Slack invitation link (#5217) Setup a new Heroku app based on rauchg/slackin, using Slack legacy token from the Chart.js (chartjs.slack@...) user and reCAPTCHA from the same Google account.
README.md
@@ -1,6 +1,6 @@ # Chart.js -[![travis](https://img.shields.io/travis/chartjs/Chart.js.svg?style=flat-square&maxAge=60)](https://travis-ci.org/chartjs/Chart.js) [![coveralls](https://img.shields.io/coveralls/chartjs/Chart.js.svg?style=flat-square&maxAge=600)](https://coveralls.io/github/chartjs/Chart.js?branch=master) [![codeclimate](https://img.shields.io/codeclimate/maintainability/chartjs/Chart.js.svg?style=flat-square&maxAge=600)](https://codeclimate.com/github/chartjs/Chart.js) [![slack](https://img.shields.io/badge/slack-Chart.js-blue.svg?style=flat-square&maxAge=3600)](https://chart-js-automation.herokuapp.com/) +[![travis](https://img.shields.io/travis/chartjs/Chart.js.svg?style=flat-square&maxAge=60)](https://travis-ci.org/chartjs/Chart.js) [![coveralls](https://img.shields.io/coveralls/chartjs/Chart.js.svg?style=flat-square&maxAge=600)](https://coveralls.io/github/chartjs/Chart.js?branch=master) [![codeclimate](https://img.shields.io/codeclimate/maintainability/chartjs/Chart.js.svg?style=flat-square&maxAge=600)](https://codeclimate.com/github/chartjs/Chart.js) [![slack](https://img.shields.io/badge/slack-chartjs-blue.svg?style=flat-square&maxAge=3600)](https://chartjs-slack.herokuapp.com/) *Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
true
Other
chartjs
Chart.js
c2681859531977fb83fee782f8aec6b50196d644.json
Fix Slack invitation link (#5217) Setup a new Heroku app based on rauchg/slackin, using Slack legacy token from the Chart.js (chartjs.slack@...) user and reCAPTCHA from the same Google account.
docs/README.md
@@ -1,6 +1,6 @@ # Chart.js -[![slack](https://img.shields.io/badge/slack-Chart.js-blue.svg?style=flat-square&maxAge=600)](https://chart-js-automation.herokuapp.com/) +[![slack](https://img.shields.io/badge/slack-chartjs-blue.svg?style=flat-square&maxAge=3600)](https://chartjs-slack.herokuapp.com/) ## Installation
true
Other
chartjs
Chart.js
c2681859531977fb83fee782f8aec6b50196d644.json
Fix Slack invitation link (#5217) Setup a new Heroku app based on rauchg/slackin, using Slack legacy token from the Chart.js (chartjs.slack@...) user and reCAPTCHA from the same Google account.
docs/developers/contributing.md
@@ -12,7 +12,7 @@ New contributions to the library are welcome, but we ask that you please follow # Joining the project - Active committers and contributors are invited to introduce yourself and request commit access to this project. We have a very active Slack community that you can join [here](https://chart-js-automation.herokuapp.com/). If you think you can help, we'd love to have you! + Active committers and contributors are invited to introduce yourself and request commit access to this project. We have a very active Slack community that you can join [here](https://chartjs-slack.herokuapp.com/). If you think you can help, we'd love to have you! # Building and Testing
true
Other
chartjs
Chart.js
33c7d941f7caa5363f68ac2135a66d7c2328e196.json
Add back Chart.Ticks.formatters (#5088)
src/chart.js
@@ -13,6 +13,7 @@ Chart.Element = require('./core/core.element'); Chart.elements = require('./elements/index'); Chart.Interaction = require('./core/core.interaction'); Chart.platform = require('./platforms/platform'); +Chart.Ticks = require('./core/core.ticks'); require('./core/core.plugin')(Chart); require('./core/core.animation')(Chart);
true
Other
chartjs
Chart.js
33c7d941f7caa5363f68ac2135a66d7c2328e196.json
Add back Chart.Ticks.formatters (#5088)
src/core/core.ticks.js
@@ -7,147 +7,6 @@ var helpers = require('../helpers/index'); * @namespace Chart.Ticks */ module.exports = { - /** - * Namespace to hold generators for different types of ticks - * @namespace Chart.Ticks.generators - */ - generators: { - /** - * Interface for the options provided to the numeric tick generator - * @interface INumericTickGenerationOptions - */ - /** - * The maximum number of ticks to display - * @name INumericTickGenerationOptions#maxTicks - * @type Number - */ - /** - * The distance between each tick. - * @name INumericTickGenerationOptions#stepSize - * @type Number - * @optional - */ - /** - * Forced minimum for the ticks. If not specified, the minimum of the data range is used to calculate the tick minimum - * @name INumericTickGenerationOptions#min - * @type Number - * @optional - */ - /** - * The maximum value of the ticks. If not specified, the maximum of the data range is used to calculate the tick maximum - * @name INumericTickGenerationOptions#max - * @type Number - * @optional - */ - - /** - * Generate a set of linear ticks - * @method Chart.Ticks.generators.linear - * @param generationOptions {INumericTickGenerationOptions} the options used to generate the ticks - * @param dataRange {IRange} the range of the data - * @returns {Array<Number>} array of tick values - */ - linear: function(generationOptions, dataRange) { - var ticks = []; - // To get a "nice" value for the tick spacing, we will use the appropriately named - // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks - // for details. - - var spacing; - if (generationOptions.stepSize && generationOptions.stepSize > 0) { - spacing = generationOptions.stepSize; - } else { - var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); - spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); - } - var niceMin = Math.floor(dataRange.min / spacing) * spacing; - var niceMax = Math.ceil(dataRange.max / spacing) * spacing; - - // If min, max and stepSize is set and they make an evenly spaced scale use it. - if (generationOptions.min && generationOptions.max && generationOptions.stepSize) { - // If very close to our whole number, use it. - if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) { - niceMin = generationOptions.min; - niceMax = generationOptions.max; - } - } - - var numSpaces = (niceMax - niceMin) / spacing; - // If very close to our rounded value, use it. - if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) { - numSpaces = Math.round(numSpaces); - } else { - numSpaces = Math.ceil(numSpaces); - } - - var precision = 1; - if (spacing < 1) { - precision = Math.pow(10, spacing.toString().length - 2); - niceMin = Math.round(niceMin * precision) / precision; - niceMax = Math.round(niceMax * precision) / precision; - } - ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin); - for (var j = 1; j < numSpaces; ++j) { - ticks.push(Math.round((niceMin + j * spacing) * precision) / precision); - } - ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax); - - return ticks; - }, - - /** - * Generate a set of logarithmic ticks - * @method Chart.Ticks.generators.logarithmic - * @param generationOptions {INumericTickGenerationOptions} the options used to generate the ticks - * @param dataRange {IRange} the range of the data - * @returns {Array<Number>} array of tick values - */ - logarithmic: function(generationOptions, dataRange) { - var ticks = []; - var valueOrDefault = helpers.valueOrDefault; - - // Figure out what the max number of ticks we can support it is based on the size of - // the axis area. For now, we say that the minimum tick spacing in pixels must be 50 - // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on - // the graph - var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min)))); - - var endExp = Math.floor(helpers.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)); - 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)); - significand = Math.floor(tickVal / Math.pow(10, exp)); - } - var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1; - - do { - ticks.push(tickVal); - - ++significand; - if (significand === 10) { - significand = 1; - ++exp; - precision = exp >= 0 ? 1 : precision; - } - - tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision; - } while (exp < endExp || (exp === endExp && significand < endSignificand)); - - var lastTick = valueOrDefault(generationOptions.max, tickVal); - ticks.push(lastTick); - - return ticks; - } - }, - /** * Namespace to hold formatters for different types of ticks * @namespace Chart.Ticks.formatters
true
Other
chartjs
Chart.js
33c7d941f7caa5363f68ac2135a66d7c2328e196.json
Add back Chart.Ticks.formatters (#5088)
src/scales/scale.linearbase.js
@@ -1,7 +1,61 @@ 'use strict'; var helpers = require('../helpers/index'); -var Ticks = require('../core/core.ticks'); + +/** + * Generate a set of linear ticks + * @param generationOptions the options used to generate the ticks + * @param dataRange the range of the data + * @returns {Array<Number>} array of tick values + */ +function generateTicks(generationOptions, dataRange) { + var ticks = []; + // To get a "nice" value for the tick spacing, we will use the appropriately named + // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks + // for details. + + var spacing; + if (generationOptions.stepSize && generationOptions.stepSize > 0) { + spacing = generationOptions.stepSize; + } else { + var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); + spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); + } + var niceMin = Math.floor(dataRange.min / spacing) * spacing; + var niceMax = Math.ceil(dataRange.max / spacing) * spacing; + + // If min, max and stepSize is set and they make an evenly spaced scale use it. + if (generationOptions.min && generationOptions.max && generationOptions.stepSize) { + // If very close to our whole number, use it. + if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) { + niceMin = generationOptions.min; + niceMax = generationOptions.max; + } + } + + var numSpaces = (niceMax - niceMin) / spacing; + // If very close to our rounded value, use it. + if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) { + numSpaces = Math.round(numSpaces); + } else { + numSpaces = Math.ceil(numSpaces); + } + + var precision = 1; + if (spacing < 1) { + precision = Math.pow(10, spacing.toString().length - 2); + niceMin = Math.round(niceMin * precision) / precision; + niceMax = Math.round(niceMax * precision) / precision; + } + ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin); + for (var j = 1; j < numSpaces; ++j) { + ticks.push(Math.round((niceMin + j * spacing) * precision) / precision); + } + ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax); + + return ticks; +} + module.exports = function(Chart) { @@ -102,7 +156,7 @@ module.exports = function(Chart) { max: tickOpts.max, stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize) }; - var ticks = me.ticks = Ticks.generators.linear(numericGeneratorOptions, me); + var ticks = me.ticks = generateTicks(numericGeneratorOptions, me); me.handleDirectionalChanges();
true
Other
chartjs
Chart.js
33c7d941f7caa5363f68ac2135a66d7c2328e196.json
Add back Chart.Ticks.formatters (#5088)
src/scales/scale.logarithmic.js
@@ -3,6 +3,58 @@ var helpers = require('../helpers/index'); var Ticks = require('../core/core.ticks'); +/** + * Generate a set of logarithmic ticks + * @param generationOptions the options used to generate the ticks + * @param dataRange the range of the data + * @returns {Array<Number>} array of tick values + */ +function generateTicks(generationOptions, dataRange) { + var ticks = []; + var valueOrDefault = helpers.valueOrDefault; + + // Figure out what the max number of ticks we can support it is based on the size of + // the axis area. For now, we say that the minimum tick spacing in pixels must be 50 + // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on + // the graph + var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min)))); + + var endExp = Math.floor(helpers.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)); + 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)); + significand = Math.floor(tickVal / Math.pow(10, exp)); + } + var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1; + + do { + ticks.push(tickVal); + + ++significand; + if (significand === 10) { + significand = 1; + ++exp; + precision = exp >= 0 ? 1 : precision; + } + + tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision; + } while (exp < endExp || (exp === endExp && significand < endSignificand)); + + var lastTick = valueOrDefault(generationOptions.max, tickVal); + ticks.push(lastTick); + + return ticks; +} + + module.exports = function(Chart) { var defaultConfig = { @@ -167,7 +219,7 @@ module.exports = function(Chart) { min: tickOpts.min, max: tickOpts.max }; - var ticks = me.ticks = Ticks.generators.logarithmic(generationOptions, me); + var ticks = me.ticks = generateTicks(generationOptions, me); // At this point, we need to update our max and min given the tick values since we have expanded the // range of the scale
true
Other
chartjs
Chart.js
33c7d941f7caa5363f68ac2135a66d7c2328e196.json
Add back Chart.Ticks.formatters (#5088)
test/specs/core.ticks.tests.js
@@ -1,4 +1,13 @@ describe('Test tick generators', function() { + // formatters are used as default config values so users want to be able to reference them + it('Should expose formatters api', function() { + expect(typeof Chart.Ticks).toBeDefined(); + expect(typeof Chart.Ticks.formatters).toBeDefined(); + expect(typeof Chart.Ticks.formatters.values).toBe('function'); + expect(typeof Chart.Ticks.formatters.linear).toBe('function'); + expect(typeof Chart.Ticks.formatters.logarithmic).toBe('function'); + }); + it('Should generate linear spaced ticks with correct precision', function() { var chart = window.acquireChart({ type: 'line',
true
Other
chartjs
Chart.js
f0bf3954fe363eda86a3db170063aba34f1be08e.json
Fix issues #4572 and #4703 (#4959) - issue #4572: logarithmic type if all numbers are zero browser crashes "Out of memory" - issue #4703: [BUG] Browser unresponsive on bubble chart with logarithmic axes
src/scales/scale.logarithmic.js
@@ -18,11 +18,9 @@ module.exports = function(Chart) { determineDataLimits: function() { var me = this; var opts = me.options; - var tickOpts = opts.ticks; var chart = me.chart; var data = chart.data; var datasets = data.datasets; - var valueOrDefault = helpers.valueOrDefault; var isHorizontal = me.isHorizontal(); function IDMatches(meta) { return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id; @@ -68,27 +66,23 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var values = valuesPerStack[key]; var value = +me.getRightValue(rawValue); - if (isNaN(value) || meta.data[index].hidden) { + // invalid, hidden and negative values are ignored + if (isNaN(value) || meta.data[index].hidden || value < 0) { return; } - values[index] = values[index] || 0; - - if (opts.relativePoints) { - values[index] = 100; - } else { - // Don't need to split positive and negative since the log scale can't handle a 0 crossing - values[index] += value; - } + values[index] += value; }); } }); helpers.each(valuesPerStack, function(valuesForType) { - var minVal = helpers.min(valuesForType); - var maxVal = helpers.max(valuesForType); - me.min = me.min === null ? minVal : Math.min(me.min, minVal); - me.max = me.max === null ? maxVal : Math.max(me.max, maxVal); + if (valuesForType.length > 0) { + var minVal = helpers.min(valuesForType); + var maxVal = helpers.max(valuesForType); + me.min = me.min === null ? minVal : Math.min(me.min, minVal); + me.max = me.max === null ? maxVal : Math.max(me.max, maxVal); + } }); } else { @@ -97,7 +91,8 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { var value = +me.getRightValue(rawValue); - if (isNaN(value) || meta.data[index].hidden) { + // invalid, hidden and negative values are ignored + if (isNaN(value) || meta.data[index].hidden || value < 0) { return; } @@ -121,6 +116,17 @@ module.exports = function(Chart) { }); } + // Common base implementation to handle ticks.min, ticks.max + this.handleTickRangeOptions(); + }, + handleTickRangeOptions: function() { + var me = this; + var opts = me.options; + var tickOpts = opts.ticks; + var valueOrDefault = helpers.valueOrDefault; + var DEFAULT_MIN = 1; + var DEFAULT_MAX = 10; + me.min = valueOrDefault(tickOpts.min, me.min); me.max = valueOrDefault(tickOpts.max, me.max); @@ -129,8 +135,25 @@ module.exports = function(Chart) { me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1); me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1); } else { - me.min = 1; - me.max = 10; + me.min = DEFAULT_MIN; + me.max = DEFAULT_MAX; + } + } + if (me.min === null) { + me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1); + } + if (me.max === null) { + me.max = me.min !== 0 + ? Math.pow(10, Math.floor(helpers.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))); + } else { + me.minNotZero = DEFAULT_MIN; } } },
true
Other
chartjs
Chart.js
f0bf3954fe363eda86a3db170063aba34f1be08e.json
Fix issues #4572 and #4703 (#4959) - issue #4572: logarithmic type if all numbers are zero browser crashes "Out of memory" - issue #4703: [BUG] Browser unresponsive on bubble chart with logarithmic axes
test/specs/scale.logarithmic.tests.js
@@ -690,142 +690,433 @@ describe('Logarithmic Scale tests', function() { expect(chart.scales.yScale1.getLabelForIndex(0, 2)).toBe(150); }); - it('should get the correct pixel value for a point', function() { - var chart = window.acquireChart({ - type: 'line', - data: { - datasets: [{ - xAxisID: 'xScale', // for the horizontal scale - yAxisID: 'yScale', - data: [{x: 10, y: 10}, {x: 5, y: 5}, {x: 1, y: 1}, {x: 25, y: 25}, {x: 78, y: 78}] - }], + describe('when', function() { + var data = [ + { + data: [1, 39], + stack: 'stack' }, - options: { - scales: { - xAxes: [{ - id: 'xScale', - type: 'logarithmic' - }], + { + data: [1, 39], + stack: 'stack' + }, + ]; + var dataWithEmptyStacks = [ + { + data: [] + }, + { + data: [] + } + ].concat(data); + var config = [ + { + axis: 'y', + firstTick: 1, // start of the axis (minimum) + describe: 'all stacks are defined' + }, + { + axis: 'y', + data: dataWithEmptyStacks, + firstTick: 1, + describe: 'not all stacks are defined' + }, + { + axis: 'y', + scale: { yAxes: [{ - id: 'yScale', - type: 'logarithmic' + ticks: { + min: 0 + } }] - } + }, + firstTick: 0, + describe: 'all stacks are defined and ticks.min: 0' + }, + { + axis: 'y', + data: dataWithEmptyStacks, + scale: { + yAxes: [{ + ticks: { + min: 0 + } + }] + }, + firstTick: 0, + describe: 'not stacks are defined and ticks.min: 0' + }, + { + axis: 'x', + firstTick: 1, + describe: 'all stacks are defined' + }, + { + axis: 'x', + data: dataWithEmptyStacks, + firstTick: 1, + describe: 'not all stacks are defined' + }, + { + axis: 'x', + scale: { + xAxes: [{ + ticks: { + min: 0 + } + }] + }, + firstTick: 0, + describe: 'all stacks are defined and ticks.min: 0' + }, + { + axis: 'x', + data: dataWithEmptyStacks, + scale: { + xAxes: [{ + ticks: { + min: 0 + } + }] + }, + firstTick: 0, + describe: 'not all stacks are defined and ticks.min: 0' + }, + ]; + config.forEach(function(setup) { + var scaleConfig = {}; + var type, chartStart, chartEnd; + + if (setup.axis === 'x') { + type = 'horizontalBar'; + chartStart = 'left'; + chartEnd = 'right'; + } else { + type = 'bar'; + chartStart = 'bottom'; + chartEnd = 'top'; } - }); + scaleConfig[setup.axis + 'Axes'] = [{ + type: 'logarithmic' + }]; + Chart.helpers.extend(scaleConfig, setup.scale); + var description = 'dataset has stack option and ' + setup.describe + + ' and axis is "' + setup.axis + '";'; + describe(description, function() { + it('should define the correct axis limits', function() { + var chart = window.acquireChart({ + type: type, + data: { + labels: ['category 1', 'category 2'], + datasets: setup.data || data, + }, + options: { + scales: scaleConfig + } + }); - var xScale = chart.scales.xScale; - expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight - expect(xScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(37 + 6); // left + paddingLeft + lineSpace - expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(278 + 6 / 2); // halfway - expect(xScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(37 + 6); // 0 is invalid, put it on the left. + var axisID = setup.axis + '-axis-0'; + var scale = chart.scales[axisID]; + var firstTick = setup.firstTick; + var lastTick = 80; // last tick (should be first available tick after: 2 * 39) + var start = chart.chartArea[chartStart]; + var end = chart.chartArea[chartEnd]; - expect(xScale.getValueForPixel(495)).toBeCloseToPixel(80); - expect(xScale.getValueForPixel(48)).toBeCloseTo(1, 1e-4); - expect(xScale.getValueForPixel(278)).toBeCloseTo(10, 1e-4); + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); - var yScale = chart.scales.yScale; - expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop - expect(yScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom - expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(246); // halfway - expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // 0 is invalid. force it on bottom - - expect(yScale.getValueForPixel(32)).toBeCloseTo(80, 1e-4); - expect(yScale.getValueForPixel(484)).toBeCloseTo(1, 1e-4); - expect(yScale.getValueForPixel(246)).toBeCloseTo(10, 1e-4); + expect(scale.getValueForPixel(start)).toBeCloseTo(firstTick, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + + chart.scales[axisID].options.ticks.reverse = true; // Reverse mode + chart.update(); + + // chartArea might have been resized in update + start = chart.chartArea[chartEnd]; + end = chart.chartArea[chartStart]; + + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); + + expect(scale.getValueForPixel(start)).toBeCloseTo(firstTick, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + }); + }); + }); }); - it('should get the correct pixel value for a point when 0 values are present or min: 0', function() { + describe('when', 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}], + dataset: [], firstTick: 1, // value of the first tick - lastTick: 80 + lastTick: 10, // value of the last tick + describe: 'empty dataset, without ticks.min/max' + }, + { + dataset: [], + scale: {stacked: true}, + firstTick: 1, + lastTick: 10, + describe: 'empty dataset, without ticks.min/max, with stacked: true' + }, + { + data: { + datasets: [ + {data: [], stack: 'stack'}, + {data: [], stack: 'stack'}, + ], + }, + type: 'bar', + firstTick: 1, + lastTick: 10, + describe: 'empty dataset with stack option, without ticks.min/max' + }, + { + data: { + datasets: [ + {data: [], stack: 'stack'}, + {data: [], stack: 'stack'}, + ], + }, + type: 'horizontalBar', + firstTick: 1, + lastTick: 10, + describe: 'empty dataset with stack option, without ticks.min/max' + }, + { + dataset: [], + scale: {ticks: {min: 1}}, + firstTick: 1, + lastTick: 10, + describe: 'empty dataset, ticks.min: 1, without ticks.max' + }, + { + dataset: [], + scale: {ticks: {max: 80}}, + firstTick: 1, + lastTick: 80, + describe: 'empty dataset, ticks.max: 80, without ticks.min' + }, + { + dataset: [], + scale: {ticks: {max: 0.8}}, + firstTick: 0.01, + lastTick: 0.8, + describe: 'empty dataset, ticks.max: 0.8, without ticks.min' + }, + { + dataset: [{x: 10, y: 10}, {x: 5, y: 5}, {x: 1, y: 1}, {x: 25, y: 25}, {x: 78, y: 78}], + firstTick: 1, + lastTick: 80, + describe: 'dataset min point {x: 1, y: 1}, max point {x:78, y:78}' + }, + ]; + config.forEach(function(setup) { + var axes = [ + { + id: 'x', // horizontal scale + start: 'left', + end: 'right' + }, + { + id: 'y', // vertical scale + start: 'bottom', + end: 'top' + } + ]; + axes.forEach(function(axis) { + var expectation = 'min = ' + setup.firstTick + ', max = ' + setup.lastTick; + describe(setup.describe + ' and axis is "' + axis.id + '"; expect: ' + expectation + ';', function() { + beforeEach(function() { + var xScaleConfig = { + type: 'logarithmic', + }; + var yScaleConfig = { + type: 'logarithmic', + }; + var data = setup.data || { + datasets: [{ + data: setup.dataset + }], + }; + Chart.helpers.extend(xScaleConfig, setup.scale); + Chart.helpers.extend(yScaleConfig, setup.scale); + Chart.helpers.extend(data, setup.data || {}); + this.chart = window.acquireChart({ + type: 'line', + data: data, + options: { + scales: { + xAxes: [xScaleConfig], + yAxes: [yScaleConfig] + } + } + }); + }); + + it('should get the correct pixel value for a point', function() { + var chart = this.chart; + var axisID = axis.id + '-axis-0'; + var scale = chart.scales[axisID]; + var firstTick = setup.firstTick; + var lastTick = setup.lastTick; + var start = chart.chartArea[axis.start]; + var end = chart.chartArea[axis.end]; + + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); + expect(scale.getPixelForValue(0, 0, 0)).toBe(start); // 0 is invalid, put it at the start. + + expect(scale.getValueForPixel(start)).toBeCloseTo(firstTick, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + + chart.scales[axisID].options.ticks.reverse = true; // Reverse mode + chart.update(); + + // chartArea might have been resized in update + start = chart.chartArea[axis.end]; + end = chart.chartArea[axis.start]; + + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); + + expect(scale.getValueForPixel(start)).toBeCloseTo(firstTick, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + }); + }); + }); + }); + }); + + describe('when', function() { + var config = [ + { + dataset: [], + scale: {ticks: {min: 0}}, + firstTick: 1, // value of the first tick + lastTick: 10, // value of the last tick + describe: 'empty dataset, ticks.min: 0, without ticks.max' + }, + { + dataset: [], + scale: {ticks: {min: 0, max: 80}}, + firstTick: 1, + lastTick: 80, + describe: 'empty dataset, ticks.min: 0, ticks.max: 80' + }, + { + dataset: [], + scale: {ticks: {min: 0, max: 0.8}}, + firstTick: 0.1, + lastTick: 0.8, + describe: 'empty dataset, ticks.min: 0, ticks.max: 0.8' + }, + { + 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, + lastTick: 80, + describe: 'dataset min point {x: 0, y: 0}, max point {x:78, y:78}, minNotZero {x: 1.2, y: 1.2}' }, { 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 + lastTick: 80, + describe: 'dataset min point {x: 0, y: 0}, max point {x:78, y:78}, minNotZero {x: 6.3, y: 6.3}' }, { 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 + lastTick: 80, + describe: 'dataset min point {x: 1.2, y: 1.2}, max point {x:78, y:78}, ticks.min: 0' }, { 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 + lastTick: 80, + describe: 'dataset min point {x: 6.3, y: 6.3}, max point {x:78, y:78}, ticks.min: 0' }, ]; - 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 = [ + config.forEach(function(setup) { + var axes = [ { - id: 'x-axis-0', // horizontal scale - axis: 'xAxes', - start: chartArea.left, - end: chartArea.right + id: 'x', // horizontal scale + start: 'left', + end: 'right' }, { - id: 'y-axis-0', // vertical scale - axis: 'yAxes', - start: chartArea.bottom, - end: chartArea.top + id: 'y', // vertical scale + start: 'bottom', + end: '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); + axes.forEach(function(axis) { + var expectation = 'min = 0, max = ' + setup.lastTick + ', first tick = ' + setup.firstTick; + describe(setup.describe + ' and axis is "' + axis.id + '"; expect: ' + expectation + ';', function() { + beforeEach(function() { + var xScaleConfig = { + type: 'logarithmic', + }; + var yScaleConfig = { + type: 'logarithmic', + }; + var data = setup.data || { + datasets: [{ + data: setup.dataset + }], + }; + Chart.helpers.extend(xScaleConfig, setup.scale); + Chart.helpers.extend(yScaleConfig, setup.scale); + Chart.helpers.extend(data, setup.data || {}); + this.chart = window.acquireChart({ + type: 'line', + data: data, + options: { + scales: { + xAxes: [xScaleConfig], + yAxes: [yScaleConfig] + } + } + }); + }); + + it('should get the correct pixel value for a point', function() { + var chart = this.chart; + var axisID = axis.id + '-axis-0'; + var scale = chart.scales[axisID]; + var firstTick = setup.firstTick; + var lastTick = setup.lastTick; + var fontSize = chart.options.defaultFontSize; + var start = chart.chartArea[axis.start]; + var end = chart.chartArea[axis.end]; + var sign = scale.isHorizontal() ? 1 : -1; + + expect(scale.getPixelForValue(0, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start + sign * fontSize); + + expect(scale.getValueForPixel(start)).toBeCloseTo(0, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + expect(scale.getValueForPixel(start + sign * fontSize)).toBeCloseTo(firstTick, 4); + + chart.scales[axisID].options.ticks.reverse = true; // Reverse mode + chart.update(); + + // chartArea might have been resized in update + start = chart.chartArea[axis.end]; + end = chart.chartArea[axis.start]; + + expect(scale.getPixelForValue(0, 0, 0)).toBe(start); + expect(scale.getPixelForValue(lastTick, 0, 0)).toBe(end); + expect(scale.getPixelForValue(firstTick, 0, 0)).toBe(start - sign * fontSize, 4); + + expect(scale.getValueForPixel(start)).toBeCloseTo(0, 4); + expect(scale.getValueForPixel(end)).toBeCloseTo(lastTick, 4); + expect(scale.getValueForPixel(start - sign * fontSize)).toBeCloseTo(firstTick, 4); + }); + }); }); }); });
true
Other
chartjs
Chart.js
b835df02cd05830fb734806f3af27fa43cc5674c.json
Add Angular2+ libraries for Chart.js in docs (#5006)
docs/notes/extensions.md
@@ -25,7 +25,12 @@ In addition, many plugins can be found on the [npm registry](https://www.npmjs.c ## Integrations -### Angular +### Angular (v2+) + + - <a href="https://github.com/emn178/angular2-chartjs" target="_blank">emn178/angular2-chartjs</a> + - <a href="https://github.com/valor-software/ng2-charts" target="_blank">valor-software/ng2-charts</a> + +### Angular (v1) - <a href="https://github.com/jtblin/angular-chart.js" target="_blank">angular-chart.js</a> - <a href="https://github.com/carlcraig/tc-angular-chartjs" target="_blank">tc-angular-chartjs</a> - <a href="https://github.com/petermelias/angular-chartjs" target="_blank">angular-chartjs</a>
false
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/SUMMARY.md
@@ -7,6 +7,7 @@ * [Usage](getting-started/usage.md) * [General](general/README.md) * [Responsive](general/responsive.md) + * [Pixel Ratio](general/device-pixel-ratio.md) * [Interactions](general/interactions/README.md) * [Events](general/interactions/events.md) * [Modes](general/interactions/modes.md)
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/axes/cartesian/README.md
@@ -75,13 +75,13 @@ var myChart = new Chart(ctx, { data: { datasets: [{ data: [20, 50, 100, 75, 25, 0], - label: 'Left dataset' + label: 'Left dataset', // This binds the dataset to the left y axis yAxisID: 'left-y-axis' }, { - data: [0.1, 0.5, 1.0, 2.0, 1.5, 0] - label: 'Right dataset' + data: [0.1, 0.5, 1.0, 2.0, 1.5, 0], + label: 'Right dataset', // This binds the dataset to the right y axis yAxisID: 'right-y-axis',
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/axes/cartesian/linear.md
@@ -20,7 +20,7 @@ The following options are provided by the linear scale. They are all located in Given the number of axis range settings, it is important to understand how they all interact with each other. -The `suggestedMax` and `suggestedMin` settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaing the auto fit behaviour. +The `suggestedMax` and `suggestedMin` settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaining the auto fit behaviour. ```javascript let minDataValue = Math.min(mostNegativeValue, options.ticks.suggestedMin); @@ -43,7 +43,7 @@ let chart = new Chart(ctx, { scales: { yAxes: [{ ticks: { - suggestedMin: 50 + suggestedMin: 50, suggestedMax: 100 } }]
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/axes/radial/linear.md
@@ -36,7 +36,7 @@ The following options are provided by the linear scale. They are all located in Given the number of axis range settings, it is important to understand how they all interact with each other. -The `suggestedMax` and `suggestedMin` settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaing the auto fit behaviour. +The `suggestedMax` and `suggestedMin` settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaining the auto fit behaviour. ```javascript let minDataValue = Math.min(mostNegativeValue, options.ticks.suggestedMin); @@ -58,7 +58,7 @@ let chart = new Chart(ctx, { options: { scale: { ticks: { - suggestedMin: 50 + suggestedMin: 50, suggestedMax: 100 } }
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/axes/styling.md
@@ -35,8 +35,8 @@ The tick configuration is nested under the scale configuration in the `ticks` ke | `fontSize` | `Number` | `12` | Font size for the tick labels. | `fontStyle` | `String` | `'normal'` | Font style for the tick labels, follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit). | `reverse` | `Boolean` | `false` | Reverses order of tick labels. -| `minor` | `object` | `{}` | Minor ticks configuration. Ommited options are inherited from options above. -| `major` | `object` | `{}` | Major ticks configuration. Ommited options are inherited from options above. +| `minor` | `object` | `{}` | Minor ticks configuration. Omitted options are inherited from options above. +| `major` | `object` | `{}` | Major ticks configuration. Omitted options are inherited from options above. ## Minor Tick Configuration The minorTick configuration is nested under the ticks configuration in the `minor` key. It defines options for the minor tick marks that are generated by the axis. Omitted options are inherited from `ticks` configuration.
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/charts/line.md
@@ -119,7 +119,7 @@ The `data` property of a dataset for a line chart can be passed in two formats. data: [20, 10] ``` -When the `data` array is an array of numbers, the x axis is generally a [category](../axes/cartesian/category.md#Category Axis). The points are placed onto the axis using their position in the array. When a line chart is created with a category axis, the `labels` property of the data object must be specified. +When the `data` array is an array of numbers, the x axis is generally a [category](../axes/cartesian/category.md#category-cartesian-axis). The points are placed onto the axis using their position in the array. When a line chart is created with a category axis, the `labels` property of the data object must be specified. ### Point[]
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/configuration/tooltip.md
@@ -30,7 +30,7 @@ The tooltip configuration is passed into the `options.tooltips` namespace. The g | `footerFontSize` | `Number` | `12` | Footer font size | `footerFontStyle` | `String` | `'bold'` | Footer font style | `footerFontColor` | `Color` | `'#fff'` | Footer font color -| `footerSpacing` | `Number` | `2` | Spacing to add to top and bottom of each fotter line. +| `footerSpacing` | `Number` | `2` | Spacing to add to top and bottom of each footer line. | `footerMarginTop` | `Number` | `6` | Margin to add before drawing the footer. | `xPadding` | `Number` | `6` | Padding to add on left and right of tooltip. | `yPadding` | `Number` | `6` | Padding to add on top and bottom of tooltip.
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/developers/axes.md
@@ -78,14 +78,14 @@ To work with Chart.js, custom scale types must implement the following interface // Get the pixel (x coordinate for horizontal axis, y coordinate for vertical axis) for a given value // @param index: index into the ticks array - // @param includeOffset: if true, get the pixel halway between the given tick and the next + // @param includeOffset: if true, get the pixel halfway between the given tick and the next getPixelForTick: function(index, includeOffset) {}, // Get the pixel (x coordinate for horizontal axis, y coordinate for vertical axis) for a given value // @param value : the value to get the pixel for // @param index : index into the data array of the value // @param datasetIndex : index of the dataset the value comes from - // @param includeOffset : if true, get the pixel halway between the given tick and the next + // @param includeOffset : if true, get the pixel halfway between the given tick and the next getPixelForValue: function(value, index, datasetIndex, includeOffset) {} // Get the value for a given pixel (x coordinate for horizontal axis, y coordinate for vertical axis)
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/getting-started/README.md
@@ -40,4 +40,4 @@ var chart = new Chart(ctx, { It's that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more. -There are many examples of Chart.js that are available in the `/samples` folder of `Chart.js.zip` that is attatched to every [release](https://github.com/chartjs/Chart.js/releases). \ No newline at end of file +There are many examples of Chart.js that are available in the `/samples` folder of `Chart.js.zip` that is attached to every [release](https://github.com/chartjs/Chart.js/releases). \ No newline at end of file
true
Other
chartjs
Chart.js
9a7182ba36d3a9f1e73f2d2cdc0011ae7837d672.json
Fix typos and broken links in the docs (#5010)
docs/getting-started/installation.md
@@ -36,7 +36,7 @@ https://www.jsdelivr.com/package/npm/chart.js?path=dist You can download the latest version of [Chart.js on GitHub](https://github.com/chartjs/Chart.js/releases/latest). -If you download or clone the repository, you must [build](../developers/contributing.md#building-chartjs) Chart.js to generate the dist files. Chart.js no longer comes with prebuilt release versions, so an alternative option to downloading the repo is **strongly** advised. +If you download or clone the repository, you must [build](../developers/contributing.md#building-and-testing) Chart.js to generate the dist files. Chart.js no longer comes with prebuilt release versions, so an alternative option to downloading the repo is **strongly** advised. # Selecting the Correct Build
true
Other
chartjs
Chart.js
73729877546e9bb0445e72a97978860685ccb0aa.json
Add scaleLabel to core.scale
src/core/core.scale.js
@@ -20,6 +20,20 @@ offsetGridLines: false, }, + // scale label + scaleLabel: { + fontColor: '#666', + fontFamily: 'Helvetica Neue', + fontSize: 12, + fontStyle: 'normal', + + // actual label + labelString: '', + + // display property + show: false, + }, + // label settings ticks: { show: true,
false
Other
chartjs
Chart.js
407eb846d0459bb3cdd4383716a256f882951761.json
Update v1.x readme to reflect release status
README.md
@@ -5,6 +5,27 @@ *Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org) +## v2.0 Development +The next generation and release of Chart.js has been well under way this year and we are very close to releasing some amazing new features including, but not limited to: +- Rewritten, optimized, and unit-tested +- New and improved scales (log, time, linear, category, multiple scales) +- Improved responsiveness and resizing +- Powerful new API for adding, removing, changing, and updating data +- Animations on all elements, colors and tooltips +- Powerful customization when you need it. Automatic and dynamic when you don't. +- Excellent support for modern frameworks and modular build systems. +- Even more extensible via new element controllers, combo chart support, and hook system +- Bug fixes not addressed in 1.x, and much, much more... + +#####Contributing to 2.0 +Submit PR's to the v2.0-dev branch. + +#####Building and Testing +`gulp build`, `gulp test` + +## v1.x Status: Feature Complete +We are now treating v1.x to be feature complete. PR's for bug fixes are welcome, but we urge any open PR's for features to 1.x to be refactored and resubmitted for v2.x (if the feature has not already been implemented). + ## Documentation You can find documentation at [chartjs.org/docs](http://www.chartjs.org/docs/). The markdown files that build the site are available under `/docs`. Please note - in some of the json examples of configuration you might notice some liquid tags - this is just for the generating the site html, please disregard.
false
Other
chartjs
Chart.js
8c94ae0441205eb90d493b728893bca7f491712f.json
Ensure bar width at least 1px
src/scales/scale.category.js
@@ -87,9 +87,9 @@ var baseWidth = Math.max(this.calculateBaseWidth() - (this.options.stacked ? 0 : (barDatasetCount - 1) * this.options.spacing), 1); if (this.options.stacked) { - return baseWidth; + return Math.max(baseWidth, 1); } - return (baseWidth / barDatasetCount); + return Math.max((baseWidth / barDatasetCount), 1); }, calculateBarX: function(barDatasetCount, datasetIndex, elementIndex) { var xWidth = this.calculateBaseWidth(),
true
Other
chartjs
Chart.js
8c94ae0441205eb90d493b728893bca7f491712f.json
Ensure bar width at least 1px
src/scales/scale.time.js
@@ -229,9 +229,9 @@ var baseWidth = this.calculateBaseWidth() - ((barDatasetCount - 1) * this.options.spacing); if (this.options.stacked) { - return baseWidth; + return Math.max(baseWidth, 1); } - return (baseWidth / barDatasetCount); + return Math.max((baseWidth / barDatasetCount), 1); }, calculateBarX: function(barDatasetCount, datasetIndex, elementIndex) {
true
Other
chartjs
Chart.js
814c2d7ffa5581804687976be9047e231fd6350a.json
Remove responsive file since it is not necessary
src/core/core.responsive.js
@@ -1,29 +0,0 @@ -(function() { - - "use strict"; - - //Declare root variable - window in the browser, global on the server - var root = this, - previous = root.Chart, - helpers = Chart.helpers; - - - // Attach global event to resize each chart instance when the browser resizes - helpers.addEvent(window, "resize", (function() { - // Basic debounce of resize function so it doesn't hurt performance when resizing browser. - var timeout; - return function() { - clearTimeout(timeout); - timeout = setTimeout(function() { - helpers.each(Chart.instances, function(instance) { - // If the responsive flag is set in the chart instance config - // Cascade the resize event down to the chart. - if (instance.options.responsive) { - instance.resize(); - } - }); - }, 16); - }; - })()); - -}).call(this);
false
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
docs/01-Scales.md
@@ -41,7 +41,7 @@ afterUpdate | Function | undefined | Callback that runs at the end of the update *gridLines*.zeroLineColor | Color | "rgba(0, 0, 0, 0.25)" | Stroke color of the grid line for the first index (index 0). *gridLines*.offsetGridLines | Boolean | false | If true, offset labels from grid lines. **scaleLabel** | Object | | Title for the entire axis. -*scaleLabel*.display | Boolean | false | +*scaleLabel*.display | Boolean | false | *scaleLabel*.labelString | String | "" | The text for the title. (i.e. "# of People", "Response Choices") *scaleLabel*.fontColor | Color | "#666" | Font color for the scale title. *scaleLabel*.fontFamily| String | "Helvetica Neue" | Font family for the scale title, follows CSS font-family options. @@ -57,12 +57,13 @@ afterUpdate | Function | undefined | Callback that runs at the end of the update *ticks*.minRotation | Number | 20 | *currently not-implemented* Minimum rotation for tick labels when condensing is necessary. *Note: Only applicable to horizontal scales.* *ticks*.maxTicksLimit | Number | 11 | Maximum number of ticks and gridlines to show. If not defined, it will limit to 11 ticks but will show all gridlines. *ticks*.padding | Number | 10 | Padding between the tick label and the axis. *Note: Only applicable to horizontal scales.* +*ticks*.labelOffset | Number | 0 | Distance in pixels to offset the label from the centre point of the tick (in the y direction for the x axis, and the x direction for the y axis). *Note: this can cause labels at the edges to be cropped by the edge of the canvas* *ticks*.mirror | Boolean | false | Flips tick labels around axis, displaying the labels inside the chart instead of outside. *Note: Only applicable to vertical scales.* *ticks*.reverse | Boolean | false | Reverses order of tick labels. *ticks*.display | Boolean | true | If true, show the ticks. *ticks*.suggestedMin | Number | - | User defined minimum number for the scale, overrides minimum value *except for if* it is higher than the minimum value. *ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value. -*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value. +*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value. *ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value *ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what *ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart. @@ -181,7 +182,7 @@ The time scale extends the core scale class with the following tick template: // string - By default, no rounding is applied. To round, set to a supported time unit eg. 'week', 'month', 'year', etc. round: false, - + // Moment js for each of the units. Replaces `displayFormat` // To override, use a pattern string from http://momentjs.com/docs/#/displaying/format/ displayFormats: { @@ -310,4 +311,4 @@ Chart.scaleService.updateScaleDefaults('linear', { min: 0 } }) -``` \ No newline at end of file +```
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
src/core/core.scale.js
@@ -41,6 +41,7 @@ module.exports = function(Chart) { display: true, autoSkip: true, autoSkipPadding: 0, + labelOffset: 0, callback: function(value) { return '' + value; } @@ -557,7 +558,7 @@ module.exports = function(Chart) { if (this.options.ticks.display) { this.ctx.save(); - this.ctx.translate(xLabelValue, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - tl : this.top + tl); + this.ctx.translate(xLabelValue + this.options.ticks.labelOffset, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - tl : this.top + tl); this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1); this.ctx.font = tickLabelFont; this.ctx.textAlign = (isRotated) ? "right" : "center"; @@ -650,7 +651,7 @@ module.exports = function(Chart) { } } - this.ctx.translate(xLabelValue, yLabelValue); + this.ctx.translate(xLabelValue, yLabelValue + this.options.ticks.labelOffset); this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1); this.ctx.font = tickLabelFont; this.ctx.textBaseline = "middle";
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/core.helpers.tests.js
@@ -239,7 +239,8 @@ describe('Core helper tests', function() { display: true, callback: merged.scales.yAxes[1].ticks.callback, // make it nicer, then check explicitly below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0, }, type: 'linear' }, { @@ -271,7 +272,8 @@ describe('Core helper tests', function() { display: true, callback: merged.scales.yAxes[2].ticks.callback, // make it nicer, then check explicitly below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0, }, type: 'linear' }]
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/scale.category.tests.js
@@ -38,7 +38,8 @@ describe('Category scale tests', function() { display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0 } });
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/scale.linear.tests.js
@@ -49,7 +49,8 @@ describe('Linear Scale', function() { display: true, callback: defaultConfig.ticks.callback, // make this work nicer, then check below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0 } });
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/scale.logarithmic.tests.js
@@ -44,7 +44,8 @@ describe('Logarithmic Scale tests', function() { display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0 }, });
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/scale.radialLinear.tests.js
@@ -63,7 +63,8 @@ describe('Test the radial linear scale', function() { display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below autoSkip: true, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0 }, });
true
Other
chartjs
Chart.js
7ee5af81af59e66a2f6e11c04cdb054c8cef934e.json
Add labelOffset option to scales
test/scale.time.tests.js
@@ -71,7 +71,8 @@ describe('Time scale tests', function() { display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below, autoSkip: false, - autoSkipPadding: 0 + autoSkipPadding: 0, + labelOffset: 0 }, time: { parser: false,
true
Other
chartjs
Chart.js
5a79b42a460e95e6adbd27f03d333183f6c0f2c1.json
Update CDN on bump
gulpfile.js
@@ -116,7 +116,8 @@ function bumpTask(complete) { choices: choices }, function(res) { var increment = res.version.split(' ')[0], - newVersion = semver.inc(package.version, increment); + newVersion = semver.inc(package.version, increment), + oldVersion = package.version; // Set the new versions into the bower/package object package.version = newVersion; @@ -125,6 +126,13 @@ function bumpTask(complete) { // Write these to their own files, then build the output fs.writeFileSync('package.json', JSON.stringify(package, null, 2)); fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2)); + + var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js', + newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js'; + + gulp.src(['./README.md']) + .pipe(replace(oldCDN, newCDN)) + .pipe(gulp.dest('./')); complete(); });
false
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
src/core/core.scale.js
@@ -33,6 +33,7 @@ module.exports = function(Chart) { // label settings ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10, @@ -190,7 +191,7 @@ module.exports = function(Chart) { var lastWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width; var firstRotated; - this.labelRotation = 0; + this.labelRotation = this.options.ticks.minRotation || 0; this.paddingRight = 0; this.paddingLeft = 0;
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/core.helpers.tests.js
@@ -231,6 +231,7 @@ describe('Core helper tests', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10, @@ -262,6 +263,7 @@ describe('Core helper tests', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/scale.category.tests.js
@@ -30,6 +30,7 @@ describe('Category scale tests', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/scale.linear.tests.js
@@ -41,6 +41,7 @@ describe('Linear Scale', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10, @@ -633,7 +634,7 @@ describe('Linear Scale', function() { } } }); - + var xScale = chartInstance.scales.xScale0; expect(xScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(501); // right - paddingRight expect(xScale.getPixelForValue(-1, 0, 0)).toBeCloseToPixel(41); // left + paddingLeft
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/scale.logarithmic.tests.js
@@ -36,6 +36,7 @@ describe('Logarithmic Scale tests', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/scale.radialLinear.tests.js
@@ -54,6 +54,7 @@ describe('Test the radial linear scale', function() { backdropPaddingY: 2, backdropPaddingX: 2, beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
3bef974c25e61c7f8b45fd105d59aca363906acd.json
Add minRotation support
test/scale.time.tests.js
@@ -63,6 +63,7 @@ describe('Time scale tests', function() { }, ticks: { beginAtZero: false, + minRotation: 0, maxRotation: 50, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
ebffa52dc2ad3c2fc5a1b3f48e4fb8596334a9ee.json
allow callback or userCallback in the time scale
src/scales/scale.time.js
@@ -299,9 +299,11 @@ module.exports = function(Chart) { // Function to format an individual tick mark tickFormatFunction: function tickFormatFunction(tick, index, ticks) { var formattedTick = tick.format(this.displayFormat); + var tickOpts = this.options.ticks; + var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback); - if (this.options.ticks.userCallback) { - return this.options.ticks.userCallback(formattedTick, index, ticks); + if (callback) { + return callback(formattedTick, index, ticks); } else { return formattedTick; }
false
Other
chartjs
Chart.js
c276926c14a0f37e71f29f810e66354d7fca1e62.json
Update CDN in Readme to 2.1.2
README.md
@@ -16,7 +16,7 @@ To install via npm / bower: npm install chart.js --save bower install Chart.js --save ``` -CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.1/Chart.min.js +CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.2/Chart.min.js ## Documentation
false
Other
chartjs
Chart.js
9cfda5a8198cee1d7d77a7732a1fd2c0beb0c93d.json
Update CDN in README to 2.1.1
README.md
@@ -16,7 +16,7 @@ To install via npm / bower: npm install chart.js --save bower install Chart.js --save ``` -CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.min.js +CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.1/Chart.min.js ## Documentation
false
Other
chartjs
Chart.js
09bcac9b5c699c75909b77dc40dc40b5a3af1030.json
Reduce element.point size
src/elements/element.point.js
@@ -61,80 +61,86 @@ module.exports = function(Chart) { var radius = vm.radius; var xOffset, - yOffset; + yOffset, + beginPath = "beginPath", + moveTo = "moveTo", + lineTo = "lineTo", + closePath = "closePath", + fillRect = "fillRect", + strokeRect = "strokeRect"; switch (pointStyle) { // Default includes circle default: - ctx.beginPath(); + ctx[beginPath](); ctx.arc(x, y, radius, 0, Math.PI * 2); - ctx.closePath(); + ctx[closePath](); ctx.fill(); break; case 'triangle': - ctx.beginPath(); + ctx[beginPath](); var edgeLength = 3 * radius / Math.sqrt(3); var height = edgeLength * Math.sqrt(3) / 2; - ctx.moveTo(x - edgeLength / 2, y + height / 3); - ctx.lineTo(x + edgeLength / 2, y + height / 3); - ctx.lineTo(x, y - 2 * height / 3); - ctx.closePath(); + ctx[moveTo](x - edgeLength / 2, y + height / 3); + ctx[lineTo](x + edgeLength / 2, y + height / 3); + ctx[lineTo](x, y - 2 * height / 3); + ctx[closePath](); ctx.fill(); break; case 'rect': - ctx.fillRect(x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); - ctx.strokeRect(x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); + ctx[fillRect](x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); + ctx[strokeRect](x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); break; case 'rectRot': ctx.translate(x, y); ctx.rotate(Math.PI / 4); - ctx.fillRect(-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); - ctx.strokeRect(-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); + ctx[fillRect](-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); + ctx[strokeRect](-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius); ctx.setTransform(1, 0, 0, 1, 0, 0); break; case 'cross': - ctx.beginPath(); - ctx.moveTo(x, y + radius); - ctx.lineTo(x, y - radius); - ctx.moveTo(x - radius, y); - ctx.lineTo(x + radius, y); - ctx.closePath(); + ctx[beginPath](); + ctx[moveTo](x, y + radius); + ctx[lineTo](x, y - radius); + ctx[moveTo](x - radius, y); + ctx[lineTo](x + radius, y); + ctx[closePath](); break; case 'crossRot': - ctx.beginPath(); + ctx[beginPath](); xOffset = Math.cos(Math.PI / 4) * radius; yOffset = Math.sin(Math.PI / 4) * radius; - ctx.moveTo(x - xOffset, y - yOffset); - ctx.lineTo(x + xOffset, y + yOffset); - ctx.moveTo(x - xOffset, y + yOffset); - ctx.lineTo(x + xOffset, y - yOffset); - ctx.closePath(); + ctx[moveTo](x - xOffset, y - yOffset); + ctx[lineTo](x + xOffset, y + yOffset); + ctx[moveTo](x - xOffset, y + yOffset); + ctx[lineTo](x + xOffset, y - yOffset); + ctx[closePath](); break; case 'star': - ctx.beginPath(); - ctx.moveTo(x, y + radius); - ctx.lineTo(x, y - radius); - ctx.moveTo(x - radius, y); - ctx.lineTo(x + radius, y); + ctx[beginPath](); + ctx[moveTo](x, y + radius); + ctx[lineTo](x, y - radius); + ctx[moveTo](x - radius, y); + ctx[lineTo](x + radius, y); xOffset = Math.cos(Math.PI / 4) * radius; yOffset = Math.sin(Math.PI / 4) * radius; - ctx.moveTo(x - xOffset, y - yOffset); - ctx.lineTo(x + xOffset, y + yOffset); - ctx.moveTo(x - xOffset, y + yOffset); - ctx.lineTo(x + xOffset, y - yOffset); - ctx.closePath(); + ctx[moveTo](x - xOffset, y - yOffset); + ctx[lineTo](x + xOffset, y + yOffset); + ctx[moveTo](x - xOffset, y + yOffset); + ctx[lineTo](x + xOffset, y - yOffset); + ctx[closePath](); break; case 'line': - ctx.beginPath(); - ctx.moveTo(x - radius, y); - ctx.lineTo(x + radius, y); - ctx.closePath(); + ctx[beginPath](); + ctx[moveTo](x - radius, y); + ctx[lineTo](x + radius, y); + ctx[closePath](); break; case 'dash': - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.lineTo(x + radius, y); - ctx.closePath(); + ctx[beginPath](); + ctx[moveTo](x, y); + ctx[lineTo](x + radius, y); + ctx[closePath](); break; }
false
Other
chartjs
Chart.js
8f6f8820686cc57ab0ee3139c4d7d7c2c13b7014.json
Fix jshint issue
src/elements/element.point.js
@@ -21,7 +21,7 @@ module.exports = function(Chart) { Chart.elements.Point = Chart.Element.extend({ inRange: function(mouseX, mouseY) { var vm = this._view; - return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false + return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false; }, inLabelRange: function(mouseX) { var vm = this._view;
false
Other
chartjs
Chart.js
4068836a42962c306a79f8baec099df0d0f4377f.json
Reduce core.title.js size
src/core/core.title.js
@@ -16,6 +16,7 @@ module.exports = function(Chart) { text: '' }; + var noop = helpers.noop; Chart.Title = Chart.Element.extend({ initialize: function(config) { @@ -28,7 +29,7 @@ module.exports = function(Chart) { // These methods are ordered by lifecyle. Utilities then follow. - beforeUpdate: helpers.noop, + beforeUpdate: noop, update: function(maxWidth, maxHeight, margins) { // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -58,11 +59,11 @@ module.exports = function(Chart) { return this.minSize; }, - afterUpdate: helpers.noop, + afterUpdate: noop, // - beforeSetDimensions: helpers.noop, + beforeSetDimensions: noop, setDimensions: function() { // Set the unconstrained dimension before label rotation if (this.isHorizontal()) { @@ -90,103 +91,83 @@ module.exports = function(Chart) { height: 0 }; }, - afterSetDimensions: helpers.noop, + afterSetDimensions: noop, // - beforeBuildLabels: helpers.noop, - buildLabels: helpers.noop, - afterBuildLabels: helpers.noop, + beforeBuildLabels: noop, + buildLabels: noop, + afterBuildLabels: noop, // - beforeFit: helpers.noop, + beforeFit: noop, fit: function() { - var ctx = this.ctx; - var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize); - var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle); - var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily); - var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily); + var ctx = this.ctx, + valueOrDefault = helpers.getValueOrDefault, + opts = this.options, + globalDefaults = Chart.defaults.global, + display = opts.display, + fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize), + minSize = this.minSize; - // Width if (this.isHorizontal()) { - this.minSize.width = this.maxWidth; // fill all the width + minSize.width = this.maxWidth; // fill all the width + minSize.height = display ? fontSize + (opts.padding * 2) : 0; } else { - this.minSize.width = 0; + minSize.width = display ? fontSize + (opts.padding * 2) : 0; + minSize.height = this.maxHeight; // fill all the height } - // height - if (this.isHorizontal()) { - this.minSize.height = 0; - } else { - this.minSize.height = this.maxHeight; // fill all the height - } - - // Increase sizes here - if (this.isHorizontal()) { - - // Title - if (this.options.display) { - this.minSize.height += fontSize + (this.options.padding * 2); - } - } else { - if (this.options.display) { - this.minSize.width += fontSize + (this.options.padding * 2); - } - } - - this.width = this.minSize.width; - this.height = this.minSize.height; + this.width = minSize.width; + this.height = minSize.height; }, - afterFit: helpers.noop, + afterFit: noop, // Shared Methods isHorizontal: function() { - return this.options.position === "top" || this.options.position === "bottom"; + var pos = this.options.position; + return pos === "top" || pos === "bottom"; }, // Actualy draw the title block on the canvas draw: function() { - if (this.options.display) { - var ctx = this.ctx; - var titleX, titleY; - - var fontColor = helpers.getValueOrDefault(this.options.fontColor, Chart.defaults.global.defaultFontColor); - var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize); - var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle); - var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily); - var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily); - - ctx.fillStyle = fontColor; // render in correct colour + var ctx = this.ctx, + valueOrDefault = helpers.getValueOrDefault, + opts = this.options, + globalDefaults = Chart.defaults.global; + + if (opts.display) { + var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize), + fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle), + fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily), + titleFont = helpers.fontString(fontSize, fontStyle, fontFamily), + rotation = 0, + titleX, + titleY; + + ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour ctx.font = titleFont; // Horizontal if (this.isHorizontal()) { - // Title - ctx.textAlign = "center"; - ctx.textBaseline = 'middle'; - titleX = this.left + ((this.right - this.left) / 2); // midpoint of the width titleY = this.top + ((this.bottom - this.top) / 2); // midpoint of the height - - ctx.fillText(this.options.text, titleX, titleY); } else { - - // Title - titleX = this.options.position === 'left' ? this.left + (fontSize / 2) : this.right - (fontSize / 2); + titleX = opts.position === 'left' ? this.left + (fontSize / 2) : this.right - (fontSize / 2); titleY = this.top + ((this.bottom - this.top) / 2); - var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI; - - ctx.save(); - ctx.translate(titleX, titleY); - ctx.rotate(rotation); - ctx.textAlign = "center"; - ctx.textBaseline = 'middle'; - ctx.fillText(this.options.text, 0, 0); - ctx.restore(); + rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5); } + + ctx.save(); + ctx.translate(titleX, titleY); + ctx.rotate(rotation); + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; + ctx.fillText(opts.text, 0, 0); + ctx.restore(); } } });
true
Other
chartjs
Chart.js
4068836a42962c306a79f8baec099df0d0f4377f.json
Reduce core.title.js size
test/core.title.tests.js
@@ -107,9 +107,21 @@ describe('Title block tests', function() { expect(context.getCalls()).toEqual([{ name: 'setFillStyle', args: ['#666'] + }, { + name: 'save', + args: [] + }, { + name: 'translate', + args: [300, 66] + }, { + name: 'rotate', + args: [0] }, { name: 'fillText', - args: ['My title', 300, 66] + args: ['My title', 0, 0] + }, { + name: 'restore', + args: [] }]); });
true
Other
chartjs
Chart.js
eeae8a6a16649be2d2b16a4e09ffc5d6cc0439b2.json
Reduce size of on-canvas legend
src/core/core.legend.js
@@ -3,6 +3,7 @@ module.exports = function(Chart) { var helpers = Chart.helpers; + var noop = helpers.noop; Chart.defaults.global.legend = { @@ -14,13 +15,14 @@ module.exports = function(Chart) { // a callback that will handle onClick: function(e, legendItem) { var index = legendItem.datasetIndex; - var meta = this.chart.getDatasetMeta(index); + var ci = this.chart; + var meta = ci.getDatasetMeta(index); // See controller.isDatasetVisible comment - meta.hidden = meta.hidden === null? !this.chart.data.datasets[index].hidden : null; + meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null; // We hid a dataset ... rerender the chart - this.chart.update(); + ci.update(); }, labels: { @@ -75,7 +77,7 @@ module.exports = function(Chart) { // Any function defined here is inherited by all legend types. // Any function can be extended by the legend type - beforeUpdate: helpers.noop, + beforeUpdate: noop, update: function(maxWidth, maxHeight, margins) { // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -104,11 +106,11 @@ module.exports = function(Chart) { return this.minSize; }, - afterUpdate: helpers.noop, + afterUpdate: noop, // - beforeSetDimensions: helpers.noop, + beforeSetDimensions: noop, setDimensions: function() { // Set the unconstrained dimension before label rotation if (this.isHorizontal()) { @@ -136,90 +138,92 @@ module.exports = function(Chart) { height: 0 }; }, - afterSetDimensions: helpers.noop, + afterSetDimensions: noop, // - beforeBuildLabels: helpers.noop, + beforeBuildLabels: noop, buildLabels: function() { this.legendItems = this.options.labels.generateLabels.call(this, this.chart); if(this.options.reverse){ this.legendItems.reverse(); } }, - afterBuildLabels: helpers.noop, + afterBuildLabels: noop, // - beforeFit: helpers.noop, + beforeFit: noop, fit: function() { + var opts = this.options; + var labelOpts = opts.labels; + var display = opts.display; var ctx = this.ctx; - var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize); - var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle); - var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily); - var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily); + + var globalDefault = Chart.defaults.global, + itemOrDefault = helpers.getValueOrDefault, + fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize), + fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle), + fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily), + labelFont = helpers.fontString(fontSize, fontStyle, fontFamily); // Reset hit boxes - this.legendHitBoxes = []; + var hitboxes = this.legendHitBoxes = []; - // Width - if (this.isHorizontal()) { - this.minSize.width = this.maxWidth; // fill all the width - } else { - this.minSize.width = this.options.display ? 10 : 0; - } + var minSize = this.minSize; + var isHorizontal = this.isHorizontal(); - // height - if (this.isHorizontal()) { - this.minSize.height = this.options.display ? 10 : 0; + if (isHorizontal) { + minSize.width = this.maxWidth; // fill all the width + minSize.height = display ? 10 : 0; } else { - this.minSize.height = this.maxHeight; // fill all the height + minSize.width = display ? 10 : 0; + minSize.height = this.maxHeight; // fill all the height } // Increase sizes here - if (this.options.display) { - if (this.isHorizontal()) { + if (display) { + if (isHorizontal) { // Labels // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one - this.lineWidths = [0]; - var totalHeight = this.legendItems.length ? fontSize + (this.options.labels.padding) : 0; + var lineWidths = this.lineWidths = [0]; + var totalHeight = this.legendItems.length ? fontSize + (labelOpts.padding) : 0; ctx.textAlign = "left"; ctx.textBaseline = 'top'; ctx.font = labelFont; helpers.each(this.legendItems, function(legendItem, i) { - var width = this.options.labels.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width; - if (this.lineWidths[this.lineWidths.length - 1] + width + this.options.labels.padding >= this.width) { - totalHeight += fontSize + (this.options.labels.padding); - this.lineWidths[this.lineWidths.length] = this.left; + var width = labelOpts.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width; + if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= this.width) { + totalHeight += fontSize + (labelOpts.padding); + lineWidths[lineWidths.length] = this.left; } // Store the hitbox width and height here. Final position will be updated in `draw` - this.legendHitBoxes[i] = { + hitboxes[i] = { left: 0, top: 0, width: width, height: fontSize }; - this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding; + lineWidths[lineWidths.length - 1] += width + labelOpts.padding; }, this); - this.minSize.height += totalHeight; + minSize.height += totalHeight; } else { // TODO vertical } } - this.width = this.minSize.width; - this.height = this.minSize.height; - + this.width = minSize.width; + this.height = minSize.height; }, - afterFit: helpers.noop, + afterFit: noop, // Shared Methods isHorizontal: function() { @@ -228,19 +232,26 @@ module.exports = function(Chart) { // Actualy draw the legend on the canvas draw: function() { - if (this.options.display) { - var ctx = this.ctx; - var cursor = { - x: this.left + ((this.width - this.lineWidths[0]) / 2), - y: this.top + this.options.labels.padding, - line: 0 - }; - - var fontColor = helpers.getValueOrDefault(this.options.labels.fontColor, Chart.defaults.global.defaultFontColor); - var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize); - var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle); - var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily); - var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily); + var opts = this.options; + var labelOpts = opts.labels; + var globalDefault = Chart.defaults.global, + lineDefault = globalDefault.elements.line, + legendWidth = this.width, + lineWidths = this.lineWidths; + + if (opts.display) { + var ctx = this.ctx, + cursor = { + x: this.left + ((legendWidth - lineWidths[0]) / 2), + y: this.top + labelOpts.padding, + line: 0 + }, + itemOrDefault = helpers.getValueOrDefault, + fontColor = itemOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor), + fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize), + fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle), + fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily), + labelFont = helpers.fontString(fontSize, fontStyle, fontFamily); // Horizontal if (this.isHorizontal()) { @@ -252,57 +263,58 @@ module.exports = function(Chart) { ctx.fillStyle = fontColor; // render in correct colour ctx.font = labelFont; + var boxWidth = labelOpts.boxWidth, + hitboxes = this.legendHitBoxes; + helpers.each(this.legendItems, function(legendItem, i) { - var textWidth = ctx.measureText(legendItem.text).width; - var width = this.options.labels.boxWidth + (fontSize / 2) + textWidth; + var textWidth = ctx.measureText(legendItem.text).width, + width = boxWidth + (fontSize / 2) + textWidth, + x = cursor.x, + y = cursor.y; - if (cursor.x + width >= this.width) { - cursor.y += fontSize + (this.options.labels.padding); + if (x + width >= legendWidth) { + cursor.y += fontSize + (labelOpts.padding); cursor.line++; - cursor.x = this.left + ((this.width - this.lineWidths[cursor.line]) / 2); + cursor.x = this.left + ((legendWidth - lineWidths[cursor.line]) / 2); } // Set the ctx for the box ctx.save(); - var itemOrDefault = function(item, defaulVal) { - return item !== undefined ? item : defaulVal; - }; - - ctx.fillStyle = itemOrDefault(legendItem.fillStyle, Chart.defaults.global.defaultColor); - ctx.lineCap = itemOrDefault(legendItem.lineCap, Chart.defaults.global.elements.line.borderCapStyle); - ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, Chart.defaults.global.elements.line.borderDashOffset); - ctx.lineJoin = itemOrDefault(legendItem.lineJoin, Chart.defaults.global.elements.line.borderJoinStyle); - ctx.lineWidth = itemOrDefault(legendItem.lineWidth, Chart.defaults.global.elements.line.borderWidth); - ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, Chart.defaults.global.defaultColor); + ctx.fillStyle = itemOrDefault(legendItem.fillStyle, globalDefault.defaultColor); + ctx.lineCap = itemOrDefault(legendItem.lineCap, lineDefault.borderCapStyle); + ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset); + ctx.lineJoin = itemOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle); + ctx.lineWidth = itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth); + ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, globalDefault.defaultColor); if (ctx.setLineDash) { // IE 9 and 10 do not support line dash - ctx.setLineDash(itemOrDefault(legendItem.lineDash, Chart.defaults.global.elements.line.borderDash)); + ctx.setLineDash(itemOrDefault(legendItem.lineDash, lineDefault.borderDash)); } // Draw the box - ctx.strokeRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize); - ctx.fillRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize); + ctx.strokeRect(x, y, boxWidth, fontSize); + ctx.fillRect(x, y, boxWidth, fontSize); ctx.restore(); - this.legendHitBoxes[i].left = cursor.x; - this.legendHitBoxes[i].top = cursor.y; + hitboxes[i].left = x; + hitboxes[i].top = y; // Fill the actual label - ctx.fillText(legendItem.text, this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y); + ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y); if (legendItem.hidden) { // Strikethrough the text if hidden ctx.beginPath(); ctx.lineWidth = 2; - ctx.moveTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y + (fontSize / 2)); - ctx.lineTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x + textWidth, cursor.y + (fontSize / 2)); + ctx.moveTo(boxWidth + (fontSize / 2) + x, y + (fontSize / 2)); + ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2)); ctx.stroke(); } - cursor.x += width + (this.options.labels.padding); + cursor.x += width + (labelOpts.padding); }, this); } else { @@ -312,17 +324,21 @@ module.exports = function(Chart) { // Handle an event handleEvent: function(e) { - var position = helpers.getRelativePosition(e, this.chart.chart); + var position = helpers.getRelativePosition(e, this.chart.chart), + x = position.x, + y = position.y, + opts = this.options; - if (position.x >= this.left && position.x <= this.right && position.y >= this.top && position.y <= this.bottom) { + if (x >= this.left && x <= this.right && y >= this.top && y <= this.bottom) { // See if we are touching one of the dataset boxes - for (var i = 0; i < this.legendHitBoxes.length; ++i) { - var hitBox = this.legendHitBoxes[i]; + var lh = this.legendHitBoxes; + for (var i = 0; i < lh.length; ++i) { + var hitBox = lh[i]; - if (position.x >= hitBox.left && position.x <= hitBox.left + hitBox.width && position.y >= hitBox.top && position.y <= hitBox.top + hitBox.height) { + if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) { // Touching an element - if (this.options.onClick) { - this.options.onClick.call(this, e, this.legendItems[i]); + if (opts.onClick) { + opts.onClick.call(this, e, this.legendItems[i]); } break; }
false
Other
chartjs
Chart.js
27b6791e7376420df7690699f856dbd2110f06bc.json
Fix build to remove all comments other than header
gulpfile.js
@@ -76,9 +76,9 @@ function buildTask() { .pipe(insert.prepend(header)) .pipe(streamify(replace('{{ version }}', package.version))) .pipe(gulp.dest(outDir)) - .pipe(streamify(uglify({ - preserveComments: 'some' - }))) + .pipe(streamify(uglify())) + .pipe(insert.prepend(header)) + .pipe(streamify(replace('{{ version }}', package.version))) .pipe(streamify(concat('Chart.bundle.min.js'))) .pipe(gulp.dest(outDir)); @@ -89,9 +89,9 @@ function buildTask() { .pipe(insert.prepend(header)) .pipe(streamify(replace('{{ version }}', package.version))) .pipe(gulp.dest(outDir)) - .pipe(streamify(uglify({ - preserveComments: 'some' - }))) + .pipe(streamify(uglify())) + .pipe(insert.prepend(header)) + .pipe(streamify(replace('{{ version }}', package.version))) .pipe(streamify(concat('Chart.min.js'))) .pipe(gulp.dest(outDir));
false
Other
chartjs
Chart.js
c2d6e4c31f027fc2bbba0a594ab41d156523bd71.json
Reset elements for polar area chart
src/Chart.PolarArea.js
@@ -121,6 +121,14 @@ _options: this.options, }, this); + // Fit the scale before we animate + this.updateScaleRange(); + this.scale.calculateRange(); + Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height); + + // so that we animate nicely + this.resetElements(); + // Update the chart with the latest data. this.update(); @@ -132,6 +140,39 @@ yCenter: this.chart.height / 2 }); }, + resetElements: function() { + var circumference = 1 / this.data.datasets[0].data.length * 2; + + // Map new data to data points + helpers.each(this.data.datasets[0].metaData, function(slice, index) { + + var value = this.data.datasets[0].data[index]; + + var startAngle = Math.PI * 1.5 + (Math.PI * circumference) * index; + var endAngle = startAngle + (circumference * Math.PI); + + helpers.extend(slice, { + _index: index, + _model: { + x: this.chart.width / 2, + y: this.chart.height / 2, + innerRadius: 0, + outerRadius: 0, + startAngle: Math.PI * 1.5, + endAngle: Math.PI * 1.5, + + backgroundColor: slice.custom && slice.custom.backgroundColor ? slice.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[0].backgroundColor, index, this.options.elements.slice.backgroundColor), + hoverBackgroundColor: slice.custom && slice.custom.hoverBackgroundColor ? slice.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(this.data.datasets[0].hoverBackgroundColor, index, this.options.elements.slice.hoverBackgroundColor), + borderWidth: slice.custom && slice.custom.borderWidth ? slice.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.data.datasets[0].borderWidth, index, this.options.elements.slice.borderWidth), + borderColor: slice.custom && slice.custom.borderColor ? slice.custom.borderColor : helpers.getValueAtIndexOrDefault(this.data.datasets[0].borderColor, index, this.options.elements.slice.borderColor), + + label: helpers.getValueAtIndexOrDefault(this.data.datasets[0].labels, index, this.data.datasets[0].labels[index]) + }, + }); + + slice.pivot(); + }, this); + }, update: function() { this.updateScaleRange();
false
Other
chartjs
Chart.js
a6c712323f86ed9d12256f824287202c9d641dd4.json
Reset elements for donut charts
src/Chart.Doughnut.js
@@ -54,6 +54,8 @@ _options: this.options, }, this); + this.resetElements(); + // Update the chart with the latest data. this.update(); @@ -66,6 +68,46 @@ return 0; } }, + resetElements: function() { + this.outerRadius = (helpers.min([this.chart.width, this.chart.height]) - this.options.elements.slice.borderWidth / 2) / 2; + this.innerRadius = this.options.cutoutPercentage ? (this.outerRadius / 100) * (this.options.cutoutPercentage) : 1; + this.radiusLength = (this.outerRadius - this.innerRadius) / this.data.datasets.length; + + // Update the points + helpers.each(this.data.datasets, function(dataset, datasetIndex) { + // So that calculateCircumference works + dataset.total = 0; + helpers.each(dataset.data, function(value) { + dataset.total += Math.abs(value); + }, this); + + dataset.outerRadius = this.outerRadius - (this.radiusLength * datasetIndex); + dataset.innerRadius = dataset.outerRadius - this.radiusLength; + + helpers.each(dataset.metaData, function(slice, index) { + helpers.extend(slice, { + _model: { + x: this.chart.width / 2, + y: this.chart.height / 2, + startAngle: Math.PI * -0.5, // use - PI / 2 instead of 3PI / 2 to make animations better. It means that we never deal with overflow during the transition function + circumference: (this.options.animation.animateRotate) ? 0 : this.calculateCircumference(metaSlice.value), + outerRadius: (this.options.animation.animateScale) ? 0 : dataset.outerRadius, + innerRadius: (this.options.animation.animateScale) ? 0 : dataset.innerRadius, + + backgroundColor: slice.custom && slice.custom.backgroundColor ? slice.custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, this.options.elements.slice.backgroundColor), + hoverBackgroundColor: slice.custom && slice.custom.hoverBackgroundColor ? slice.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, this.options.elements.slice.hoverBackgroundColor), + borderWidth: slice.custom && slice.custom.borderWidth ? slice.custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, this.options.elements.slice.borderWidth), + borderColor: slice.custom && slice.custom.borderColor ? slice.custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, this.options.elements.slice.borderColor), + + label: helpers.getValueAtIndexOrDefault(dataset.label, index, this.data.labels[index]) + }, + }); + + slice.pivot(); + }, this); + + }, this); + }, update: function() { this.outerRadius = (helpers.min([this.chart.width, this.chart.height]) - this.options.elements.slice.borderWidth / 2) / 2; @@ -112,7 +154,7 @@ }); if (index === 0) { - slice._model.startAngle = Math.PI * 1.5; + slice._model.startAngle = Math.PI * -0.5; // use - PI / 2 instead of 3PI / 2 to make animations better. It means that we never deal with overflow during the transition function } else { slice._model.startAngle = dataset.metaData[index - 1]._model.endAngle; }
false
Other
chartjs
Chart.js
37cfbdb8028b24715589620e9e1ed191486f410a.json
Fix an issue with bar charts that are not stacked
src/Chart.Bar.js
@@ -335,7 +335,7 @@ var offset = 0; - for (j = datasetIndex; j < datasets.length; j++) { + for (var j = datasetIndex; j < self.data.datasets.length; j++) { if (j === datasetIndex && value) { offset += value; } else {
false
Other
chartjs
Chart.js
42e2c237d4e17db68929e47c9146ba023dca69ad.json
Bind events in scatter chart
src/Chart.Scatter.js
@@ -92,6 +92,10 @@ name: "Scatter", defaults: defaultConfig, initialize: function() { + + // Events + helpers.bindEvents(this, this.options.events, this.events); + //Custom Point Defaults helpers.each(this.data.datasets, function(dataset, datasetIndex) { dataset.metaDataset = new Chart.Line({
false
Other
chartjs
Chart.js
8db79ae365cd212045c3f11701dd9665eb4b4db1.json
nnnick/Chart.js#1140: Watch sample folder
gulpfile.js
@@ -122,7 +122,7 @@ gulp.task('watch', function(){ livereload.changed(evt.path); }; - gulp.watch('Chart.js', reloadPage); + gulp.watch(['Chart.js', 'samples/*'], reloadPage); });
false
Other
chartjs
Chart.js
8ef3aaa87da570148d2b6ae3a8fceff912b67ec7.json
Add livereload to Gulp task
gulpfile.js
@@ -12,7 +12,8 @@ var gulp = require('gulp'), exec = require('child_process').exec, fs = require('fs'), package = require('./package.json'), - bower = require('./bower.json'); + bower = require('./bower.json'), + livereload = require('gulp-livereload'); var srcDir = './src/'; /* @@ -114,6 +115,15 @@ gulp.task('module-sizes', function(){ gulp.task('watch', function(){ gulp.watch('./src/*', ['build']); + + livereload.listen(35729); + + var reloadPage = function (evt) { + livereload.changed(evt.path); + }; + + gulp.watch('Chart.js', reloadPage); + }); gulp.task('test', ['jshint', 'valid']);
true
Other
chartjs
Chart.js
8ef3aaa87da570148d2b6ae3a8fceff912b67ec7.json
Add livereload to Gulp task
package.json
@@ -20,9 +20,10 @@ "gulp-util": "~2.2.x", "gulp-html-validator": "^0.0.2", "inquirer": "^0.5.1", - "semver": "^3.0.1" + "semver": "^3.0.1", + "gulp-livereload": "^3.8.0" }, "spm": { "main": "Chart.js" } -} \ No newline at end of file +}
true
Other
chartjs
Chart.js
e774a893da4f7be405af2926ae74499f2ab0d813.json
Use new animation options in the animation service.
src/Chart.Core.js
@@ -999,10 +999,10 @@ redraw: noop, render: function(duration) { - if (this.options.animation) { + if (this.options.animation.duration !== 0) { var animation = new Chart.Animation(); - animation.numSteps = (duration || this.options.animationDuration) / 16.66; //60 fps - animation.easing = this.options.animationEasing; + animation.numSteps = (duration || this.options.animation.duration) / 16.66; //60 fps + animation.easing = this.options.animation.easing; // render function animation.render = function(chartInstance, animationObject) {
false
Other
chartjs
Chart.js
73b579c9626b0f5f5d2ea4d24c36901a8d785cef.json
Remove old linear scale
src/Chart.Core.js
@@ -1782,279 +1782,6 @@ }, }); - Chart.Scale = Chart.Element.extend({ - initialize: function() { - this.fit(); - }, - buildYLabels: function() { - this.yLabels = []; - - var stepDecimalPlaces = getDecimalPlaces(this.stepValue); - - for (var i = 0; i <= this.steps; i++) { - this.yLabels.push(template(this.templateString, { - value: (this.min + (i * this.stepValue)).toFixed(stepDecimalPlaces) - })); - } - this.yLabelWidth = (this.display && this.showLabels) ? longestText(this.ctx, this.font, this.yLabels) + 10 : 0; - }, - addXLabel: function(label) { - this.xLabels.push(label); - this.valuesCount++; - this.fit(); - }, - removeXLabel: function() { - this.xLabels.shift(); - this.valuesCount--; - this.fit(); - }, - // Fitting loop to rotate x Labels and figure out what fits there, and also calculate how many Y steps to use - fit: function() { - // First we need the width of the yLabels, assuming the xLabels aren't rotated - - // To do that we need the base line at the top and base of the chart, assuming there is no x label rotation - this.startPoint = (this.display) ? this.fontSize : 0; - this.endPoint = (this.display) ? this.height - (this.fontSize * 1.5) - 5 : this.height; // -5 to pad labels - - // Apply padding settings to the start and end point. - this.startPoint += this.padding; - this.endPoint -= this.padding; - - // Cache the starting endpoint, excluding the space for x labels - var cachedEndPoint = this.endPoint; - - // Cache the starting height, so can determine if we need to recalculate the scale yAxis - var cachedHeight = this.endPoint - this.startPoint, - cachedYLabelWidth; - - // Build the current yLabels so we have an idea of what size they'll be to start - /* - * This sets what is returned from calculateScaleRange as static properties of this class: - * - this.steps; - this.stepValue; - this.min; - this.max; - * - */ - this.calculateYRange(cachedHeight); - - // With these properties set we can now build the array of yLabels - // and also the width of the largest yLabel - this.buildYLabels(); - - this.calculateXLabelRotation(); - - while ((cachedHeight > this.endPoint - this.startPoint)) { - cachedHeight = this.endPoint - this.startPoint; - cachedYLabelWidth = this.yLabelWidth; - - this.calculateYRange(cachedHeight); - this.buildYLabels(); - - // Only go through the xLabel loop again if the yLabel width has changed - if (cachedYLabelWidth < this.yLabelWidth) { - this.endPoint = cachedEndPoint; - this.calculateXLabelRotation(); - } - } - - }, - calculateXLabelRotation: function() { - //Get the width of each grid by calculating the difference - //between x offsets between 0 and 1. - - this.ctx.font = this.font; - - var firstWidth = this.ctx.measureText(this.xLabels[0]).width, - lastWidth = this.ctx.measureText(this.xLabels[this.xLabels.length - 1]).width, - firstRotated, - lastRotated; - - - this.xScalePaddingRight = lastWidth / 2 + 3; - this.xScalePaddingLeft = (firstWidth / 2 > this.yLabelWidth) ? firstWidth / 2 : this.yLabelWidth; - - this.xLabelRotation = 0; - if (this.display) { - var originalLabelWidth = longestText(this.ctx, this.font, this.xLabels), - cosRotation, - firstRotatedWidth; - this.xLabelWidth = originalLabelWidth; - //Allow 3 pixels x2 padding either side for label readability - var xGridWidth = Math.floor(this.calculateX(1) - this.calculateX(0)) - 6; - - //Max label rotate should be 90 - also act as a loop counter - while ((this.xLabelWidth > xGridWidth && this.xLabelRotation === 0) || (this.xLabelWidth > xGridWidth && this.xLabelRotation <= 90 && this.xLabelRotation > 0)) { - cosRotation = Math.cos(toRadians(this.xLabelRotation)); - - firstRotated = cosRotation * firstWidth; - lastRotated = cosRotation * lastWidth; - - // We're right aligning the text now. - if (firstRotated + this.fontSize / 2 > this.yLabelWidth) { - this.xScalePaddingLeft = firstRotated + this.fontSize / 2; - } - this.xScalePaddingRight = this.fontSize / 2; - - - this.xLabelRotation++; - this.xLabelWidth = cosRotation * originalLabelWidth; - - } - if (this.xLabelRotation > 0) { - this.endPoint -= Math.sin(toRadians(this.xLabelRotation)) * originalLabelWidth + 3; - } - } else { - this.xLabelWidth = 0; - this.xScalePaddingRight = this.padding; - this.xScalePaddingLeft = this.padding; - } - - }, - // Needs to be overidden in each Chart type - // Otherwise we need to pass all the data into the scale class - calculateYRange: noop, - drawingArea: function() { - return this.startPoint - this.endPoint; - }, - calculateY: function(value) { - var scalingFactor = this.drawingArea() / (this.min - this.max); - return this.endPoint - (scalingFactor * (value - this.min)); - }, - calculateX: function(index) { - var isRotated = (this.xLabelRotation > 0), - // innerWidth = (this.offsetGridLines) ? this.width - offsetLeft - this.padding : this.width - (offsetLeft + halfLabelWidth * 2) - this.padding, - innerWidth = this.width - (this.xScalePaddingLeft + this.xScalePaddingRight), - valueWidth = innerWidth / Math.max((this.valuesCount - ((this.offsetGridLines) ? 0 : 1)), 1), - valueOffset = (valueWidth * index) + this.xScalePaddingLeft; - - if (this.offsetGridLines) { - valueOffset += (valueWidth / 2); - } - - return Math.round(valueOffset); - }, - update: function(newProps) { - helpers.extend(this, newProps); - this.fit(); - }, - draw: function() { - var ctx = this.ctx, - yLabelGap = (this.endPoint - this.startPoint) / this.steps, - xStart = Math.round(this.xScalePaddingLeft); - if (this.display) { - ctx.fillStyle = this.textColor; - ctx.font = this.font; - each(this.yLabels, function(labelString, index) { - var yLabelCenter = this.endPoint - (yLabelGap * index), - linePositionY = Math.round(yLabelCenter), - drawHorizontalLine = this.showHorizontalLines; - - ctx.textAlign = "right"; - ctx.textBaseline = "middle"; - if (this.showLabels) { - ctx.fillText(labelString, xStart - 10, yLabelCenter); - } - - // This is X axis, so draw it - if (index === 0 && !drawHorizontalLine) { - drawHorizontalLine = true; - } - - if (drawHorizontalLine) { - ctx.beginPath(); - } - - if (index > 0) { - // This is a grid line in the centre, so drop that - ctx.lineWidth = this.gridLineWidth; - ctx.strokeStyle = this.gridLineColor; - } else { - // This is the first line on the scale - ctx.lineWidth = this.lineWidth; - ctx.strokeStyle = this.lineColor; - } - - linePositionY += helpers.aliasPixel(ctx.lineWidth); - - if (drawHorizontalLine) { - ctx.moveTo(xStart, linePositionY); - ctx.lineTo(this.width, linePositionY); - ctx.stroke(); - ctx.closePath(); - } - - ctx.lineWidth = this.lineWidth; - ctx.strokeStyle = this.lineColor; - ctx.beginPath(); - ctx.moveTo(xStart - 5, linePositionY); - ctx.lineTo(xStart, linePositionY); - ctx.stroke(); - ctx.closePath(); - - }, this); - - each(this.xLabels, function(label, index) { - var xPos = this.calculateX(index) + aliasPixel(this.lineWidth), - // Check to see if line/bar here and decide where to place the line - linePos = this.calculateX(index - (this.offsetGridLines ? 0.5 : 0)) + aliasPixel(this.lineWidth), - isRotated = (this.xLabelRotation > 0), - drawVerticalLine = this.showVerticalLines; - - // This is Y axis, so draw it - if (index === 0 && !drawVerticalLine) { - drawVerticalLine = true; - } - - if (drawVerticalLine) { - ctx.beginPath(); - } - - if (index > 0) { - // This is a grid line in the centre, so drop that - ctx.lineWidth = this.gridLineWidth; - ctx.strokeStyle = this.gridLineColor; - } else { - // This is the first line on the scale - ctx.lineWidth = this.lineWidth; - ctx.strokeStyle = this.lineColor; - } - - if (drawVerticalLine) { - ctx.moveTo(linePos, this.endPoint); - ctx.lineTo(linePos, this.startPoint - 3); - ctx.stroke(); - ctx.closePath(); - } - - - ctx.lineWidth = this.lineWidth; - ctx.strokeStyle = this.lineColor; - - - // Small lines at the bottom of the base grid line - ctx.beginPath(); - ctx.moveTo(linePos, this.endPoint); - ctx.lineTo(linePos, this.endPoint + 5); - ctx.stroke(); - ctx.closePath(); - - ctx.save(); - ctx.translate(xPos, (isRotated) ? this.endPoint + 12 : this.endPoint + 8); - ctx.rotate(toRadians(this.xLabelRotation) * -1); - ctx.font = this.font; - ctx.textAlign = (isRotated) ? "right" : "center"; - ctx.textBaseline = (isRotated) ? "middle" : "top"; - ctx.fillText(label, 0, 0); - ctx.restore(); - }, this); - - } - } - - }); - Chart.RadialScale = Chart.Element.extend({ initialize: function() { this.size = min([this.height, this.width]);
false