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
8d5b3809f6a607ebf2be7af40fb538ea5e42c4db.json
Fix global font settings
test/scale.radialLinear.tests.js
@@ -28,18 +28,11 @@ describe('Test the radial linear scale', function() { }, lineArc: false, pointLabels: { - fontColor: "#666", - fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", fontSize: 10, - fontStyle: "normal", callback: defaultConfig.pointLabels.callback, // make this nicer, then check explicitly below }, position: "chartArea", scaleLabel: { - fontColor: '#666', - fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - fontSize: 12, - fontStyle: 'normal', labelString: '', display: false, }, @@ -48,10 +41,6 @@ describe('Test the radial linear scale', function() { backdropPaddingY: 2, backdropPaddingX: 2, beginAtZero: false, - fontColor: "#666", - fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - fontSize: 12, - fontStyle: "normal", maxRotation: 90, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
8d5b3809f6a607ebf2be7af40fb538ea5e42c4db.json
Fix global font settings
test/scale.time.tests.js
@@ -27,19 +27,11 @@ describe('Time scale tests', function() { }, position: "bottom", scaleLabel: { - fontColor: '#666', - fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - fontSize: 12, - fontStyle: 'normal', labelString: '', display: false, }, ticks: { beginAtZero: false, - fontColor: "#666", - fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - fontSize: 12, - fontStyle: "normal", maxRotation: 90, mirror: false, padding: 10,
true
Other
chartjs
Chart.js
33a1fa928ddb15ae88ee6cb3dbb66ddc8ab6e8c6.json
fix consistency with other samples
samples/bubble.html
@@ -6,7 +6,7 @@ <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="../dist/Chart.bundle.js"></script> <style type="text/css"> - #canvas{ + canvas{ -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; @@ -45,24 +45,69 @@ datasets: [{ label: "My First dataset", backgroundColor: randomColor(), - data: [] + data: [{ + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }] }, { label: "My Second dataset", backgroundColor: randomColor(), - data: [] - }] - }; - - // add random data to initial datasets - for(var i in bubbleChartData.datasets){ - for(var j=0; j<DEFAULT_DATASET_SIZE; ++j){ - bubbleChartData.datasets[i].data.push({ + data: [{ x: randomScalingFactor(), y: randomScalingFactor(), - r: Math.abs(randomScalingFactor()) / 5 - }); - } - } + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }, { + x: randomScalingFactor(), + y: randomScalingFactor(), + r: Math.abs(randomScalingFactor()) / 5, + }] + }] + }; window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d");
true
Other
chartjs
Chart.js
33a1fa928ddb15ae88ee6cb3dbb66ddc8ab6e8c6.json
fix consistency with other samples
samples/line.html
@@ -6,7 +6,7 @@ <script src="../dist/Chart.bundle.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <style> - #canvas{ + canvas{ -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;
true
Other
chartjs
Chart.js
2977c8eb9c901d2cc6f54ba0f5a56adf04754195.json
improve doughnut sample - set title - set same size canvas as other samples - remove user select from canvas - remove html legend - remove logs
samples/doughnut.html
@@ -6,32 +6,23 @@ <script src="../dist/Chart.bundle.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <style> - body { - padding: 0; - margin: 0; - } - - #canvas-holder { - width: 30%; + canvas { + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; } </style> </head> <body> - <div id="canvas-holder" style="width:100%"> + <div id="canvas-holder" style="width:75%"> <canvas id="chart-area" /> </div> <button id="randomizeData">Randomize Data</button> <button id="addDataset">Add Dataset</button> <button id="removeDataset">Remove Dataset</button> <button id="addData">Add Data</button> <button id="removeData">Remove Data</button> - <div> - <h3>Legend</h3> - <div id="legendContainer"> - - </div> - </div> <script> var randomScalingFactor = function() { return Math.round(Math.random() * 100); @@ -116,18 +107,9 @@ <h3>Legend</h3> } }; - function updateLegend() { - $legendContainer = $('#legendContainer'); - $legendContainer.empty(); - $legendContainer.append(window.myDoughnut.generateLegend()); - } - window.onload = function() { var ctx = document.getElementById("chart-area").getContext("2d"); window.myDoughnut = new Chart(ctx, config); - console.log(window.myDoughnut); - - updateLegend(); }; $('#randomizeData').click(function() { @@ -142,7 +124,6 @@ <h3>Legend</h3> }); window.myDoughnut.update(); - updateLegend(); }); $('#addDataset').click(function() { @@ -159,7 +140,6 @@ <h3>Legend</h3> config.data.datasets.push(newDataset); window.myDoughnut.update(); - updateLegend(); }); $('#addData').click(function() { @@ -172,14 +152,12 @@ <h3>Legend</h3> }); window.myDoughnut.update(); - updateLegend(); } }); $('#removeDataset').click(function() { config.data.datasets.splice(0, 1); window.myDoughnut.update(); - updateLegend(); }); $('#removeData').click(function() { @@ -191,7 +169,6 @@ <h3>Legend</h3> }); window.myDoughnut.update(); - updateLegend(); }); </script> </body>
false
Other
chartjs
Chart.js
a4fa956ab4ee941c8d104adf80cb0ef2117e3bf0.json
improve scatter sample - set title - set same size canvas as other samples - remove user select from canvas
samples/scatter.html
@@ -5,12 +5,19 @@ <title>Scatter Chart</title> <script src="../dist/Chart.bundle.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> + <style> + canvas { + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + } + </style> </head> <body> - <div style="width:50%"> + <div style="width:75%"> <div> - <canvas id="canvas" height="450" width="600"></canvas> + <canvas id="canvas"></canvas> </div> </div> <button id="randomizeData">Randomize Data</button> @@ -82,13 +89,15 @@ dataset.pointBorderWidth = 1; }); - console.log(scatterChartData); - window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); window.myScatter = Chart.Scatter(ctx, { data: scatterChartData, options: { + title: { + display: true, + text: 'Chart.js Scatter Chart' + }, scales: { xAxes: [{ position: 'top',
false
Other
chartjs
Chart.js
0985e6d56491115b46c2d956aa718fefbd83b017.json
improve bar sample - set title - set same size canvas as other samples - remove user select from canvas - remove html legend - fix x-axis labels when adding data
samples/bar.html
@@ -5,29 +5,27 @@ <title>Bar Chart</title> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="../dist/Chart.bundle.js"></script> - <style type="text/css"> - canvas { - border: 1px solid red; - } + <style> + canvas { + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + } </style> </head> <body> - <div id="container" style="width: 50%; height: 25%;"> - <canvas id="canvas" height="450" width="600"></canvas> + <div id="container" style="width: 75%;"> + <canvas id="canvas"></canvas> </div> <button id="randomizeData">Randomize Data</button> <button id="addDataset">Add Dataset</button> <button id="removeDataset">Remove Dataset</button> <button id="addData">Add Data</button> <button id="removeData">Remove Data</button> - <button id="show">Show</button> - <div> - <h3>Legend</h3> - <div id="legendContainer"> - </div> - </div> <script> + var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + var randomScalingFactor = function() { return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100); }; @@ -57,12 +55,6 @@ <h3>Legend</h3> }; - function updateLegend() { - $legendContainer = $('#legendContainer'); - $legendContainer.empty(); - $legendContainer.append(window.myBar.generateLegend()); - } - window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); window.myBar = new Chart(ctx, { @@ -83,12 +75,11 @@ <h3>Legend</h3> }, title: { display: true, - text: 'Our 3 Favorite Datasets' + text: 'Chart.js Bar Chart' } } }); - updateLegend(); }; $('#randomizeData').click(function() { @@ -101,7 +92,6 @@ <h3>Legend</h3> }); window.myBar.update(); - updateLegend(); }); $('#addDataset').click(function() { @@ -117,27 +107,25 @@ <h3>Legend</h3> barChartData.datasets.push(newDataset); window.myBar.update(); - updateLegend(); }); $('#addData').click(function() { if (barChartData.datasets.length > 0) { - barChartData.labels.push('data #' + barChartData.labels.length); + var month = MONTHS[barChartData.labels.length % MONTHS.length]; + barChartData.labels.push(month); for (var index = 0; index < barChartData.datasets.length; ++index) { //window.myBar.addData(randomScalingFactor(), index); barChartData.datasets[index].data.push(randomScalingFactor()); } window.myBar.update(); - updateLegend(); } }); $('#removeDataset').click(function() { barChartData.datasets.splice(0, 1); window.myBar.update(); - updateLegend(); }); $('#removeData').click(function() { @@ -148,11 +136,6 @@ <h3>Legend</h3> }); window.myBar.update(); - updateLegend(); - }); - - $('#show').click(function() { - document.getElementById('container').style.display = ''; }); </script> </body>
false
Other
chartjs
Chart.js
428567d8cf376fb4bd6352654136a113ebee2d46.json
improve radar sample - improve title - set same size canvas as other samples - remove user select from canvas - remove html legend
samples/radar.html
@@ -5,23 +5,24 @@ <title>Radar Chart</title> <script src="../dist/Chart.bundle.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> + <style> + canvas { + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + } + </style> </head> <body> - <div style="width:100%"> + <div style="width:75%"> <canvas id="canvas"></canvas> </div> <button id="randomizeData">Randomize Data</button> <button id="addDataset">Add Dataset</button> <button id="removeDataset">Remove Dataset</button> <button id="addData">Add Data</button> <button id="removeData">Remove Data</button> - <div> - <h3>Legend</h3> - <div id="legendContainer"> - - </div> - </div> <script> var randomScalingFactor = function() { return Math.round(Math.random() * 100); @@ -45,7 +46,7 @@ <h3>Legend</h3> }, { label: 'Hidden dataset', hidden: true, - data: [], + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], }, { label: "My Second dataset", backgroundColor: "rgba(151,187,205,0.2)", @@ -61,7 +62,7 @@ <h3>Legend</h3> }, title: { display: true, - text: 'Our 3 Favorite Datasets' + text: 'Chart.js Radar Chart' }, scale: { reverse: false, @@ -72,15 +73,8 @@ <h3>Legend</h3> } }; - function updateLegend() { - $legendContainer = $('#legendContainer'); - $legendContainer.empty(); - $legendContainer.append(window.myRadar.generateLegend()); - } - window.onload = function() { window.myRadar = new Chart(document.getElementById("canvas"), config); - updateLegend(); }; $('#randomizeData').click(function() { @@ -92,7 +86,6 @@ <h3>Legend</h3> }); window.myRadar.update(); - updateLegend(); }); $('#addDataset').click(function() { @@ -112,7 +105,6 @@ <h3>Legend</h3> config.data.datasets.push(newDataset); window.myRadar.update(); - updateLegend(); }); $('#addData').click(function() { @@ -124,14 +116,12 @@ <h3>Legend</h3> }); window.myRadar.update(); - updateLegend(); } }); $('#removeDataset').click(function() { config.data.datasets.splice(0, 1); window.myRadar.update(); - updateLegend(); }); $('#removeData').click(function() { @@ -142,7 +132,6 @@ <h3>Legend</h3> }); window.myRadar.update(); - updateLegend(); }); </script> </body>
false
Other
chartjs
Chart.js
4729b05cc108977014366cc7e76346d7c9532def.json
improve line chart sample - set title for chart - remove html legend - set same size canvas as other samples - remove user select from canvas
samples/line.html
@@ -6,15 +6,17 @@ <script src="../dist/Chart.bundle.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <style> - canvas { - -webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, .5); - } + #canvas{ + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + } </style> </head> <body> - <div style="width:100%;"> - <canvas id="canvas" style="width:100%;height:100%"></canvas> + <div style="width:75%;"> + <canvas id="canvas"></canvas> </div> <br> <br> @@ -24,11 +26,6 @@ <button id="removeDataset">Remove Dataset</button> <button id="addData">Add Data</button> <button id="removeData">Remove Data</button> - <div> - <h3>Legend</h3> - <div id="legendContainer"> - </div> - </div> <script> var randomScalingFactor = function() { return Math.round(Math.random() * 100); @@ -53,14 +50,18 @@ <h3>Legend</h3> }, { hidden: true, label: 'hidden dataset', - data: [], + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], }, { label: "My Second dataset", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], }] }, options: { responsive: true, + title:{ + display:true, + text:'Chart.js Line Chart' + }, tooltips: { mode: 'label', callbacks: { @@ -121,21 +122,11 @@ <h3>Legend</h3> dataset.pointBorderWidth = 1; }); - console.log(config.data); - window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); window.myLine = new Chart(ctx, config); - - updateLegend(); }; - function updateLegend() { - $legendContainer = $('#legendContainer'); - $legendContainer.empty(); - $legendContainer.append(window.myLine.generateLegend()); - } - $('#randomizeData').click(function() { $.each(config.data.datasets, function(i, dataset) { dataset.data = dataset.data.map(function() { @@ -145,7 +136,6 @@ <h3>Legend</h3> }); window.myLine.update(); - updateLegend(); }); $('#changeDataObject').click(function() { @@ -191,7 +181,6 @@ <h3>Legend</h3> config.data.datasets.push(newDataset); window.myLine.update(); - updateLegend(); }); $('#addData').click(function() { @@ -203,14 +192,12 @@ <h3>Legend</h3> }); window.myLine.update(); - updateLegend(); } }); $('#removeDataset').click(function() { config.data.datasets.splice(0, 1); window.myLine.update(); - updateLegend(); }); $('#removeData').click(function() { @@ -221,7 +208,6 @@ <h3>Legend</h3> }); window.myLine.update(); - updateLegend(); }); </script> </body>
false
Other
chartjs
Chart.js
f5a2e394c86df31b6baf47cf22a1e3ac9194bd5c.json
Fix radius 0
src/elements/element.point.js
@@ -60,14 +60,14 @@ module.exports = function(Chart) { return; } - if (vm.radius > 0 || vm.borderWidth > 0) { + if (!isNaN(vm.radius) && vm.radius > 0) { ctx.strokeStyle = vm.borderColor || Chart.defaults.global.defaultColor; - ctx.lineWidth = vm.borderWidth || Chart.defaults.global.elements.point.borderWidth; + ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, Chart.defaults.global.elements.point.borderWidth); ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor; - var radius = vm.radius || Chart.defaults.global.elements.point.radius; + var radius = vm.radius; var xOffset; var yOffset;
false
Other
chartjs
Chart.js
8d6209271be212718fce28df241c960556a55ab6.json
Add link to slack invite
README.md
@@ -2,7 +2,7 @@ # Chart.js -[![Build Status](https://travis-ci.org/nnnick/Chart.js.svg?branch=master)](https://travis-ci.org/nnnick/Chart.js) [![Code Climate](https://codeclimate.com/github/nnnick/Chart.js/badges/gpa.svg)](https://codeclimate.com/github/nnnick/Chart.js) +[![Build Status](https://travis-ci.org/nnnick/Chart.js.svg?branch=master)](https://travis-ci.org/nnnick/Chart.js) [![Code Climate](https://codeclimate.com/github/nnnick/Chart.js/badges/gpa.svg)](https://codeclimate.com/github/nnnick/Chart.js) [![Chart.js on Slack](https://img.shields.io/badge/slack-Chart.js-blue.svg)](https://chartjs-slack-automation.herokuapp.com/) *Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
false
Other
chartjs
Chart.js
111ada730cd69452e5c8303c72f4b50063b4474a.json
Fix typo in docs. Fixes #1042
docs/06-Advanced.md
@@ -96,7 +96,7 @@ var myPieChart = new Chart(ctx).Pie(data, { // tooltip.y // etc... - }; + } }); ```
false
Other
chartjs
Chart.js
4f4f804a7180e8b0a43ee4c551479a540a271c26.json
Use a named define to fix #768
src/Chart.Core.js
@@ -2233,7 +2233,7 @@ if (amd) { - define(function(){ + define('Chart', [], function(){ return Chart; }); } else if (typeof module === 'object' && module.exports) {
false
Other
chartjs
Chart.js
ef1acfa0e85f5b2d5aca473eb5027b91f89d6fb1.json
Build single scales in core
src/core/core.controller.js
@@ -121,6 +121,20 @@ this.scales[scale.id] = scale; }, this); } + + if (this.options.scale) { + // Build radial axes + var ScaleClass = Chart.scaleService.getScaleConstructor(axisOptions.type); + var scale = new ScaleClass({ + ctx: this.chart.ctx, + options: axisOptions, + data: this.data, + id: axisOptions.id, + chart: this.chart, + }); + + this.scale = scale; + } } Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
false
Other
chartjs
Chart.js
fa1b0db453c679320d97513692cf1aac4819da02.json
Apply correct hover styles
src/core/core.controller.js
@@ -331,7 +331,7 @@ break; case 'label': for (var i = 0; i < this.lastActive.length; i++) { - this.data.datasets[this.lastActive[0]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index); + this.data.datasets[this.lastActive[i]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index); } break; case 'dataset': @@ -349,7 +349,7 @@ break; case 'label': for (var i = 0; i < this.active.length; i++) { - this.data.datasets[this.active[0]._datasetIndex].controller.setHoverStyle(this.active[i]); + this.data.datasets[this.active[i]._datasetIndex].controller.setHoverStyle(this.active[i]); } break; case 'dataset':
false
Other
chartjs
Chart.js
22c40fe752fd6754ba16963c3af7ac235eeb3f0e.json
Fix 2 bar samples
samples/bar-multi-axis.html
@@ -45,7 +45,8 @@ }; window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); - window.myBar = new Chart(ctx).Bar({ + window.myBar = new Chart(ctx, { + type: 'bar', data: barChartData, options: { responsive: true,
true
Other
chartjs
Chart.js
22c40fe752fd6754ba16963c3af7ac235eeb3f0e.json
Fix 2 bar samples
samples/bar-stacked.html
@@ -39,7 +39,8 @@ }; window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); - window.myBar = new Chart(ctx).Bar({ + window.myBar = new Chart(ctx, { + type: 'bar', data: barChartData, options: { responsive: true,
true
Other
chartjs
Chart.js
d3538a1fbde0d0468f123531dd92eae215d75bd3.json
use inLabelRange when tooltips are in label mode
src/core/core.controller.js
@@ -223,7 +223,7 @@ helpers.each(this.data.datasets, function(dataset, datasetIndex) { helpers.each(dataset.metaData, function(element, index) { - if (element.inRange(eventPosition.x, eventPosition.y)) { + if (element.inLabelRange(eventPosition.x, eventPosition.y)) { elementsArray.push(element); } }, this);
false
Other
chartjs
Chart.js
b21061c164e265490fe3eb80df266cc62b334044.json
Remove hover styles
src/controllers/controller.bar.js
@@ -128,8 +128,6 @@ }, this); }, - - setHoverStyle: function(rectangle) { var dataset = this.chart.data.datasets[rectangle._datasetIndex]; var index = rectangle._index; @@ -140,7 +138,12 @@ }, removeHoverStyle: function(rectangle) { - // TODO + var dataset = this.chart.data.datasets[rectangle._datasetIndex]; + var index = rectangle._index; + + rectangle._model.backgroundColor = rectangle.custom && rectangle.custom.backgroundColor ? rectangle.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.rectangle.backgroundColor); + rectangle._model.borderColor = rectangle.custom && rectangle.custom.borderColor ? rectangle.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.rectangle.borderColor); + rectangle._model.borderWidth = rectangle.custom && rectangle.custom.borderWidth ? rectangle.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.rectangle.borderWidth); } });
true
Other
chartjs
Chart.js
b21061c164e265490fe3eb80df266cc62b334044.json
Remove hover styles
src/controllers/controller.line.js
@@ -215,7 +215,13 @@ }, removeHoverStyle: function(point) { - // TODO + var dataset = this.chart.data.datasets[point._datasetIndex]; + var index = point._index; + + point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius); + point._model.backgroundColor = point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor); + point._model.borderColor = point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor); + point._model.borderWidth = point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth, index, this.chart.options.elements.point.borderWidth); } });
true
Other
chartjs
Chart.js
81c66c8d8549a458518a6534ae3e81c5c496fe85.json
Fix duplicate property
src/scales/scale.linear.js
@@ -37,7 +37,6 @@ }; var LinearScale = Chart.Element.extend({ - calculateRange: helpers.noop, // overridden in the chart. Will set min and max as properties of the scale for later use isHorizontal: function() { return this.options.position == "top" || this.options.position == "bottom"; },
false
Other
chartjs
Chart.js
ecd3b58b281cf604ad871f91f167d4374e5cc75e.json
Fix typo in linear scale.
src/scales/scale.linear.js
@@ -133,7 +133,7 @@ if (this.options.labels.userCallback) { // If the user provided a callback for label generation, use that as first priority - label = this.options.lables.userCallback(tick, index, ticks); + label = this.options.labels.userCallback(tick, index, ticks); } else if (this.options.labels.template) { // else fall back to the template string label = helpers.template(this.options.labels.template, {
false
Other
chartjs
Chart.js
98253fea5d0e2ecc1dcdad6321e5bf3137fd7ae2.json
Fix some bugs in the animation stuff
src/Chart.Core.js
@@ -948,7 +948,7 @@ var stepDecimal = animationObject.currentStep / animationObject.numSteps; var easeDecimal = easingFunction(stepDecimal); - chartInstance.draw(chartInstance, easeDecimal, stepDecimal, currentStep); + chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep); }; // user events @@ -2094,9 +2094,13 @@ // If there are no animations queued, manually kickstart a digest, for lack of a better word if (this.animations.length) { - helpers.requestAnimFrame(this.startDigest); + helpers.requestAnimFrame.call(window, this.digestWrapper); } }, + // calls startDigest with the proper context + digestWrapper: function() { + Chart.animationService.startDigest.call(Chart.animationService); + }, startDigest: function() { for (var i = 0; i < this.animations.length; i++) { @@ -2121,7 +2125,7 @@ // Do we have more stuff to animate? if (this.animations.length > 0){ - requestAnimationFrame(this.startDigest); + helpers.requestAnimFrame.call(window, this.digestWrapper); } } };
false
Other
chartjs
Chart.js
9a13dd78fc6a37e5239fabd428973bdfd5a8f8a0.json
Fix a typo
src/Chart.Core.js
@@ -2093,7 +2093,7 @@ }); // If there are no animations queued, manually kickstart a digest, for lack of a better word - if(!this.animations.length){ + if (this.animations.length) { helpers.requestAnimFrame(this.startDigest); } },
false
Other
chartjs
Chart.js
3e59438646382d66b2b1313731f237f43c4cc9dc.json
Integrate animation service with chart
src/Chart.Core.js
@@ -2076,9 +2076,9 @@ Chart.animationService = { animations: [], - addAnimation: function(chart, animationObject) { + addAnimation: function(chartInstance, animationObject) { for (var index = 0; index < this.animations.length; ++ index){ - if (this.animations[index].chart === chart){ + if (this.animations[index].chartInstance === chartInstance){ // replacing an in progress animation this.animations[index].lastTimeRun = null; this.animations[index].animationObject = animationObject; @@ -2087,7 +2087,7 @@ } this.animations.push({ - chart: chart, + chartInstance: chartInstance, animationObject: animationObject, lastTimeRun: null }); @@ -2109,7 +2109,7 @@ currentAnimation.animationObject.currentStep++; } - currentAnimation.animationObject.render(currentAnimation.animationObject); + currentAnimation.animationObject.render(currentAnimation.chartInstance, currentAnimation.animationObject); if (currentAnimation.animationObject.currentStep == currentAnimation.animationObject.numSteps){ // executed the last frame. Remove the animation.
false
Other
chartjs
Chart.js
2677360f4bcda5109664c6f2fc93378f46f82760.json
Add offsetGridLines option to Line charts
docs/01-Line-Chart.md
@@ -102,6 +102,9 @@ These are the customisation options specific to Line charts. These options are m //String - A legend template legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>" {% endraw %} + + //Boolean - Whether to horizontally center the label and point dot inside the grid + offsetGridLines : false }; ```
true
Other
chartjs
Chart.js
2677360f4bcda5109664c6f2fc93378f46f82760.json
Add offsetGridLines option to Line charts
src/Chart.Line.js
@@ -50,7 +50,10 @@ datasetFill : true, //String - A legend template - legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>" + legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>", + + //Boolean - Whether to horizontally center the label and point dot inside the grid + offsetGridLines : false }; @@ -61,6 +64,7 @@ initialize: function(data){ //Declare the extension of the default point, to cater for the options passed in to the constructor this.PointClass = Chart.Point.extend({ + offsetGridLines : this.options.offsetGridLines, strokeWidth : this.options.pointDotStrokeWidth, radius : this.options.pointDotRadius, display: this.options.pointDot, @@ -176,6 +180,7 @@ width : this.chart.width, ctx : this.chart.ctx, textColor : this.options.scaleFontColor, + offsetGridLines : this.options.offsetGridLines, fontSize : this.options.scaleFontSize, fontStyle : this.options.scaleFontStyle, fontFamily : this.options.scaleFontFamily,
true
Other
chartjs
Chart.js
47d23601b1e3cfc18c7a661ff56c4545c8e6a29d.json
Fix CodeClimate issues
gulpfile.js
@@ -24,11 +24,11 @@ var srcDir = './src/'; gulp.task('build', function(){ // Default to all of the chart types, with Chart.Core first - var srcFiles = [FileName('Core')], + var srcFiles = [new FileName('Core')], isCustom = !!(util.env.types), outputDir = (isCustom) ? 'custom' : '.'; if (isCustom){ - util.env.types.split(',').forEach(function(type){ return srcFiles.push(FileName(type))}); + util.env.types.split(',').forEach(function(type){ return srcFiles.push(new FileName(type));}); } else{ // Seems gulp-concat remove duplicates - nice! @@ -46,7 +46,7 @@ gulp.task('build', function(){ function FileName(moduleName){ return srcDir+'Chart.'+moduleName+'.js'; - }; + } }); /* @@ -109,7 +109,7 @@ gulp.task('module-sizes', function(){ .pipe(size({ showFiles: true, gzip: true - })) + })); }); gulp.task('watch', function(){
true
Other
chartjs
Chart.js
47d23601b1e3cfc18c7a661ff56c4545c8e6a29d.json
Fix CodeClimate issues
src/Chart.Core.js
@@ -35,7 +35,7 @@ { return document.defaultView.getComputedStyle(element).getPropertyValue(dimension); } - } + }; var width = this.width = computeDimension(context.canvas,'Width') || context.canvas.width; var height = this.height = computeDimension(context.canvas,'Height') || context.canvas.height; @@ -44,8 +44,8 @@ context.canvas.width = width; context.canvas.height = height; - var width = this.width = context.canvas.width; - var height = this.height = context.canvas.height; + width = this.width = context.canvas.width; + height = this.height = context.canvas.height; this.aspectRatio = this.width / this.height; //High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. helpers.retinaScale(this); @@ -210,14 +210,18 @@ clone = helpers.clone = function(obj){ var objClone = {}; each(obj,function(value,key){ - if (obj.hasOwnProperty(key)) objClone[key] = value; + if (obj.hasOwnProperty(key)){ + objClone[key] = value; + } }); return objClone; }, extend = helpers.extend = function(base){ each(Array.prototype.slice.call(arguments,1), function(extensionObject) { each(extensionObject,function(value,key){ - if (extensionObject.hasOwnProperty(key)) base[key] = value; + if (extensionObject.hasOwnProperty(key)){ + base[key] = value; + } }); }); return base; @@ -300,9 +304,9 @@ })(), warn = helpers.warn = function(str){ //Method for warning of errors - if (window.console && typeof window.console.warn == "function") console.warn(str); + if (window.console && typeof window.console.warn === "function") console.warn(str); }, - amd = helpers.amd = (typeof define == 'function' && define.amd), + amd = helpers.amd = (typeof define === 'function' && define.amd), //-- Math methods isNumber = helpers.isNumber = function(n){ return !isNaN(parseFloat(n)) && isFinite(n); @@ -526,7 +530,9 @@ return -1 * t * (t - 2); }, easeInOutQuad: function (t) { - if ((t /= 1 / 2) < 1) return 1 / 2 * t * t; + if ((t /= 1 / 2) < 1){ + return 1 / 2 * t * t; + } return -1 / 2 * ((--t) * (t - 2) - 1); }, easeInCubic: function (t) { @@ -536,7 +542,9 @@ return 1 * ((t = t / 1 - 1) * t * t + 1); }, easeInOutCubic: function (t) { - if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t; + if ((t /= 1 / 2) < 1){ + return 1 / 2 * t * t * t; + } return 1 / 2 * ((t -= 2) * t * t + 2); }, easeInQuart: function (t) { @@ -546,7 +554,9 @@ return -1 * ((t = t / 1 - 1) * t * t * t - 1); }, easeInOutQuart: function (t) { - if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t; + if ((t /= 1 / 2) < 1){ + return 1 / 2 * t * t * t * t; + } return -1 / 2 * ((t -= 2) * t * t * t - 2); }, easeInQuint: function (t) { @@ -556,7 +566,9 @@ return 1 * ((t = t / 1 - 1) * t * t * t * t + 1); }, easeInOutQuint: function (t) { - if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t * t; + if ((t /= 1 / 2) < 1){ + return 1 / 2 * t * t * t * t * t; + } return 1 / 2 * ((t -= 2) * t * t * t * t + 2); }, easeInSine: function (t) { @@ -575,60 +587,95 @@ return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1); }, easeInOutExpo: function (t) { - if (t === 0) return 0; - if (t === 1) return 1; - if ((t /= 1 / 2) < 1) return 1 / 2 * Math.pow(2, 10 * (t - 1)); + if (t === 0){ + return 0; + } + if (t === 1){ + return 1; + } + if ((t /= 1 / 2) < 1){ + return 1 / 2 * Math.pow(2, 10 * (t - 1)); + } return 1 / 2 * (-Math.pow(2, -10 * --t) + 2); }, easeInCirc: function (t) { - if (t >= 1) return t; + if (t >= 1){ + return t; + } return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1); }, easeOutCirc: function (t) { return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t); }, easeInOutCirc: function (t) { - if ((t /= 1 / 2) < 1) return -1 / 2 * (Math.sqrt(1 - t * t) - 1); + if ((t /= 1 / 2) < 1){ + return -1 / 2 * (Math.sqrt(1 - t * t) - 1); + } return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1); }, easeInElastic: function (t) { var s = 1.70158; var p = 0; var a = 1; - if (t === 0) return 0; - if ((t /= 1) == 1) return 1; - if (!p) p = 1 * 0.3; + if (t === 0){ + return 0; + } + if ((t /= 1) == 1){ + return 1; + } + if (!p){ + p = 1 * 0.3; + } if (a < Math.abs(1)) { a = 1; s = p / 4; - } else s = p / (2 * Math.PI) * Math.asin(1 / a); + } else{ + s = p / (2 * Math.PI) * Math.asin(1 / a); + } return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p)); }, easeOutElastic: function (t) { var s = 1.70158; var p = 0; var a = 1; - if (t === 0) return 0; - if ((t /= 1) == 1) return 1; - if (!p) p = 1 * 0.3; + if (t === 0){ + return 0; + } + if ((t /= 1) == 1){ + return 1; + } + if (!p){ + p = 1 * 0.3; + } if (a < Math.abs(1)) { a = 1; s = p / 4; - } else s = p / (2 * Math.PI) * Math.asin(1 / a); + } else{ + s = p / (2 * Math.PI) * Math.asin(1 / a); + } return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1; }, easeInOutElastic: function (t) { var s = 1.70158; var p = 0; var a = 1; - if (t === 0) return 0; - if ((t /= 1 / 2) == 2) return 1; - if (!p) p = 1 * (0.3 * 1.5); + if (t === 0){ + return 0; + } + if ((t /= 1 / 2) == 2){ + return 1; + } + if (!p){ + p = 1 * (0.3 * 1.5); + } if (a < Math.abs(1)) { a = 1; s = p / 4; - } else s = p / (2 * Math.PI) * Math.asin(1 / a); - if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p)); + } else { + s = p / (2 * Math.PI) * Math.asin(1 / a); + } + if (t < 1){ + return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));} return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1; }, easeInBack: function (t) { @@ -641,7 +688,9 @@ }, easeInOutBack: function (t) { var s = 1.70158; - if ((t /= 1 / 2) < 1) return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)); + if ((t /= 1 / 2) < 1){ + return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)); + } return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2); }, easeInBounce: function (t) { @@ -659,7 +708,9 @@ } }, easeInOutBounce: function (t) { - if (t < 1 / 2) return easingEffects.easeInBounce(t * 2) * 0.5; + if (t < 1 / 2){ + return easingEffects.easeInBounce(t * 2) * 0.5; + } return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5; } },
true
Other
chartjs
Chart.js
de564326b098583bf4edd95d698d6c97a8e612b3.json
Target src files from #142
src/Chart.Core.js
@@ -25,6 +25,25 @@ this.ctx = context; //Variables global to the chart + var computeDimension = function(element,dimension) + { + if (element['offset'+dimension]) + { + return element['offset'+dimension]; + } + else + { + return document.defaultView.getComputedStyle(element).getPropertyValue(dimension); + } + } + + var width = this.width = computeDimension(context.canvas,'Width'); + var height = this.height = computeDimension(context.canvas,'Height'); + + // Firefox requires this to work correctly + context.canvas.width = width; + context.canvas.height = height; + var width = this.width = context.canvas.width; var height = this.height = context.canvas.height; this.aspectRatio = this.width / this.height;
false
Other
chartjs
Chart.js
2d28075cdeee07fbfaf045cf00f2db0bc755d7a6.json
ADD GH PR guidelines
CONTRIBUTING.md
@@ -33,7 +33,7 @@ Please provide any additional details associated with the bug, if it's browser o Pull requests ------------- -Clear, concise pull requests are excellent at continuing the project's community driven growth. But please review the guidelines below before starting work on the project. +Clear, concise pull requests are excellent at continuing the project's community driven growth. But please review [these guidelines](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) and the guidelines below before starting work on the project. Guidlines:
false
Other
chartjs
Chart.js
2e0211320bbff4bc81e40062a4c4815cca256e2d.json
Fix a divide by 0 error when there is only 1 label
src/Chart.Core.js
@@ -1575,7 +1575,7 @@ 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/(this.valuesCount - ((this.offsetGridLines) ? 0 : 1)), + valueWidth = innerWidth/Math.max((this.valuesCount - ((this.offsetGridLines) ? 0 : 1)), 1), valueOffset = (valueWidth * index) + this.xScalePaddingLeft; if (this.offsetGridLines){
false
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/charts/Chart.Doughnut.js
@@ -15,6 +15,6 @@ config.type = 'doughnut'; return new Chart(context, config); - } + }; }).call(this);
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/charts/Chart.Line.js
@@ -9,6 +9,6 @@ config.type = 'line'; return new Chart(context, config); - } + }; }).call(this);
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/charts/Chart.PolarArea.js
@@ -15,6 +15,6 @@ config.type = 'polarArea'; return new Chart(context, config); - } + }; }).call(this);
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/charts/Chart.Radar.js
@@ -14,6 +14,6 @@ config.type = 'radar'; return new Chart(context, config); - } + }; }).call(this);
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/charts/Chart.Scatter.js
@@ -34,6 +34,6 @@ config.options = helpers.configMerge(defaultConfig, config.options); config.type = 'line'; return new Chart(context, config); - } + }; }).call(this); \ No newline at end of file
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/controllers/controller.doughnut.js
@@ -92,7 +92,7 @@ // Make sure that we handle number of datapoints changing if (numData < numArcs) { // Remove excess bars for data points that have been removed - this.getDataset().metaData.splice(numData, numArcs - numData) + this.getDataset().metaData.splice(numData, numArcs - numData); } else if (numData > numArcs) { // Add new elements for (var index = numArcs; index < numData; ++index) {
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/controllers/controller.polarArea.js
@@ -87,7 +87,7 @@ // Make sure that we handle number of datapoints changing if (numData < numPoints) { // Remove excess bars for data points that have been removed - this.getDataset().metaData.splice(numData, numPoints - numData) + this.getDataset().metaData.splice(numData, numPoints - numData); } else if (numData > numPoints) { // Add new elements for (var index = numPoints; index < numData; ++index) { @@ -206,12 +206,4 @@ }, }); - - - - return; - - - Chart.Type.extend({}); - }).call(this);
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/controllers/controller.radar.js
@@ -103,7 +103,7 @@ // Make sure that we handle number of datapoints changing if (numData < numPoints) { // Remove excess bars for data points that have been removed - this.getDataset().metaData.splice(numData, numPoints - numData) + this.getDataset().metaData.splice(numData, numPoints - numData); } else if (numData > numPoints) { // Add new elements for (var index = numPoints; index < numData; ++index) {
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/core/core.controller.js
@@ -158,7 +158,7 @@ this.scale = scale; - this.scales['radialScale'] = scale; + this.scales.radialScale = scale; } Chart.scaleService.update(this, this.chart.width, this.chart.height); @@ -313,13 +313,13 @@ helpers.each(this.data.datasets, function(dataset, datasetIndex) { if (helpers.isDatasetVisible(dataset)) { - for (var elementIndex = 0; elementIndex < dataset.metaData.length; elementIndex++) { - if (dataset.metaData[elementIndex].inLabelRange(eventPosition.x, eventPosition.y)) { + helpers.each(dataset.metaData, function(element, elementIndex) { + if (element.inLabelRange(eventPosition.x, eventPosition.y)) { helpers.each(dataset.metaData, function(element, index) { elementsArray.push(element); }, this); } - } + }, this); } }, this); @@ -428,8 +428,8 @@ break; case 'label': case 'dataset': - for (var i = 0; i < this.active.length; i++) { - this.data.datasets[this.active[i]._datasetIndex].controller.setHoverStyle(this.active[i]); + for (var j = 0; j < this.active.length; j++) { + this.data.datasets[this.active[j]._datasetIndex].controller.setHoverStyle(this.active[j]); } break; default:
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/core/core.helpers.js
@@ -135,7 +135,7 @@ base[key].push(helpers.configMerge(valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj)); } else if (valueObj.type !== base[key][index].type) { // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults - base[key][index] = helpers.configMerge(base[key][index], valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj) + base[key][index] = helpers.configMerge(base[key][index], valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj); } else { // Type is the same base[key][index] = helpers.configMerge(base[key][index], valueObj); @@ -272,7 +272,7 @@ }, log10 = helpers.log10 = function(x) { if (Math.log10) { - return Math.log10(x) + return Math.log10(x); } else { return Math.log(x) / Math.LN10; } @@ -837,7 +837,7 @@ // can use classlist hiddenIframe.classlist.add(hiddenIframeClass); } else { - hiddenIframe.setAttribute('class', hiddenIframeClass) + hiddenIframe.setAttribute('class', hiddenIframeClass); } // Set the style @@ -860,7 +860,7 @@ if (callback) { callback(); } - } + }; }, removeResizeListener = helpers.removeResizeListener = function(node) { var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/core/core.scale.js
@@ -112,7 +112,7 @@ // Reset position before calculating rotation this.top = 0; - this.bottom = this.height + this.bottom = this.height; } // Reset padding
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/elements/element.arc.js
@@ -45,7 +45,7 @@ // Put into the range of (-PI/2, 3PI/2] var startAngle = vm.startAngle < (-0.5 * Math.PI) ? vm.startAngle + (2.0 * Math.PI) : vm.startAngle > (1.5 * Math.PI) ? vm.startAngle - (2.0 * Math.PI) : vm.startAngle; - var endAngle = vm.endAngle < (-0.5 * Math.PI) ? vm.endAngle + (2.0 * Math.PI) : vm.endAngle > (1.5 * Math.PI) ? vm.endAngle - (2.0 * Math.PI) : vm.endAngle + var endAngle = vm.endAngle < (-0.5 * Math.PI) ? vm.endAngle + (2.0 * Math.PI) : vm.endAngle > (1.5 * Math.PI) ? vm.endAngle - (2.0 * Math.PI) : vm.endAngle; //Check if within the range of the open/close angle var betweenAngles = (pointRelativePosition.angle >= startAngle && pointRelativePosition.angle <= endAngle),
true
Other
chartjs
Chart.js
e46a2cb074e92342ec8d52a18177ac91bec04cde.json
Fix JSHint errors
src/scales/scale.category.js
@@ -21,23 +21,23 @@ if (this.isHorizontal()) { var innerWidth = this.width - (this.paddingLeft + this.paddingRight); var valueWidth = innerWidth / Math.max((this.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1); - var valueOffset = (valueWidth * index) + this.paddingLeft; + var widthOffset = (valueWidth * index) + this.paddingLeft; if (this.options.gridLines.offsetGridLines && includeOffset) { - valueOffset += (valueWidth / 2); + widthOffset += (valueWidth / 2); } - return this.left + Math.round(valueOffset); + return this.left + Math.round(widthOffset); } else { var innerHeight = this.height - (this.paddingTop + this.paddingBottom); var valueHeight = innerHeight / Math.max((this.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1); - var valueOffset = (valueHeight * index) + this.paddingTop; + var heightOffset = (valueHeight * index) + this.paddingTop; if (this.options.gridLines.offsetGridLines && includeOffset) { - valueOffset += (valueHeight / 2); + heightOffset += (valueHeight / 2); } - return this.top + Math.round(valueOffset); + return this.top + Math.round(heightOffset); } }, });
true
Other
chartjs
Chart.js
35011e5ae396d5dd68961d14ec50d8ef5f3a809e.json
Support min and max dates on time scale
src/scales/scale.time.js
@@ -91,8 +91,17 @@ scaleLabelMoments.push(labelMoment); }, this); - this.firstTick = moment.min.call(this, scaleLabelMoments); - this.lastTick = moment.max.call(this, scaleLabelMoments); + if (this.options.time.min) { + this.firstTick = this.parseTime(this.options.time.min); + } else { + this.firstTick = moment.min.call(this, scaleLabelMoments); + } + + if (this.options.time.max) { + this.lastTick = this.parseTime(this.options.time.max); + } else { + this.lastTick = moment.max.call(this, scaleLabelMoments); + } } else { this.firstTick = null; this.lastTick = null;
false
Other
chartjs
Chart.js
86a52d030233944cdedc14bc1c5076c74826ea87.json
Fix some test failures
src/core/core.scale.js
@@ -48,7 +48,7 @@ reverse: false, show: true, callback: function(value) { - return value; + return '' + value; }, }, };
true
Other
chartjs
Chart.js
86a52d030233944cdedc14bc1c5076c74826ea87.json
Fix some test failures
src/scales/scale.logarithmic.js
@@ -10,7 +10,15 @@ // label settings ticks: { - template: "<%var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));if (remain === 1 || remain === 2 || remain === 5) {%><%=value.toExponential()%><%} else {%><%= null %><%}%>", + callback: function(value) { + var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value)))); + + if (remain === 1 || remain === 2 || remain === 5) { + return value.toExponential() + } else { + return ''; + } + } } };
true
Other
chartjs
Chart.js
ceaa4ff03f7bc53bbc19711a023ea9313fdfde7f.json
Add a helper function to reduce code size
src/core/core.tooltip.js
@@ -60,6 +60,19 @@ }, }; + // Helper to push or concat based on if the 2nd parameter is an array or not + function pushOrConcat(base, toPush) { + if (toPush) { + if (helpers.isArray(toPush)) { + base = base.concat(toPush); + } else { + base.push(toPush); + } + } + + return base; + } + Chart.Tooltip = Chart.Element.extend({ initialize: function() { var options = this._options; @@ -106,34 +119,17 @@ }); }, + // Get the title getTitle: function() { var beforeTitle = this._options.tooltips.callbacks.beforeTitle.apply(this, arguments), title = this._options.tooltips.callbacks.title.apply(this, arguments), afterTitle = this._options.tooltips.callbacks.afterTitle.apply(this, arguments); var lines = []; + lines = pushOrConcat(lines, beforeTitle); + lines = pushOrConcat(lines, title); + lines = pushOrConcat(lines, afterTitle); - if (beforeTitle) { - if (helpers.isArray(beforeTitle)) { - lines = lines.concat(beforeTitle); - } else { - lines.push(beforeTitle); - } - } - if (title) { - if (helpers.isArray(title)) { - lines = lines.concat(title); - } else { - lines.push(title); - } - } - if (afterTitle) { - if (helpers.isArray(afterTitle)) { - lines = lines.concat(afterTitle); - } else { - lines.push(afterTitle); - } - } return lines; }, @@ -189,34 +185,16 @@ return helpers.isArray(lines) ? lines : [lines]; }, + // Get the footer and beforeFooter and afterFooter lines getFooter: function() { - var beforeFooter = this._options.tooltips.callbacks.beforeFooter.apply(this, arguments), - footer = this._options.tooltips.callbacks.footer.apply(this, arguments), - afterFooter = this._options.tooltips.callbacks.afterFooter.apply(this, arguments); + var beforeFooter = this._options.tooltips.callbacks.beforeFooter.apply(this, arguments); + var footer = this._options.tooltips.callbacks.footer.apply(this, arguments); + var afterFooter = this._options.tooltips.callbacks.afterFooter.apply(this, arguments); var lines = []; - - if (beforeFooter) { - if (helpers.isArray(beforeFooter)) { - lines = lines.concat(beforeFooter); - } else { - lines.push(beforeFooter); - } - } - if (footer) { - if (helpers.isArray(footer)) { - lines = lines.concat(footer); - } else { - lines.push(footer); - } - } - if (afterFooter) { - if (helpers.isArray(afterFooter)) { - lines = lines.concat(afterFooter); - } else { - lines.push(afterFooter); - } - } + lines = pushOrConcat(lines, beforeFooter); + lines = pushOrConcat(lines, footer); + lines = pushOrConcat(lines, afterFooter); return lines; },
false
Other
chartjs
Chart.js
6001a1e4e7d4a572e70cd55c049449ac85cbe134.json
Fix JSHint task
gulpfile.js
@@ -117,7 +117,7 @@ function releaseTask() { function jshintTask() { - return gulp.src(srcDir + '*.js') + return gulp.src(srcDir + '**/*.js') .pipe(jshint()) .pipe(jshint.reporter('default')); }
false
Other
chartjs
Chart.js
93ee8f85f66e3dcfc9b213ae9733ae12a513953e.json
Put comment back in correct spot
src/core/core.js
@@ -57,11 +57,11 @@ // High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. Chart.helpers.retinaScale(this); - // Always bind this so that if the responsive state changes we still work if (config) { this.controller = new Chart.Controller(this); } + // Always bind this so that if the responsive state changes we still work var _this = this; Chart.helpers.addResizeListener(context.canvas.parentNode, function() { if (_this.controller && _this.controller.config.options.responsive) {
false
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/bar.html
@@ -45,6 +45,7 @@ <h3>Legend</h3> backgroundColor: "rgba(220,220,220,0.5)", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] }, { + hidden: true, label: 'Dataset 2', backgroundColor: "rgba(151,187,205,0.5)", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
true
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/combo-bar-line.html
@@ -2,7 +2,7 @@ <html> <head> - <title>Bar Chart</title> + <title>Combo Bar-Line Chart</title> <script src="../node_modules/jquery/dist/jquery.min.js"></script> <script src="../Chart.js"></script> </head> @@ -30,14 +30,14 @@ borderColor: 'white', borderWidth: 2 }, { - type: 'bar', + type: 'line', label: 'Dataset 2', backgroundColor: "rgba(151,187,205,0.5)", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], borderColor: 'white', borderWidth: 2 }, { - type: 'line', + type: 'bar', label: 'Dataset 3', backgroundColor: "rgba(220,220,220,0.5)", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
true
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/doughnut.html
@@ -61,6 +61,7 @@ <h3>Legend</h3> "#4D5360", ], }, { + hidden: true, data: [ randomScalingFactor(), randomScalingFactor(),
true
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/line-x-axis-filter.html
@@ -54,8 +54,8 @@ xAxes: [{ display: true, ticks: { - callback: function(dataLabel, index) { - return dataLabel; + userCallback: function(dataLabel, index) { + return index % 2 === 0 ? dataLabel : ''; } } }],
true
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/line.html
@@ -48,6 +48,10 @@ <h3>Legend</h3> data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], fill: false, borderDash: [5, 5], + }, { + hidden: true, + label: 'hidden dataset', + data: [], }, { label: "My Second dataset", data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
true
Other
chartjs
Chart.js
0d2fa807da54e2c56d3a3778741c8ee139238725.json
Update samples with some hidden datasets
samples/radar.html
@@ -42,14 +42,18 @@ <h3>Legend</h3> backgroundColor: "rgba(220,220,220,0.2)", pointBackgroundColor: "rgba(220,220,220,1)", data: [null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] + }, { + label: 'Hidden dataset', + hidden: true, + data: [], }, { label: "My Second dataset", backgroundColor: "rgba(151,187,205,0.2)", pointBackgroundColor: "rgba(151,187,205,1)", hoverPointBackgroundColor: "#fff", pointHighlightStroke: "rgba(151,187,205,1)", data: [null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] - }] + },] }, options: { scale: {
true
Other
chartjs
Chart.js
5543041fcdf89d11be448fd341df37ae9fee1ccb.json
Add Moment.js back into test reps
gulpfile.js
@@ -37,6 +37,7 @@ var srcFiles = [ ]; var testFiles = [ + './node_modules/moment/min/moment.min.js', './test/mockContext.js', './test/*.js' ];
true
Other
chartjs
Chart.js
5543041fcdf89d11be448fd341df37ae9fee1ccb.json
Add Moment.js back into test reps
package.json
@@ -35,5 +35,8 @@ }, "spm": { "main": "Chart.js" + }, + "dependencies": { + "moment": "^2.10.6" } }
true
Other
chartjs
Chart.js
63a0273591b2943f9ff96262b26f1d5c9f5ca058.json
Remove moment and onecolor as deps
package.json
@@ -31,8 +31,6 @@ "karma-firefox-launcher": "^0.1.6", "karma-jasmine": "^0.3.6", "karma-jasmine-html-reporter": "^0.1.8", - "moment": "^2.10.6", - "onecolor": "^2.5.0", "semver": "^3.0.1" }, "spm": {
false
Other
chartjs
Chart.js
db3b5c1735216fecc6721fc271c6d2dd922adbd7.json
Fix broken helper test
test/core.helpers.tests.js
@@ -210,18 +210,19 @@ describe('Core helper tests', function() { type: 'linear', axisProp: 456 }, { - type: 'linear', display: true, - position: "right", + gridLines: { - show: true, color: "rgba(0, 0, 0, 0.1)", - lineWidth: 1, drawOnChartArea: true, - drawTicks: true, - zeroLineWidth: 1, + drawTicks: true, // draw ticks extending towards the label + lineWidth: 1, + offsetGridLines: false, + show: true, zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineWidth: 1, }, + position: "right", scaleLabel: { fontColor: '#666', fontFamily: 'Helvetica Neue', @@ -230,32 +231,35 @@ describe('Core helper tests', function() { labelString: '', show: false, }, - reverse: false, - beginAtZero: false, - override: null, - labels: { - show: true, - mirror: false, - padding: 10, - template: "<%=value.toLocaleString()%>", + ticks: { + beginAtZero: false, + fontColor: "#666", + fontFamily: "Helvetica Neue", fontSize: 12, fontStyle: "normal", - fontColor: "#666", - fontFamily: "Helvetica Neue" - } + maxRotation: 90, + minRotation: 20, + mirror: false, + padding: 10, + reverse: false, + show: true, + template: "<%=value%>" + }, + type: 'linear' }, { - type: 'linear', display: true, - position: "left", + gridLines: { - show: true, color: "rgba(0, 0, 0, 0.1)", - lineWidth: 1, drawOnChartArea: true, - drawTicks: true, - zeroLineWidth: 1, + drawTicks: true, // draw ticks extending towards the label + lineWidth: 1, + offsetGridLines: false, + show: true, zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineWidth: 1, }, + position: "left", scaleLabel: { fontColor: '#666', fontFamily: 'Helvetica Neue', @@ -264,19 +268,21 @@ describe('Core helper tests', function() { labelString: '', show: false, }, - reverse: false, - beginAtZero: false, - override: null, - labels: { - show: true, - mirror: false, - padding: 10, - template: "<%=value.toLocaleString()%>", + ticks: { + beginAtZero: false, + fontColor: "#666", + fontFamily: "Helvetica Neue", fontSize: 12, fontStyle: "normal", - fontColor: "#666", - fontFamily: "Helvetica Neue" - } + maxRotation: 90, + minRotation: 20, + mirror: false, + padding: 10, + reverse: false, + show: true, + template: "<%=value%>" + }, + type: 'linear' }] } });
false
Other
chartjs
Chart.js
dd62944b79e0294880dd510961bd2a85df540f9f.json
Fix bracket placement
src/scales/scale.linear.js
@@ -157,7 +157,7 @@ }, // Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not getRightValue: function(rawValue) { - return typeof (rawValue === "object" && rawValue !== null) ? (this.isHorizontal() ? rawValue.x : rawValue.y) : rawValue; + return (typeof (rawValue) === "object" && rawValue !== null) ? (this.isHorizontal() ? rawValue.x : rawValue.y) : rawValue; }, getPixelForValue: function(value) { // This must be called after fit has been run so that
false
Other
chartjs
Chart.js
0c6f37fff744e8f00c57c51407136cc39d506409.json
Add support for mirror option
docs/00-Getting-Started.md
@@ -364,6 +364,12 @@ the following options. labels: { // Boolean - if true show labels show: true, + + // Boolean - if true the chart will mirror the axis labels. If the labels are on the left, mirroring the axis will render them to the right + mirror: false, + + // Number - controls the padding between the label and the axis + padding: 10, // String - template string for labels template: "<%=value%>",
true
Other
chartjs
Chart.js
0c6f37fff744e8f00c57c51407136cc39d506409.json
Add support for mirror option
src/scales/scale.linear.js
@@ -28,11 +28,13 @@ // label settings labels: { show: true, + mirror: false, + padding: 10, template: "<%=value.toLocaleString()%>", fontSize: 12, fontStyle: "normal", fontColor: "#666", - fontFamily: "Helvetica Neue", + fontFamily: "Helvetica Neue" } }; @@ -548,12 +550,22 @@ var labelStartX; if (this.options.position == "left") { - labelStartX = this.right - 10; - this.ctx.textAlign = "right"; + if (this.options.labels.mirror) { + labelStartX = this.right + this.options.labels.padding; + this.ctx.textAlign = "left"; + } else { + labelStartX = this.right - this.options.labels.padding; + this.ctx.textAlign = "right"; + } } else { // right side - labelStartX = this.left + 5; - this.ctx.textAlign = "left"; + if (this.options.labels.mirror) { + labelStartX = this.left - this.options.labels.padding; + this.ctx.textAlign = "right"; + } else { + labelStartX = this.left + this.options.labels.padding; + this.ctx.textAlign = "left"; + } } this.ctx.textBaseline = "middle";
true
Other
chartjs
Chart.js
d7ee18372a0dbd857691725de8523baa8fc128e5.json
Fix error in generateLegend() function
src/Chart.Core.js
@@ -967,7 +967,7 @@ return this; }, generateLegend : function(){ - return template(this.options.legendTemplate,this); + return helpers.template(this.options.legendTemplate, {datasets: this.data.datasets}); }, destroy : function(){ this.clear();
false
Other
chartjs
Chart.js
79b02bcf26e2338e7acd01ffeb3a9f87c20a8088.json
add license to package.json just to be a good npm citizen :)
package.json
@@ -8,6 +8,7 @@ "type": "git", "url": "https://github.com/nnnick/Chart.js.git" }, + "license" : "MIT", "dependences": {}, "devDependencies": { "gulp": "3.5.x", @@ -25,4 +26,4 @@ "spm": { "main": "Chart.js" } -} \ No newline at end of file +}
false
Other
chartjs
Chart.js
f7e39620870787c4a49ee4c0085a46171d5f57b6.json
Call onAnimationComplete when reached last frame
src/Chart.Core.js
@@ -2141,8 +2141,11 @@ this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject); + // Check if executed the last frame. if (this.animations[i].animationObject.currentStep == this.animations[i].animationObject.numSteps){ - // executed the last frame. Remove the animation. + // Call onAnimationComplete + this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance); + // Remove the animation. this.animations.splice(i, 1); // Keep the index in place to offset the splice i--;
false
Other
chartjs
Chart.js
6110352df8c732dcda28777bdd87abd25ddf74f8.json
Add userCallback to category scale + demo file
samples/line-x-axis-filter.html
@@ -0,0 +1,138 @@ +<!doctype html> +<html> + +<head> + <title>Chart with xAxis Filtering</title> + <script src="../Chart.js"></script> + <script src="../node_modules/jquery/dist/jquery.min.js"></script> + <style> + canvas { + -webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, .5); + } + </style> +</head> + +<body> + <div style="width:50%;"> + <canvas id="canvas" style="width:100%;height:100%"></canvas> + </div> + <br> + <br> + <button id="randomizeData">Randomize Data</button> + <button id="addDataset">Add Dataset</button> + <button id="removeDataset">Remove Dataset</button> + <button id="addData">Add Data</button> + <button id="removeData">Remove Data</button> + <script> + var randomScalingFactor = function() { + return Math.round(Math.random() * 50 * (Math.random() > 0.5 ? 1 : 1)) + 50; + }; + var randomColorFactor = function() { + return Math.round(Math.random() * 255); + }; + var randomColor = function(opacity) { + return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')'; + }; + + var config = { + type: 'line', + data: { + labels: ["January", "February", "March", "April", "May", "June", "July"], + datasets: [{ + label: "My First dataset", + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], + fill: false, + borderDash: [5, 5], + }, { + label: "My Second dataset", + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()], + }] + }, + options: { + responsive: true, + scales: { + xAxes: [{ + display: true, + labels: { + userCallback: function(dataLabel, index) { + return index % 2 === 0 ? dataLabel : ''; + } + } + }], + yAxes: [{ + display: true, + beginAtZero: false + }] + } + } + }; + + $.each(config.data.datasets, function(i, dataset) { + dataset.borderColor = randomColor(0.4); + dataset.backgroundColor = randomColor(0.5); + dataset.pointBorderColor = randomColor(0.7); + dataset.pointBackgroundColor = randomColor(0.5); + dataset.pointBorderWidth = 1; + }); + + console.log(config.data); + + window.onload = function() { + var ctx = document.getElementById("canvas").getContext("2d"); + window.myLine = new Chart(ctx, config); + }; + + $('#randomizeData').click(function() { + $.each(config.data.datasets, function(i, dataset) { + dataset.data = dataset.data.map(function() { + return randomScalingFactor(); + }); + + }); + + window.myLine.update(); + }); + + $('#addDataset').click(function() { + var newDataset = { + label: 'Dataset ' + config.data.datasets.length, + borderColor: randomColor(0.4), + backgroundColor: randomColor(0.5), + pointBorderColor: randomColor(0.7), + pointBackgroundColor: randomColor(0.5), + pointBorderWidth: 1, + data: [], + }; + + for (var index = 0; index < config.data.labels.length; ++index) { + newDataset.data.push(randomScalingFactor()); + } + + window.myLine.addDataset(newDataset); + }); + + $('#addData').click(function() { + if (config.data.datasets.length > 0) { + config.data.labels.push('dataset #' + config.data.labels.length); + + for (var index = 0; index < config.data.datasets.length; ++index) { + window.myLine.addData(randomScalingFactor(), index); + } + } + }); + + $('#removeDataset').click(function() { + window.myLine.removeDataset(0); + }); + + $('#removeData').click(function() { + config.data.labels.splice(-1, 1); // remove the label first + + config.data.datasets.forEach(function(dataset, datasetIndex) { + window.myLine.removeData(datasetIndex, -1); + }); + }); + </script> +</body> + +</html>
true
Other
chartjs
Chart.js
6110352df8c732dcda28777bdd87abd25ddf74f8.json
Add userCallback to category scale + demo file
src/scales/scale.category.js
@@ -37,13 +37,24 @@ isHorizontal: function() { return this.options.position == "top" || this.options.position == "bottom"; }, + buildLabels: function(index) { + this.labels = []; + + if (this.options.labels.userCallback) { + this.data.labels.forEach(function(labelString, index) { + this.labels.push(this.options.labels.userCallback(labelString, index)); + }, this); + } else { + this.labels = this.data.labels; + } + }, getPixelForValue: function(value, index, datasetIndex, includeOffset) { // This must be called after fit has been run so that // this.left, this.top, this.right, and this.bottom have been defined if (this.isHorizontal()) { var isRotated = (this.labelRotation > 0); var innerWidth = this.width - (this.paddingLeft + this.paddingRight); - var valueWidth = innerWidth / Math.max((this.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1); + var valueWidth = innerWidth / Math.max((this.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1); var valueOffset = (valueWidth * index) + this.paddingLeft; if (this.options.gridLines.offsetGridLines && includeOffset) { @@ -52,7 +63,7 @@ return this.left + Math.round(valueOffset); } else { - return this.top + (index * (this.height / this.data.labels.length)); + return this.top + (index * (this.height / this.labels.length)); } }, getPointPixelForValue: function(value, index, datasetIndex) { @@ -90,8 +101,8 @@ var labelFont = helpers.fontString(this.options.labels.fontSize, this.options.labels.fontStyle, this.options.labels.fontFamily); this.ctx.font = labelFont; - var firstWidth = this.ctx.measureText(this.data.labels[0]).width; - var lastWidth = this.ctx.measureText(this.data.labels[this.data.labels.length - 1]).width; + var firstWidth = this.ctx.measureText(this.labels[0]).width; + var lastWidth = this.ctx.measureText(this.labels[this.labels.length - 1]).width; var firstRotated; var lastRotated; @@ -101,7 +112,7 @@ this.labelRotation = 0; if (this.options.display) { - var originalLabelWidth = helpers.longestText(this.ctx, labelFont, this.data.labels); + var originalLabelWidth = helpers.longestText(this.ctx, labelFont, this.labels); var cosRotation; var sinRotation; var firstRotatedWidth; @@ -164,6 +175,7 @@ this.height = maxHeight; } + this.buildLabels(); this.calculateLabelRotation(maxHeight, margins); var minSize = { @@ -172,7 +184,7 @@ }; var labelFont = helpers.fontString(this.options.labels.fontSize, this.options.labels.fontStyle, this.options.labels.fontFamily); - var longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.data.labels); + var longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.labels); // Width if (this.isHorizontal()) { @@ -209,7 +221,7 @@ var yTickEnd = this.options.position == "bottom" ? this.top + 10 : this.bottom; var isRotated = this.labelRotation !== 0; - helpers.each(this.data.labels, function(label, index) { + helpers.each(this.labels, function(label, index) { var xLineValue = this.getPixelForValue(label, index, null, false); // xvalues for grid lines var xLabelValue = this.getPixelForValue(label, index, null, true); // x values for labels (need to consider offsetLabel option)
true
Other
chartjs
Chart.js
02616b9f17b336762ad061dc96b0688affd79b79.json
Fix the spelling of "separate"
docs/06-Advanced.md
@@ -176,7 +176,7 @@ npm install -g gulp This will install the local development dependencies for Chart.js, along with a CLI for the JavaScript task runner <a href="http://gulpjs.com/" target="_blank">gulp</a>. -Now, we can run the `gulp build` task, and pass in a comma seperated list of types as an argument to build a custom version of Chart.js with only specified chart types. +Now, we can run the `gulp build` task, and pass in a comma-separated list of types as an argument to build a custom version of Chart.js with only specified chart types. Here we will create a version of Chart.js with only Line, Radar and Bar charts included:
true
Other
chartjs
Chart.js
02616b9f17b336762ad061dc96b0688affd79b79.json
Fix the spelling of "separate"
src/Chart.Core.js
@@ -407,7 +407,7 @@ var maxValue = max(valuesArray), minValue = min(valuesArray); - // We need some degree of seperation here to calculate the scales if all the values are the same + // We need some degree of separation here to calculate the scales if all the values are the same // Adding/minusing 0.5 will give us a range of 1. if (maxValue === minValue){ maxValue += 0.5;
true
Other
chartjs
Chart.js
02616b9f17b336762ad061dc96b0688affd79b79.json
Fix the spelling of "separate"
src/Chart.Line.js
@@ -294,7 +294,7 @@ },this); - // Control points need to be calculated in a seperate loop, because we need to know the current x/y of the point + // Control points need to be calculated in a separate loop, because we need to know the current x/y of the point // This would cause issues when there is no animation, because the y of the next point would be 0, so beziers would be skewed if (this.options.bezierCurve){ helpers.each(pointsWithValues, function(point, index){
true
Other
chartjs
Chart.js
3985d50201cafe53cbb9abad5910fae2553e83e5.json
use correct option in radar chart
docs/05-Radar-Chart.md
@@ -46,7 +46,7 @@ pointBackgroundColor | `Color or Array<Color>` | The fill color for points pointBorderWidth | `Number or Array<Number>` | The width of the point border in pixels pointRadius | `Number or Array<Number>` | The radius of the point shape. If set to 0, nothing is rendered. pointHoverRadius | `Number or Array<Number>` | The radius of the point when hovered -hitRadius | `Number or Array<Number>` | The pixel size of the non-displayed point that reacts to mouse events +pointHitRadius | `Number or Array<Number>` | The pixel size of the non-displayed point that reacts to mouse events pointHoverBackgroundColor | `Color or Array<Color>` | Point background color when hovered pointHoverBorderColor | `Color or Array<Color>` | Point border color when hovered pointHoverBorderWidth | `Number or Array<Number>` | Border width of point when hovered
false
Other
chartjs
Chart.js
9ac0293b1ab57d058bd736bc175bed1544dd9331.json
Fix path in 09-Advanced.md
docs/09-Advanced.md
@@ -182,7 +182,7 @@ var myPieChart = new Chart(ctx, { }); ``` -See `sample/line-customTooltips.html` for examples on how to get started. +See `samples/tooltips/line-customTooltips.html` for examples on how to get started. ### Writing New Scale Types
false
Other
chartjs
Chart.js
3f2d7efc70409f9a8fd70ea093bf008f592132af.json
Add a function to filter items out of the legend
docs/01-Chart-Configuration.md
@@ -154,6 +154,7 @@ fontColor | Color | "#666" | Font color inherited from global configuration fontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" | Font family inherited from global configuration padding | Number | 10 | Padding between rows of colored boxes generateLabels: | Function | `function(chart) { }` | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See [Legend Item](#chart-configuration-legend-item-interface) for details. +filter | Function | null | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#chart-configuration-legend-item-interface) and the chart data usePointStyle | Boolean | false | Label style will match corresponding point style (size is based on fontSize, boxWidth is not used in this case). #### Legend Item Interface
true
Other
chartjs
Chart.js
3f2d7efc70409f9a8fd70ea093bf008f592132af.json
Add a function to filter items out of the legend
src/core/core.legend.js
@@ -162,10 +162,20 @@ module.exports = function(Chart) { beforeBuildLabels: noop, buildLabels: function() { var me = this; - me.legendItems = me.options.labels.generateLabels.call(me, me.chart); + var labelOpts = me.options.labels; + var legendItems = labelOpts.generateLabels.call(me, me.chart); + + if (labelOpts.filter) { + legendItems = legendItems.filter(function(item) { + return labelOpts.filter(item, me.chart.data); + }); + } + if (me.options.reverse) { - me.legendItems.reverse(); + legendItems.reverse(); } + + me.legendItems = legendItems; }, afterBuildLabels: noop,
true
Other
chartjs
Chart.js
3f2d7efc70409f9a8fd70ea093bf008f592132af.json
Add a function to filter items out of the legend
test/core.legend.tests.js
@@ -90,6 +90,71 @@ describe('Legend block tests', function() { }]); }); + it('should filter items', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [{ + label: 'dataset1', + backgroundColor: '#f31', + borderCapStyle: 'butt', + borderDash: [2, 2], + borderDashOffset: 5.5, + data: [] + }, { + label: 'dataset2', + hidden: true, + borderJoinStyle: 'miter', + data: [], + legendHidden: true + }, { + label: 'dataset3', + borderWidth: 10, + borderColor: 'green', + pointStyle: 'crossRot', + data: [] + }], + labels: [] + }, + options: { + legend: { + labels: { + filter: function(legendItem, data) { + var dataset = data.datasets[legendItem.datasetIndex]; + return !dataset.legendHidden; + } + } + } + } + }); + + expect(chart.legend.legendItems).toEqual([{ + text: 'dataset1', + fillStyle: '#f31', + hidden: false, + lineCap: 'butt', + lineDash: [2, 2], + lineDashOffset: 5.5, + lineJoin: undefined, + lineWidth: undefined, + strokeStyle: undefined, + pointStyle: undefined, + datasetIndex: 0 + }, { + text: 'dataset3', + fillStyle: undefined, + hidden: false, + lineCap: undefined, + lineDash: undefined, + lineDashOffset: undefined, + lineJoin: undefined, + lineWidth: 10, + strokeStyle: 'green', + pointStyle: 'crossRot', + datasetIndex: 2 + }]); + }); + it('should draw correctly', function() { var chart = window.acquireChart({ type: 'bar',
true
Other
chartjs
Chart.js
6b449a9e7c56d873edc28b3e2dcf976b2ea27404.json
Fix retina scale when display size is implicit The retinaScale helper now enforces the display size to the correct values because if no style has been set on the canvas, the render size is used as display size, making the chart bigger (or smaller) when deviceAspectRatio is different of 1.
src/core/core.controller.js
@@ -287,12 +287,11 @@ module.exports = function(Chart) { canvas.width = chart.width = newWidth; canvas.height = chart.height = newHeight; - - helpers.retinaScale(chart); - canvas.style.width = newWidth + 'px'; canvas.style.height = newHeight + 'px'; + helpers.retinaScale(chart); + // Notify any plugins about the resize var newSize = {width: newWidth, height: newHeight}; Chart.plugins.notify('resize', [me, newSize]);
true
Other
chartjs
Chart.js
6b449a9e7c56d873edc28b3e2dcf976b2ea27404.json
Fix retina scale when display size is implicit The retinaScale helper now enforces the display size to the correct values because if no style has been set on the canvas, the render size is used as display size, making the chart bigger (or smaller) when deviceAspectRatio is different of 1.
src/core/core.helpers.js
@@ -832,17 +832,24 @@ module.exports = function(Chart) { document.defaultView.getComputedStyle(el, null).getPropertyValue(property); }; helpers.retinaScale = function(chart) { - var ctx = chart.ctx; - var canvas = chart.canvas; - var width = canvas.width; - var height = canvas.height; var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1; - - if (pixelRatio !== 1) { - canvas.height = height * pixelRatio; - canvas.width = width * pixelRatio; - ctx.scale(pixelRatio, pixelRatio); + if (pixelRatio === 1) { + return; } + + var canvas = chart.canvas; + var height = chart.height; + var width = chart.width; + + canvas.height = height * pixelRatio; + canvas.width = width * pixelRatio; + chart.ctx.scale(pixelRatio, pixelRatio); + + // If no style has been set on the canvas, the render size is used as display size, + // making the chart visually bigger, so let's enforce it to the "correct" values. + // See https://github.com/chartjs/Chart.js/issues/3575 + canvas.style.height = height + 'px'; + canvas.style.width = width + 'px'; }; // -- Canvas methods helpers.clear = function(chart) {
true
Other
chartjs
Chart.js
6b449a9e7c56d873edc28b3e2dcf976b2ea27404.json
Fix retina scale when display size is implicit The retinaScale helper now enforces the display size to the correct values because if no style has been set on the canvas, the render size is used as display size, making the chart bigger (or smaller) when deviceAspectRatio is different of 1.
test/core.controller.tests.js
@@ -93,7 +93,7 @@ describe('Chart.Controller', function() { expect(data.datasets.length).toBe(0); }); - it('should NOT alter config.data references', function() { + it('should not alter config.data references', function() { var ds0 = {data: [10, 11, 12, 13]}; var ds1 = {data: [20, 21, 22, 23]}; var datasets = [ds0, ds1]; @@ -218,7 +218,7 @@ describe('Chart.Controller', function() { }); }); - it('should NOT apply aspect ratio when height specified', function() { + it('should not apply aspect ratio when height specified', function() { var chart = acquireChart({ options: { responsive: false, @@ -310,7 +310,7 @@ describe('Chart.Controller', function() { }); }); - it('should NOT inject the resizer element', function() { + it('should not inject the resizer element', function() { var chart = acquireChart({ options: { responsive: false @@ -425,7 +425,7 @@ describe('Chart.Controller', function() { }); }); - it('should NOT include parent padding when resizing the canvas', function(done) { + it('should not include parent padding when resizing the canvas', function(done) { var chart = acquireChart({ type: 'line', options: { @@ -625,7 +625,7 @@ describe('Chart.Controller', function() { }); }); - it('should NOT resize the canvas when parent height changes', function(done) { + it('should not resize the canvas when parent height changes', function(done) { var chart = acquireChart({ options: { responsive: true, @@ -666,6 +666,53 @@ describe('Chart.Controller', function() { }); }); + describe('Retina scale (a.k.a. device pixel ratio)', function() { + beforeEach(function() { + this.devicePixelRatio = window.devicePixelRatio; + window.devicePixelRatio = 3; + }); + + afterEach(function() { + window.devicePixelRatio = this.devicePixelRatio; + }); + + // see https://github.com/chartjs/Chart.js/issues/3575 + it ('should scale the render size but not the "implicit" display size', function() { + var chart = acquireChart({ + options: { + responsive: false + } + }, { + canvas: { + width: 320, + height: 240, + } + }); + + expect(chart).toBeChartOfSize({ + dw: 320, dh: 240, + rw: 960, rh: 720, + }); + }); + + it ('should scale the render size but not the "explicit" display size', function() { + var chart = acquireChart({ + options: { + responsive: false + } + }, { + canvas: { + style: 'width: 320px; height: 240px' + } + }); + + expect(chart).toBeChartOfSize({ + dw: 320, dh: 240, + rw: 960, rh: 720, + }); + }); + }); + describe('controller.destroy', function() { it('should reset context to default values', function() { var chart = acquireChart({});
true
Other
chartjs
Chart.js
6b449a9e7c56d873edc28b3e2dcf976b2ea27404.json
Fix retina scale when display size is implicit The retinaScale helper now enforces the display size to the correct values because if no style has been set on the canvas, the render size is used as display size, making the chart bigger (or smaller) when deviceAspectRatio is different of 1.
test/mockContext.js
@@ -214,16 +214,19 @@ var chart = actual.chart; var canvas = chart.ctx.canvas; var style = getComputedStyle(canvas); + var pixelRatio = window.devicePixelRatio; var dh = parseInt(style.height, 10); var dw = parseInt(style.width, 10); var rh = canvas.height; var rw = canvas.width; + var orh = rh / pixelRatio; + var orw = rw / pixelRatio; // sanity checks - if (chart.height !== rh) { - message = 'Expected chart height ' + chart.height + ' to be equal to render height ' + rh; - } else if (chart.width !== rw) { - message = 'Expected chart width ' + chart.width + ' to be equal to render width ' + rw; + if (chart.height !== orh) { + message = 'Expected chart height ' + chart.height + ' to be equal to original render height ' + orh; + } else if (chart.width !== orw) { + message = 'Expected chart width ' + chart.width + ' to be equal to original render width ' + orw; } // validity checks
true
Other
chartjs
Chart.js
a94885e32d611723f35393726dac93872e1b1a74.json
Fix the event handler when legend is disabled (#3544) When legend is disabled (i.e. {options: {legend: false}}), me.legend is null. Add the same test on me.tooltip even if the tooltip object is always created in case of {options: {tooltips: false}}.
src/core/core.controller.js
@@ -719,15 +719,17 @@ module.exports = function(Chart) { eventHandler: function(e) { var me = this; + var legend = me.legend; + var tooltip = me.tooltip; var hoverOptions = me.options.hover; // Buffer any update calls so that renders do not occur me._bufferedRender = true; me._bufferedRequest = null; var changed = me.handleEvent(e); - changed |= me.legend.handleEvent(e); - changed |= me.tooltip.handleEvent(e); + changed |= legend && legend.handleEvent(e); + changed |= tooltip && tooltip.handleEvent(e); var bufferedRequest = me._bufferedRequest; if (bufferedRequest) {
false
Other
chartjs
Chart.js
5012dcbdaefa7a11a8dfcd9ff264655e9860ee50.json
Fix iframe resize handler when re-attached to DOM (#3527) When the iframe is attached to the DOM, its content is reloaded (invaliding the resize listener) so make sure to install the handler after the iframe is loaded. Optimize resize events by throttling resize process until the next animation frame. Rewrite the unit test "waitForResize" method, the previous one (timeout) was too weak and most tests was failing on FF.
src/core/core.helpers.js
@@ -943,9 +943,7 @@ module.exports = function(Chart) { return color(c); }; helpers.addResizeListener = function(node, callback) { - // Hide an iframe before the node var iframe = document.createElement('iframe'); - iframe.className = 'chartjs-hidden-iframe'; iframe.style.cssText = 'display:block;'+ @@ -966,15 +964,37 @@ module.exports = function(Chart) { // https://github.com/chartjs/Chart.js/issues/3090 iframe.tabIndex = -1; - // Insert the iframe so that contentWindow is available - node.insertBefore(iframe, node.firstChild); - // Let's keep track of this added iframe and thus avoid DOM query when removing it. - node._chartjs = { - resizer: iframe + var stub = node._chartjs = { + resizer: iframe, + ticking: false + }; + + // Throttle the callback notification until the next animation frame. + var notify = function() { + if (!stub.ticking) { + stub.ticking = true; + helpers.requestAnimFrame.call(window, function() { + if (stub.resizer) { + stub.ticking = false; + return callback(); + } + }); + } }; - this.addEvent(iframe.contentWindow || iframe, 'resize', callback); + // If the iframe is re-attached to the DOM, the resize listener is removed because the + // content is reloaded, so make sure to install the handler after the iframe is loaded. + // https://github.com/chartjs/Chart.js/issues/3521 + helpers.addEvent(iframe, 'load', function() { + helpers.addEvent(iframe.contentWindow || iframe, 'resize', notify); + + // The iframe size might have changed while loading, which can also + // happen if the size has been changed while detached from the DOM. + notify(); + }); + + node.insertBefore(iframe, node.firstChild); }; helpers.removeResizeListener = function(node) { if (!node || !node._chartjs) { @@ -984,6 +1004,7 @@ module.exports = function(Chart) { var iframe = node._chartjs.resizer; if (iframe) { iframe.parentNode.removeChild(iframe); + node._chartjs.resizer = null; } delete node._chartjs;
true
Other
chartjs
Chart.js
5012dcbdaefa7a11a8dfcd9ff264655e9860ee50.json
Fix iframe resize handler when re-attached to DOM (#3527) When the iframe is attached to the DOM, its content is reloaded (invaliding the resize listener) so make sure to install the handler after the iframe is loaded. Optimize resize events by throttling resize process until the next animation frame. Rewrite the unit test "waitForResize" method, the previous one (timeout) was too weak and most tests was failing on FF.
test/core.controller.tests.js
@@ -1,7 +1,16 @@ describe('Chart.Controller', function() { - function processResizeEvent(chart, callback) { - setTimeout(callback, 100); + function waitForResize(chart, callback) { + var resizer = chart.chart.canvas.parentNode._chartjs.resizer; + var content = resizer.contentWindow || resizer; + var state = content.document.readyState || 'complete'; + var handler = function() { + Chart.helpers.removeEvent(content, 'load', handler); + Chart.helpers.removeEvent(content, 'resize', handler); + setTimeout(callback, 50); + }; + + Chart.helpers.addEvent(content, state !== 'complete'? 'load' : 'resize', handler); } describe('context acquisition', function() { @@ -358,14 +367,14 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.width = '455px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 455, dh: 350, rw: 455, rh: 350, }); wrapper.style.width = '150px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 150, dh: 350, rw: 150, rh: 350, @@ -398,14 +407,14 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.height = '455px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 300, dh: 455, rw: 300, rh: 455, }); wrapper.style.height = '150px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 300, dh: 150, rw: 300, rh: 150, @@ -440,7 +449,7 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.height = '355px'; wrapper.style.width = '455px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 455, dh: 355, rw: 455, rh: 355, @@ -467,7 +476,7 @@ describe('Chart.Controller', function() { var canvas = chart.chart.canvas; canvas.style.display = 'block'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 320, dh: 350, rw: 320, rh: 350, @@ -494,7 +503,7 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.display = 'block'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 460, dh: 380, rw: 460, rh: 380, @@ -503,6 +512,54 @@ describe('Chart.Controller', function() { done(); }); }); + + // https://github.com/chartjs/Chart.js/issues/3521 + it('should resize the canvas after the wrapper has been re-attached to the DOM', function(done) { + var chart = acquireChart({ + options: { + responsive: true, + maintainAspectRatio: false + } + }, { + canvas: { + style: '' + }, + wrapper: { + style: 'width: 320px; height: 350px' + } + }); + + expect(chart).toBeChartOfSize({ + dw: 320, dh: 350, + rw: 320, rh: 350, + }); + + var wrapper = chart.chart.canvas.parentNode; + var parent = wrapper.parentNode; + parent.removeChild(wrapper); + parent.appendChild(wrapper); + wrapper.style.height = '355px'; + + waitForResize(chart, function() { + expect(chart).toBeChartOfSize({ + dw: 320, dh: 355, + rw: 320, rh: 355, + }); + + parent.removeChild(wrapper); + wrapper.style.width = '455px'; + parent.appendChild(wrapper); + + waitForResize(chart, function() { + expect(chart).toBeChartOfSize({ + dw: 455, dh: 355, + rw: 455, rh: 355, + }); + + done(); + }); + }); + }); }); describe('config.options.responsive: true (maintainAspectRatio: true)', function() { @@ -550,14 +607,14 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.width = '450px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 450, dh: 225, rw: 450, rh: 225, }); wrapper.style.width = '150px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 150, dh: 75, rw: 150, rh: 75, @@ -590,14 +647,14 @@ describe('Chart.Controller', function() { var wrapper = chart.chart.canvas.parentNode; wrapper.style.height = '455px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 320, dh: 160, rw: 320, rh: 160, }); wrapper.style.height = '150px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 320, dh: 160, rw: 320, rh: 160, @@ -629,7 +686,7 @@ describe('Chart.Controller', function() { var canvas = chart.chart.canvas; var wrapper = canvas.parentNode; wrapper.style.width = '475px'; - processResizeEvent(chart, function() { + waitForResize(chart, function() { expect(chart).toBeChartOfSize({ dw: 475, dh: 450, rw: 475, rh: 450,
true
Other
chartjs
Chart.js
99041de31a80af789441a84181953a7282d6c64d.json
Update installation instructions in README
README.md
@@ -8,15 +8,24 @@ ## Installation -You can download the latest version of [Chart.js on GitHub](https://github.com/chartjs/Chart.js/releases/latest) or just use these [Chart.js CDN](https://cdnjs.com/libraries/Chart.js) links. +You can download the latest version of Chart.js from the [GitHub releases](https://github.com/chartjs/Chart.js/releases/latest) or use a [Chart.js CDN](https://cdnjs.com/libraries/Chart.js). To install via npm: ```bash npm install chart.js --save ``` -To Install via bower, please follow [these instructions](http://www.chartjs.org/docs/#getting-started-installation). +To install via bower: +```bash +bower install chart.js --save +``` + +#### Selecting the Correct Build + +Chart.js provides two different builds that are available for your use. The `Chart.js` and `Chart.min.js` files include Chart.js and the accompanying color parsing library. If this version is used and you require the use of the time axis, [Moment.js](http://momentjs.com/) will need to be included before Chart.js. + +The `Chart.bundle.js` and `Chart.bundle.min.js` builds include Moment.js in a single file. This version should be used if you require time axes and want a single file to include, select this version. Do not use this build if your application already includes Moment.js. If you do, Moment.js will be included twice, increasing the page load time and potentially introducing version issues. ## Documentation
false
Other
chartjs
Chart.js
274aa290ca69f38aac5fd1a5fb55cc5043ea5d8c.json
Fix bug in 'y' tooltip mode
src/core/core.interaction.js
@@ -260,7 +260,7 @@ module.exports = function(Chart) { var position = helpers.getRelativePosition(e, chart.chart); var items = []; parseVisibleItems(chart, function(element) { - if (element.inYRange(position.x)) { + if (element.inYRange(position.y)) { items.push(element); } });
false
Other
chartjs
Chart.js
5ae268e94236b921d6cc966c580cd4984d5f4f94.json
Add a way to filter items in the tooltip
docs/01-Chart-Configuration.md
@@ -225,6 +225,7 @@ mode | String | 'nearest' | Sets which elements appear in the tooltip. See [Inte intersect | Boolean | true | if true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times. position | String | 'average' | The mode for positioning the tooltip. 'average' mode will place the tooltip at the average position of the items displayed in the tooltip. 'nearest' will place the tooltip at the position of the element closest to the event position. New modes can be defined by adding functions to the Chart.Tooltip.positioners map. itemSort | Function | undefined | Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). This function can also accept a third parameter that is the data object passed to the chart. +filter | Function | undefined | Allows filtering of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a second parameter that is the data object passed to the chart. backgroundColor | Color | 'rgba(0,0,0,0.8)' | Background color of the tooltip titleFontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" | Font family for tooltip title inherited from global font family titleFontSize | Number | 12 | Font size for tooltip title inherited from global font size
true
Other
chartjs
Chart.js
5ae268e94236b921d6cc966c580cd4984d5f4f94.json
Add a way to filter items in the tooltip
src/core/core.tooltip.js
@@ -485,6 +485,13 @@ module.exports = function(Chart) { tooltipItems.push(createTooltipItem(active[i])); } + // If the user provided a filter function, use it to modify the tooltip items + if (opts.filter) { + tooltipItems = tooltipItems.filter(function(a) { + return opts.filter(a, data); + }); + } + // If the user provided a sorting function, use it to modify the tooltip items if (opts.itemSort) { tooltipItems = tooltipItems.sort(function(a, b) {
true
Other
chartjs
Chart.js
5ae268e94236b921d6cc966c580cd4984d5f4f94.json
Add a way to filter items in the tooltip
test/core.tooltip.tests.js
@@ -543,6 +543,78 @@ describe('Core.Tooltip', function() { expect(tooltip._view.y).toBeCloseToPixel(155); }); + it('should filter items from the tooltip using the callback', function() { + var chartInstance = window.acquireChart({ + type: 'line', + data: { + datasets: [{ + label: 'Dataset 1', + data: [10, 20, 30], + pointHoverBorderColor: 'rgb(255, 0, 0)', + pointHoverBackgroundColor: 'rgb(0, 255, 0)', + tooltipHidden: true + }, { + label: 'Dataset 2', + data: [40, 40, 40], + pointHoverBorderColor: 'rgb(0, 0, 255)', + pointHoverBackgroundColor: 'rgb(0, 255, 255)' + }], + labels: ['Point 1', 'Point 2', 'Point 3'] + }, + options: { + tooltips: { + mode: 'label', + filter: function(tooltipItem, data) { + // For testing purposes remove the first dataset that has a tooltipHidden property + return !data.datasets[tooltipItem.datasetIndex].tooltipHidden; + } + } + } + }); + + // Trigger an event over top of the + var meta0 = chartInstance.getDatasetMeta(0); + var point0 = meta0.data[1]; + + var node = chartInstance.chart.canvas; + var rect = node.getBoundingClientRect(); + + var evt = new MouseEvent('mousemove', { + view: window, + bubbles: true, + cancelable: true, + clientX: rect.left + point0._model.x, + clientY: rect.top + point0._model.y + }); + + // Manully trigger rather than having an async test + node.dispatchEvent(evt); + + // Check and see if tooltip was displayed + var tooltip = chartInstance.tooltip; + + expect(tooltip._view).toEqual(jasmine.objectContaining({ + // Positioning + xAlign: 'left', + yAlign: 'center', + + // Text + title: ['Point 2'], + beforeBody: [], + body: [{ + before: [], + lines: ['Dataset 2: 40'], + after: [] + }], + afterBody: [], + footer: [], + labelColors: [{ + borderColor: 'rgb(0, 0, 255)', + backgroundColor: 'rgb(0, 255, 255)' + }] + })); + }); + it('Should have dataPoints', function() { var chartInstance = window.acquireChart({ type: 'line',
true
Other
chartjs
Chart.js
3bd4d283f758ccac1e3dd378d9157faef4a133bd.json
Custom tooltip: add data points infos (#3201) Expose tooltip items from tooltip model and added `x` and `y` properties to `TooltipItemInterface`
docs/01-Chart-Configuration.md
@@ -271,6 +271,7 @@ afterBody | `Array[tooltipItem], data` | Text to render after the body section beforeFooter | `Array[tooltipItem], data` | Text to render before the footer section footer | `Array[tooltipItem], data` | Text to render as the footer afterFooter | `Array[tooltipItem], data` | Text to render after the footer section +dataPoints | `Array[tooltipItem]` | List of matching point informations. #### Tooltip Item Interface @@ -288,7 +289,13 @@ The tooltip items passed to the tooltip callbacks implement the following interf datasetIndex: Number, // Index of this data item in the dataset - index: Number + index: Number, + + // X position of matching point + x: Number, + + // Y position of matching point + y: Number, } ```
true
Other
chartjs
Chart.js
3bd4d283f758ccac1e3dd378d9157faef4a133bd.json
Custom tooltip: add data points infos (#3201) Expose tooltip items from tooltip model and added `x` and `y` properties to `TooltipItemInterface`
docs/09-Advanced.md
@@ -226,12 +226,12 @@ Scale instances are given the following properties during the fitting process. { left: Number, // left edge of the scale bounding box right: Number, // right edge of the bounding box' - top: Number, + top: Number, bottom: Number, width: Number, // the same as right - left height: Number, // the same as bottom - top - // Margin on each side. Like css, this is outside the bounding box. + // Margin on each side. Like css, this is outside the bounding box. margins: { left: Number, right: Number, @@ -248,7 +248,7 @@ Scale instances are given the following properties during the fitting process. ``` #### Scale Interface -To work with Chart.js, custom scale types must implement the following interface. +To work with Chart.js, custom scale types must implement the following interface. ```javascript { @@ -283,10 +283,10 @@ To work with Chart.js, custom scale types must implement the following interface Optionally, the following methods may also be overwritten, but an implementation is already provided by the `Chart.Scale` base class. ```javascript - // Transform the ticks array of the scale instance into strings. The default implementation simply calls this.options.ticks.callback(numericalTick, index, ticks); + // Transform the ticks array of the scale instance into strings. The default implementation simply calls this.options.ticks.callback(numericalTick, index, ticks); convertTicksToLabels: function() {}, - // Determine how much the labels will rotate by. The default implementation will only rotate labels if the scale is horizontal. + // Determine how much the labels will rotate by. The default implementation will only rotate labels if the scale is horizontal. calculateTickRotation: function() {}, // Fits the scale into the canvas. @@ -303,7 +303,7 @@ Optionally, the following methods may also be overwritten, but an implementation The Core.Scale base class also has some utility functions that you may find useful. ```javascript -{ +{ // Returns true if the scale instance is horizontal isHorizontal: function() {}, @@ -373,7 +373,7 @@ The following methods may optionally be overridden by derived dataset controller // chart types using a single scale linkScales: function() {}, - // Called by the main chart controller when an update is triggered. The default implementation handles the number of data points changing and creating elements appropriately. + // Called by the main chart controller when an update is triggered. The default implementation handles the number of data points changing and creating elements appropriately. buildOrUpdateElements: function() {} } ``` @@ -442,7 +442,7 @@ Plugins should derive from Chart.PluginBase and implement the following interfac ### Building Chart.js -Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single JavaScript file. +Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single JavaScript file. Firstly, we need to ensure development dependencies are installed. With node and npm installed, after cloning the Chart.js repo to a local directory, and navigating to that directory in the command line, we can run the following:
true
Other
chartjs
Chart.js
3bd4d283f758ccac1e3dd378d9157faef4a133bd.json
Custom tooltip: add data points infos (#3201) Expose tooltip items from tooltip model and added `x` and `y` properties to `TooltipItemInterface`
samples/dataPoints-customTooltips.html
@@ -0,0 +1,104 @@ +<!doctype html> +<html> + +<head> + <title>Custom Tooltips using Data Points</title> + <script src="../dist/Chart.bundle.js"></script> + <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> + <style> + canvas{ + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + } + .chartjs-tooltip { + opacity: 1; + position: absolute; + background: rgba(0, 0, 0, .7); + color: white; + border-radius: 3px; + -webkit-transition: all .1s ease; + transition: all .1s ease; + pointer-events: none; + -webkit-transform: translate(-50%, 0); + transform: translate(-50%, 0); + padding: 4px; + } + + .chartjs-tooltip-key { + display: inline-block; + width: 10px; + height: 10px; + } + </style> +</head> + +<body> + <div id="canvas-holder1" style="width:75%;"> + <canvas id="chart1"></canvas> + </div> + <div class="chartjs-tooltip" id="tooltip-0"></div> + <div class="chartjs-tooltip" id="tooltip-1"></div> + <script> + var customTooltips = function (tooltip) { + $(this._chart.canvas).css("cursor", "pointer"); + + $(".chartjs-tooltip").css({ + opacity: 0, + }); + + if (!tooltip || !tooltip.opacity) { + return; + } + + if (tooltip.dataPoints.length > 0) { + tooltip.dataPoints.forEach(function (dataPoint) { + var content = [dataPoint.xLabel, dataPoint.yLabel].join(": "); + var $tooltip = $("#tooltip-" + dataPoint.datasetIndex); + + $tooltip.html(content); + $tooltip.css({ + opacity: 1, + top: dataPoint.y + "px", + left: dataPoint.x + "px", + }); + }); + } + }; + var randomScalingFactor = function() { + return Math.round(Math.random() * 100); + }; + var lineChartData = { + labels: ["January", "February", "March", "April", "May", "June", "July"], + datasets: [{ + pointHitRadius: 100, + label: "My First dataset", + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] + }, { + pointHitRadius: 100, + label: "My Second dataset", + data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] + }] + }; + + window.onload = function() { + var chartEl = document.getElementById("chart1"); + var chart = new Chart(chartEl, { + type: "line", + data: lineChartData, + options: { + title:{ + display: true, + text: "Chart.js - Custom Tooltips using Data Points" + }, + tooltips: { + enabled: false, + custom: customTooltips + } + } + }); + }; + </script> +</body> + +</html>
true
Other
chartjs
Chart.js
3bd4d283f758ccac1e3dd378d9157faef4a133bd.json
Custom tooltip: add data points infos (#3201) Expose tooltip items from tooltip model and added `x` and `y` properties to `TooltipItemInterface`
src/core/core.tooltip.js
@@ -118,7 +118,9 @@ module.exports = function(Chart) { xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '', yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '', index: index, - datasetIndex: datasetIndex + datasetIndex: datasetIndex, + x: element._model.x, + y: element._model.y }; } @@ -508,6 +510,9 @@ module.exports = function(Chart) { model.caretPadding = helpers.getValueOrDefault(tooltipPosition.padding, 2); model.labelColors = labelColors; + // data points + model.dataPoints = tooltipItems; + // We need to determine alignment of the tooltip tooltipSize = getTooltipSize(this, model); alignment = determineAlignment(this, tooltipSize);
true
Other
chartjs
Chart.js
3bd4d283f758ccac1e3dd378d9157faef4a133bd.json
Custom tooltip: add data points infos (#3201) Expose tooltip items from tooltip model and added `x` and `y` properties to `TooltipItemInterface`
test/core.tooltip.tests.js
@@ -542,4 +542,64 @@ describe('Core.Tooltip', function() { expect(tooltip._view.x).toBeCloseToPixel(269); expect(tooltip._view.y).toBeCloseToPixel(155); }); + + it('Should have dataPoints', function() { + var chartInstance = window.acquireChart({ + type: 'line', + data: { + datasets: [{ + label: 'Dataset 1', + data: [10, 20, 30], + pointHoverBorderColor: 'rgb(255, 0, 0)', + pointHoverBackgroundColor: 'rgb(0, 255, 0)' + }, { + label: 'Dataset 2', + data: [40, 40, 40], + pointHoverBorderColor: 'rgb(0, 0, 255)', + pointHoverBackgroundColor: 'rgb(0, 255, 255)' + }], + labels: ['Point 1', 'Point 2', 'Point 3'] + }, + options: { + tooltips: { + mode: 'single' + } + } + }); + + // Trigger an event over top of the + var pointIndex = 1; + var datasetIndex = 0; + var meta = chartInstance.getDatasetMeta(datasetIndex); + var point = meta.data[pointIndex]; + var node = chartInstance.chart.canvas; + var rect = node.getBoundingClientRect(); + var evt = new MouseEvent('mousemove', { + view: window, + bubbles: true, + cancelable: true, + clientX: rect.left + point._model.x, + clientY: rect.top + point._model.y + }); + + // Manully trigger rather than having an async test + node.dispatchEvent(evt); + + // Check and see if tooltip was displayed + var tooltip = chartInstance.tooltip; + + expect(tooltip._view instanceof Object).toBe(true); + expect(tooltip._view.dataPoints instanceof Array).toBe(true); + expect(tooltip._view.dataPoints.length).toEqual(1); + expect(tooltip._view.dataPoints[0].index).toEqual(pointIndex); + expect(tooltip._view.dataPoints[0].datasetIndex).toEqual(datasetIndex); + expect(tooltip._view.dataPoints[0].xLabel).toEqual( + chartInstance.config.data.labels[pointIndex] + ); + expect(tooltip._view.dataPoints[0].yLabel).toEqual( + chartInstance.config.data.datasets[datasetIndex].data[pointIndex] + ); + expect(tooltip._view.dataPoints[0].x).toBeCloseToPixel(point._model.x); + expect(tooltip._view.dataPoints[0].y).toBeCloseToPixel(point._model.y); + }); });
true
Other
chartjs
Chart.js
a0ce74643f3d6f7ad6f2f4a8ac4343d6526b91a8.json
Fix eslint errors in layout service test
gulpfile.js
@@ -152,7 +152,8 @@ function lintTask() { 'it', 'jasmine', 'moment', - 'spyOn' + 'spyOn', + 'xit' ] };
true
Other
chartjs
Chart.js
a0ce74643f3d6f7ad6f2f4a8ac4343d6526b91a8.json
Fix eslint errors in layout service test
test/core.layoutService.tests.js
@@ -1,8 +1,8 @@ // Tests of the scale service describe('Test the layout service', function() { // Disable tests which need to be rewritten based on changes introduced by - // the following changes: https://github.com/chartjs/Chart.js/pull/2346 - // using xit marks the test as pending: http://jasmine.github.io/2.0/introduction.html#section-Pending_Specs + // the following changes: https://github.com/chartjs/Chart.js/pull/2346 + // using xit marks the test as pending: http://jasmine.github.io/2.0/introduction.html#section-Pending_Specs xit('should fit a simple chart with 2 scales', function() { var chart = window.acquireChart({ type: 'bar', @@ -249,7 +249,9 @@ describe('Test the layout service', function() { type: 'bar', data: { datasets: [ - { data: [10, 5, 0, 25, 78, -10] } + { + data: [10, 5, 0, 25, 78, -10] + } ], labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] }, @@ -294,7 +296,9 @@ describe('Test the layout service', function() { type: 'bar', data: { datasets: [ - { data: [10, 5, 0, 25, 78, -10] } + { + data: [10, 5, 0, 25, 78, -10] + } ], labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] }, @@ -344,7 +348,9 @@ describe('Test the layout service', function() { type: 'bar', data: { datasets: [ - { data: [10, 5, 0, 25, 78, -10] } + { + data: [10, 5, 0, 25, 78, -10] + } ], labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] },
true
Other
chartjs
Chart.js
16f23b2c44ebeccda1e144b3dd75e9c63f81307b.json
Add reset method to chart prototype
docs/09-Advanced.md
@@ -34,6 +34,14 @@ myLineChart.data.datasets[0].data[2] = 50; // Would update the first dataset's v myLineChart.update(); // Calling update now animates the position of March from 90 to 50. ``` +#### .reset() + +Reset the chart to it's state before the initial animation. A new animation can then be triggered using `update`. + +```javascript +myLineChart.reset(); +``` + #### .render(duration, lazy) Triggers a redraw of all chart elements. Note, this does not update elements for new data. Use `.update()` in that case.
true
Other
chartjs
Chart.js
16f23b2c44ebeccda1e144b3dd75e9c63f81307b.json
Add reset method to chart prototype
src/core/core.controller.js
@@ -409,13 +409,27 @@ module.exports = function(Chart) { return newControllers; }, + /** + * Reset the elements of all datasets + * @method resetElements + * @private + */ resetElements: function() { var me = this; helpers.each(me.data.datasets, function(dataset, datasetIndex) { me.getDatasetMeta(datasetIndex).controller.reset(); }, me); }, + /** + * Resets the chart back to it's state before the initial animation + * @method reset + */ + reset: function() { + this.resetElements(); + this.tooltip.initialize(); + }, + update: function(animationDuration, lazy) { var me = this; Chart.plugins.notify('beforeUpdate', [me]);
true
Other
chartjs
Chart.js
16f23b2c44ebeccda1e144b3dd75e9c63f81307b.json
Add reset method to chart prototype
test/core.controller.tests.js
@@ -666,4 +666,38 @@ describe('Chart.Controller', function() { expect(wrapper.firstChild.tagName).toBe('CANVAS'); }); }); + + describe('controller.reset', function() { + it('should reset the chart elements', function() { + var chart = acquireChart({ + type: 'line', + data: { + labels: ['A', 'B', 'C', 'D'], + datasets: [{ + data: [10, 20, 30, 0] + }] + }, + options: { + responsive: true + } + }); + + var meta = chart.getDatasetMeta(0); + + // Verify that points are at their initial correct location, + // then we will reset and see that they moved + expect(meta.data[0]._model.y).toBe(333); + expect(meta.data[1]._model.y).toBe(183); + expect(meta.data[2]._model.y).toBe(32); + expect(meta.data[3]._model.y).toBe(484); + + chart.reset(); + + // For a line chart, the animation state is the bottom + expect(meta.data[0]._model.y).toBe(484); + expect(meta.data[1]._model.y).toBe(484); + expect(meta.data[2]._model.y).toBe(484); + expect(meta.data[3]._model.y).toBe(484); + }); + }); });
true
Other
chartjs
Chart.js
766ca49cd094562f3a2e870e0c2b162ee16c8189.json
Extend eslint to test files (#3473) * Add eslint to test files * Fix mockContext for tests * Make formatting look better for nested objects
gulpfile.js
@@ -22,6 +22,7 @@ var package = require('./package.json'); var srcDir = './src/'; var outDir = './dist/'; +var testDir = './test/'; var header = "/*!\n" + " * Chart.js\n" + @@ -132,6 +133,7 @@ function packageTask() { function lintTask() { var files = [ srcDir + '**/*.js', + testDir + '**/*.js' ]; // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict @@ -141,7 +143,21 @@ function lintTask() { rules: { 'complexity': [1, 6], 'max-statements': [1, 30] - } + }, + globals: [ + 'Chart', + 'acquireChart', + 'afterAll', + 'afterEach', + 'beforeAll', + 'beforeEach', + 'describe', + 'expect', + 'it', + 'jasmine', + 'moment', + 'spyOn' + ] }; return gulp.src(files)
true