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 | a10e245e5ad743686f691d549b2ec3257c7650cb.json | Use correct tooltip events in each chart | src/Chart.Doughnut.js | @@ -53,7 +53,7 @@
//Set up tooltip events on the chart
if (this.options.showTooltips) {
- helpers.bindEvents(this, this.options.tooltipEvents, this.onHover);
+ helpers.bindEvents(this, this.options.events, this.onHover);
}
// Create new slice for each piece of data | true |
Other | chartjs | Chart.js | a10e245e5ad743686f691d549b2ec3257c7650cb.json | Use correct tooltip events in each chart | src/Chart.PolarArea.js | @@ -103,7 +103,7 @@
//Set up tooltip events on the chart
if (this.options.showTooltips){
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
+ helpers.bindEvents(this, this.options.events, function(evt){
var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
helpers.each(this.segments,function(segment){
segment.restore(["fillColor"]); | true |
Other | chartjs | Chart.js | a10e245e5ad743686f691d549b2ec3257c7650cb.json | Use correct tooltip events in each chart | src/Chart.Radar.js | @@ -81,7 +81,7 @@
//Set up tooltip events on the chart
if (this.options.showTooltips){
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
+ helpers.bindEvents(this, this.options.events, function(evt){
var activePointsCollection = (evt.type !== 'mouseout') ? this.getPointsAtEvent(evt) : [];
this.eachPoints(function(point){ | true |
Other | chartjs | Chart.js | a10e245e5ad743686f691d549b2ec3257c7650cb.json | Use correct tooltip events in each chart | src/Chart.Scatter.js | @@ -114,7 +114,7 @@
});
// Events
- helpers.bindEvents(this, this.options.tooltipEvents, this.events);
+ helpers.bindEvents(this, this.options.events, this.events);
// Build Scale
this.buildScale(); | true |
Other | chartjs | Chart.js | a559ab85cd16a1e18e14f4aacbbc0fd6f7f75cbd.json | Ensure consistency in the helpers.toRadians name | src/Chart.Core.js | @@ -402,7 +402,7 @@
return 0;
}
},
- toRadians = helpers.radians = function(degrees) {
+ toRadians = helpers.toRadians = function(degrees) {
return degrees * (Math.PI / 180);
},
toDegrees = helpers.toDegrees = function(radians) { | false |
Other | chartjs | Chart.js | 008bb1aab365c46cbf479cbf9ae2bd98f2350bef.json | Set new tooltip templates for the scatter chart | samples/scatter.html | @@ -88,7 +88,7 @@
var ctx = document.getElementById("canvas").getContext("2d");
window.myScatter = new Chart(ctx).Scatter(scatterChartData, {
responsive: true,
- hoverMode: 'single',
+ hoverMode: 'single', // should always use single for a scatter chart
scales: {
xAxes: [{
gridLines: { | true |
Other | chartjs | Chart.js | 008bb1aab365c46cbf479cbf9ae2bd98f2350bef.json | Set new tooltip templates for the scatter chart | src/Chart.Scatter.js | @@ -6,7 +6,7 @@
helpers = Chart.helpers;
var defaultConfig = {
-
+ hoverMode: 'single',
scales: {
xAxes: [{
scaleType: "linear", // scatter should not use a dataset axis
@@ -94,6 +94,9 @@
//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].borderColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
+ tooltipTemplate: "(<%= dataX %>, <%= dataY %>)",
+ multiTooltipTemplate: "<%if (datasetLabel){%><%=datasetLabel%>: <%}%>(<%= dataX %>, <%= dataY %>)",
+
};
@@ -334,8 +337,10 @@
helpers.extend(point, {
x: xScale.getPixelForValue(this.data.datasets[datasetIndex].data[index].x),
y: yScale.getPixelForValue(this.data.datasets[datasetIndex].data[index].y),
- value: this.data.datasets[datasetIndex].data[index].y,
- label: this.data.datasets[datasetIndex].data[index].x,
+ dataX: this.data.datasets[datasetIndex].data[index].x,
+ dataY: this.data.datasets[datasetIndex].data[index].y,
+ label: '', // so that the multitooltip looks ok
+ value: this.data.datasets[datasetIndex].data[index].y, // for legacy reasons
datasetLabel: this.data.datasets[datasetIndex].label,
// Appearance
hoverBackgroundColor: this.data.datasets[datasetIndex].pointHoverBackgroundColor || this.options.pointHoverBackgroundColor, | true |
Other | chartjs | Chart.js | 4b8c9bc30d9137bc375c3527c8742036ed524377.json | Fix a drawing bug when drawTicks is false. | samples/scatter-multi-axis.html | @@ -95,6 +95,7 @@
hoverMode: 'single',
scales: {
xAxes: [{
+ position: "bottom",
gridLines: {
zeroLineColor: "rgba(0,0,0,1)"
} | true |
Other | chartjs | Chart.js | 4b8c9bc30d9137bc375c3527c8742036ed524377.json | Fix a drawing bug when drawTicks is false. | src/Chart.Scale.js | @@ -538,8 +538,9 @@
xValue += helpers.aliasPixel(this.ctx.lineWidth);
// Draw the label area
- if (this.options.gridLines.drawTicks) {
- this.ctx.beginPath();
+ this.ctx.beginPath();
+
+ if (this.options.gridLines.drawTicks) {
this.ctx.moveTo(xValue, yTickStart);
this.ctx.lineTo(xValue, yTickEnd);
}
@@ -604,8 +605,9 @@
yValue += helpers.aliasPixel(this.ctx.lineWidth);
// Draw the label area
+ this.ctx.beginPath();
+
if (this.options.gridLines.drawTicks) {
- this.ctx.beginPath();
this.ctx.moveTo(xTickStart, yValue);
this.ctx.lineTo(xTickEnd, yValue);
} | true |
Other | chartjs | Chart.js | 43438d630308fb81662d6549ec74ddf49c33cd99.json | Update doc version # | docs/07-Advanced.md | @@ -368,7 +368,7 @@ The bar controller has a special property that you should be aware of. To correc
### Creating Plugins
-Starting with v2.0.3, you can create plugins for chart.js. To register your plugin, simply call `Chart.pluginService.register` and pass your plugin in.
+Starting with v2.1.0, you can create plugins for chart.js. To register your plugin, simply call `Chart.pluginService.register` and pass your plugin in.
Plugins will be called at the following times
* Start of initialization
* End of initialization | false |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/01-Line-Chart.md | @@ -1,169 +0,0 @@
----
-title: Line Chart
-anchor: line-chart
----
-###Introduction
-A line chart is a way of plotting data points on a line.
-
-Often, it is used to show trend data, and the comparison of two data sets.
-
-<div class="canvas-holder">
- <canvas width="250" height="125"></canvas>
-</div>
-
-###Example usage
-```javascript
-var myLineChart = new Chart(ctx).Line(data, options);
-```
-###Data structure
-
-```javascript
-var data = {
- labels: ["January", "February", "March", "April", "May", "June", "July"],
- datasets: [
- {
- label: "My First dataset",
- fillColor: "rgba(220,220,220,0.2)",
- strokeColor: "rgba(220,220,220,1)",
- pointColor: "rgba(220,220,220,1)",
- pointStrokeColor: "#fff",
- pointHighlightFill: "#fff",
- pointHighlightStroke: "rgba(220,220,220,1)",
- data: [65, 59, 80, 81, 56, 55, 40]
- },
- {
- label: "My Second dataset",
- fillColor: "rgba(151,187,205,0.2)",
- strokeColor: "rgba(151,187,205,1)",
- pointColor: "rgba(151,187,205,1)",
- pointStrokeColor: "#fff",
- pointHighlightFill: "#fff",
- pointHighlightStroke: "rgba(151,187,205,1)",
- data: [28, 48, 40, 19, 86, 27, 90]
- }
- ]
-};
-```
-
-The line chart requires an array of labels. This labels are shown on the X axis. There must be one label for each data point. More labels than datapoints are allowed, in which case the line ends at the last data point.
-The data for line charts is broken up into an array of datasets. Each dataset has a colour for the fill, a colour for the line and colours for the points and strokes of the points. These colours are strings just like CSS. You can use RGBA, RGB, HEX or HSL notation.
-
-The label key on each dataset is optional, and can be used when generating a scale for the chart.
-
-### Chart options
-
-These are the customisation options specific to Line charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
-
-```javascript
-{
-
- ///Boolean - Whether grid lines are shown across the chart
- scaleShowGridLines : true,
-
- //String - Colour of the grid lines
- scaleGridLineColor : "rgba(0,0,0,.05)",
-
- //Number - Width of the grid lines
- scaleGridLineWidth : 1,
-
- //Boolean - Whether to show horizontal lines (except X axis)
- scaleShowHorizontalLines: true,
-
- //Boolean - Whether to show vertical lines (except Y axis)
- scaleShowVerticalLines: true,
-
- //Boolean - Whether the line is curved between points
- bezierCurve : true,
-
- //Number - Tension of the bezier curve between points
- bezierCurveTension : 0.4,
-
- //Boolean - Whether to show a dot for each point
- pointDot : true,
-
- //Number - Radius of each point dot in pixels
- pointDotRadius : 4,
-
- //Number - Pixel width of point dot stroke
- pointDotStrokeWidth : 1,
-
- //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
- pointHitDetectionRadius : 20,
-
- //Boolean - Whether to show a stroke for datasets
- datasetStroke : true,
-
- //Number - Pixel width of dataset stroke
- datasetStrokeWidth : 2,
-
- //Boolean - Whether to fill the dataset with a colour
- datasetFill : true,
- {% raw %}
- //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%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
- {% endraw %}
-
- //Boolean - Whether to horizontally center the label and point dot inside the grid
- offsetGridLines : false
-};
-```
-
-You can override these for your `Chart` instance by passing a second argument into the `Line` method as an object with the keys you want to override.
-
-For example, we could have a line chart without bezier curves between points by doing the following:
-
-```javascript
-new Chart(ctx).Line(data, {
- bezierCurve: false
-});
-// This will create a chart with all of the default options, merged from the global config,
-// and the Line chart defaults, but this particular instance will have `bezierCurve` set to false.
-```
-
-We can also change these defaults values for each Line type that is created, this object is available at `Chart.defaults.Line`.
-
-
-### Prototype methods
-
-#### .getPointsAtEvent( event )
-
-Calling `getPointsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the point elements that are at that the same position of that event.
-
-```javascript
-canvas.onclick = function(evt){
- var activePoints = myLineChart.getPointsAtEvent(evt);
- // => activePoints is an array of points on the canvas that are at the same position as the click event.
-};
-```
-
-This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
-
-#### .update( )
-
-Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
-
-```javascript
-myLineChart.datasets[0].points[2].value = 50;
-// Would update the first dataset's value of 'March' to be 50
-myLineChart.update();
-// Calling update now animates the position of March from 90 to 50.
-```
-
-#### .addData( valuesArray, label )
-
-Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those points.
-
-```javascript
-// The values array passed into addData should be one for each dataset in the chart
-myLineChart.addData([40, 60], "August");
-// This new data will now animate at the end of the chart.
-```
-
-#### .removeData( )
-
-Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
-
-```javascript
-myLineChart.removeData();
-// The chart will remove the first point and animate other points into place
-``` | true |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/02-Bar-Chart.md | @@ -1,149 +0,0 @@
----
-title: Bar Chart
-anchor: bar-chart
----
-
-### Introduction
-A bar chart is a way of showing data as bars.
-
-It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
-
-<div class="canvas-holder">
- <canvas width="250" height="125"></canvas>
-</div>
-
-### Example usage
-```javascript
-var myBarChart = new Chart(ctx).Bar(data, options);
-```
-
-### Data structure
-
-```javascript
-var data = {
- labels: ["January", "February", "March", "April", "May", "June", "July"],
- datasets: [
- {
- label: "My First dataset",
- fillColor: "rgba(220,220,220,0.5)",
- strokeColor: "rgba(220,220,220,0.8)",
- highlightFill: "rgba(220,220,220,0.75)",
- highlightStroke: "rgba(220,220,220,1)",
- data: [65, 59, 80, 81, 56, 55, 40]
- },
- {
- label: "My Second dataset",
- fillColor: "rgba(151,187,205,0.5)",
- strokeColor: "rgba(151,187,205,0.8)",
- highlightFill: "rgba(151,187,205,0.75)",
- highlightStroke: "rgba(151,187,205,1)",
- data: [28, 48, 40, 19, 86, 27, 90]
- }
- ]
-};
-```
-The bar chart has the a very similar data structure to the line chart, and has an array of datasets, each with colours and an array of data. Again, colours are in CSS format.
-We have an array of labels too for display. In the example, we are showing the same data as the previous line chart example.
-
-The label key on each dataset is optional, and can be used when generating a scale for the chart.
-
-### Chart Options
-
-These are the customisation options specific to Bar charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
-
-```javascript
-{
- //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
- scaleBeginAtZero : true,
-
- //Boolean - Whether grid lines are shown across the chart
- scaleShowGridLines : true,
-
- //String - Colour of the grid lines
- scaleGridLineColor : "rgba(0,0,0,.05)",
-
- //Number - Width of the grid lines
- scaleGridLineWidth : 1,
-
- //Boolean - Whether to show horizontal lines (except X axis)
- scaleShowHorizontalLines: true,
-
- //Boolean - Whether to show vertical lines (except Y axis)
- scaleShowVerticalLines: true,
-
- //Boolean - If there is a stroke on each bar
- barShowStroke : true,
-
- //Number - Pixel width of the bar stroke
- barStrokeWidth : 2,
-
- //Number - Spacing between each of the X value sets
- barValueSpacing : 5,
-
- //Number - Spacing between data sets within X values
- barDatasetSpacing : 1,
- {% raw %}
- //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].fillColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
- {% endraw %}
-}
-```
-
-You can override these for your `Chart` instance by passing a second argument into the `Bar` method as an object with the keys you want to override.
-
-For example, we could have a bar chart without a stroke on each bar by doing the following:
-
-```javascript
-new Chart(ctx).Bar(data, {
- barShowStroke: false
-});
-// This will create a chart with all of the default options, merged from the global config,
-// and the Bar chart defaults but this particular instance will have `barShowStroke` set to false.
-```
-
-We can also change these defaults values for each Bar type that is created, this object is available at `Chart.defaults.Bar`.
-
-### Prototype methods
-
-#### .getBarsAtEvent( event )
-
-Calling `getBarsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the bar elements that are at that the same position of that event.
-
-```javascript
-canvas.onclick = function(evt){
- var activeBars = myBarChart.getBarsAtEvent(evt);
- // => activeBars is an array of bars on the canvas that are at the same position as the click event.
-};
-```
-
-This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
-
-#### .update( )
-
-Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
-
-```javascript
-myBarChart.datasets[0].bars[2].value = 50;
-// Would update the first dataset's value of 'March' to be 50
-myBarChart.update();
-// Calling update now animates the position of March from 90 to 50.
-```
-
-#### .addData( valuesArray, label )
-
-Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those bars.
-
-```javascript
-// The values array passed into addData should be one for each dataset in the chart
-myBarChart.addData([40, 60], "August");
-// The new data will now animate at the end of the chart.
-```
-
-#### .removeData( )
-
-Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
-
-```javascript
-myBarChart.removeData();
-// The chart will now animate and remove the first bar
-``` | true |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/03-Radar-Chart.md | @@ -1,180 +0,0 @@
----
-title: Radar Chart
-anchor: radar-chart
----
-
-###Introduction
-A radar chart is a way of showing multiple data points and the variation between them.
-
-They are often useful for comparing the points of two or more different data sets.
-
-<div class="canvas-holder">
- <canvas width="250" height="125"></canvas>
-</div>
-
-###Example usage
-
-```javascript
-var myRadarChart = new Chart(ctx).Radar(data, options);
-```
-
-###Data structure
-```javascript
-var data = {
- labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
- datasets: [
- {
- label: "My First dataset",
- fillColor: "rgba(220,220,220,0.2)",
- strokeColor: "rgba(220,220,220,1)",
- pointColor: "rgba(220,220,220,1)",
- pointStrokeColor: "#fff",
- pointHighlightFill: "#fff",
- pointHighlightStroke: "rgba(220,220,220,1)",
- data: [65, 59, 90, 81, 56, 55, 40]
- },
- {
- label: "My Second dataset",
- fillColor: "rgba(151,187,205,0.2)",
- strokeColor: "rgba(151,187,205,1)",
- pointColor: "rgba(151,187,205,1)",
- pointStrokeColor: "#fff",
- pointHighlightFill: "#fff",
- pointHighlightStroke: "rgba(151,187,205,1)",
- data: [28, 48, 40, 19, 96, 27, 100]
- }
- ]
-};
-```
-For a radar chart, to provide context of what each point means, we include an array of strings that show around each point in the chart.
-For the radar chart data, we have an array of datasets. Each of these is an object, with a fill colour, a stroke colour, a colour for the fill of each point, and a colour for the stroke of each point. We also have an array of data values.
-
-The label key on each dataset is optional, and can be used when generating a scale for the chart.
-
-### Chart options
-
-These are the customisation options specific to Radar charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
-
-
-```javascript
-{
- //Boolean - Whether to show lines for each scale point
- scaleShowLine : true,
-
- //Boolean - Whether we show the angle lines out of the radar
- angleShowLineOut : true,
-
- //Boolean - Whether to show labels on the scale
- scaleShowLabels : false,
-
- // Boolean - Whether the scale should begin at zero
- scaleBeginAtZero : true,
-
- //String - Colour of the angle line
- angleLineColor : "rgba(0,0,0,.1)",
-
- //Number - Pixel width of the angle line
- angleLineWidth : 1,
-
- //Number - Interval at which to draw angle lines ("every Nth point")
- angleLineInterval: 1,
-
- //String - Point label font declaration
- pointLabelFontFamily : "'Arial'",
-
- //String - Point label font weight
- pointLabelFontStyle : "normal",
-
- //Number - Point label font size in pixels
- pointLabelFontSize : 10,
-
- //String - Point label font colour
- pointLabelFontColor : "#666",
-
- //Boolean - Whether to show a dot for each point
- pointDot : true,
-
- //Number - Radius of each point dot in pixels
- pointDotRadius : 3,
-
- //Number - Pixel width of point dot stroke
- pointDotStrokeWidth : 1,
-
- //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
- pointHitDetectionRadius : 20,
-
- //Boolean - Whether to show a stroke for datasets
- datasetStroke : true,
-
- //Number - Pixel width of dataset stroke
- datasetStrokeWidth : 2,
-
- //Boolean - Whether to fill the dataset with a colour
- datasetFill : true,
- {% raw %}
- //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%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
- {% endraw %}
-}
-```
-
-
-You can override these for your `Chart` instance by passing a second argument into the `Radar` method as an object with the keys you want to override.
-
-For example, we could have a radar chart without a point for each on piece of data by doing the following:
-
-```javascript
-new Chart(ctx).Radar(data, {
- pointDot: false
-});
-// This will create a chart with all of the default options, merged from the global config,
-// and the Bar chart defaults but this particular instance will have `pointDot` set to false.
-```
-
-We can also change these defaults values for each Radar type that is created, this object is available at `Chart.defaults.Radar`.
-
-
-### Prototype methods
-
-#### .getPointsAtEvent( event )
-
-Calling `getPointsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the point elements that are at that the same position of that event.
-
-```javascript
-canvas.onclick = function(evt){
- var activePoints = myRadarChart.getPointsAtEvent(evt);
- // => activePoints is an array of points on the canvas that are at the same position as the click event.
-};
-```
-
-This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
-
-#### .update( )
-
-Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
-
-```javascript
-myRadarChart.datasets[0].points[2].value = 50;
-// Would update the first dataset's value of 'Sleeping' to be 50
-myRadarChart.update();
-// Calling update now animates the position of Sleeping from 90 to 50.
-```
-
-#### .addData( valuesArray, label )
-
-Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those points.
-
-```javascript
-// The values array passed into addData should be one for each dataset in the chart
-myRadarChart.addData([40, 60], "Dancing");
-// The new data will now animate at the end of the chart.
-```
-
-#### .removeData( )
-
-Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
-
-```javascript
-myRadarChart.removeData();
-// Other points will now animate to their correct positions.
-``` | true |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/04-Polar-Area-Chart.md | @@ -1,172 +0,0 @@
----
-title: Polar Area Chart
-anchor: polar-area-chart
----
-### Introduction
-Polar area charts are similar to pie charts, but each segment has the same angle - the radius of the segment differs depending on the value.
-
-This type of chart is often useful when we want to show a comparison data similar to a pie chart, but also show a scale of values for context.
-
-<div class="canvas-holder">
- <canvas width="250" height="125"></canvas>
-</div>
-
-### Example usage
-
-```javascript
-new Chart(ctx).PolarArea(data, options);
-```
-
-### Data structure
-
-```javascript
-var data = [
- {
- value: 300,
- color:"#F7464A",
- highlight: "#FF5A5E",
- label: "Red"
- },
- {
- value: 50,
- color: "#46BFBD",
- highlight: "#5AD3D1",
- label: "Green"
- },
- {
- value: 100,
- color: "#FDB45C",
- highlight: "#FFC870",
- label: "Yellow"
- },
- {
- value: 40,
- color: "#949FB1",
- highlight: "#A8B3C5",
- label: "Grey"
- },
- {
- value: 120,
- color: "#4D5360",
- highlight: "#616774",
- label: "Dark Grey"
- }
-
-];
-```
-As you can see, for the chart data you pass in an array of objects, with a value and a colour. The value attribute should be a number, while the color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
-
-### Chart options
-
-These are the customisation options specific to Polar Area charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
-
-```javascript
-{
- //Boolean - Show a backdrop to the scale label
- scaleShowLabelBackdrop : true,
-
- //String - The colour of the label backdrop
- scaleBackdropColor : "rgba(255,255,255,0.75)",
-
- // Boolean - Whether the scale should begin at zero
- scaleBeginAtZero : true,
-
- //Number - The backdrop padding above & below the label in pixels
- scaleBackdropPaddingY : 2,
-
- //Number - The backdrop padding to the side of the label in pixels
- scaleBackdropPaddingX : 2,
-
- //Boolean - Show line for each value in the scale
- scaleShowLine : true,
-
- //Boolean - Stroke a line around each segment in the chart
- segmentShowStroke : true,
-
- //String - The colour of the stroke on each segment.
- segmentStrokeColor : "#fff",
-
- //Number - The width of the stroke value in pixels
- segmentStrokeWidth : 2,
-
- //Number - Amount of animation steps
- animationSteps : 100,
-
- //String - Animation easing effect.
- animationEasing : "easeOutBounce",
-
- //Boolean - Whether to animate the rotation of the chart
- animateRotate : true,
-
- //Boolean - Whether to animate scaling the chart from the centre
- animateScale : false,
- {% raw %}
- //String - A legend template
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
- {% endraw %}
-}
-```
-
-You can override these for your `Chart` instance by passing a second argument into the `PolarArea` method as an object with the keys you want to override.
-
-For example, we could have a polar area chart with a black stroke on each segment like so:
-
-```javascript
-new Chart(ctx).PolarArea(data, {
- segmentStrokeColor: "#000000"
-});
-// This will create a chart with all of the default options, merged from the global config,
-// and the PolarArea chart defaults but this particular instance will have `segmentStrokeColor` set to `"#000000"`.
-```
-
-We can also change these defaults values for each PolarArea type that is created, this object is available at `Chart.defaults.PolarArea`.
-
-### Prototype methods
-
-#### .getSegmentsAtEvent( event )
-
-Calling `getSegmentsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the segment elements that are at that the same position of that event.
-
-```javascript
-canvas.onclick = function(evt){
- var activePoints = myPolarAreaChart.getSegmentsAtEvent(evt);
- // => activePoints is an array of segments on the canvas that are at the same position as the click event.
-};
-```
-
-This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
-
-#### .update( )
-
-Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
-
-```javascript
-myPolarAreaChart.segments[1].value = 10;
-// Would update the first dataset's value of 'Green' to be 10
-myPolarAreaChart.update();
-// Calling update now animates the position of Green from 50 to 10.
-```
-
-#### .addData( segmentData, index )
-
-Calling `addData(segmentData, index)` on your Chart instance passing an object in the same format as in the constructor. There is an option second argument of 'index', this determines at what index the new segment should be inserted into the chart.
-
-```javascript
-// An object in the same format as the original data source
-myPolarAreaChart.addData({
- value: 130,
- color: "#B48EAD",
- highlight: "#C69CBE",
- label: "Purple"
-});
-// The new segment will now animate in.
-```
-
-#### .removeData( index )
-
-Calling `removeData(index)` on your Chart instance will remove segment at that particular index. If none is provided, it will default to the last segment.
-
-```javascript
-myPolarAreaChart.removeData();
-// Other segments will update to fill the empty space left.
-``` | true |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/05-Pie-Doughnut-Chart.md | @@ -1,160 +0,0 @@
----
-title: Pie & Doughnut Charts
-anchor: doughnut-pie-chart
----
-###Introduction
-Pie and doughnut charts are probably the most commonly used chart there are. They are divided into segments, the arc of each segment shows the proportional value of each piece of data.
-
-They are excellent at showing the relational proportions between data.
-
-Pie and doughnut charts are effectively the same class in Chart.js, but have one different default value - their `percentageInnerCutout`. This equates what percentage of the inner should be cut out. This defaults to `0` for pie charts, and `50` for doughnuts.
-
-They are also registered under two aliases in the `Chart` core. Other than their different default value, and different alias, they are exactly the same.
-
-<div class="canvas-holder half">
- <canvas width="250" height="125"></canvas>
-</div>
-
-<div class="canvas-holder half">
- <canvas width="250" height="125"></canvas>
-</div>
-
-
-### Example usage
-
-```javascript
-// For a pie chart
-var myPieChart = new Chart(ctx[0]).Pie(data,options);
-
-// And for a doughnut chart
-var myDoughnutChart = new Chart(ctx[1]).Doughnut(data,options);
-```
-
-### Data structure
-
-```javascript
-var data = [
- {
- value: 300,
- color:"#F7464A",
- highlight: "#FF5A5E",
- label: "Red"
- },
- {
- value: 50,
- color: "#46BFBD",
- highlight: "#5AD3D1",
- label: "Green"
- },
- {
- value: 100,
- color: "#FDB45C",
- highlight: "#FFC870",
- label: "Yellow"
- }
-]
-```
-
-For a pie chart, you must pass in an array of objects with a value and an optional color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
-
-### Chart options
-
-These are the customisation options specific to Pie & Doughnut charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
-
-```javascript
-{
- //Boolean - Whether we should show a stroke on each segment
- segmentShowStroke : true,
-
- //String - The colour of each segment stroke
- segmentStrokeColor : "#fff",
-
- //Number - The width of each segment stroke
- segmentStrokeWidth : 2,
-
- //Number - The percentage of the chart that we cut out of the middle
- percentageInnerCutout : 50, // This is 0 for Pie charts
-
- //Number - Amount of animation steps
- animationSteps : 100,
-
- //String - Animation easing effect
- animationEasing : "easeOutBounce",
-
- //Boolean - Whether we animate the rotation of the Doughnut
- animateRotate : true,
-
- //Boolean - Whether we animate scaling the Doughnut from the centre
- animateScale : false,
- {% raw %}
- //String - A legend template
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
- {% endraw %}
-}
-```
-You can override these for your `Chart` instance by passing a second argument into the `Doughnut` method as an object with the keys you want to override.
-
-For example, we could have a doughnut chart that animates by scaling out from the centre like so:
-
-```javascript
-new Chart(ctx).Doughnut(data, {
- animateScale: true
-});
-// This will create a chart with all of the default options, merged from the global config,
-// and the Doughnut chart defaults but this particular instance will have `animateScale` set to `true`.
-```
-
-We can also change these default values for each Doughnut type that is created, this object is available at `Chart.defaults.Doughnut`. Pie charts also have a clone of these defaults available to change at `Chart.defaults.Pie`, with the only difference being `percentageInnerCutout` being set to 0.
-
-### Prototype methods
-
-#### .getSegmentsAtEvent( event )
-
-Calling `getSegmentsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the segment elements that are at the same position of that event.
-
-```javascript
-canvas.onclick = function(evt){
- var activePoints = myDoughnutChart.getSegmentsAtEvent(evt);
- // => activePoints is an array of segments on the canvas that are at the same position as the click event.
-};
-```
-
-This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
-
-#### .update( )
-
-Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
-
-```javascript
-myDoughnutChart.segments[1].value = 10;
-// Would update the first dataset's value of 'Green' to be 10
-myDoughnutChart.update();
-// Calling update now animates the circumference of the segment 'Green' from 50 to 10.
-// and transitions other segment widths
-```
-
-#### .addData( segmentData, index )
-
-Calling `addData(segmentData, index)` on your Chart instance passing an object in the same format as in the constructor. There is an optional second argument of 'index', this determines at what index the new segment should be inserted into the chart.
-
-If you don't specify a color and highliht, one will be chosen from the global default array: segmentColorDefault and the corresponding segmentHighlightColorDefault. The index of the addded data is used to lookup a corresponding color from the defaults.
-
-```javascript
-// An object in the same format as the original data source
-myDoughnutChart.addData({
- value: 130,
- color: "#B48EAD",
- highlight: "#C69CBE",
- label: "Purple"
-});
-// The new segment will now animate in.
-```
-
-#### .removeData( index )
-
-Calling `removeData(index)` on your Chart instance will remove segment at that particular index. If none is provided, it will default to the last segment.
-
-```javascript
-myDoughnutChart.removeData();
-// Other segments will update to fill the empty space left.
-``` | true |
Other | chartjs | Chart.js | d5af01b2c76e144c6c7a7830903a67709cb17763.json | Remove old doc files | docs/06-Advanced.md | @@ -1,187 +0,0 @@
----
-title: Advanced usage
-anchor: advanced-usage
----
-
-
-### Prototype methods
-
-For each chart, there are a set of global prototype methods on the shared `ChartType` which you may find useful. These are available on all charts created with Chart.js, but for the examples, let's use a line chart we've made.
-
-```javascript
-// For example:
-var myLineChart = new Chart(ctx).Line(data);
-```
-
-#### .clear()
-
-Will clear the chart canvas. Used extensively internally between animation frames, but you might find it useful.
-
-```javascript
-// Will clear the canvas that myLineChart is drawn on
-myLineChart.clear();
-// => returns 'this' for chainability
-```
-
-#### .stop()
-
-Use this to stop any current animation loop. This will pause the chart during any current animation frame. Call `.render()` to re-animate.
-
-```javascript
-// Stops the charts animation loop at its current frame
-myLineChart.stop();
-// => returns 'this' for chainability
-```
-
-#### .resize()
-
-Use this to manually resize the canvas element. This is run each time the browser is resized, but you can call this method manually if you change the size of the canvas nodes container element.
-
-```javascript
-// Resizes & redraws to fill its container element
-myLineChart.resize();
-// => returns 'this' for chainability
-```
-
-#### .destroy()
-
-Use this to destroy any chart instances that are created. This will clean up any references stored to the chart object within Chart.js, along with any associated event listeners attached by Chart.js.
-
-```javascript
-// Destroys a specific chart instance
-myLineChart.destroy();
-```
-
-#### .toBase64Image()
-
-This returns a base 64 encoded string of the chart in its current state.
-
-```javascript
-myLineChart.toBase64Image();
-// => returns png data url of the image on the canvas
-```
-
-#### .generateLegend()
-
-Returns an HTML string of a legend for that chart. The template for this legend is at `legendTemplate` in the chart options.
-
-```javascript
-myLineChart.generateLegend();
-// => returns HTML string of a legend for this chart
-```
-
-### External Tooltips
-
-You can enable custom tooltips in the global or chart configuration like so:
-
-```javascript
-var myPieChart = new Chart(ctx).Pie(data, {
- customTooltips: function(tooltip) {
-
- // tooltip will be false if tooltip is not visible or should be hidden
- if (!tooltip) {
- return;
- }
-
- // Otherwise, tooltip will be an object with all tooltip properties like:
-
- // tooltip.caretHeight
- // tooltip.caretPadding
- // tooltip.chart
- // tooltip.cornerRadius
- // tooltip.fillColor
- // tooltip.font...
- // tooltip.text
- // tooltip.x
- // tooltip.y
- // etc...
-
- }
-});
-```
-
-See files `sample/pie-customTooltips.html` and `sample/line-customTooltips.html` for examples on how to get started.
-
-
-### Writing new chart types
-
-Chart.js 1.0 has been rewritten to provide a platform for developers to create their own custom chart types, and be able to share and utilise them through the Chart.js API.
-
-The format is relatively simple, there are a set of utility helper methods under `Chart.helpers`, including things such as looping over collections, requesting animation frames, and easing equations.
-
-On top of this, there are also some simple base classes of Chart elements, these all extend from `Chart.Element`, and include things such as points, bars and scales.
-
-```javascript
-Chart.Type.extend({
- // Passing in a name registers this chart in the Chart namespace
- name: "Scatter",
- // Providing a defaults will also register the deafults in the chart namespace
- defaults : {
- options: "Here",
- available: "at this.options"
- },
- // Initialize is fired when the chart is initialized - Data is passed in as a parameter
- // Config is automatically merged by the core of Chart.js, and is available at this.options
- initialize: function(data){
- this.chart.ctx // The drawing context for this chart
- this.chart.canvas // the canvas node for this chart
- },
- // Used to draw something on the canvas
- draw: function() {
- }
-});
-
-// Now we can create a new instance of our chart, using the Chart.js API
-new Chart(ctx).Scatter(data);
-// initialize is now run
-```
-
-### Extending existing chart types
-
-We can also extend existing chart types, and expose them to the API in the same way. Let's say for example, we might want to run some more code when we initialize every Line chart.
-
-```javascript
-// Notice now we're extending the particular Line chart type, rather than the base class.
-Chart.types.Line.extend({
- // Passing in a name registers this chart in the Chart namespace in the same way
- name: "LineAlt",
- initialize: function(data){
- console.log('My Line chart extension');
- Chart.types.Line.prototype.initialize.apply(this, arguments);
- }
-});
-
-// Creates a line chart in the same way
-new Chart(ctx).LineAlt(data);
-// but this logs 'My Line chart extension' in the console.
-```
-
-### Community extensions
-
-- <a href="https://github.com/Regaddi/Chart.StackedBar.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/Regaddi" target="_blank">@Regaddi</a>
-- <a href="https://github.com/tannerlinsley/Chart.StackedArea.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/tannerlinsley" target="_blank">@tannerlinsley</a>
-- <a href="https://github.com/CAYdenberg/Chart.js" target="_blank">Error bars (bar and line charts)</a> by <a href="https://twitter.com/CAYdenberg" target="_blank">@CAYdenberg</a>
-- <a href="http://dima117.github.io/Chart.Scatter/" target="_blank">Scatter chart (number & date scales are supported)</a> by <a href="https://github.com/dima117" target="_blank">@dima117</a>
-
-### Creating custom builds
-
-Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single JavaScript file. We can use this same build script with custom parameters in order to build a custom version.
-
-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:
-
-```bash
-npm install
-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-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:
-
-```bash
-gulp build --types=Line,Radar,Bar
-```
-
-This will output to the `/custom` directory, and write two files, Chart.js, and Chart.min.js with only those chart types included. | true |
Other | chartjs | Chart.js | fbb6da139333b0172cd27f7b9cad23869eb3081d.json | Remove unnecessary line from code climate config | .codeclimate.yml | @@ -1,4 +1,3 @@
----
engines:
duplication:
enabled: true | false |
Other | chartjs | Chart.js | 5fa60033611690ef48db1e6b934e7a8c095349af.json | fix "main" file path in bower.json | bower.json | @@ -5,9 +5,9 @@
"homepage": "https://github.com/nnnick/Chart.js",
"author": "nnnick",
"main": [
- "Chart.js"
+ "dist/Chart.js"
],
"devDependencies": {
"jquery": "~2.1.4"
}
-}
\ No newline at end of file
+} | false |
Other | chartjs | Chart.js | 8c2bc34b9c36eb1c79b4aa0313cb01012059444d.json | Fix whitespace in Line Chart documentation | docs/02-Line-Chart.md | @@ -48,16 +48,16 @@ var data = {
borderColor: "rgba(220,220,220,1)",
// String - cap style of the line. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap
- borderCapStyle: 'butt',
+ borderCapStyle: 'butt',
- // Array - Length and spacing of dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
- borderDash: [],
+ // Array - Length and spacing of dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
+ borderDash: [],
- // Number - Offset for line dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
- borderDashOffset: 0.0,
+ // Number - Offset for line dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
+ borderDashOffset: 0.0,
- // String - line join style. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
- borderJoinStyle: 'miter',
+ // String - line join style. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
+ borderJoinStyle: 'miter',
// String or array - Point stroke color
pointBorderColor: "rgba(220,220,220,1)", | false |
Other | chartjs | Chart.js | c6318749da660f6d8599b466b3871f437123c1d0.json | Drop official support for Bower
Remove the bower.json file and update the documentation with the alternative bower-npm-resolver solution. | README.md | @@ -10,13 +10,14 @@
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.
-To install via npm / bower:
+To install via npm:
```bash
npm install chart.js --save
-bower install Chart.js --save
```
+To Install via bower, please follow [these instructions](http://www.chartjs.org/docs/#getting-started-installation).
+
## Documentation
You can find documentation at [www.chartjs.org/docs](http://www.chartjs.org/docs). The markdown files that build the site are available under `/docs`. Previous version documentation is available at [www.chartjs.org/docs/#notes-previous-versions](http://www.chartjs.org/docs/#notes-previous-versions). | true |
Other | chartjs | Chart.js | c6318749da660f6d8599b466b3871f437123c1d0.json | Drop official support for Bower
Remove the bower.json file and update the documentation with the alternative bower-npm-resolver solution. | bower.json | @@ -1,14 +0,0 @@
-{
- "name": "Chart.js",
- "version": "2.1.6",
- "description": "Simple HTML5 Charts using the canvas element",
- "homepage": "https://github.com/chartjs/Chart.js",
- "author": "nnnick",
- "license": "MIT",
- "main": [
- "dist/Chart.js"
- ],
- "devDependencies": {
- "jquery": "~2.1.4"
- }
-}
\ No newline at end of file | true |
Other | chartjs | Chart.js | c6318749da660f6d8599b466b3871f437123c1d0.json | Drop official support for Bower
Remove the bower.json file and update the documentation with the alternative bower-npm-resolver solution. | docs/00-Getting-Started.md | @@ -9,13 +9,30 @@ You can download the latest version of [Chart.js on GitHub](https://github.com/c
### Installation
-To install via npm / bower:
+#### npm
```bash
npm install chart.js --save
```
+
+#### bower
+
+Bower support has been dropped since version 2.2.0 but you can still use Chart.js with Bower thanks to [bower-npm-resolver](https://www.npmjs.com/package/bower-npm-resolver).
+
+First, add the resolver in your .bowerrc file:
+```json
+{
+ "resolvers": [
+ "bower-npm-resolver"
+ ]
+}
+```
+
+Then:
+
```bash
-bower install Chart.js --save
+npm install -g bower-npm-resolver
+bower install npm:chart.js --save
```
### Selecting the Correct Build
@@ -24,7 +41,7 @@ Chart.js provides two different builds that are available for your use. The `Cha
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.
-### Installation
+### Usage
To import Chart.js using an old-school script tag:
| true |
Other | chartjs | Chart.js | c6318749da660f6d8599b466b3871f437123c1d0.json | Drop official support for Bower
Remove the bower.json file and update the documentation with the alternative bower-npm-resolver solution. | gulpfile.js | @@ -14,7 +14,6 @@ var gulp = require('gulp'),
exec = require('child_process').exec,
fs = require('fs'),
package = require('./package.json'),
- bower = require('./bower.json'),
karma = require('gulp-karma'),
browserify = require('browserify'),
streamify = require('gulp-streamify'),
@@ -121,7 +120,7 @@ function packageTask() {
/*
* Usage : gulp bump
* Prompts: Version increment to bump
- * Output: - New version number written into package.json & bower.json
+ * Output: - New version number written into package.json
*/
function bumpTask(complete) {
util.log('Current version:', util.colors.cyan(package.version));
@@ -138,13 +137,11 @@ function bumpTask(complete) {
newVersion = semver.inc(package.version, increment),
oldVersion = package.version;
- // Set the new versions into the bower/package object
+ // Set the new versions into the package object
package.version = newVersion;
- bower.version = newVersion;
// Write these to their own files, then build the output
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
- fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js'; | true |
Other | chartjs | Chart.js | 782b84ae944f74dd3ccddf35273ae6538a21c45a.json | Make Travis to release the npm package
Add .npmignore to include dist/*.js files to the npm release (but exclude zip files). See https://docs.travis-ci.com/user/deployment/npm/. Also cleanup the .gitignore file. | .gitignore | @@ -1,14 +1,8 @@
+/coverage
+/custom
+/dist
+/docs/index.md
+/node_modules
.DS_Store
-
-node_modules/*
-custom/*
-dist/*
-
-docs/index.md
-
-bower_components/
-
-coverage/*
.idea
-nbproject/* | true |
Other | chartjs | Chart.js | 782b84ae944f74dd3ccddf35273ae6538a21c45a.json | Make Travis to release the npm package
Add .npmignore to include dist/*.js files to the npm release (but exclude zip files). See https://docs.travis-ci.com/user/deployment/npm/. Also cleanup the .gitignore file. | .npmignore | @@ -0,0 +1,13 @@
+/.git
+/.github
+/coverage
+/custom
+/dist/*.zip
+/docs/index.md
+/node_modules
+
+.codeclimate.yml
+.DS_Store
+.gitignore
+.idea
+.travis.yml | true |
Other | chartjs | Chart.js | 782b84ae944f74dd3ccddf35273ae6538a21c45a.json | Make Travis to release the npm package
Add .npmignore to include dist/*.js files to the npm release (but exclude zip files). See https://docs.travis-ci.com/user/deployment/npm/. Also cleanup the .gitignore file. | .travis.yml | @@ -32,7 +32,7 @@ addons:
- google-chrome-stable
deploy:
- provider: releases
+- provider: releases
api_key:
secure: E6JiZzA/Qy+UD1so/rVfqYnMhgU4m0cUsljxyrKIiYKlt/ZXo1XJabNkpEIYLvckrNx+g/4cmidNcuLfrnAZJtUg53qHLxyqMTXa9zAqmxxJ6aIpQpNK25FIEk9Xwm2XZdbI5rrm0ZciP5rcgg0X8/j5+RtnU3ZpTOCVkp0P73A=
file:
@@ -44,3 +44,11 @@ deploy:
skip_cleanup: true
on:
tags: true
+- provider: npm
+ email:
+ secure: f6jQXdqhoKtEZ3WBvnNM9PB2l9yg8SGmnUwQzeuLpW731opmv1ngPcMA+CotDAavIRs2BvAgVoLJOVGxMRXRSi5pgahfR0O2LetFoT/Px+q4MMqtn3zMgV/OuYL/fIyKXjyoYwSRfjuaIIGX7VTCOpqOEe29UQJAb7XcG9jhgIo=
+ api_key:
+ secure: O5lgPeX5ofkMSiUeijs+0hrK9Dejmpki/UABd+rgx3Cmjlxvi5DVugHpcn/6C0if0CoHv5/TqwQHVgL43kwR5ZKcspl7bzK2vD2YBpingF42Oz91YVNZwQIJyWNVSSWzzFYzG9xOXO26ZD1gTZ26Z3X+xfZVtugWkzbBa/c8NmQ=
+ skip_cleanup: true
+ on:
+ tags: true | true |
Other | chartjs | Chart.js | 0579fbb7415836728aff0595cf15ec44ac244f6c.json | Add download links to the latest version
Remove outdated *standard build* and *bundled with Moment.js* links from the documentation and add a link to the latest GitHub release, from where the user can download `*.js` files. | README.md | @@ -8,15 +8,14 @@
## Installation
-To download a zip, go to the Chart.js on Github
+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.
To install via npm / bower:
```bash
npm install chart.js --save
bower install Chart.js --save
```
-CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.6/Chart.min.js
## Documentation
| true |
Other | chartjs | Chart.js | 0579fbb7415836728aff0595cf15ec44ac244f6c.json | Add download links to the latest version
Remove outdated *standard build* and *bundled with Moment.js* links from the documentation and add a link to the latest GitHub release, from where the user can download `*.js` files. | docs/00-Getting-Started.md | @@ -5,10 +5,9 @@ anchor: getting-started
### Download Chart.js
-To download a zip, go to [Chart.js on Github](https://github.com/chartjs/Chart.js) and choose the version that is right for your application.
-* [Standard build](https://raw.githubusercontent.com/chartjs/Chart.js/master/dist/Chart.js) (~31kB gzipped)
-* [Bundled with Moment.js](https://raw.githubusercontent.com/chartjs/Chart.js/master/dist/Chart.bundle.js) (~45kB gzipped)
-* [CDN Versions](https://cdnjs.com/libraries/Chart.js)
+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.
+
+### Installation
To install via npm / bower:
| true |
Other | chartjs | Chart.js | 72edacd877f59c2f471b2366d60d0fb051734aed.json | Make Travis to deploy built files for tags
See https://docs.travis-ci.com/user/deployment/releases | .travis.yml | @@ -11,6 +11,7 @@ before_script:
- npm install
script:
+ - gulp build
- gulp test
- gulp coverage
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
@@ -28,3 +29,16 @@ addons:
- google-chrome
packages:
- google-chrome-stable
+
+deploy:
+ provider: releases
+ api_key:
+ secure: E6JiZzA/Qy+UD1so/rVfqYnMhgU4m0cUsljxyrKIiYKlt/ZXo1XJabNkpEIYLvckrNx+g/4cmidNcuLfrnAZJtUg53qHLxyqMTXa9zAqmxxJ6aIpQpNK25FIEk9Xwm2XZdbI5rrm0ZciP5rcgg0X8/j5+RtnU3ZpTOCVkp0P73A=
+ file:
+ - "./dist/Chart.bundle.js"
+ - "./dist/Chart.bundle.min.js"
+ - "./dist/Chart.js"
+ - "./dist/Chart.min.js"
+ skip_cleanup: true
+ on:
+ tags: true | false |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.bar.js | @@ -40,7 +40,7 @@ module.exports = function(Chart) {
},
// Get the number of datasets that display bars. We use this to correctly calculate the bar width
- getBarCount: function getBarCount() {
+ getBarCount: function() {
var me = this;
var barCount = 0;
helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
@@ -52,14 +52,14 @@ module.exports = function(Chart) {
return barCount;
},
- update: function update(reset) {
+ update: function(reset) {
var me = this;
helpers.each(me.getMeta().data, function(rectangle, index) {
me.updateElement(rectangle, index, reset);
}, me);
},
- updateElement: function updateElement(rectangle, index, reset) {
+ updateElement: function(rectangle, index, reset) {
var me = this;
var meta = me.getMeta();
var xScale = me.getScaleForId(meta.xAxisID);
@@ -338,7 +338,7 @@ module.exports = function(Chart) {
};
Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
- updateElement: function updateElement(rectangle, index, reset) {
+ updateElement: function(rectangle, index, reset) {
var me = this;
var meta = me.getMeta();
var xScale = me.getScaleForId(meta.xAxisID); | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.bubble.js | @@ -41,7 +41,7 @@ module.exports = function(Chart) {
dataElementType: Chart.elements.Point,
- update: function update(reset) {
+ update: function(reset) {
var me = this;
var meta = me.getMeta();
var points = meta.data; | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.doughnut.js | @@ -119,7 +119,7 @@ module.exports = function(Chart) {
linkScales: helpers.noop,
// Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
- getRingIndex: function getRingIndex(datasetIndex) {
+ getRingIndex: function(datasetIndex) {
var ringIndex = 0;
for (var j = 0; j < datasetIndex; ++j) {
@@ -131,7 +131,7 @@ module.exports = function(Chart) {
return ringIndex;
},
- update: function update(reset) {
+ update: function(reset) {
var me = this;
var chart = me.chart,
chartArea = chart.chartArea, | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.line.js | @@ -46,7 +46,7 @@ module.exports = function(Chart) {
}
},
- update: function update(reset) {
+ update: function(reset) {
var me = this;
var meta = me.getMeta();
var line = meta.dataset; | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.polarArea.js | @@ -105,7 +105,7 @@ module.exports = function(Chart) {
linkScales: helpers.noop,
- update: function update(reset) {
+ update: function(reset) {
var me = this;
var chart = me.chart;
var chartArea = chart.chartArea; | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/controllers/controller.radar.js | @@ -30,7 +30,7 @@ module.exports = function(Chart) {
this.updateBezierControlPoints();
},
- update: function update(reset) {
+ update: function(reset) {
var me = this;
var meta = me.getMeta();
var line = meta.dataset; | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/core/core.controller.js | @@ -45,7 +45,7 @@ module.exports = function(Chart) {
helpers.extend(Chart.Controller.prototype, /** @lends Chart.Controller */ {
- initialize: function initialize() {
+ initialize: function() {
var me = this;
// Before init plugin notification
Chart.plugins.notify('beforeInit', [me]);
@@ -68,12 +68,12 @@ module.exports = function(Chart) {
return me;
},
- clear: function clear() {
+ clear: function() {
helpers.clear(this.chart);
return this;
},
- stop: function stop() {
+ stop: function() {
// Stops any current animation loop occuring
Chart.animationService.cancelAnimation(this);
return this;
@@ -115,7 +115,7 @@ module.exports = function(Chart) {
return me;
},
- ensureScalesHaveIDs: function ensureScalesHaveIDs() {
+ ensureScalesHaveIDs: function() {
var options = this.options;
var scalesOptions = options.scales || {};
var scaleOptions = options.scale;
@@ -136,7 +136,7 @@ module.exports = function(Chart) {
/**
* Builds a map of scale ID to scale object for future lookup.
*/
- buildScales: function buildScales() {
+ buildScales: function() {
var me = this;
var options = me.options;
var scales = me.scales = {};
@@ -186,7 +186,7 @@ module.exports = function(Chart) {
Chart.layoutService.update(this, this.chart.width, this.chart.height);
},
- buildOrUpdateControllers: function buildOrUpdateControllers() {
+ buildOrUpdateControllers: function() {
var me = this;
var types = [];
var newControllers = [];
@@ -219,7 +219,7 @@ module.exports = function(Chart) {
return newControllers;
},
- resetElements: function resetElements() {
+ resetElements: function() {
var me = this;
helpers.each(me.data.datasets, function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.reset();
@@ -486,11 +486,11 @@ module.exports = function(Chart) {
return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
},
- generateLegend: function generateLegend() {
+ generateLegend: function() {
return this.options.legendCallback(this);
},
- destroy: function destroy() {
+ destroy: function() {
var me = this;
me.stop();
me.clear();
@@ -516,11 +516,11 @@ module.exports = function(Chart) {
delete Chart.instances[me.id];
},
- toBase64Image: function toBase64Image() {
+ toBase64Image: function() {
return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
},
- initToolTip: function initToolTip() {
+ initToolTip: function() {
var me = this;
me.tooltip = new Chart.Tooltip({
_chart: me.chart,
@@ -530,7 +530,7 @@ module.exports = function(Chart) {
}, me);
},
- bindEvents: function bindEvents() {
+ bindEvents: function() {
var me = this;
helpers.bindEvents(me, me.options.events, function(evt) {
me.eventHandler(evt); | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/core/core.datasetController.js | @@ -105,7 +105,7 @@ module.exports = function(Chart) {
me.updateElement(element, index, true);
},
- buildOrUpdateElements: function buildOrUpdateElements() {
+ buildOrUpdateElements: function() {
// Handle the number of data points changing
var meta = this.getMeta(),
md = meta.data, | true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/core/core.scale.js | @@ -390,7 +390,7 @@ module.exports = function(Chart) {
},
// Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
- getRightValue: function getRightValue(rawValue) {
+ getRightValue: function(rawValue) {
// Null and undefined values first
if (rawValue === null || typeof(rawValue) === 'undefined') {
return NaN;
@@ -404,7 +404,7 @@ module.exports = function(Chart) {
if ((rawValue instanceof Date) || (rawValue.isValid)) {
return rawValue;
} else {
- return getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
+ return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
}
| true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/core/core.tooltip.js | @@ -328,7 +328,7 @@ module.exports = function(Chart) {
return me;
},
- getTooltipSize: function getTooltipSize(vm) {
+ getTooltipSize: function(vm) {
var ctx = this._chart.ctx;
var size = {
@@ -391,7 +391,7 @@ module.exports = function(Chart) {
return size;
},
- determineAlignment: function determineAlignment(size) {
+ determineAlignment: function(size) {
var me = this;
var model = me._model;
var chart = me._chart;
@@ -453,7 +453,7 @@ module.exports = function(Chart) {
}
}
},
- getBackgroundPoint: function getBackgroundPoint(vm, size) {
+ getBackgroundPoint: function(vm, size) {
// Background Position
var pt = {
x: vm.x,
@@ -498,7 +498,7 @@ module.exports = function(Chart) {
return pt;
},
- drawCaret: function drawCaret(tooltipPoint, size, opacity) {
+ drawCaret: function(tooltipPoint, size, opacity) {
var vm = this._view;
var ctx = this._chart.ctx;
var x1, x2, x3;
@@ -562,7 +562,7 @@ module.exports = function(Chart) {
ctx.closePath();
ctx.fill();
},
- drawTitle: function drawTitle(pt, vm, ctx, opacity) {
+ drawTitle: function(pt, vm, ctx, opacity) {
var title = vm.title;
if (title.length) {
@@ -587,7 +587,7 @@ module.exports = function(Chart) {
}
}
},
- drawBody: function drawBody(pt, vm, ctx, opacity) {
+ drawBody: function(pt, vm, ctx, opacity) {
var bodyFontSize = vm.bodyFontSize;
var bodySpacing = vm.bodySpacing;
var body = vm.body;
@@ -648,7 +648,7 @@ module.exports = function(Chart) {
helpers.each(vm.afterBody, fillLineOfText);
pt.y -= bodySpacing; // Remove last body spacing
},
- drawFooter: function drawFooter(pt, vm, ctx, opacity) {
+ drawFooter: function(pt, vm, ctx, opacity) {
var footer = vm.footer;
if (footer.length) {
@@ -667,7 +667,7 @@ module.exports = function(Chart) {
});
}
},
- draw: function draw() {
+ draw: function() {
var ctx = this._chart.ctx;
var vm = this._view;
| true |
Other | chartjs | Chart.js | 47912f49b410334e547f710ff473ac36682a2c76.json | Remove duplicated function names | src/scales/scale.time.js | @@ -309,7 +309,7 @@ module.exports = function(Chart) {
return label;
},
// Function to format an individual tick mark
- tickFormatFunction: function tickFormatFunction(tick, index, ticks) {
+ tickFormatFunction: function(tick, index, ticks) {
var formattedTick = tick.format(this.displayFormat);
var tickOpts = this.options.ticks;
var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback); | true |
Other | chartjs | Chart.js | f106e1bf2db1aa604edb62b8e3b309329c41dd94.json | fix tooltip with array returns | src/core/core.tooltip.js | @@ -86,7 +86,8 @@ module.exports = function(Chart) {
function pushOrConcat(base, toPush) {
if (toPush) {
if (helpers.isArray(toPush)) {
- base = base.concat(toPush);
+ //base = base.concat(toPush);
+ Array.prototype.push.apply(base, toPush);
} else {
base.push(toPush);
} | false |
Other | chartjs | Chart.js | a55c17d73fa7bfa9e2780fce3ea9a7770a11d8d3.json | Enhance plugin notification system
Change the plugin notification behavior: this method now returns false as soon as a plugin *explicitly* returns false, else returns true. Also, plugins are now called in their own scope (so remove the never used `scope` parameter). | src/core/core.plugin.js | @@ -2,8 +2,7 @@
module.exports = function(Chart) {
- var helpers = Chart.helpers;
- var noop = helpers.noop;
+ var noop = Chart.helpers.noop;
/**
* The plugin service singleton
@@ -30,21 +29,33 @@ module.exports = function(Chart) {
},
/**
- * Calls registered plugins on the specified method, with the given args. This
- * method immediately returns as soon as a plugin explicitly returns false.
+ * Calls registered plugins on the specified extension, with the given args. This
+ * method immediately returns as soon as a plugin explicitly returns false. The
+ * returned value can be used, for instance, to interrupt the current action.
+ * @param {String} extension the name of the plugin method to call (e.g. 'beforeUpdate').
+ * @param {Array} [args] extra arguments to apply to the extension call.
* @returns {Boolean} false if any of the plugins return false, else returns true.
*/
- notify: function(method, args, scope) {
- helpers.each(this._plugins, function(plugin) {
- if (plugin[method] && typeof plugin[method] === 'function') {
- plugin[method].apply(scope, args);
+ notify: function(extension, args) {
+ var plugins = this._plugins;
+ var ilen = plugins.length;
+ var i, plugin;
+
+ for (i=0; i<ilen; ++i) {
+ plugin = plugins[i];
+ if (typeof plugin[extension] === 'function') {
+ if (plugin[extension].apply(plugin, args || []) === false) {
+ return false;
+ }
}
- }, scope);
+ }
+
+ return true;
}
};
Chart.PluginBase = Chart.Element.extend({
- // Plugin methods. All functions are passed the chart instance
+ // Plugin extensions. All functions are passed the chart instance
// Called at start of chart init
beforeInit: noop, | true |
Other | chartjs | Chart.js | a55c17d73fa7bfa9e2780fce3ea9a7770a11d8d3.json | Enhance plugin notification system
Change the plugin notification behavior: this method now returns false as soon as a plugin *explicitly* returns false, else returns true. Also, plugins are now called in their own scope (so remove the never used `scope` parameter). | test/core.plugin.tests.js | @@ -37,17 +37,36 @@ describe('Test the plugin system', function() {
Chart.plugins.remove(myplugin);
});
- it ('Should allow notifying plugins', function() {
- var myplugin = {
- count: 0,
- trigger: function(chart) {
- myplugin.count = chart.count;
- }
- };
- Chart.plugins.register(myplugin);
+ describe('Chart.plugins.notify', function() {
+ it ('should call plugins with arguments', function() {
+ var myplugin = {
+ count: 0,
+ trigger: function(chart) {
+ myplugin.count = chart.count;
+ }
+ };
+
+ Chart.plugins.register(myplugin);
+ Chart.plugins.notify('trigger', [{ count: 10 }]);
+ expect(myplugin.count).toBe(10);
+ });
- Chart.plugins.notify('trigger', [{ count: 10 }]);
+ it('should return TRUE if no plugin explicitly returns FALSE', function() {
+ Chart.plugins.register({ check: function() {} });
+ Chart.plugins.register({ check: function() { return; } });
+ Chart.plugins.register({ check: function() { return null; } });
+ Chart.plugins.register({ check: function() { return 42 } });
+ var res = Chart.plugins.notify('check');
+ expect(res).toBeTruthy();
+ });
- expect(myplugin.count).toBe(10);
+ it('should return FALSE if no plugin explicitly returns FALSE', function() {
+ Chart.plugins.register({ check: function() {} });
+ Chart.plugins.register({ check: function() { return; } });
+ Chart.plugins.register({ check: function() { return false; } });
+ Chart.plugins.register({ check: function() { return 42 } });
+ var res = Chart.plugins.notify('check');
+ expect(res).toBeFalsy();
+ });
});
}); | true |
Other | chartjs | Chart.js | fbecfa2baf81cd009896ebbca4a225d95dd83084.json | Reduce duplicated code in core scale draw method | src/core/core.scale.js | @@ -490,9 +490,8 @@ module.exports = function(Chart) {
var isRotated = me.labelRotation !== 0;
var skipRatio;
- var scaleLabelX;
- var scaleLabelY;
var useAutoskipper = optionTicks.autoSkip;
+ var isHorizontal = me.isHorizontal();
// figure out the maximum number of gridlines to show
var maxTicks;
@@ -522,9 +521,9 @@ module.exports = function(Chart) {
// Make sure we draw text in the correct color and font
context.fillStyle = tickFontColor;
- if (me.isHorizontal()) {
- var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
- var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
+ var itemsToDraw = [];
+
+ if (isHorizontal) {
skipRatio = false;
// Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
@@ -551,177 +550,178 @@ module.exports = function(Chart) {
if (!useAutoskipper) {
skipRatio = false;
}
+ }
- helpers.each(me.ticks, function (label, index) {
- // Blank optionTicks
- var isLastTick = me.ticks.length === index + 1;
-
- // Since we always show the last tick,we need may need to hide the last shown one before
- var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
- if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
- return;
- }
- var xLineValue = me.getPixelForTick(index); // xvalues for grid lines
- var xLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
-
- if (gridLines.display) {
- if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
- // Draw the first index specially
- context.lineWidth = gridLines.zeroLineWidth;
- context.strokeStyle = gridLines.zeroLineColor;
- } else {
- context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
- context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, index);
- }
-
- xLineValue += helpers.aliasPixel(context.lineWidth);
-
- // Draw the label area
- context.beginPath();
- if (gridLines.drawTicks) {
- context.moveTo(xLineValue, yTickStart);
- context.lineTo(xLineValue, yTickEnd);
- }
+ var xTickStart = options.position === "right" ? me.left : me.right - tl;
+ var xTickEnd = options.position === "right" ? me.left + tl : me.right;
+ var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
+ var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
- // Draw the chart area
- if (gridLines.drawOnChartArea) {
- context.moveTo(xLineValue, chartArea.top);
- context.lineTo(xLineValue, chartArea.bottom);
- }
-
- // Need to stroke in the loop because we are potentially changing line widths & colours
- context.stroke();
- }
-
- if (optionTicks.display) {
- context.save();
- context.translate(xLabelValue + optionTicks.labelOffset, (isRotated) ? me.top + 12 : options.position === "top" ? me.bottom - tl : me.top + tl);
- context.rotate(labelRotationRadians * -1);
- context.font = tickLabelFont;
- context.textAlign = (isRotated) ? "right" : "center";
- context.textBaseline = (isRotated) ? "middle" : options.position === "top" ? "bottom" : "top";
-
- if (helpers.isArray(label)) {
- for (var i = 0, y = 0; i < label.length; ++i) {
- // We just make sure the multiline element is a string here..
- context.fillText('' + label[i], 0, y);
- // apply same lineSpacing as calculated @ L#320
- y += (tickFontSize * 1.5);
- }
- } else {
- context.fillText(label, 0, 0);
- }
-
- context.restore();
- }
- }, me);
+ helpers.each(me.ticks, function(label, index) {
+ // If the callback returned a null or undefined value, do not draw this line
+ if (label === undefined || label === null) {
+ return;
+ }
- if (scaleLabel.display) {
- // Draw the scale label
- context.textAlign = "center";
- context.textBaseline = 'middle';
- context.fillStyle = scaleLabelFontColor; // render in correct colour
- context.font = scaleLabelFont;
+ var isLastTick = me.ticks.length === index + 1;
- scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
- scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
+ // Since we always show the last tick,we need may need to hide the last shown one before
+ var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
+ if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
+ return;
+ }
- context.fillText(scaleLabel.labelString, scaleLabelX, scaleLabelY);
+ var lineWidth, lineColor;
+ if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
+ // Draw the first index specially
+ lineWidth = gridLines.zeroLineWidth;
+ lineColor = gridLines.zeroLineColor;
+ } else {
+ lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
+ lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
}
- } else {
- var xTickStart = options.position === "right" ? me.left : me.right - 5;
- var xTickEnd = options.position === "right" ? me.left + 5 : me.right;
+ // Common properties
+ var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
+ var textAlign, textBaseline = 'middle';
- helpers.each(me.ticks, function (label, index) {
- // If the callback returned a null or undefined value, do not draw this line
- if (label === undefined || label === null) {
- return;
+ if (isHorizontal) {
+ if (!isRotated) {
+ textBaseline = options.position === 'top' ? 'bottom' : 'top';
}
- var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
+ textAlign = isRotated ? 'right' : 'center';
+
+ var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
+ labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
+ labelY = (isRotated) ? me.top + 12 : options.position === 'top' ? me.bottom - tl : me.top + tl;
- if (gridLines.display) {
- if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
- // Draw the first index specially
- context.lineWidth = gridLines.zeroLineWidth;
- context.strokeStyle = gridLines.zeroLineColor;
+ tx1 = tx2 = x1 = x2 = xLineValue;
+ ty1 = yTickStart;
+ ty2 = yTickEnd;
+ y1 = chartArea.top;
+ y2 = chartArea.bottom;
+ } else {
+ if (options.position === 'left') {
+ if (optionTicks.mirror) {
+ labelX = me.right + optionTicks.padding;
+ textAlign = 'left';
} else {
- context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
- context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, index);
+ labelX = me.right - optionTicks.padding;
+ textAlign = 'right';
}
-
- yLineValue += helpers.aliasPixel(context.lineWidth);
-
- // Draw the label area
- context.beginPath();
-
- if (gridLines.drawTicks) {
- context.moveTo(xTickStart, yLineValue);
- context.lineTo(xTickEnd, yLineValue);
+ } else {
+ // right side
+ if (optionTicks.mirror) {
+ labelX = me.left - optionTicks.padding;
+ textAlign = 'right';
+ } else {
+ labelX = me.left + optionTicks.padding;
+ textAlign = 'left';
}
+ }
- // Draw the chart area
- if (gridLines.drawOnChartArea) {
- context.moveTo(chartArea.left, yLineValue);
- context.lineTo(chartArea.right, yLineValue);
- }
+ var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
+ yLineValue += helpers.aliasPixel(lineWidth);
+ labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
+
+ tx1 = xTickStart;
+ tx2 = xTickEnd;
+ x1 = chartArea.left;
+ x2 = chartArea.right;
+ ty1 = ty2 = y1 = y2 = yLineValue;
+ }
- // Need to stroke in the loop because we are potentially changing line widths & colours
- context.stroke();
+ itemsToDraw.push({
+ tx1: tx1,
+ ty1: ty1,
+ tx2: tx2,
+ ty2: ty2,
+ x1: x1,
+ y1: y1,
+ x2: x2,
+ y2: y2,
+ labelX: labelX,
+ labelY: labelY,
+ glWidth: lineWidth,
+ glColor: lineColor,
+ rotation: -1 * labelRotationRadians,
+ label: label,
+ textBaseline: textBaseline,
+ textAlign: textAlign
+ });
+ });
+
+ // Draw all of the tick labels, tick marks, and grid lines at the correct places
+ helpers.each(itemsToDraw, function(itemToDraw) {
+ if (gridLines.display) {
+ context.lineWidth = itemToDraw.glWidth;
+ context.strokeStyle = itemToDraw.glColor;
+
+ context.beginPath();
+
+ if (gridLines.drawTicks) {
+ context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
+ context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
}
- if (optionTicks.display) {
- var xLabelValue;
- var yLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
+ if (gridLines.drawOnChartArea) {
+ context.moveTo(itemToDraw.x1, itemToDraw.y1);
+ context.lineTo(itemToDraw.x2, itemToDraw.y2);
+ }
- context.save();
+ context.stroke();
+ }
- if (options.position === "left") {
- if (optionTicks.mirror) {
- xLabelValue = me.right + optionTicks.padding;
- context.textAlign = "left";
- } else {
- xLabelValue = me.right - optionTicks.padding;
- context.textAlign = "right";
- }
- } else {
- // right side
- if (optionTicks.mirror) {
- xLabelValue = me.left - optionTicks.padding;
- context.textAlign = "right";
- } else {
- xLabelValue = me.left + optionTicks.padding;
- context.textAlign = "left";
- }
+ if (optionTicks.display) {
+ context.save();
+ context.translate(itemToDraw.labelX, itemToDraw.labelY);
+ context.rotate(itemToDraw.rotation);
+ context.font = tickLabelFont;
+ context.textBaseline = itemToDraw.textBaseline;
+ context.textAlign = itemToDraw.textAlign;
+
+ var label = itemToDraw.label;
+ if (helpers.isArray(label)) {
+ for (var i = 0, y = 0; i < label.length; ++i) {
+ // We just make sure the multiline element is a string here..
+ context.fillText('' + label[i], 0, y);
+ // apply same lineSpacing as calculated @ L#320
+ y += (tickFontSize * 1.5);
}
-
- context.translate(xLabelValue, yLabelValue + optionTicks.labelOffset);
- context.rotate(labelRotationRadians * -1);
- context.font = tickLabelFont;
- context.textBaseline = "middle";
+ } else {
context.fillText(label, 0, 0);
- context.restore();
}
- }, me);
+ context.restore();
+ }
+ });
- if (scaleLabel.display) {
- // Draw the scale label
- scaleLabelX = options.position === 'left' ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
- scaleLabelY = me.top + ((me.bottom - me.top) / 2);
- var rotation = options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
+ if (scaleLabel.display) {
+ // Draw the scale label
+ var scaleLabelX;
+ var scaleLabelY;
+ var rotation = 0;
- context.save();
- context.translate(scaleLabelX, scaleLabelY);
- context.rotate(rotation);
- context.textAlign = "center";
- context.fillStyle = scaleLabelFontColor; // render in correct colour
- context.font = scaleLabelFont;
- context.textBaseline = 'middle';
- context.fillText(scaleLabel.labelString, 0, 0);
- context.restore();
+ if (isHorizontal) {
+ scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
+ scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
+ } else {
+ var isLeft = options.position === 'left';
+ scaleLabelX = isLeft ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
+ scaleLabelY = me.top + ((me.bottom - me.top) / 2);
+ rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
}
+
+ context.save();
+ context.translate(scaleLabelX, scaleLabelY);
+ context.rotate(rotation);
+ context.textAlign = 'center';
+ context.textBaseline = 'middle';
+ context.fillStyle = scaleLabelFontColor; // render in correct colour
+ context.font = scaleLabelFont;
+ context.fillText(scaleLabel.labelString, 0, 0);
+ context.restore();
}
if (gridLines.drawBorder) {
@@ -734,7 +734,7 @@ module.exports = function(Chart) {
y2 = me.bottom;
var aliasPixel = helpers.aliasPixel(context.lineWidth);
- if (me.isHorizontal()) {
+ if (isHorizontal) {
y1 = y2 = options.position === 'top' ? me.bottom : me.top;
y1 += aliasPixel;
y2 += aliasPixel; | false |
Other | chartjs | Chart.js | f71f525caf852ad46ae6fc875e879cc10804b051.json | fix typo in tooltip conf doc. | docs/01-Chart-Configuration.md | @@ -189,7 +189,7 @@ var chartInstance = new Chart(ctx, {
### Tooltip Configuration
-The title configuration is passed into the `options.tooltips` namespace. The global options for the chart tooltips is defined in `Chart.defaults.global.title`.
+The title configuration is passed into the `options.tooltips` namespace. The global options for the chart tooltips is defined in `Chart.defaults.global.tooltips`.
Name | Type | Default | Description
--- | --- | --- | --- | false |
Other | chartjs | Chart.js | 5c56f5cd9d437c13d5f158e1ae7a0bdfbbb8ef72.json | Use bundle-collapser to reduce build size
This browserify plugin converts required string paths to int (see https://github.com/substack/bundle-collapser), lowering our *.min.js by ~1.8KB. | gulpfile.js | @@ -18,7 +18,8 @@ var gulp = require('gulp'),
browserify = require('browserify'),
streamify = require('gulp-streamify'),
source = require('vinyl-source-stream'),
- merge = require('merge-stream');
+ merge = require('merge-stream'),
+ collapse = require('bundle-collapser/plugin');
var srcDir = './src/';
var outDir = './dist/';
@@ -70,6 +71,7 @@ gulp.task('default', ['build', 'watch']);
function buildTask() {
var bundled = browserify('./src/chart.js', { standalone: 'Chart' })
+ .plugin(collapse)
.bundle()
.pipe(source('Chart.bundle.js'))
.pipe(insert.prepend(header))
@@ -83,6 +85,7 @@ function buildTask() {
var nonBundled = browserify('./src/chart.js', { standalone: 'Chart' })
.ignore('moment')
+ .plugin(collapse)
.bundle()
.pipe(source('Chart.js'))
.pipe(insert.prepend(header))
@@ -125,10 +128,10 @@ function bumpTask(complete) {
// Write these to their own files, then build the output
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
-
+
var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js';
-
+
gulp.src(['./README.md'])
.pipe(replace(oldCDN, newCDN))
.pipe(gulp.dest('./')); | true |
Other | chartjs | Chart.js | 5c56f5cd9d437c13d5f158e1ae7a0bdfbbb8ef72.json | Use bundle-collapser to reduce build size
This browserify plugin converts required string paths to int (see https://github.com/substack/bundle-collapser), lowering our *.min.js by ~1.8KB. | package.json | @@ -12,6 +12,7 @@
"devDependencies": {
"browserify": "^13.0.0",
"browserify-istanbul": "^0.2.1",
+ "bundle-collapser": "^1.2.1",
"coveralls": "^2.11.6",
"gulp": "3.9.x",
"gulp-concat": "~2.1.x",
@@ -50,4 +51,4 @@
"chartjs-color": "^2.0.0",
"moment": "^2.10.6"
}
-}
\ No newline at end of file
+} | true |
Other | chartjs | Chart.js | 148c66fe957e1211d65f975b72945a66118a514e.json | Update this -> me with master | src/core/core.controller.js | @@ -83,7 +83,7 @@ module.exports = function(Chart) {
var newWidth = helpers.getMaximumWidth(canvas);
var aspectRatio = chart.aspectRatio;
var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
-
+
var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
if (!sizeChanged) { | false |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | docs/01-Chart-Configuration.md | @@ -72,6 +72,7 @@ maintainAspectRatio | Boolean | true | Maintain the original canvas aspect ratio
events | Array[String] | `["mousemove", "mouseout", "click", "touchstart", "touchmove", "touchend"]` | Events that the chart should listen to for tooltips and hovering
onClick | Function | null | Called if the event is of type 'mouseup' or 'click'. Called in the context of the chart and passed an array of active elements
legendCallback | Function | ` function (chart) { }` | Function to generate a legend. Receives the chart object to generate a legend from. Default implementation returns an HTML string.
+onResize | Function | null | Called when a resize occurs. Gets passed two arguemnts: the chart instance and the new size.
### Title Configuration
| true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | docs/09-Advanced.md | @@ -381,6 +381,9 @@ Plugins will be called at the following times
* End of update (before render occurs)
* Start of draw
* End of draw
+* Before datasets draw
+* After datasets draw
+* Resize
* Before an animation is started
Plugins should derive from Chart.PluginBase and implement the following interface
@@ -389,6 +392,8 @@ Plugins should derive from Chart.PluginBase and implement the following interfac
beforeInit: function(chartInstance) { },
afterInit: function(chartInstance) { },
+ resize: function(chartInstance, newChartSize) { },
+
beforeUpdate: function(chartInstance) { },
afterScaleUpdate: function(chartInstance) { }
afterUpdate: function(chartInstance) { }, | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/controllers/controller.bar.js | @@ -41,50 +41,53 @@ module.exports = function(Chart) {
// Get the number of datasets that display bars. We use this to correctly calculate the bar width
getBarCount: function getBarCount() {
+ var me = this;
var barCount = 0;
- helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
- var meta = this.chart.getDatasetMeta(datasetIndex);
- if (meta.bar && this.chart.isDatasetVisible(datasetIndex)) {
+ helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
+ var meta = me.chart.getDatasetMeta(datasetIndex);
+ if (meta.bar && me.chart.isDatasetVisible(datasetIndex)) {
++barCount;
}
- }, this);
+ }, me);
return barCount;
},
update: function update(reset) {
- helpers.each(this.getMeta().data, function(rectangle, index) {
- this.updateElement(rectangle, index, reset);
- }, this);
+ var me = this;
+ helpers.each(me.getMeta().data, function(rectangle, index) {
+ me.updateElement(rectangle, index, reset);
+ }, me);
},
updateElement: function updateElement(rectangle, index, reset) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
- var yScale = this.getScaleForId(meta.yAxisID);
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
+ var yScale = me.getScaleForId(meta.yAxisID);
var scaleBase = yScale.getBasePixel();
- var rectangleElementOptions = this.chart.options.elements.rectangle;
+ var rectangleElementOptions = me.chart.options.elements.rectangle;
var custom = rectangle.custom || {};
- var dataset = this.getDataset();
+ var dataset = me.getDataset();
helpers.extend(rectangle, {
// Utility
_xScale: xScale,
_yScale: yScale,
- _datasetIndex: this.index,
+ _datasetIndex: me.index,
_index: index,
// Desired view properties
_model: {
- x: this.calculateBarX(index, this.index),
- y: reset ? scaleBase : this.calculateBarY(index, this.index),
+ x: me.calculateBarX(index, me.index),
+ y: reset ? scaleBase : me.calculateBarY(index, me.index),
// Tooltip
- label: this.chart.data.labels[index],
+ label: me.chart.data.labels[index],
datasetLabel: dataset.label,
// Appearance
- base: reset ? scaleBase : this.calculateBarBase(this.index, index),
- width: this.calculateBarWidth(index),
+ base: reset ? scaleBase : me.calculateBarBase(me.index, index),
+ width: me.calculateBarWidth(index),
backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
@@ -95,12 +98,13 @@ module.exports = function(Chart) {
},
calculateBarBase: function(datasetIndex, index) {
- var meta = this.getMeta();
- var yScale = this.getScaleForId(meta.yAxisID);
+ var me = this;
+ var meta = me.getMeta();
+ var yScale = me.getScaleForId(meta.yAxisID);
var base = 0;
if (yScale.options.stacked) {
- var chart = this.chart;
+ var chart = me.chart;
var datasets = chart.data.datasets;
var value = datasets[datasetIndex].data[index];
@@ -129,9 +133,10 @@ module.exports = function(Chart) {
},
getRuler: function(index) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
- var datasetCount = this.getBarCount();
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
+ var datasetCount = me.getBarCount();
var tickWidth;
@@ -145,8 +150,8 @@ module.exports = function(Chart) {
var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
var fullBarWidth = categoryWidth / datasetCount;
- if (xScale.ticks.length !== this.chart.data.labels.length) {
- var perc = xScale.ticks.length / this.chart.data.labels.length;
+ if (xScale.ticks.length !== me.chart.data.labels.length) {
+ var perc = xScale.ticks.length / me.chart.data.labels.length;
fullBarWidth = fullBarWidth * perc;
}
@@ -186,13 +191,14 @@ module.exports = function(Chart) {
},
calculateBarX: function(index, datasetIndex) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
- var barIndex = this.getBarIndex(datasetIndex);
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
+ var barIndex = me.getBarIndex(datasetIndex);
- var ruler = this.getRuler(index);
- var leftTick = xScale.getPixelForValue(null, index, datasetIndex, this.chart.isCombo);
- leftTick -= this.chart.isCombo ? (ruler.tickWidth / 2) : 0;
+ var ruler = me.getRuler(index);
+ var leftTick = xScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
+ leftTick -= me.chart.isCombo ? (ruler.tickWidth / 2) : 0;
if (xScale.options.stacked) {
return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
@@ -207,19 +213,20 @@ module.exports = function(Chart) {
},
calculateBarY: function(index, datasetIndex) {
- var meta = this.getMeta();
- var yScale = this.getScaleForId(meta.yAxisID);
- var value = this.getDataset().data[index];
+ var me = this;
+ var meta = me.getMeta();
+ var yScale = me.getScaleForId(meta.yAxisID);
+ var value = me.getDataset().data[index];
if (yScale.options.stacked) {
var sumPos = 0,
sumNeg = 0;
for (var i = 0; i < datasetIndex; i++) {
- var ds = this.chart.data.datasets[i];
- var dsMeta = this.chart.getDatasetMeta(i);
- if (dsMeta.bar && dsMeta.yAxisID === yScale.id && this.chart.isDatasetVisible(i)) {
+ var ds = me.chart.data.datasets[i];
+ var dsMeta = me.chart.getDatasetMeta(i);
+ if (dsMeta.bar && dsMeta.yAxisID === yScale.id && me.chart.isDatasetVisible(i)) {
if (ds.data[index] < 0) {
sumNeg += ds.data[index] || 0;
} else {
@@ -239,13 +246,14 @@ module.exports = function(Chart) {
},
draw: function(ease) {
+ var me = this;
var easingDecimal = ease || 1;
- helpers.each(this.getMeta().data, function(rectangle, index) {
- var d = this.getDataset().data[index];
+ helpers.each(me.getMeta().data, function(rectangle, index) {
+ var d = me.getDataset().data[index];
if (d !== null && d !== undefined && !isNaN(d)) {
rectangle.transition(easingDecimal).draw();
}
- }, this);
+ }, me);
},
setHoverStyle: function(rectangle) {
@@ -331,41 +339,41 @@ module.exports = function(Chart) {
Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
updateElement: function updateElement(rectangle, index, reset, numBars) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
- var yScale = this.getScaleForId(meta.yAxisID);
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
+ var yScale = me.getScaleForId(meta.yAxisID);
var scaleBase = xScale.getBasePixel();
var custom = rectangle.custom || {};
- var dataset = this.getDataset();
- var rectangleElementOptions = this.chart.options.elements.rectangle;
+ var dataset = me.getDataset();
+ var rectangleElementOptions = me.chart.options.elements.rectangle;
helpers.extend(rectangle, {
// Utility
_xScale: xScale,
_yScale: yScale,
- _datasetIndex: this.index,
+ _datasetIndex: me.index,
_index: index,
// Desired view properties
_model: {
- x: reset ? scaleBase : this.calculateBarX(index, this.index),
- y: this.calculateBarY(index, this.index),
+ x: reset ? scaleBase : me.calculateBarX(index, me.index),
+ y: me.calculateBarY(index, me.index),
// Tooltip
- label: this.chart.data.labels[index],
+ label: me.chart.data.labels[index],
datasetLabel: dataset.label,
// Appearance
- base: reset ? scaleBase : this.calculateBarBase(this.index, index),
- height: this.calculateBarHeight(index),
+ base: reset ? scaleBase : me.calculateBarBase(me.index, index),
+ height: me.calculateBarHeight(index),
backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
},
draw: function () {
-
var ctx = this._chart.ctx;
var vm = this._view;
@@ -440,27 +448,28 @@ module.exports = function(Chart) {
},
calculateBarBase: function (datasetIndex, index) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
var base = 0;
if (xScale.options.stacked) {
- var value = this.chart.data.datasets[datasetIndex].data[index];
+ var value = me.chart.data.datasets[datasetIndex].data[index];
if (value < 0) {
for (var i = 0; i < datasetIndex; i++) {
- var negDS = this.chart.data.datasets[i];
- var negDSMeta = this.chart.getDatasetMeta(i);
- if (negDSMeta.bar && negDSMeta.xAxisID === xScale.id && this.chart.isDatasetVisible(i)) {
+ var negDS = me.chart.data.datasets[i];
+ var negDSMeta = me.chart.getDatasetMeta(i);
+ if (negDSMeta.bar && negDSMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i)) {
base += negDS.data[index] < 0 ? negDS.data[index] : 0;
}
}
} else {
for (var j = 0; j < datasetIndex; j++) {
- var posDS = this.chart.data.datasets[j];
- var posDSMeta = this.chart.getDatasetMeta(j);
- if (posDSMeta.bar && posDSMeta.xAxisID === xScale.id && this.chart.isDatasetVisible(j)) {
+ var posDS = me.chart.data.datasets[j];
+ var posDSMeta = me.chart.getDatasetMeta(j);
+ if (posDSMeta.bar && posDSMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(j)) {
base += posDS.data[index] > 0 ? posDS.data[index] : 0;
}
}
@@ -473,9 +482,10 @@ module.exports = function(Chart) {
},
getRuler: function (index) {
- var meta = this.getMeta();
- var yScale = this.getScaleForId(meta.yAxisID);
- var datasetCount = this.getBarCount();
+ var me = this;
+ var meta = me.getMeta();
+ var yScale = me.getScaleForId(meta.yAxisID);
+ var datasetCount = me.getBarCount();
var tickHeight;
if (yScale.options.type === 'category') {
@@ -488,8 +498,8 @@ module.exports = function(Chart) {
var categorySpacing = (tickHeight - (tickHeight * yScale.options.categoryPercentage)) / 2;
var fullBarHeight = categoryHeight / datasetCount;
- if (yScale.ticks.length !== this.chart.data.labels.length) {
- var perc = yScale.ticks.length / this.chart.data.labels.length;
+ if (yScale.ticks.length !== me.chart.data.labels.length) {
+ var perc = yScale.ticks.length / me.chart.data.labels.length;
fullBarHeight = fullBarHeight * perc;
}
@@ -508,25 +518,27 @@ module.exports = function(Chart) {
},
calculateBarHeight: function (index) {
- var yScale = this.getScaleForId(this.getMeta().yAxisID);
- var ruler = this.getRuler(index);
+ var me = this;
+ var yScale = me.getScaleForId(me.getMeta().yAxisID);
+ var ruler = me.getRuler(index);
return yScale.options.stacked ? ruler.categoryHeight : ruler.barHeight;
},
calculateBarX: function (index, datasetIndex) {
- var meta = this.getMeta();
- var xScale = this.getScaleForId(meta.xAxisID);
- var value = this.getDataset().data[index];
+ var me = this;
+ var meta = me.getMeta();
+ var xScale = me.getScaleForId(meta.xAxisID);
+ var value = me.getDataset().data[index];
if (xScale.options.stacked) {
var sumPos = 0,
sumNeg = 0;
for (var i = 0; i < datasetIndex; i++) {
- var ds = this.chart.data.datasets[i];
- var dsMeta = this.chart.getDatasetMeta(i);
- if (dsMeta.bar && dsMeta.xAxisID === xScale.id && this.chart.isDatasetVisible(i)) {
+ var ds = me.chart.data.datasets[i];
+ var dsMeta = me.chart.getDatasetMeta(i);
+ if (dsMeta.bar && dsMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i)) {
if (ds.data[index] < 0) {
sumNeg += ds.data[index] || 0;
} else {
@@ -546,13 +558,14 @@ module.exports = function(Chart) {
},
calculateBarY: function (index, datasetIndex) {
- var meta = this.getMeta();
- var yScale = this.getScaleForId(meta.yAxisID);
- var barIndex = this.getBarIndex(datasetIndex);
-
- var ruler = this.getRuler(index);
- var topTick = yScale.getPixelForValue(null, index, datasetIndex, this.chart.isCombo);
- topTick -= this.chart.isCombo ? (ruler.tickHeight / 2) : 0;
+ var me = this;
+ var meta = me.getMeta();
+ var yScale = me.getScaleForId(meta.yAxisID);
+ var barIndex = me.getBarIndex(datasetIndex);
+
+ var ruler = me.getRuler(index);
+ var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
+ topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
if (yScale.options.stacked) {
return topTick + (ruler.categoryHeight / 2) + ruler.categorySpacing; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/controllers/controller.doughnut.js | @@ -132,8 +132,8 @@ module.exports = function(Chart) {
},
update: function update(reset) {
- var _this = this;
- var chart = _this.chart,
+ var me = this;
+ var chart = me.chart,
chartArea = chart.chartArea,
opts = chart.options,
arcOpts = opts.elements.arc,
@@ -144,7 +144,7 @@ module.exports = function(Chart) {
x: 0,
y: 0
},
- meta = _this.getMeta(),
+ meta = me.getMeta(),
cutoutPercentage = opts.cutoutPercentage,
circumference = opts.circumference;
@@ -173,19 +173,19 @@ module.exports = function(Chart) {
chart.offsetX = offset.x * chart.outerRadius;
chart.offsetY = offset.y * chart.outerRadius;
- meta.total = _this.calculateTotal();
+ meta.total = me.calculateTotal();
- _this.outerRadius = chart.outerRadius - (chart.radiusLength * _this.getRingIndex(_this.index));
- _this.innerRadius = _this.outerRadius - chart.radiusLength;
+ me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
+ me.innerRadius = me.outerRadius - chart.radiusLength;
helpers.each(meta.data, function(arc, index) {
- _this.updateElement(arc, index, reset);
+ me.updateElement(arc, index, reset);
});
},
updateElement: function(arc, index, reset) {
- var _this = this;
- var chart = _this.chart,
+ var me = this;
+ var chart = me.chart,
chartArea = chart.chartArea,
opts = chart.options,
animationOpts = opts.animation,
@@ -194,16 +194,16 @@ module.exports = function(Chart) {
centerY = (chartArea.top + chartArea.bottom) / 2,
startAngle = opts.rotation, // non reset case handled later
endAngle = opts.rotation, // non reset case handled later
- dataset = _this.getDataset(),
- circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : _this.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI)),
- innerRadius = reset && animationOpts.animateScale ? 0 : _this.innerRadius,
- outerRadius = reset && animationOpts.animateScale ? 0 : _this.outerRadius,
+ dataset = me.getDataset(),
+ circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI)),
+ innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius,
+ outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius,
custom = arc.custom || {},
valueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
helpers.extend(arc, {
// Utility
- _datasetIndex: _this.index,
+ _datasetIndex: me.index,
_index: index,
// Desired view properties
@@ -228,7 +228,7 @@ module.exports = function(Chart) {
if (index === 0) {
model.startAngle = opts.rotation;
} else {
- model.startAngle = _this.getMeta().data[index - 1]._model.endAngle;
+ model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
}
model.endAngle = model.startAngle + model.circumference; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/controllers/controller.line.js | @@ -260,7 +260,7 @@ module.exports = function(Chart) {
draw: function(ease) {
var me = this;
- var meta = this.getMeta();
+ var meta = me.getMeta();
var points = meta.data || [];
var easingDecimal = ease || 1;
var i, ilen; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/controllers/controller.polarArea.js | @@ -106,32 +106,32 @@ module.exports = function(Chart) {
linkScales: helpers.noop,
update: function update(reset) {
- var _this = this;
- var chart = _this.chart;
+ var me = this;
+ var chart = me.chart;
var chartArea = chart.chartArea;
- var meta = _this.getMeta();
+ var meta = me.getMeta();
var opts = chart.options;
var arcOpts = opts.elements.arc;
var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
- _this.outerRadius = chart.outerRadius - (chart.radiusLength * _this.index);
- _this.innerRadius = _this.outerRadius - chart.radiusLength;
+ me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
+ me.innerRadius = me.outerRadius - chart.radiusLength;
- meta.count = _this.countVisibleElements();
+ meta.count = me.countVisibleElements();
helpers.each(meta.data, function(arc, index) {
- _this.updateElement(arc, index, reset);
+ me.updateElement(arc, index, reset);
});
},
updateElement: function(arc, index, reset) {
- var _this = this;
- var chart = _this.chart;
+ var me = this;
+ var chart = me.chart;
var chartArea = chart.chartArea;
- var dataset = _this.getDataset();
+ var dataset = me.getDataset();
var opts = chart.options;
var animationOpts = opts.animation;
var arcOpts = opts.elements.arc;
@@ -140,14 +140,14 @@ module.exports = function(Chart) {
var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
var labels = chart.data.labels;
- var circumference = _this.calculateCircumference(dataset.data[index]);
+ var circumference = me.calculateCircumference(dataset.data[index]);
var centerX = (chartArea.left + chartArea.right) / 2;
var centerY = (chartArea.top + chartArea.bottom) / 2;
// If there is NaN data before us, we need to calculate the starting angle correctly.
// We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
var visibleCount = 0;
- var meta = _this.getMeta();
+ var meta = me.getMeta();
for (var i = 0; i < index; ++i) {
if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
++visibleCount;
@@ -163,7 +163,7 @@ module.exports = function(Chart) {
helpers.extend(arc, {
// Utility
- _datasetIndex: _this.index,
+ _datasetIndex: me.index,
_index: index,
_scale: scale,
@@ -180,7 +180,7 @@ module.exports = function(Chart) {
});
// Apply border and fill style
- _this.removeHoverStyle(arc);
+ me.removeHoverStyle(arc);
arc.pivot();
}, | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/controllers/controller.radar.js | @@ -31,13 +31,14 @@ module.exports = function(Chart) {
},
update: function update(reset) {
- var meta = this.getMeta();
+ var me = this;
+ var meta = me.getMeta();
var line = meta.dataset;
var points = meta.data;
var custom = line.custom || {};
- var dataset = this.getDataset();
- var lineElementOptions = this.chart.options.elements.line;
- var scale = this.chart.scale;
+ var dataset = me.getDataset();
+ var lineElementOptions = me.chart.options.elements.line;
+ var scale = me.chart.scale;
// Compatibility: If the properties are defined with only the old name, use those values
if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
@@ -46,7 +47,7 @@ module.exports = function(Chart) {
helpers.extend(meta.dataset, {
// Utility
- _datasetIndex: this.index,
+ _datasetIndex: me.index,
// Data
_children: points,
_loop: true,
@@ -74,23 +75,24 @@ module.exports = function(Chart) {
// Update Points
helpers.each(points, function(point, index) {
- this.updateElement(point, index, reset);
- }, this);
+ me.updateElement(point, index, reset);
+ }, me);
// Update bezier control points
- this.updateBezierControlPoints();
+ me.updateBezierControlPoints();
},
updateElement: function(point, index, reset) {
+ var me = this;
var custom = point.custom || {};
- var dataset = this.getDataset();
- var scale = this.chart.scale;
- var pointElementOptions = this.chart.options.elements.point;
+ var dataset = me.getDataset();
+ var scale = me.chart.scale;
+ var pointElementOptions = me.chart.options.elements.point;
var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
helpers.extend(point, {
// Utility
- _datasetIndex: this.index,
+ _datasetIndex: me.index,
_index: index,
_scale: scale,
@@ -100,7 +102,7 @@ module.exports = function(Chart) {
y: reset ? scale.yCenter : pointPosition.y,
// Appearance
- tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.tension, this.chart.options.elements.line.tension),
+ tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.tension, me.chart.options.elements.line.tension),
radius: custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
@@ -136,7 +138,7 @@ module.exports = function(Chart) {
// Now pivot the point for animation
point.pivot();
- }, this);
+ });
},
draw: function(ease) { | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.animation.js | @@ -28,27 +28,28 @@ module.exports = function(Chart) {
dropFrames: 0,
request: null,
addAnimation: function(chartInstance, animationObject, duration, lazy) {
+ var me = this;
if (!lazy) {
chartInstance.animating = true;
}
- for (var index = 0; index < this.animations.length; ++index) {
- if (this.animations[index].chartInstance === chartInstance) {
+ for (var index = 0; index < me.animations.length; ++index) {
+ if (me.animations[index].chartInstance === chartInstance) {
// replacing an in progress animation
- this.animations[index].animationObject = animationObject;
+ me.animations[index].animationObject = animationObject;
return;
}
}
- this.animations.push({
+ me.animations.push({
chartInstance: chartInstance,
animationObject: animationObject
});
// If there are no animations queued, manually kickstart a digest, for lack of a better word
- if (this.animations.length === 1) {
- this.requestAnimationFrame();
+ if (me.animations.length === 1) {
+ me.requestAnimationFrame();
}
},
// Cancel the animation for a given chart instance
@@ -75,54 +76,55 @@ module.exports = function(Chart) {
}
},
startDigest: function() {
+ var me = this;
var startTime = Date.now();
var framesToDrop = 0;
- if (this.dropFrames > 1) {
- framesToDrop = Math.floor(this.dropFrames);
- this.dropFrames = this.dropFrames % 1;
+ if (me.dropFrames > 1) {
+ framesToDrop = Math.floor(me.dropFrames);
+ me.dropFrames = me.dropFrames % 1;
}
var i = 0;
- while (i < this.animations.length) {
- if (this.animations[i].animationObject.currentStep === null) {
- this.animations[i].animationObject.currentStep = 0;
+ while (i < me.animations.length) {
+ if (me.animations[i].animationObject.currentStep === null) {
+ me.animations[i].animationObject.currentStep = 0;
}
- this.animations[i].animationObject.currentStep += 1 + framesToDrop;
+ me.animations[i].animationObject.currentStep += 1 + framesToDrop;
- if (this.animations[i].animationObject.currentStep > this.animations[i].animationObject.numSteps) {
- this.animations[i].animationObject.currentStep = this.animations[i].animationObject.numSteps;
+ if (me.animations[i].animationObject.currentStep > me.animations[i].animationObject.numSteps) {
+ me.animations[i].animationObject.currentStep = me.animations[i].animationObject.numSteps;
}
- this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
- if (this.animations[i].animationObject.onAnimationProgress && this.animations[i].animationObject.onAnimationProgress.call) {
- this.animations[i].animationObject.onAnimationProgress.call(this.animations[i].chartInstance, this.animations[i]);
+ me.animations[i].animationObject.render(me.animations[i].chartInstance, me.animations[i].animationObject);
+ if (me.animations[i].animationObject.onAnimationProgress && me.animations[i].animationObject.onAnimationProgress.call) {
+ me.animations[i].animationObject.onAnimationProgress.call(me.animations[i].chartInstance, me.animations[i]);
}
- if (this.animations[i].animationObject.currentStep === this.animations[i].animationObject.numSteps) {
- if (this.animations[i].animationObject.onAnimationComplete && this.animations[i].animationObject.onAnimationComplete.call) {
- this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance, this.animations[i]);
+ if (me.animations[i].animationObject.currentStep === me.animations[i].animationObject.numSteps) {
+ if (me.animations[i].animationObject.onAnimationComplete && me.animations[i].animationObject.onAnimationComplete.call) {
+ me.animations[i].animationObject.onAnimationComplete.call(me.animations[i].chartInstance, me.animations[i]);
}
// executed the last frame. Remove the animation.
- this.animations[i].chartInstance.animating = false;
+ me.animations[i].chartInstance.animating = false;
- this.animations.splice(i, 1);
+ me.animations.splice(i, 1);
} else {
++i;
}
}
var endTime = Date.now();
- var dropFrames = (endTime - startTime) / this.frameDuration;
+ var dropFrames = (endTime - startTime) / me.frameDuration;
- this.dropFrames += dropFrames;
+ me.dropFrames += dropFrames;
// Do we have more stuff to animate?
- if (this.animations.length > 0) {
- this.requestAnimationFrame();
+ if (me.animations.length > 0) {
+ me.requestAnimationFrame();
}
}
}; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.controller.js | @@ -43,25 +43,26 @@ module.exports = function(Chart) {
helpers.extend(Chart.Controller.prototype, {
initialize: function initialize() {
+ var me = this;
// Before init plugin notification
- Chart.pluginService.notifyPlugins('beforeInit', [this]);
+ Chart.pluginService.notifyPlugins('beforeInit', [me]);
- this.bindEvents();
+ me.bindEvents();
// Make sure controllers are built first so that each dataset is bound to an axis before the scales
// are built
- this.ensureScalesHaveIDs();
- this.buildOrUpdateControllers();
- this.buildScales();
- this.updateLayout();
- this.resetElements();
- this.initToolTip();
- this.update();
+ me.ensureScalesHaveIDs();
+ me.buildOrUpdateControllers();
+ me.buildScales();
+ me.updateLayout();
+ me.resetElements();
+ me.initToolTip();
+ me.update();
// After init plugin notification
- Chart.pluginService.notifyPlugins('afterInit', [this]);
+ Chart.pluginService.notifyPlugins('afterInit', [me]);
- return this;
+ return me;
},
clear: function clear() {
@@ -76,26 +77,39 @@ module.exports = function(Chart) {
},
resize: function resize(silent) {
- var canvas = this.chart.canvas;
- var newWidth = helpers.getMaximumWidth(this.chart.canvas);
- var newHeight = (this.options.maintainAspectRatio && isNaN(this.chart.aspectRatio) === false && isFinite(this.chart.aspectRatio) && this.chart.aspectRatio !== 0) ? newWidth / this.chart.aspectRatio : helpers.getMaximumHeight(this.chart.canvas);
+ var me = this;
+ var chart = me.chart;
+ var canvas = chart.canvas;
+ var newWidth = helpers.getMaximumWidth(canvas);
+ var aspectRatio = chart.aspectRatio;
+ var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
- var sizeChanged = this.chart.width !== newWidth || this.chart.height !== newHeight;
+ var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
- if (!sizeChanged)
- return this;
+ if (!sizeChanged) {
+ return me;
+ }
+
+ canvas.width = chart.width = newWidth;
+ canvas.height = chart.height = newHeight;
- canvas.width = this.chart.width = newWidth;
- canvas.height = this.chart.height = newHeight;
+ helpers.retinaScale(chart);
- helpers.retinaScale(this.chart);
+ // Notify any plugins about the resize
+ var newSize = { width: newWidth, height: newHeight };
+ Chart.pluginService.notifyPlugins('resize', [me, newSize]);
+
+ // Notify of resize
+ if (me.options.onResize) {
+ me.options.onResize(me, newSize);
+ }
if (!silent) {
- this.stop();
- this.update(this.options.responsiveAnimationDuration);
+ me.stop();
+ me.update(me.options.responsiveAnimationDuration);
}
- return this;
+ return me;
},
ensureScalesHaveIDs: function ensureScalesHaveIDs() {
@@ -170,29 +184,30 @@ module.exports = function(Chart) {
},
buildOrUpdateControllers: function buildOrUpdateControllers() {
+ var me = this;
var types = [];
var newControllers = [];
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- var meta = this.getDatasetMeta(datasetIndex);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ var meta = me.getDatasetMeta(datasetIndex);
if (!meta.type) {
- meta.type = dataset.type || this.config.type;
+ meta.type = dataset.type || me.config.type;
}
types.push(meta.type);
if (meta.controller) {
meta.controller.updateIndex(datasetIndex);
} else {
- meta.controller = new Chart.controllers[meta.type](this, datasetIndex);
+ meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
newControllers.push(meta.controller);
}
- }, this);
+ }, me);
if (types.length > 1) {
for (var i = 1; i < types.length; i++) {
if (types[i] !== types[i - 1]) {
- this.isCombo = true;
+ me.isCombo = true;
break;
}
}
@@ -202,50 +217,53 @@ module.exports = function(Chart) {
},
resetElements: function resetElements() {
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- this.getDatasetMeta(datasetIndex).controller.reset();
- }, this);
+ var me = this;
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ me.getDatasetMeta(datasetIndex).controller.reset();
+ }, me);
},
update: function update(animationDuration, lazy) {
- Chart.pluginService.notifyPlugins('beforeUpdate', [this]);
+ var me = this;
+ Chart.pluginService.notifyPlugins('beforeUpdate', [me]);
// In case the entire data object changed
- this.tooltip._data = this.data;
+ me.tooltip._data = me.data;
// Make sure dataset controllers are updated and new controllers are reset
- var newControllers = this.buildOrUpdateControllers();
+ var newControllers = me.buildOrUpdateControllers();
// Make sure all dataset controllers have correct meta data counts
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- this.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
- }, this);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
+ }, me);
- Chart.layoutService.update(this, this.chart.width, this.chart.height);
+ Chart.layoutService.update(me, me.chart.width, me.chart.height);
// Apply changes to the dataets that require the scales to have been calculated i.e BorderColor chages
- Chart.pluginService.notifyPlugins('afterScaleUpdate', [this]);
+ Chart.pluginService.notifyPlugins('afterScaleUpdate', [me]);
// Can only reset the new controllers after the scales have been updated
helpers.each(newControllers, function(controller) {
controller.reset();
});
// This will loop through any data and do the appropriate element update for the type
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- this.getDatasetMeta(datasetIndex).controller.update();
- }, this);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ me.getDatasetMeta(datasetIndex).controller.update();
+ }, me);
// Do this before render so that any plugins that need final scale updates can use it
- Chart.pluginService.notifyPlugins('afterUpdate', [this]);
+ Chart.pluginService.notifyPlugins('afterUpdate', [me]);
- this.render(animationDuration, lazy);
+ me.render(animationDuration, lazy);
},
render: function render(duration, lazy) {
- Chart.pluginService.notifyPlugins('beforeRender', [this]);
+ var me = this;
+ Chart.pluginService.notifyPlugins('beforeRender', [me]);
- var animationOptions = this.options.animation;
+ var animationOptions = me.options.animation;
if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
var animation = new Chart.Animation();
animation.numSteps = (duration || animationOptions.duration) / 16.66; //60 fps
@@ -264,77 +282,80 @@ module.exports = function(Chart) {
animation.onAnimationProgress = animationOptions.onProgress;
animation.onAnimationComplete = animationOptions.onComplete;
- Chart.animationService.addAnimation(this, animation, duration, lazy);
+ Chart.animationService.addAnimation(me, animation, duration, lazy);
} else {
- this.draw();
+ me.draw();
if (animationOptions && animationOptions.onComplete && animationOptions.onComplete.call) {
- animationOptions.onComplete.call(this);
+ animationOptions.onComplete.call(me);
}
}
- return this;
+ return me;
},
draw: function(ease) {
+ var me = this;
var easingDecimal = ease || 1;
- this.clear();
+ me.clear();
- Chart.pluginService.notifyPlugins('beforeDraw', [this, easingDecimal]);
+ Chart.pluginService.notifyPlugins('beforeDraw', [me, easingDecimal]);
// Draw all the scales
- helpers.each(this.boxes, function(box) {
- box.draw(this.chartArea);
- }, this);
- if (this.scale) {
- this.scale.draw();
+ helpers.each(me.boxes, function(box) {
+ box.draw(me.chartArea);
+ }, me);
+ if (me.scale) {
+ me.scale.draw();
}
- Chart.pluginService.notifyPlugins('beforeDatasetDraw', [this, easingDecimal]);
+ Chart.pluginService.notifyPlugins('beforeDatasetDraw', [me, easingDecimal]);
// Draw each dataset via its respective controller (reversed to support proper line stacking)
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- if (this.isDatasetVisible(datasetIndex)) {
- this.getDatasetMeta(datasetIndex).controller.draw(ease);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ if (me.isDatasetVisible(datasetIndex)) {
+ me.getDatasetMeta(datasetIndex).controller.draw(ease);
}
- }, this, true);
+ }, me, true);
- Chart.pluginService.notifyPlugins('afterDatasetDraw', [this, easingDecimal]);
+ Chart.pluginService.notifyPlugins('afterDatasetDraw', [me, easingDecimal]);
// Finally draw the tooltip
- this.tooltip.transition(easingDecimal).draw();
+ me.tooltip.transition(easingDecimal).draw();
- Chart.pluginService.notifyPlugins('afterDraw', [this, easingDecimal]);
+ Chart.pluginService.notifyPlugins('afterDraw', [me, easingDecimal]);
},
// Get the single element that was clicked on
// @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
getElementAtEvent: function(e) {
- var eventPosition = helpers.getRelativePosition(e, this.chart);
+ var me = this;
+ var eventPosition = helpers.getRelativePosition(e, me.chart);
var elementsArray = [];
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- if (this.isDatasetVisible(datasetIndex)) {
- var meta = this.getDatasetMeta(datasetIndex);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ if (me.isDatasetVisible(datasetIndex)) {
+ var meta = me.getDatasetMeta(datasetIndex);
helpers.each(meta.data, function(element, index) {
if (element.inRange(eventPosition.x, eventPosition.y)) {
elementsArray.push(element);
return elementsArray;
}
});
}
- }, this);
+ });
return elementsArray;
},
getElementsAtEvent: function(e) {
- var eventPosition = helpers.getRelativePosition(e, this.chart);
+ var me = this;
+ var eventPosition = helpers.getRelativePosition(e, me.chart);
var elementsArray = [];
var found = (function() {
- if (this.data.datasets) {
- for (var i = 0; i < this.data.datasets.length; i++) {
- var meta = this.getDatasetMeta(i);
- if (this.isDatasetVisible(i)) {
+ if (me.data.datasets) {
+ for (var i = 0; i < me.data.datasets.length; i++) {
+ var meta = me.getDatasetMeta(i);
+ if (me.isDatasetVisible(i)) {
for (var j = 0; j < meta.data.length; j++) {
if (meta.data[j].inRange(eventPosition.x, eventPosition.y)) {
return meta.data[j];
@@ -343,18 +364,18 @@ module.exports = function(Chart) {
}
}
}
- }).call(this);
+ }).call(me);
if (!found) {
return elementsArray;
}
- helpers.each(this.data.datasets, function(dataset, datasetIndex) {
- if (this.isDatasetVisible(datasetIndex)) {
- var meta = this.getDatasetMeta(datasetIndex);
+ helpers.each(me.data.datasets, function(dataset, datasetIndex) {
+ if (me.isDatasetVisible(datasetIndex)) {
+ var meta = me.getDatasetMeta(datasetIndex);
elementsArray.push(meta.data[found._index]);
}
- }, this);
+ }, me);
return elementsArray;
},
@@ -384,14 +405,15 @@ module.exports = function(Chart) {
},
getDatasetMeta: function(datasetIndex) {
- var dataset = this.data.datasets[datasetIndex];
+ var me = this;
+ var dataset = me.data.datasets[datasetIndex];
if (!dataset._meta) {
dataset._meta = {};
}
- var meta = dataset._meta[this.id];
+ var meta = dataset._meta[me.id];
if (!meta) {
- meta = dataset._meta[this.id] = {
+ meta = dataset._meta[me.id] = {
type: null,
data: [],
dataset: null,
@@ -428,46 +450,49 @@ module.exports = function(Chart) {
},
destroy: function destroy() {
- this.stop();
- this.clear();
- helpers.unbindEvents(this, this.events);
- helpers.removeResizeListener(this.chart.canvas.parentNode);
+ var me = this;
+ me.stop();
+ me.clear();
+ helpers.unbindEvents(me, me.events);
+ helpers.removeResizeListener(me.chart.canvas.parentNode);
// Reset canvas height/width attributes
- var canvas = this.chart.canvas;
- canvas.width = this.chart.width;
- canvas.height = this.chart.height;
+ var canvas = me.chart.canvas;
+ canvas.width = me.chart.width;
+ canvas.height = me.chart.height;
// if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
- if (this.chart.originalDevicePixelRatio !== undefined) {
- this.chart.ctx.scale(1 / this.chart.originalDevicePixelRatio, 1 / this.chart.originalDevicePixelRatio);
+ if (me.chart.originalDevicePixelRatio !== undefined) {
+ me.chart.ctx.scale(1 / me.chart.originalDevicePixelRatio, 1 / me.chart.originalDevicePixelRatio);
}
// Reset to the old style since it may have been changed by the device pixel ratio changes
- canvas.style.width = this.chart.originalCanvasStyleWidth;
- canvas.style.height = this.chart.originalCanvasStyleHeight;
+ canvas.style.width = me.chart.originalCanvasStyleWidth;
+ canvas.style.height = me.chart.originalCanvasStyleHeight;
- Chart.pluginService.notifyPlugins('destroy', [this]);
+ Chart.pluginService.notifyPlugins('destroy', [me]);
- delete Chart.instances[this.id];
+ delete Chart.instances[me.id];
},
toBase64Image: function toBase64Image() {
return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
},
initToolTip: function initToolTip() {
- this.tooltip = new Chart.Tooltip({
- _chart: this.chart,
- _chartInstance: this,
- _data: this.data,
- _options: this.options.tooltips
- }, this);
+ var me = this;
+ me.tooltip = new Chart.Tooltip({
+ _chart: me.chart,
+ _chartInstance: me,
+ _data: me.data,
+ _options: me.options.tooltips
+ }, me);
},
bindEvents: function bindEvents() {
- helpers.bindEvents(this, this.options.events, function(evt) {
- this.eventHandler(evt);
+ var me = this;
+ helpers.bindEvents(me, me.options.events, function(evt) {
+ me.eventHandler(evt);
});
},
| true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.datasetController.js | @@ -25,25 +25,27 @@ module.exports = function(Chart) {
dataElementType: null,
initialize: function(chart, datasetIndex) {
- this.chart = chart;
- this.index = datasetIndex;
- this.linkScales();
- this.addElements();
+ var me = this;
+ me.chart = chart;
+ me.index = datasetIndex;
+ me.linkScales();
+ me.addElements();
},
updateIndex: function(datasetIndex) {
this.index = datasetIndex;
},
linkScales: function() {
- var meta = this.getMeta();
- var dataset = this.getDataset();
+ var me = this;
+ var meta = me.getMeta();
+ var dataset = me.getDataset();
if (meta.xAxisID === null) {
- meta.xAxisID = dataset.xAxisID || this.chart.options.scales.xAxes[0].id;
+ meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
}
if (meta.yAxisID === null) {
- meta.yAxisID = dataset.yAxisID || this.chart.options.scales.yAxes[0].id;
+ meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
}
},
| true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.element.js | @@ -10,81 +10,90 @@ module.exports = function(Chart) {
helpers.extend(this, configuration);
this.initialize.apply(this, arguments);
};
+
helpers.extend(Chart.Element.prototype, {
+
initialize: function() {
this.hidden = false;
},
+
pivot: function() {
- if (!this._view) {
- this._view = helpers.clone(this._model);
+ var me = this;
+ if (!me._view) {
+ me._view = helpers.clone(me._model);
}
- this._start = helpers.clone(this._view);
- return this;
+ me._start = helpers.clone(me._view);
+ return me;
},
+
transition: function(ease) {
- if (!this._view) {
- this._view = helpers.clone(this._model);
+ var me = this;
+
+ if (!me._view) {
+ me._view = helpers.clone(me._model);
}
// No animation -> No Transition
if (ease === 1) {
- this._view = this._model;
- this._start = null;
- return this;
+ me._view = me._model;
+ me._start = null;
+ return me;
}
- if (!this._start) {
- this.pivot();
+ if (!me._start) {
+ me.pivot();
}
- helpers.each(this._model, function(value, key) {
+ helpers.each(me._model, function(value, key) {
if (key[0] === '_') {
// Only non-underscored properties
}
// Init if doesn't exist
- else if (!this._view.hasOwnProperty(key)) {
- if (typeof value === 'number' && !isNaN(this._view[key])) {
- this._view[key] = value * ease;
+ else if (!me._view.hasOwnProperty(key)) {
+ if (typeof value === 'number' && !isNaN(me._view[key])) {
+ me._view[key] = value * ease;
} else {
- this._view[key] = value;
+ me._view[key] = value;
}
}
// No unnecessary computations
- else if (value === this._view[key]) {
+ else if (value === me._view[key]) {
// It's the same! Woohoo!
}
// Color transitions if possible
else if (typeof value === 'string') {
try {
- var color = helpers.color(this._model[key]).mix(helpers.color(this._start[key]), ease);
- this._view[key] = color.rgbString();
+ var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
+ me._view[key] = color.rgbString();
} catch (err) {
- this._view[key] = value;
+ me._view[key] = value;
}
}
// Number transitions
else if (typeof value === 'number') {
- var startVal = this._start[key] !== undefined && isNaN(this._start[key]) === false ? this._start[key] : 0;
- this._view[key] = ((this._model[key] - startVal) * ease) + startVal;
+ var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
+ me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
}
// Everything else
else {
- this._view[key] = value;
+ me._view[key] = value;
}
- }, this);
+ }, me);
- return this;
+ return me;
},
+
tooltipPosition: function() {
return {
x: this._model.x,
y: this._model.y
};
},
+
hasValue: function() {
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
} | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.legend.js | @@ -44,7 +44,7 @@ module.exports = function(Chart) {
return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
return {
text: dataset.label,
- fillStyle: dataset.backgroundColor,
+ fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
hidden: !chart.isDatasetVisible(i),
lineCap: dataset.borderCapStyle,
lineDash: dataset.borderDash,
@@ -79,61 +79,63 @@ module.exports = function(Chart) {
beforeUpdate: noop,
update: function(maxWidth, maxHeight, margins) {
+ var me = this;
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
- this.beforeUpdate();
+ me.beforeUpdate();
// Absorb the master measurements
- this.maxWidth = maxWidth;
- this.maxHeight = maxHeight;
- this.margins = margins;
+ me.maxWidth = maxWidth;
+ me.maxHeight = maxHeight;
+ me.margins = margins;
// Dimensions
- this.beforeSetDimensions();
- this.setDimensions();
- this.afterSetDimensions();
+ me.beforeSetDimensions();
+ me.setDimensions();
+ me.afterSetDimensions();
// Labels
- this.beforeBuildLabels();
- this.buildLabels();
- this.afterBuildLabels();
+ me.beforeBuildLabels();
+ me.buildLabels();
+ me.afterBuildLabels();
// Fit
- this.beforeFit();
- this.fit();
- this.afterFit();
+ me.beforeFit();
+ me.fit();
+ me.afterFit();
//
- this.afterUpdate();
+ me.afterUpdate();
- return this.minSize;
+ return me.minSize;
},
afterUpdate: noop,
//
beforeSetDimensions: noop,
setDimensions: function() {
+ var me = this;
// Set the unconstrained dimension before label rotation
- if (this.isHorizontal()) {
+ if (me.isHorizontal()) {
// Reset position before calculating rotation
- this.width = this.maxWidth;
- this.left = 0;
- this.right = this.width;
+ me.width = me.maxWidth;
+ me.left = 0;
+ me.right = me.width;
} else {
- this.height = this.maxHeight;
+ me.height = me.maxHeight;
// Reset position before calculating rotation
- this.top = 0;
- this.bottom = this.height;
+ me.top = 0;
+ me.bottom = me.height;
}
// Reset padding
- this.paddingLeft = 0;
- this.paddingTop = 0;
- this.paddingRight = 0;
- this.paddingBottom = 0;
+ me.paddingLeft = 0;
+ me.paddingTop = 0;
+ me.paddingRight = 0;
+ me.paddingBottom = 0;
// Reset minSize
- this.minSize = {
+ me.minSize = {
width: 0,
height: 0
};
@@ -144,9 +146,10 @@ module.exports = function(Chart) {
beforeBuildLabels: noop,
buildLabels: function() {
- this.legendItems = this.options.labels.generateLabels.call(this, this.chart);
- if(this.options.reverse){
- this.legendItems.reverse();
+ var me = this;
+ me.legendItems = me.options.labels.generateLabels.call(me, me.chart);
+ if(me.options.reverse){
+ me.legendItems.reverse();
}
},
afterBuildLabels: noop,
@@ -155,11 +158,12 @@ module.exports = function(Chart) {
beforeFit: noop,
fit: function() {
- var opts = this.options;
+ var me = this;
+ var opts = me.options;
var labelOpts = opts.labels;
var display = opts.display;
- var ctx = this.ctx;
+ var ctx = me.ctx;
var globalDefault = Chart.defaults.global,
itemOrDefault = helpers.getValueOrDefault,
@@ -169,17 +173,17 @@ module.exports = function(Chart) {
labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
// Reset hit boxes
- var hitboxes = this.legendHitBoxes = [];
+ var hitboxes = me.legendHitBoxes = [];
- var minSize = this.minSize;
- var isHorizontal = this.isHorizontal();
+ var minSize = me.minSize;
+ var isHorizontal = me.isHorizontal();
if (isHorizontal) {
- minSize.width = this.maxWidth; // fill all the width
+ minSize.width = me.maxWidth; // fill all the width
minSize.height = display ? 10 : 0;
} else {
minSize.width = display ? 10 : 0;
- minSize.height = this.maxHeight; // fill all the height
+ minSize.height = me.maxHeight; // fill all the height
}
// Increase sizes here
@@ -188,18 +192,18 @@ module.exports = function(Chart) {
// Labels
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
- var lineWidths = this.lineWidths = [0];
- var totalHeight = this.legendItems.length ? fontSize + (labelOpts.padding) : 0;
+ var lineWidths = me.lineWidths = [0];
+ var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
ctx.textAlign = "left";
ctx.textBaseline = 'top';
ctx.font = labelFont;
- helpers.each(this.legendItems, function(legendItem, i) {
+ helpers.each(me.legendItems, function(legendItem, i) {
var width = labelOpts.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
- if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= this.width) {
+ if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
totalHeight += fontSize + (labelOpts.padding);
- lineWidths[lineWidths.length] = this.left;
+ lineWidths[lineWidths.length] = me.left;
}
// Store the hitbox width and height here. Final position will be updated in `draw`
@@ -211,7 +215,7 @@ module.exports = function(Chart) {
};
lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
- }, this);
+ }, me);
minSize.height += totalHeight;
@@ -220,8 +224,8 @@ module.exports = function(Chart) {
}
}
- this.width = minSize.width;
- this.height = minSize.height;
+ me.width = minSize.width;
+ me.height = minSize.height;
},
afterFit: noop,
@@ -232,18 +236,19 @@ module.exports = function(Chart) {
// Actualy draw the legend on the canvas
draw: function() {
- var opts = this.options;
+ var me = this;
+ var opts = me.options;
var labelOpts = opts.labels;
var globalDefault = Chart.defaults.global,
lineDefault = globalDefault.elements.line,
- legendWidth = this.width,
- lineWidths = this.lineWidths;
+ legendWidth = me.width,
+ lineWidths = me.lineWidths;
if (opts.display) {
- var ctx = this.ctx,
+ var ctx = me.ctx,
cursor = {
- x: this.left + ((legendWidth - lineWidths[0]) / 2),
- y: this.top + labelOpts.padding,
+ x: me.left + ((legendWidth - lineWidths[0]) / 2),
+ y: me.top + labelOpts.padding,
line: 0
},
itemOrDefault = helpers.getValueOrDefault,
@@ -254,7 +259,7 @@ module.exports = function(Chart) {
labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
// Horizontal
- if (this.isHorizontal()) {
+ if (me.isHorizontal()) {
// Labels
ctx.textAlign = "left";
ctx.textBaseline = 'top';
@@ -264,9 +269,9 @@ module.exports = function(Chart) {
ctx.font = labelFont;
var boxWidth = labelOpts.boxWidth,
- hitboxes = this.legendHitBoxes;
+ hitboxes = me.legendHitBoxes;
- helpers.each(this.legendItems, function(legendItem, i) {
+ helpers.each(me.legendItems, function(legendItem, i) {
var textWidth = ctx.measureText(legendItem.text).width,
width = boxWidth + (fontSize / 2) + textWidth,
x = cursor.x,
@@ -275,7 +280,7 @@ module.exports = function(Chart) {
if (x + width >= legendWidth) {
y = cursor.y += fontSize + (labelOpts.padding);
cursor.line++;
- x = cursor.x = this.left + ((legendWidth - lineWidths[cursor.line]) / 2);
+ x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
}
// Set the ctx for the box
@@ -315,7 +320,7 @@ module.exports = function(Chart) {
}
cursor.x += width + (labelOpts.padding);
- }, this);
+ }, me);
} else {
}
@@ -324,21 +329,22 @@ module.exports = function(Chart) {
// Handle an event
handleEvent: function(e) {
- var position = helpers.getRelativePosition(e, this.chart.chart),
+ var me = this;
+ var position = helpers.getRelativePosition(e, me.chart.chart),
x = position.x,
y = position.y,
- opts = this.options;
+ opts = me.options;
- if (x >= this.left && x <= this.right && y >= this.top && y <= this.bottom) {
+ if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
// See if we are touching one of the dataset boxes
- var lh = this.legendHitBoxes;
+ var lh = me.legendHitBoxes;
for (var i = 0; i < lh.length; ++i) {
var hitBox = lh[i];
if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
// Touching an element
if (opts.onClick) {
- opts.onClick.call(this, e, this.legendItems[i]);
+ opts.onClick.call(me, e, me.legendItems[i]);
}
break;
} | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.scale.js | @@ -59,51 +59,52 @@ module.exports = function(Chart) {
helpers.callCallback(this.options.beforeUpdate, [this]);
},
update: function(maxWidth, maxHeight, margins) {
+ var me = this;
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
- this.beforeUpdate();
+ me.beforeUpdate();
// Absorb the master measurements
- this.maxWidth = maxWidth;
- this.maxHeight = maxHeight;
- this.margins = helpers.extend({
+ me.maxWidth = maxWidth;
+ me.maxHeight = maxHeight;
+ me.margins = helpers.extend({
left: 0,
right: 0,
top: 0,
bottom: 0
}, margins);
// Dimensions
- this.beforeSetDimensions();
- this.setDimensions();
- this.afterSetDimensions();
+ me.beforeSetDimensions();
+ me.setDimensions();
+ me.afterSetDimensions();
// Data min/max
- this.beforeDataLimits();
- this.determineDataLimits();
- this.afterDataLimits();
+ me.beforeDataLimits();
+ me.determineDataLimits();
+ me.afterDataLimits();
// Ticks
- this.beforeBuildTicks();
- this.buildTicks();
- this.afterBuildTicks();
+ me.beforeBuildTicks();
+ me.buildTicks();
+ me.afterBuildTicks();
- this.beforeTickToLabelConversion();
- this.convertTicksToLabels();
- this.afterTickToLabelConversion();
+ me.beforeTickToLabelConversion();
+ me.convertTicksToLabels();
+ me.afterTickToLabelConversion();
// Tick Rotation
- this.beforeCalculateTickRotation();
- this.calculateTickRotation();
- this.afterCalculateTickRotation();
+ me.beforeCalculateTickRotation();
+ me.calculateTickRotation();
+ me.afterCalculateTickRotation();
// Fit
- this.beforeFit();
- this.fit();
- this.afterFit();
+ me.beforeFit();
+ me.fit();
+ me.afterFit();
//
- this.afterUpdate();
+ me.afterUpdate();
- return this.minSize;
+ return me.minSize;
},
afterUpdate: function() {
@@ -116,25 +117,26 @@ module.exports = function(Chart) {
helpers.callCallback(this.options.beforeSetDimensions, [this]);
},
setDimensions: function() {
+ var me = this;
// Set the unconstrained dimension before label rotation
- if (this.isHorizontal()) {
+ if (me.isHorizontal()) {
// Reset position before calculating rotation
- this.width = this.maxWidth;
- this.left = 0;
- this.right = this.width;
+ me.width = me.maxWidth;
+ me.left = 0;
+ me.right = me.width;
} else {
- this.height = this.maxHeight;
+ me.height = me.maxHeight;
// Reset position before calculating rotation
- this.top = 0;
- this.bottom = this.height;
+ me.top = 0;
+ me.bottom = me.height;
}
// Reset padding
- this.paddingLeft = 0;
- this.paddingTop = 0;
- this.paddingRight = 0;
- this.paddingBottom = 0;
+ me.paddingLeft = 0;
+ me.paddingTop = 0;
+ me.paddingRight = 0;
+ me.paddingBottom = 0;
},
afterSetDimensions: function() {
helpers.callCallback(this.options.afterSetDimensions, [this]);
@@ -162,14 +164,15 @@ module.exports = function(Chart) {
helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
},
convertTicksToLabels: function() {
+ var me = this;
// Convert ticks to strings
- this.ticks = this.ticks.map(function(numericalTick, index, ticks) {
- if (this.options.ticks.userCallback) {
- return this.options.ticks.userCallback(numericalTick, index, ticks);
+ me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
+ if (me.options.ticks.userCallback) {
+ return me.options.ticks.userCallback(numericalTick, index, ticks);
}
- return this.options.ticks.callback(numericalTick, index, ticks);
+ return me.options.ticks.callback(numericalTick, index, ticks);
},
- this);
+ me);
},
afterTickToLabelConversion: function() {
helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
@@ -181,9 +184,10 @@ module.exports = function(Chart) {
helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
},
calculateTickRotation: function() {
- var context = this.ctx;
+ var me = this;
+ var context = me.ctx;
var globalDefaults = Chart.defaults.global;
- var optionTicks = this.options.ticks;
+ var optionTicks = me.options.ticks;
//Get the width of each grid by calculating the difference
//between x offsets between 0 and 1.
@@ -193,60 +197,60 @@ module.exports = function(Chart) {
var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
context.font = tickLabelFont;
- var firstWidth = context.measureText(this.ticks[0]).width;
- var lastWidth = context.measureText(this.ticks[this.ticks.length - 1]).width;
+ var firstWidth = context.measureText(me.ticks[0]).width;
+ var lastWidth = context.measureText(me.ticks[me.ticks.length - 1]).width;
var firstRotated;
- this.labelRotation = optionTicks.minRotation || 0;
- this.paddingRight = 0;
- this.paddingLeft = 0;
+ me.labelRotation = optionTicks.minRotation || 0;
+ me.paddingRight = 0;
+ me.paddingLeft = 0;
- if (this.options.display) {
- if (this.isHorizontal()) {
- this.paddingRight = lastWidth / 2 + 3;
- this.paddingLeft = firstWidth / 2 + 3;
+ if (me.options.display) {
+ if (me.isHorizontal()) {
+ me.paddingRight = lastWidth / 2 + 3;
+ me.paddingLeft = firstWidth / 2 + 3;
- if (!this.longestTextCache) {
- this.longestTextCache = {};
+ if (!me.longestTextCache) {
+ me.longestTextCache = {};
}
- var originalLabelWidth = helpers.longestText(context, tickLabelFont, this.ticks, this.longestTextCache);
+ var originalLabelWidth = helpers.longestText(context, tickLabelFont, me.ticks, me.longestTextCache);
var labelWidth = originalLabelWidth;
var cosRotation;
var sinRotation;
// Allow 3 pixels x2 padding either side for label readability
// only the index matters for a dataset scale, but we want a consistent interface between scales
- var tickWidth = this.getPixelForTick(1) - this.getPixelForTick(0) - 6;
+ var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
//Max label rotation can be set or default to 90 - also act as a loop counter
- while (labelWidth > tickWidth && this.labelRotation < optionTicks.maxRotation) {
- cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
- sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
+ while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) {
+ cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
+ sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
firstRotated = cosRotation * firstWidth;
// We're right aligning the text now.
- if (firstRotated + tickFontSize / 2 > this.yLabelWidth) {
- this.paddingLeft = firstRotated + tickFontSize / 2;
+ if (firstRotated + tickFontSize / 2 > me.yLabelWidth) {
+ me.paddingLeft = firstRotated + tickFontSize / 2;
}
- this.paddingRight = tickFontSize / 2;
+ me.paddingRight = tickFontSize / 2;
- if (sinRotation * originalLabelWidth > this.maxHeight) {
+ if (sinRotation * originalLabelWidth > me.maxHeight) {
// go back one step
- this.labelRotation--;
+ me.labelRotation--;
break;
}
- this.labelRotation++;
+ me.labelRotation++;
labelWidth = cosRotation * originalLabelWidth;
}
}
}
- if (this.margins) {
- this.paddingLeft = Math.max(this.paddingLeft - this.margins.left, 0);
- this.paddingRight = Math.max(this.paddingRight - this.margins.right, 0);
+ if (me.margins) {
+ me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
+ me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
}
},
afterCalculateTickRotation: function() {
@@ -259,18 +263,19 @@ module.exports = function(Chart) {
helpers.callCallback(this.options.beforeFit, [this]);
},
fit: function() {
+ var me = this;
// Reset
- var minSize = this.minSize = {
+ var minSize = me.minSize = {
width: 0,
height: 0
};
- var opts = this.options;
+ var opts = me.options;
var globalDefaults = Chart.defaults.global;
var tickOpts = opts.ticks;
var scaleLabelOpts = opts.scaleLabel;
var display = opts.display;
- var isHorizontal = this.isHorizontal();
+ var isHorizontal = me.isHorizontal();
var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
var tickFontStyle = helpers.getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
@@ -287,7 +292,7 @@ module.exports = function(Chart) {
// Width
if (isHorizontal) {
// subtract the margins to line up with the chartArea if we are a full width scale
- minSize.width = this.isFullWidth() ? this.maxWidth - this.margins.left - this.margins.right : this.maxWidth;
+ minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
} else {
minSize.width = display ? tickMarkLength : 0;
}
@@ -296,7 +301,7 @@ module.exports = function(Chart) {
if (isHorizontal) {
minSize.height = display ? tickMarkLength : 0;
} else {
- minSize.height = this.maxHeight; // fill all the height
+ minSize.height = me.maxHeight; // fill all the height
}
// Are we showing a title for the scale?
@@ -310,39 +315,39 @@ module.exports = function(Chart) {
if (tickOpts.display && display) {
// Don't bother fitting the ticks if we are not showing them
- if (!this.longestTextCache) {
- this.longestTextCache = {};
+ if (!me.longestTextCache) {
+ me.longestTextCache = {};
}
- var largestTextWidth = helpers.longestText(this.ctx, tickLabelFont, this.ticks, this.longestTextCache);
+ var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
if (isHorizontal) {
// A horizontal axis is more constrained by the height.
- this.longestLabelWidth = largestTextWidth;
+ me.longestLabelWidth = largestTextWidth;
// TODO - improve this calculation
- var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * this.longestLabelWidth) + 1.5 * tickFontSize;
+ var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + 1.5 * tickFontSize;
- minSize.height = Math.min(this.maxHeight, minSize.height + labelHeight);
- this.ctx.font = tickLabelFont;
+ minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
+ me.ctx.font = tickLabelFont;
- var firstLabelWidth = this.ctx.measureText(this.ticks[0]).width;
- var lastLabelWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
+ var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
+ var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
// Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
// by the font height
- var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
- var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
- this.paddingLeft = this.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
- this.paddingRight = this.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
+ var cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
+ var sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
+ me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
+ me.paddingRight = me.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
} else {
// A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
- var maxLabelWidth = this.maxWidth - minSize.width;
+ var maxLabelWidth = me.maxWidth - minSize.width;
// Account for padding
var mirror = tickOpts.mirror;
if (!mirror) {
- largestTextWidth += this.options.ticks.padding;
+ largestTextWidth += me.options.ticks.padding;
} else {
// If mirrored text is on the inside so don't expand
largestTextWidth = 0;
@@ -353,23 +358,23 @@ module.exports = function(Chart) {
minSize.width += largestTextWidth;
} else {
// Expand to max size
- minSize.width = this.maxWidth;
+ minSize.width = me.maxWidth;
}
- this.paddingTop = tickFontSize / 2;
- this.paddingBottom = tickFontSize / 2;
+ me.paddingTop = tickFontSize / 2;
+ me.paddingBottom = tickFontSize / 2;
}
}
- if (this.margins) {
- this.paddingLeft = Math.max(this.paddingLeft - this.margins.left, 0);
- this.paddingTop = Math.max(this.paddingTop - this.margins.top, 0);
- this.paddingRight = Math.max(this.paddingRight - this.margins.right, 0);
- this.paddingBottom = Math.max(this.paddingBottom - this.margins.bottom, 0);
+ if (me.margins) {
+ me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
+ me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
+ me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
+ me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
}
- this.width = minSize.width;
- this.height = minSize.height;
+ me.width = minSize.width;
+ me.height = minSize.height;
},
afterFit: function() {
@@ -419,35 +424,37 @@ module.exports = function(Chart) {
// Used for tick location, should
getPixelForTick: function(index, includeOffset) {
- if (this.isHorizontal()) {
- var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
- var tickWidth = innerWidth / Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
- var pixel = (tickWidth * index) + this.paddingLeft;
+ var me = this;
+ if (me.isHorizontal()) {
+ var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
+ var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
+ var pixel = (tickWidth * index) + me.paddingLeft;
if (includeOffset) {
pixel += tickWidth / 2;
}
- var finalVal = this.left + Math.round(pixel);
- finalVal += this.isFullWidth() ? this.margins.left : 0;
+ var finalVal = me.left + Math.round(pixel);
+ finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
} else {
- var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
- return this.top + (index * (innerHeight / (this.ticks.length - 1)));
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ return me.top + (index * (innerHeight / (me.ticks.length - 1)));
}
},
// Utility for getting the pixel location of a percentage of scale
getPixelForDecimal: function(decimal /*, includeOffset*/ ) {
- if (this.isHorizontal()) {
- var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
- var valueOffset = (innerWidth * decimal) + this.paddingLeft;
+ var me = this;
+ if (me.isHorizontal()) {
+ var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
+ var valueOffset = (innerWidth * decimal) + me.paddingLeft;
- var finalVal = this.left + Math.round(valueOffset);
- finalVal += this.isFullWidth() ? this.margins.left : 0;
+ var finalVal = me.left + Math.round(valueOffset);
+ finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
} else {
- return this.top + (decimal * this.height);
+ return me.top + (decimal * me.height);
}
},
@@ -466,19 +473,20 @@ module.exports = function(Chart) {
// Actualy draw the scale on the canvas
// @param {rectangle} chartArea : the area of the chart to draw full grid lines on
draw: function(chartArea) {
- var options = this.options;
+ var me = this;
+ var options = me.options;
if (!options.display) {
return;
}
- var context = this.ctx;
+ var context = me.ctx;
var globalDefaults = Chart.defaults.global;
var optionTicks = options.ticks;
var gridLines = options.gridLines;
var scaleLabel = options.scaleLabel;
var setContextLineSettings;
- var isRotated = this.labelRotation !== 0;
+ var isRotated = me.labelRotation !== 0;
var skipRatio;
var scaleLabelX;
var scaleLabelY;
@@ -503,19 +511,19 @@ module.exports = function(Chart) {
var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabel.fontFamily, globalDefaults.defaultFontFamily);
var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
- var labelRotationRadians = helpers.toRadians(this.labelRotation);
+ var labelRotationRadians = helpers.toRadians(me.labelRotation);
var cosRotation = Math.cos(labelRotationRadians);
var sinRotation = Math.sin(labelRotationRadians);
- var longestRotatedLabel = this.longestLabelWidth * cosRotation;
+ var longestRotatedLabel = me.longestLabelWidth * cosRotation;
var rotatedLabelHeight = tickFontSize * sinRotation;
// Make sure we draw text in the correct color and font
context.fillStyle = tickFontColor;
- if (this.isHorizontal()) {
+ if (me.isHorizontal()) {
setContextLineSettings = true;
- var yTickStart = options.position === "bottom" ? this.top : this.bottom - tl;
- var yTickEnd = options.position === "bottom" ? this.top + tl : this.bottom;
+ var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
+ var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
skipRatio = false;
// Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
@@ -524,14 +532,14 @@ module.exports = function(Chart) {
longestRotatedLabel /= 2;
}
- if ((longestRotatedLabel + optionTicks.autoSkipPadding) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
- skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
+ if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
+ skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
}
// if they defined a max number of optionTicks,
// increase skipRatio until that number is met
- if (maxTicks && this.ticks.length > maxTicks) {
- while (!skipRatio || this.ticks.length / (skipRatio || 1) > maxTicks) {
+ if (maxTicks && me.ticks.length > maxTicks) {
+ while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
if (!skipRatio) {
skipRatio = 1;
}
@@ -543,20 +551,20 @@ module.exports = function(Chart) {
skipRatio = false;
}
- helpers.each(this.ticks, function (label, index) {
+ helpers.each(me.ticks, function (label, index) {
// Blank optionTicks
- var isLastTick = this.ticks.length === index + 1;
+ var isLastTick = me.ticks.length === index + 1;
// Since we always show the last tick,we need may need to hide the last shown one before
- var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= this.ticks.length);
+ var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
return;
}
- var xLineValue = this.getPixelForTick(index); // xvalues for grid lines
- var xLabelValue = this.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
+ var xLineValue = me.getPixelForTick(index); // xvalues for grid lines
+ var xLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
if (gridLines.display) {
- if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
+ if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
// Draw the first index specially
context.lineWidth = gridLines.zeroLineWidth;
context.strokeStyle = gridLines.zeroLineColor;
@@ -589,15 +597,15 @@ module.exports = function(Chart) {
if (optionTicks.display) {
context.save();
- context.translate(xLabelValue + optionTicks.labelOffset, (isRotated) ? this.top + 12 : options.position === "top" ? this.bottom - tl : this.top + tl);
+ context.translate(xLabelValue + optionTicks.labelOffset, (isRotated) ? me.top + 12 : options.position === "top" ? me.bottom - tl : me.top + tl);
context.rotate(labelRotationRadians * -1);
context.font = tickLabelFont;
context.textAlign = (isRotated) ? "right" : "center";
context.textBaseline = (isRotated) ? "middle" : options.position === "top" ? "bottom" : "top";
context.fillText(label, 0, 0);
context.restore();
}
- }, this);
+ }, me);
if (scaleLabel.display) {
// Draw the scale label
@@ -606,27 +614,27 @@ module.exports = function(Chart) {
context.fillStyle = scaleLabelFontColor; // render in correct colour
context.font = scaleLabelFont;
- scaleLabelX = this.left + ((this.right - this.left) / 2); // midpoint of the width
- scaleLabelY = options.position === 'bottom' ? this.bottom - (scaleLabelFontSize / 2) : this.top + (scaleLabelFontSize / 2);
+ scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
+ scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
context.fillText(scaleLabel.labelString, scaleLabelX, scaleLabelY);
}
} else {
setContextLineSettings = true;
- var xTickStart = options.position === "right" ? this.left : this.right - 5;
- var xTickEnd = options.position === "right" ? this.left + 5 : this.right;
+ var xTickStart = options.position === "right" ? me.left : me.right - 5;
+ var xTickEnd = options.position === "right" ? me.left + 5 : me.right;
- helpers.each(this.ticks, function (label, index) {
+ helpers.each(me.ticks, function (label, index) {
// If the callback returned a null or undefined value, do not draw this line
if (label === undefined || label === null) {
return;
}
- var yLineValue = this.getPixelForTick(index); // xvalues for grid lines
+ var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
if (gridLines.display) {
- if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
+ if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
// Draw the first index specially
context.lineWidth = gridLines.zeroLineWidth;
context.strokeStyle = gridLines.zeroLineColor;
@@ -659,25 +667,25 @@ module.exports = function(Chart) {
if (optionTicks.display) {
var xLabelValue;
- var yLabelValue = this.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
+ var yLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
context.save();
if (options.position === "left") {
if (optionTicks.mirror) {
- xLabelValue = this.right + optionTicks.padding;
+ xLabelValue = me.right + optionTicks.padding;
context.textAlign = "left";
} else {
- xLabelValue = this.right - optionTicks.padding;
+ xLabelValue = me.right - optionTicks.padding;
context.textAlign = "right";
}
} else {
// right side
if (optionTicks.mirror) {
- xLabelValue = this.left - optionTicks.padding;
+ xLabelValue = me.left - optionTicks.padding;
context.textAlign = "right";
} else {
- xLabelValue = this.left + optionTicks.padding;
+ xLabelValue = me.left + optionTicks.padding;
context.textAlign = "left";
}
}
@@ -689,12 +697,12 @@ module.exports = function(Chart) {
context.fillText(label, 0, 0);
context.restore();
}
- }, this);
+ }, me);
if (scaleLabel.display) {
// Draw the scale label
- scaleLabelX = options.position === 'left' ? this.left + (scaleLabelFontSize / 2) : this.right - (scaleLabelFontSize / 2);
- scaleLabelY = this.top + ((this.bottom - this.top) / 2);
+ scaleLabelX = options.position === 'left' ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
+ scaleLabelY = me.top + ((me.bottom - me.top) / 2);
var rotation = options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
context.save();
@@ -713,18 +721,18 @@ module.exports = function(Chart) {
// Draw the line at the edge of the axis
context.lineWidth = gridLines.lineWidth;
context.strokeStyle = gridLines.color;
- var x1 = this.left,
- x2 = this.right,
- y1 = this.top,
- y2 = this.bottom;
+ var x1 = me.left,
+ x2 = me.right,
+ y1 = me.top,
+ y2 = me.bottom;
var aliasPixel = helpers.aliasPixel(context.lineWidth);
- if (this.isHorizontal()) {
- y1 = y2 = options.position === 'top' ? this.bottom : this.top;
+ if (me.isHorizontal()) {
+ y1 = y2 = options.position === 'top' ? me.bottom : me.top;
y1 += aliasPixel;
y2 += aliasPixel;
} else {
- x1 = x2 = options.position === 'left' ? this.right : this.left;
+ x1 = x2 = options.position === 'left' ? me.right : me.left;
x1 += aliasPixel;
x2 += aliasPixel;
} | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.title.js | @@ -20,43 +20,50 @@ module.exports = function(Chart) {
Chart.Title = Chart.Element.extend({
initialize: function(config) {
- helpers.extend(this, config);
- this.options = helpers.configMerge(Chart.defaults.global.title, config.options);
+ var me = this;
+ helpers.extend(me, config);
+ me.options = helpers.configMerge(Chart.defaults.global.title, config.options);
// Contains hit boxes for each dataset (in dataset order)
- this.legendHitBoxes = [];
+ me.legendHitBoxes = [];
},
// These methods are ordered by lifecyle. Utilities then follow.
- beforeUpdate: noop,
+ beforeUpdate: function () {
+ var chartOpts = this.chart.options;
+ if (chartOpts && chartOpts.title) {
+ this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title);
+ }
+ },
update: function(maxWidth, maxHeight, margins) {
-
+ var me = this;
+
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
- this.beforeUpdate();
+ me.beforeUpdate();
// Absorb the master measurements
- this.maxWidth = maxWidth;
- this.maxHeight = maxHeight;
- this.margins = margins;
+ me.maxWidth = maxWidth;
+ me.maxHeight = maxHeight;
+ me.margins = margins;
// Dimensions
- this.beforeSetDimensions();
- this.setDimensions();
- this.afterSetDimensions();
+ me.beforeSetDimensions();
+ me.setDimensions();
+ me.afterSetDimensions();
// Labels
- this.beforeBuildLabels();
- this.buildLabels();
- this.afterBuildLabels();
+ me.beforeBuildLabels();
+ me.buildLabels();
+ me.afterBuildLabels();
// Fit
- this.beforeFit();
- this.fit();
- this.afterFit();
+ me.beforeFit();
+ me.fit();
+ me.afterFit();
//
- this.afterUpdate();
+ me.afterUpdate();
- return this.minSize;
+ return me.minSize;
},
afterUpdate: noop,
@@ -65,28 +72,29 @@ module.exports = function(Chart) {
beforeSetDimensions: noop,
setDimensions: function() {
+ var me = this;
// Set the unconstrained dimension before label rotation
- if (this.isHorizontal()) {
+ if (me.isHorizontal()) {
// Reset position before calculating rotation
- this.width = this.maxWidth;
- this.left = 0;
- this.right = this.width;
+ me.width = me.maxWidth;
+ me.left = 0;
+ me.right = me.width;
} else {
- this.height = this.maxHeight;
+ me.height = me.maxHeight;
// Reset position before calculating rotation
- this.top = 0;
- this.bottom = this.height;
+ me.top = 0;
+ me.bottom = me.height;
}
// Reset padding
- this.paddingLeft = 0;
- this.paddingTop = 0;
- this.paddingRight = 0;
- this.paddingBottom = 0;
+ me.paddingLeft = 0;
+ me.paddingTop = 0;
+ me.paddingRight = 0;
+ me.paddingBottom = 0;
// Reset minSize
- this.minSize = {
+ me.minSize = {
width: 0,
height: 0
};
@@ -104,25 +112,25 @@ module.exports = function(Chart) {
beforeFit: noop,
fit: function() {
- var _this = this,
- ctx = _this.ctx,
+ var me = this,
+ ctx = me.ctx,
valueOrDefault = helpers.getValueOrDefault,
- opts = _this.options,
+ opts = me.options,
globalDefaults = Chart.defaults.global,
display = opts.display,
fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
- minSize = _this.minSize;
+ minSize = me.minSize;
- if (_this.isHorizontal()) {
- minSize.width = _this.maxWidth; // fill all the width
+ if (me.isHorizontal()) {
+ minSize.width = me.maxWidth; // fill all the width
minSize.height = display ? fontSize + (opts.padding * 2) : 0;
} else {
minSize.width = display ? fontSize + (opts.padding * 2) : 0;
- minSize.height = _this.maxHeight; // fill all the height
+ minSize.height = me.maxHeight; // fill all the height
}
- _this.width = minSize.width;
- _this.height = minSize.height;
+ me.width = minSize.width;
+ me.height = minSize.height;
},
afterFit: noop,
@@ -135,10 +143,10 @@ module.exports = function(Chart) {
// Actualy draw the title block on the canvas
draw: function() {
- var _this = this,
- ctx = _this.ctx,
+ var me = this,
+ ctx = me.ctx,
valueOrDefault = helpers.getValueOrDefault,
- opts = _this.options,
+ opts = me.options,
globalDefaults = Chart.defaults.global;
if (opts.display) {
@@ -149,16 +157,16 @@ module.exports = function(Chart) {
rotation = 0,
titleX,
titleY,
- top = _this.top,
- left = _this.left,
- bottom = _this.bottom,
- right = _this.right;
+ top = me.top,
+ left = me.left,
+ bottom = me.bottom,
+ right = me.right;
ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
ctx.font = titleFont;
// Horizontal
- if (_this.isHorizontal()) {
+ if (me.isHorizontal()) {
titleX = left + ((right - left) / 2); // midpoint of the width
titleY = top + ((bottom - top) / 2); // midpoint of the height
} else {
@@ -195,4 +203,4 @@ module.exports = function(Chart) {
}
}
});
-};
\ No newline at end of file
+}; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/core/core.tooltip.js | @@ -215,8 +215,7 @@ module.exports = function(Chart) {
// Args are: (tooltipItem, data)
getBeforeBody: function() {
- var me = this;
- var lines = me._options.callbacks.beforeBody.apply(me, arguments);
+ var lines = this._options.callbacks.beforeBody.apply(this, arguments);
return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
},
@@ -244,8 +243,7 @@ module.exports = function(Chart) {
// Args are: (tooltipItem, data)
getAfterBody: function() {
- var me = this;
- var lines = me._options.callbacks.afterBody.apply(me, arguments);
+ var lines = this._options.callbacks.afterBody.apply(this, arguments);
return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
},
@@ -330,8 +328,7 @@ module.exports = function(Chart) {
return me;
},
getTooltipSize: function getTooltipSize(vm) {
- var me = this;
- var ctx = me._chart.ctx;
+ var ctx = this._chart.ctx;
var size = {
height: vm.yPadding * 2, // Tooltip Padding
@@ -501,9 +498,8 @@ module.exports = function(Chart) {
return pt;
},
drawCaret: function drawCaret(tooltipPoint, size, opacity, caretPadding) {
- var me = this;
- var vm = me._view;
- var ctx = me._chart.ctx;
+ var vm = this._view;
+ var ctx = this._chart.ctx;
var x1, x2, x3;
var y1, y2, y3;
var caretSize = vm.caretSize;
@@ -591,7 +587,6 @@ module.exports = function(Chart) {
}
},
drawBody: function drawBody(pt, vm, ctx, opacity) {
- var me = this;
var bodyFontSize = vm.bodyFontSize;
var bodySpacing = vm.bodySpacing;
var body = vm.body; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/elements/element.line.js | @@ -19,12 +19,13 @@ module.exports = function(Chart) {
Chart.elements.Line = Chart.Element.extend({
lineToNextPoint: function(previousPoint, point, nextPoint, skipHandler, previousSkipHandler) {
- var ctx = this._chart.ctx;
+ var me = this;
+ var ctx = me._chart.ctx;
if (point._view.skip) {
- skipHandler.call(this, previousPoint, point, nextPoint);
+ skipHandler.call(me, previousPoint, point, nextPoint);
} else if (previousPoint._view.skip) {
- previousSkipHandler.call(this, previousPoint, point, nextPoint);
+ previousSkipHandler.call(me, previousPoint, point, nextPoint);
} else if (point._view.tension === 0) {
ctx.lineTo(point._view.x, point._view.y);
} else {
@@ -41,12 +42,12 @@ module.exports = function(Chart) {
},
draw: function() {
- var _this = this;
+ var me = this;
- var vm = this._view;
- var ctx = this._chart.ctx;
- var first = this._children[0];
- var last = this._children[this._children.length - 1];
+ var vm = me._view;
+ var ctx = me._chart.ctx;
+ var first = me._children[0];
+ var last = me._children[me._children.length - 1];
function loopBackToStart(drawLineToCenter) {
if (!first._view.skip && !last._view.skip) {
@@ -61,59 +62,59 @@ module.exports = function(Chart) {
);
} else if (drawLineToCenter) {
// Go to center
- ctx.lineTo(_this._view.scaleZero.x, _this._view.scaleZero.y);
+ ctx.lineTo(me._view.scaleZero.x, me._view.scaleZero.y);
}
}
ctx.save();
// If we had points and want to fill this line, do so.
- if (this._children.length > 0 && vm.fill) {
+ if (me._children.length > 0 && vm.fill) {
// Draw the background first (so the border is always on top)
ctx.beginPath();
- helpers.each(this._children, function(point, index) {
- var previous = helpers.previousItem(this._children, index);
- var next = helpers.nextItem(this._children, index);
+ helpers.each(me._children, function(point, index) {
+ var previous = helpers.previousItem(me._children, index);
+ var next = helpers.nextItem(me._children, index);
// First point moves to it's starting position no matter what
if (index === 0) {
- if (this._loop) {
+ if (me._loop) {
ctx.moveTo(vm.scaleZero.x, vm.scaleZero.y);
} else {
ctx.moveTo(point._view.x, vm.scaleZero);
}
if (point._view.skip) {
- if (!this._loop) {
- ctx.moveTo(next._view.x, this._view.scaleZero);
+ if (!me._loop) {
+ ctx.moveTo(next._view.x, me._view.scaleZero);
}
} else {
ctx.lineTo(point._view.x, point._view.y);
}
} else {
- this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
- if (this._loop) {
+ me.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
+ if (me._loop) {
// Go to center
- ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
+ ctx.lineTo(me._view.scaleZero.x, me._view.scaleZero.y);
} else {
- ctx.lineTo(previousPoint._view.x, this._view.scaleZero);
- ctx.moveTo(nextPoint._view.x, this._view.scaleZero);
+ ctx.lineTo(previousPoint._view.x, me._view.scaleZero);
+ ctx.moveTo(nextPoint._view.x, me._view.scaleZero);
}
}, function(previousPoint, point) {
// If we skipped the last point, draw a line to ourselves so that the fill is nice
ctx.lineTo(point._view.x, point._view.y);
});
}
- }, this);
+ }, me);
// For radial scales, loop back around to the first point
- if (this._loop) {
+ if (me._loop) {
loopBackToStart(true);
} else {
//Round off the line by going to the base of the chart, back to the start, then fill.
- ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
- ctx.lineTo(this._children[0]._view.x, vm.scaleZero);
+ ctx.lineTo(me._children[me._children.length - 1]._view.x, vm.scaleZero);
+ ctx.lineTo(me._children[0]._view.x, vm.scaleZero);
}
ctx.fillStyle = vm.backgroundColor || globalDefaults.defaultColor;
@@ -136,23 +137,23 @@ module.exports = function(Chart) {
ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
ctx.beginPath();
- helpers.each(this._children, function(point, index) {
- var previous = helpers.previousItem(this._children, index);
- var next = helpers.nextItem(this._children, index);
+ helpers.each(me._children, function(point, index) {
+ var previous = helpers.previousItem(me._children, index);
+ var next = helpers.nextItem(me._children, index);
if (index === 0) {
ctx.moveTo(point._view.x, point._view.y);
} else {
- this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
+ me.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
ctx.moveTo(nextPoint._view.x, nextPoint._view.y);
}, function(previousPoint, point) {
// If we skipped the last point, move up to our point preventing a line from being drawn
ctx.moveTo(point._view.x, point._view.y);
});
}
- }, this);
+ }, me);
- if (this._loop && this._children.length > 0) {
+ if (me._loop && me._children.length > 0) {
loopBackToStart();
}
| true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.category.js | @@ -11,29 +11,31 @@ module.exports = function(Chart) {
var DatasetScale = Chart.Scale.extend({
// Implement this so that
determineDataLimits: function() {
- this.minIndex = 0;
- this.maxIndex = this.chart.data.labels.length - 1;
+ var me = this;
+ me.minIndex = 0;
+ me.maxIndex = me.chart.data.labels.length - 1;
var findIndex;
- if (this.options.ticks.min !== undefined) {
+ if (me.options.ticks.min !== undefined) {
// user specified min value
- findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
- this.minIndex = findIndex !== -1 ? findIndex : this.minIndex;
+ findIndex = helpers.indexOf(me.chart.data.labels, me.options.ticks.min);
+ me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
}
- if (this.options.ticks.max !== undefined) {
+ if (me.options.ticks.max !== undefined) {
// user specified max value
- findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.max);
- this.maxIndex = findIndex !== -1 ? findIndex : this.maxIndex;
+ findIndex = helpers.indexOf(me.chart.data.labels, me.options.ticks.max);
+ me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
}
- this.min = this.chart.data.labels[this.minIndex];
- this.max = this.chart.data.labels[this.maxIndex];
+ me.min = me.chart.data.labels[me.minIndex];
+ me.max = me.chart.data.labels[me.maxIndex];
},
buildTicks: function(index) {
+ var me = this;
// If we are viewing some subset of labels, slice the original array
- this.ticks = (this.minIndex === 0 && this.maxIndex === this.chart.data.labels.length - 1) ? this.chart.data.labels : this.chart.data.labels.slice(this.minIndex, this.maxIndex + 1);
+ me.ticks = (me.minIndex === 0 && me.maxIndex === me.chart.data.labels.length - 1) ? me.chart.data.labels : me.chart.data.labels.slice(me.minIndex, me.maxIndex + 1);
},
getLabelForIndex: function(index, datasetIndex) {
@@ -42,45 +44,47 @@ module.exports = function(Chart) {
// Used to get data value locations. Value can either be an index or a numerical value
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
+ var me = this;
// 1 is added because we need the length but we have the indexes
- var offsetAmt = Math.max((this.maxIndex + 1 - this.minIndex - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
+ var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
- if (this.isHorizontal()) {
- var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
+ if (me.isHorizontal()) {
+ var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
var valueWidth = innerWidth / offsetAmt;
- var widthOffset = (valueWidth * (index - this.minIndex)) + this.paddingLeft;
+ var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft;
- if (this.options.gridLines.offsetGridLines && includeOffset) {
+ if (me.options.gridLines.offsetGridLines && includeOffset) {
widthOffset += (valueWidth / 2);
}
- return this.left + Math.round(widthOffset);
+ return me.left + Math.round(widthOffset);
} else {
- var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
var valueHeight = innerHeight / offsetAmt;
- var heightOffset = (valueHeight * (index - this.minIndex)) + this.paddingTop;
+ var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
- if (this.options.gridLines.offsetGridLines && includeOffset) {
+ if (me.options.gridLines.offsetGridLines && includeOffset) {
heightOffset += (valueHeight / 2);
}
- return this.top + Math.round(heightOffset);
+ return me.top + Math.round(heightOffset);
}
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
},
getValueForPixel: function(pixel) {
- var value
-; var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
- var horz = this.isHorizontal();
- var innerDimension = horz ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
+ var me = this;
+ var value;
+ var offsetAmt = Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
+ var horz = me.isHorizontal();
+ var innerDimension = horz ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
var valueDimension = innerDimension / offsetAmt;
- if (this.options.gridLines.offsetGridLines) {
+ if (me.options.gridLines.offsetGridLines) {
pixel -= (valueDimension / 2);
}
- pixel -= horz ? this.paddingLeft : this.paddingTop;
+ pixel -= horz ? me.paddingLeft : me.paddingTop;
if (pixel <= 0) {
value = 0; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.linear.js | @@ -37,21 +37,21 @@ module.exports = function(Chart) {
var LinearScale = Chart.LinearScaleBase.extend({
determineDataLimits: function() {
- var _this = this;
- var opts = _this.options;
+ var me = this;
+ var opts = me.options;
var tickOpts = opts.ticks;
- var chart = _this.chart;
+ var chart = me.chart;
var data = chart.data;
var datasets = data.datasets;
- var isHorizontal = _this.isHorizontal();
+ var isHorizontal = me.isHorizontal();
function IDMatches(meta) {
- return isHorizontal ? meta.xAxisID === _this.id : meta.yAxisID === _this.id;
+ return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
}
// First Calculate the range
- _this.min = null;
- _this.max = null;
+ me.min = null;
+ me.max = null;
if (opts.stacked) {
var valuesPerType = {};
@@ -73,7 +73,7 @@ module.exports = function(Chart) {
if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
- var value = +_this.getRightValue(rawValue);
+ var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
return;
}
@@ -100,30 +100,30 @@ module.exports = function(Chart) {
var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
var minVal = helpers.min(values);
var maxVal = helpers.max(values);
- _this.min = _this.min === null ? minVal : Math.min(_this.min, minVal);
- _this.max = _this.max === null ? maxVal : Math.max(_this.max, maxVal);
+ me.min = me.min === null ? minVal : Math.min(me.min, minVal);
+ me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
});
} else {
helpers.each(datasets, function(dataset, datasetIndex) {
var meta = chart.getDatasetMeta(datasetIndex);
if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
- var value = +_this.getRightValue(rawValue);
+ var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
return;
}
- if (_this.min === null) {
- _this.min = value;
- } else if (value < _this.min) {
- _this.min = value;
+ if (me.min === null) {
+ me.min = value;
+ } else if (value < me.min) {
+ me.min = value;
}
- if (_this.max === null) {
- _this.max = value;
- } else if (value > _this.max) {
- _this.max = value;
+ if (me.max === null) {
+ me.max = value;
+ } else if (value > me.max) {
+ me.max = value;
}
});
}
@@ -150,10 +150,9 @@ module.exports = function(Chart) {
},
// Called after the ticks are built. We need
handleDirectionalChanges: function() {
- var me = this;
- if (!me.isHorizontal()) {
+ if (!this.isHorizontal()) {
// We are in a vertical orientation. The top value is the highest. So reverse the array
- me.ticks.reverse();
+ this.ticks.reverse();
}
},
getLabelForIndex: function(index, datasetIndex) {
@@ -163,34 +162,34 @@ module.exports = function(Chart) {
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
- var _this = this;
- var paddingLeft = _this.paddingLeft;
- var paddingBottom = _this.paddingBottom;
- var start = _this.start;
+ var me = this;
+ var paddingLeft = me.paddingLeft;
+ var paddingBottom = me.paddingBottom;
+ var start = me.start;
- var rightValue = +_this.getRightValue(value);
+ var rightValue = +me.getRightValue(value);
var pixel;
var innerDimension;
- var range = _this.end - start;
+ var range = me.end - start;
- if (_this.isHorizontal()) {
- innerDimension = _this.width - (paddingLeft + _this.paddingRight);
- pixel = _this.left + (innerDimension / range * (rightValue - start));
+ if (me.isHorizontal()) {
+ innerDimension = me.width - (paddingLeft + me.paddingRight);
+ pixel = me.left + (innerDimension / range * (rightValue - start));
return Math.round(pixel + paddingLeft);
} else {
- innerDimension = _this.height - (_this.paddingTop + paddingBottom);
- pixel = (_this.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
+ innerDimension = me.height - (me.paddingTop + paddingBottom);
+ pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
return Math.round(pixel);
}
},
getValueForPixel: function(pixel) {
- var _this = this;
- var isHorizontal = _this.isHorizontal();
- var paddingLeft = _this.paddingLeft;
- var paddingBottom = _this.paddingBottom;
- var innerDimension = isHorizontal ? _this.width - (paddingLeft + _this.paddingRight) : _this.height - (_this.paddingTop + paddingBottom);
- var offset = (isHorizontal ? pixel - _this.left - paddingLeft : _this.bottom - paddingBottom - pixel) / innerDimension;
- return _this.start + ((_this.end - _this.start) * offset);
+ var me = this;
+ var isHorizontal = me.isHorizontal();
+ var paddingLeft = me.paddingLeft;
+ var paddingBottom = me.paddingBottom;
+ var innerDimension = isHorizontal ? me.width - (paddingLeft + me.paddingRight) : me.height - (me.paddingTop + paddingBottom);
+ var offset = (isHorizontal ? pixel - me.left - paddingLeft : me.bottom - paddingBottom - pixel) / innerDimension;
+ return me.start + ((me.end - me.start) * offset);
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticksAsNumbers[index], null, null, includeOffset); | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.linearbase.js | @@ -7,64 +7,64 @@ module.exports = function(Chart) {
Chart.LinearScaleBase = Chart.Scale.extend({
handleTickRangeOptions: function() {
- var _this = this;
- var opts = _this.options;
+ var me = this;
+ var opts = me.options;
var tickOpts = opts.ticks;
// If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
// do nothing since that would make the chart weird. If the user really wants a weird chart
// axis, they can manually override it
if (tickOpts.beginAtZero) {
- var minSign = helpers.sign(_this.min);
- var maxSign = helpers.sign(_this.max);
+ var minSign = helpers.sign(me.min);
+ var maxSign = helpers.sign(me.max);
if (minSign < 0 && maxSign < 0) {
// move the top up to 0
- _this.max = 0;
+ me.max = 0;
} else if (minSign > 0 && maxSign > 0) {
// move the botttom down to 0
- _this.min = 0;
+ me.min = 0;
}
}
if (tickOpts.min !== undefined) {
- _this.min = tickOpts.min;
+ me.min = tickOpts.min;
} else if (tickOpts.suggestedMin !== undefined) {
- _this.min = Math.min(_this.min, tickOpts.suggestedMin);
+ me.min = Math.min(me.min, tickOpts.suggestedMin);
}
if (tickOpts.max !== undefined) {
- _this.max = tickOpts.max;
+ me.max = tickOpts.max;
} else if (tickOpts.suggestedMax !== undefined) {
- _this.max = Math.max(_this.max, tickOpts.suggestedMax);
+ me.max = Math.max(me.max, tickOpts.suggestedMax);
}
- if (_this.min === _this.max) {
- _this.max++;
+ if (me.min === me.max) {
+ me.max++;
if (!tickOpts.beginAtZero) {
- _this.min--;
+ me.min--;
}
}
},
getTickLimit: noop,
handleDirectionalChanges: noop,
buildTicks: function() {
- var _this = this;
- var opts = _this.options;
+ var me = this;
+ var opts = me.options;
var tickOpts = opts.ticks;
var getValueOrDefault = helpers.getValueOrDefault;
- var isHorizontal = _this.isHorizontal();
+ var isHorizontal = me.isHorizontal();
- var ticks = _this.ticks = [];
+ var ticks = me.ticks = [];
// Figure out what the max number of ticks we can support it is based on the size of
// the axis area. For now, we say that the minimum tick spacing in pixels must be 50
// We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
// the graph
- var maxTicks = this.getTickLimit();
+ var maxTicks = me.getTickLimit();
// Make sure we always have at least 2 ticks
maxTicks = Math.max(2, maxTicks);
@@ -78,11 +78,11 @@ module.exports = function(Chart) {
if (fixedStepSizeSet) {
spacing = getValueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize);
} else {
- var niceRange = helpers.niceNum(_this.max - _this.min, false);
+ var niceRange = helpers.niceNum(me.max - me.min, false);
spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
}
- var niceMin = Math.floor(_this.min / spacing) * spacing;
- var niceMax = Math.ceil(_this.max / spacing) * spacing;
+ var niceMin = Math.floor(me.min / spacing) * spacing;
+ var niceMax = Math.ceil(me.max / spacing) * spacing;
var numSpaces = (niceMax - niceMin) / spacing;
// If very close to our rounded value, use it.
@@ -99,29 +99,29 @@ module.exports = function(Chart) {
}
ticks.push(tickOpts.max !== undefined ? tickOpts.max : niceMax);
- this.handleDirectionalChanges();
+ me.handleDirectionalChanges();
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
- _this.max = helpers.max(ticks);
- _this.min = helpers.min(ticks);
+ me.max = helpers.max(ticks);
+ me.min = helpers.min(ticks);
if (tickOpts.reverse) {
ticks.reverse();
- _this.start = _this.max;
- _this.end = _this.min;
+ me.start = me.max;
+ me.end = me.min;
} else {
- _this.start = _this.min;
- _this.end = _this.max;
+ me.start = me.min;
+ me.end = me.max;
}
},
convertTicksToLabels: function() {
- var _this = this;
- _this.ticksAsNumbers = _this.ticks.slice();
- _this.zeroLineIndex = _this.ticks.indexOf(0);
+ var me = this;
+ me.ticksAsNumbers = me.ticks.slice();
+ me.zeroLineIndex = me.ticks.indexOf(0);
- Chart.Scale.prototype.convertTicksToLabels.call(_this);
+ Chart.Scale.prototype.convertTicksToLabels.call(me);
},
});
};
\ No newline at end of file | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.logarithmic.js | @@ -23,21 +23,21 @@ module.exports = function(Chart) {
var LogarithmicScale = Chart.Scale.extend({
determineDataLimits: function() {
- var _this = this;
- var opts = _this.options;
+ var me = this;
+ var opts = me.options;
var tickOpts = opts.ticks;
- var chart = _this.chart;
+ var chart = me.chart;
var data = chart.data;
var datasets = data.datasets;
var getValueOrDefault = helpers.getValueOrDefault;
- var isHorizontal = _this.isHorizontal();
+ var isHorizontal = me.isHorizontal();
function IDMatches(meta) {
- return isHorizontal ? meta.xAxisID === _this.id : meta.yAxisID === _this.id;
+ return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
}
// Calculate Range
- _this.min = null;
- _this.max = null;
+ me.min = null;
+ me.max = null;
if (opts.stacked) {
var valuesPerType = {};
@@ -51,7 +51,7 @@ module.exports = function(Chart) {
helpers.each(dataset.data, function(rawValue, index) {
var values = valuesPerType[meta.type];
- var value = +_this.getRightValue(rawValue);
+ var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
return;
}
@@ -71,67 +71,67 @@ module.exports = function(Chart) {
helpers.each(valuesPerType, function(valuesForType) {
var minVal = helpers.min(valuesForType);
var maxVal = helpers.max(valuesForType);
- _this.min = _this.min === null ? minVal : Math.min(_this.min, minVal);
- _this.max = _this.max === null ? maxVal : Math.max(_this.max, maxVal);
+ me.min = me.min === null ? minVal : Math.min(me.min, minVal);
+ me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
});
} else {
helpers.each(datasets, function(dataset, datasetIndex) {
var meta = chart.getDatasetMeta(datasetIndex);
if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
- var value = +_this.getRightValue(rawValue);
+ var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
return;
}
- if (_this.min === null) {
- _this.min = value;
- } else if (value < _this.min) {
- _this.min = value;
+ if (me.min === null) {
+ me.min = value;
+ } else if (value < me.min) {
+ me.min = value;
}
- if (_this.max === null) {
- _this.max = value;
- } else if (value > _this.max) {
- _this.max = value;
+ if (me.max === null) {
+ me.max = value;
+ } else if (value > me.max) {
+ me.max = value;
}
});
}
});
}
- _this.min = getValueOrDefault(tickOpts.min, _this.min);
- _this.max = getValueOrDefault(tickOpts.max, _this.max);
+ me.min = getValueOrDefault(tickOpts.min, me.min);
+ me.max = getValueOrDefault(tickOpts.max, me.max);
- if (_this.min === _this.max) {
- if (_this.min !== 0 && _this.min !== null) {
- _this.min = Math.pow(10, Math.floor(helpers.log10(_this.min)) - 1);
- _this.max = Math.pow(10, Math.floor(helpers.log10(_this.max)) + 1);
+ if (me.min === me.max) {
+ if (me.min !== 0 && me.min !== null) {
+ me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
+ me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
} else {
- _this.min = 1;
- _this.max = 10;
+ me.min = 1;
+ me.max = 10;
}
}
},
buildTicks: function() {
- var _this = this;
- var opts = _this.options;
+ var me = this;
+ var opts = me.options;
var tickOpts = opts.ticks;
var getValueOrDefault = helpers.getValueOrDefault;
// Reset the ticks array. Later on, we will draw a grid line at these positions
// The array simply contains the numerical value of the spots where ticks will be
- var ticks = _this.ticks = [];
+ var ticks = me.ticks = [];
// Figure out what the max number of ticks we can support it is based on the size of
// the axis area. For now, we say that the minimum tick spacing in pixels must be 50
// We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
// the graph
- var tickVal = getValueOrDefault(tickOpts.min, Math.pow(10, Math.floor(helpers.log10(_this.min))));
+ var tickVal = getValueOrDefault(tickOpts.min, Math.pow(10, Math.floor(helpers.log10(me.min))));
- while (tickVal < _this.max) {
+ while (tickVal < me.max) {
ticks.push(tickVal);
var exp = Math.floor(helpers.log10(tickVal));
@@ -148,24 +148,24 @@ module.exports = function(Chart) {
var lastTick = getValueOrDefault(tickOpts.max, tickVal);
ticks.push(lastTick);
- if (!_this.isHorizontal()) {
+ if (!me.isHorizontal()) {
// We are in a vertical orientation. The top value is the highest. So reverse the array
ticks.reverse();
}
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
- _this.max = helpers.max(ticks);
- _this.min = helpers.min(ticks);
+ me.max = helpers.max(ticks);
+ me.min = helpers.min(ticks);
if (tickOpts.reverse) {
ticks.reverse();
- _this.start = _this.max;
- _this.end = _this.min;
+ me.start = me.max;
+ me.end = me.min;
} else {
- _this.start = _this.min;
- _this.end = _this.max;
+ me.start = me.min;
+ me.end = me.max;
}
},
convertTicksToLabels: function() {
@@ -181,51 +181,51 @@ module.exports = function(Chart) {
return this.getPixelForValue(this.tickValues[index], null, null, includeOffset);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
- var _this = this;
+ var me = this;
var innerDimension;
var pixel;
- var start = _this.start;
- var newVal = +_this.getRightValue(value);
- var range = helpers.log10(_this.end) - helpers.log10(start);
- var paddingTop = _this.paddingTop;
- var paddingBottom = _this.paddingBottom;
- var paddingLeft = _this.paddingLeft;
+ var start = me.start;
+ var newVal = +me.getRightValue(value);
+ var range = helpers.log10(me.end) - helpers.log10(start);
+ var paddingTop = me.paddingTop;
+ var paddingBottom = me.paddingBottom;
+ var paddingLeft = me.paddingLeft;
- if (_this.isHorizontal()) {
+ if (me.isHorizontal()) {
if (newVal === 0) {
- pixel = _this.left + paddingLeft;
+ pixel = me.left + paddingLeft;
} else {
- innerDimension = _this.width - (paddingLeft + _this.paddingRight);
- pixel = _this.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
+ innerDimension = me.width - (paddingLeft + me.paddingRight);
+ pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
pixel += paddingLeft;
}
} else {
// Bottom - top since pixels increase downard on a screen
if (newVal === 0) {
- pixel = _this.top + paddingTop;
+ pixel = me.top + paddingTop;
} else {
- innerDimension = _this.height - (paddingTop + paddingBottom);
- pixel = (_this.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
+ innerDimension = me.height - (paddingTop + paddingBottom);
+ pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
}
}
return pixel;
},
getValueForPixel: function(pixel) {
- var _this = this;
+ var me = this;
var offset;
- var range = helpers.log10(_this.end) - helpers.log10(_this.start);
+ var range = helpers.log10(me.end) - helpers.log10(me.start);
var value;
var innerDimension;
- if (_this.isHorizontal()) {
- innerDimension = _this.width - (_this.paddingLeft + _this.paddingRight);
- value = _this.start * Math.pow(10, (pixel - _this.left - _this.paddingLeft) * range / innerDimension);
+ if (me.isHorizontal()) {
+ innerDimension = me.width - (me.paddingLeft + me.paddingRight);
+ value = me.start * Math.pow(10, (pixel - me.left - me.paddingLeft) * range / innerDimension);
} else {
- innerDimension = _this.height - (_this.paddingTop + _this.paddingBottom);
- value = Math.pow(10, (_this.bottom - _this.paddingBottom - pixel) * range / innerDimension) / _this.start;
+ innerDimension = me.height - (me.paddingTop + me.paddingBottom);
+ value = Math.pow(10, (me.bottom - me.paddingBottom - pixel) * range / innerDimension) / me.start;
}
return value; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.radialLinear.js | @@ -99,10 +99,9 @@ module.exports = function(Chart) {
me.handleTickRangeOptions();
},
getTickLimit: function() {
- var me = this;
- var tickOpts = me.options.ticks;
+ var tickOpts = this.options.ticks;
var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
- return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.drawingArea / (1.5 * tickFontSize)));
+ return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
},
convertTicksToLabels: function() {
var me = this; | true |
Other | chartjs | Chart.js | 5fae4dd3050fbd51da13ec1f5433d7f487758763.json | Change this -> me in source files
This change allows for smaller minified code in the final version, resulting in a smaller file size. Some files had previously used _this, but that has been changed to me to keep consistency throughout the project. | src/scales/scale.time.js | @@ -79,227 +79,231 @@ module.exports = function(Chart) {
return this.labelMoments[datasetIndex][index];
},
getMomentStartOf: function(tick) {
- if (this.options.time.unit === 'week' && this.options.time.isoWeekday !== false) {
- return tick.clone().startOf('isoWeek').isoWeekday(this.options.time.isoWeekday);
+ var me = this;
+ if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
+ return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
} else {
- return tick.clone().startOf(this.tickUnit);
+ return tick.clone().startOf(me.tickUnit);
}
},
determineDataLimits: function() {
- this.labelMoments = [];
+ var me = this;
+ me.labelMoments = [];
// Only parse these once. If the dataset does not have data as x,y pairs, we will use
// these
var scaleLabelMoments = [];
- if (this.chart.data.labels && this.chart.data.labels.length > 0) {
- helpers.each(this.chart.data.labels, function(label, index) {
- var labelMoment = this.parseTime(label);
+ if (me.chart.data.labels && me.chart.data.labels.length > 0) {
+ helpers.each(me.chart.data.labels, function(label, index) {
+ var labelMoment = me.parseTime(label);
if (labelMoment.isValid()) {
- if (this.options.time.round) {
- labelMoment.startOf(this.options.time.round);
+ if (me.options.time.round) {
+ labelMoment.startOf(me.options.time.round);
}
scaleLabelMoments.push(labelMoment);
}
- }, this);
+ }, me);
- this.firstTick = moment.min.call(this, scaleLabelMoments);
- this.lastTick = moment.max.call(this, scaleLabelMoments);
+ me.firstTick = moment.min.call(me, scaleLabelMoments);
+ me.lastTick = moment.max.call(me, scaleLabelMoments);
} else {
- this.firstTick = null;
- this.lastTick = null;
+ me.firstTick = null;
+ me.lastTick = null;
}
- helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
+ helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
var momentsForDataset = [];
- var datasetVisible = this.chart.isDatasetVisible(datasetIndex);
+ var datasetVisible = me.chart.isDatasetVisible(datasetIndex);
if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
helpers.each(dataset.data, function(value, index) {
- var labelMoment = this.parseTime(this.getRightValue(value));
+ var labelMoment = me.parseTime(me.getRightValue(value));
if (labelMoment.isValid()) {
- if (this.options.time.round) {
- labelMoment.startOf(this.options.time.round);
+ if (me.options.time.round) {
+ labelMoment.startOf(me.options.time.round);
}
momentsForDataset.push(labelMoment);
if (datasetVisible) {
// May have gone outside the scale ranges, make sure we keep the first and last ticks updated
- this.firstTick = this.firstTick !== null ? moment.min(this.firstTick, labelMoment) : labelMoment;
- this.lastTick = this.lastTick !== null ? moment.max(this.lastTick, labelMoment) : labelMoment;
+ me.firstTick = me.firstTick !== null ? moment.min(me.firstTick, labelMoment) : labelMoment;
+ me.lastTick = me.lastTick !== null ? moment.max(me.lastTick, labelMoment) : labelMoment;
}
}
- }, this);
+ }, me);
} else {
// We have no labels. Use the ones from the scale
momentsForDataset = scaleLabelMoments;
}
- this.labelMoments.push(momentsForDataset);
- }, this);
+ me.labelMoments.push(momentsForDataset);
+ }, me);
// Set these after we've done all the data
- if (this.options.time.min) {
- this.firstTick = this.parseTime(this.options.time.min);
+ if (me.options.time.min) {
+ me.firstTick = me.parseTime(me.options.time.min);
}
- if (this.options.time.max) {
- this.lastTick = this.parseTime(this.options.time.max);
+ if (me.options.time.max) {
+ me.lastTick = me.parseTime(me.options.time.max);
}
// We will modify these, so clone for later
- this.firstTick = (this.firstTick || moment()).clone();
- this.lastTick = (this.lastTick || moment()).clone();
+ me.firstTick = (me.firstTick || moment()).clone();
+ me.lastTick = (me.lastTick || moment()).clone();
},
buildTicks: function(index) {
+ var me = this;
- this.ctx.save();
- var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
- var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
- var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
+ me.ctx.save();
+ var tickFontSize = helpers.getValueOrDefault(me.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
+ var tickFontStyle = helpers.getValueOrDefault(me.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
+ var tickFontFamily = helpers.getValueOrDefault(me.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
- this.ctx.font = tickLabelFont;
+ me.ctx.font = tickLabelFont;
- this.ticks = [];
- this.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
- this.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
+ me.ticks = [];
+ me.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
+ me.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
// Set unit override if applicable
- if (this.options.time.unit) {
- this.tickUnit = this.options.time.unit || 'day';
- this.displayFormat = this.options.time.displayFormats[this.tickUnit];
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
- this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, 1);
+ if (me.options.time.unit) {
+ me.tickUnit = me.options.time.unit || 'day';
+ me.displayFormat = me.options.time.displayFormats[me.tickUnit];
+ me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
+ me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, 1);
} else {
// Determine the smallest needed unit of the time
- var innerWidth = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
+ var innerWidth = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
// Crude approximation of what the label length might be
- var tempFirstLabel = this.tickFormatFunction(this.firstTick, 0, []);
- var tickLabelWidth = this.ctx.measureText(tempFirstLabel).width;
- var cosRotation = Math.cos(helpers.toRadians(this.options.ticks.maxRotation));
- var sinRotation = Math.sin(helpers.toRadians(this.options.ticks.maxRotation));
+ var tempFirstLabel = me.tickFormatFunction(me.firstTick, 0, []);
+ var tickLabelWidth = me.ctx.measureText(tempFirstLabel).width;
+ var cosRotation = Math.cos(helpers.toRadians(me.options.ticks.maxRotation));
+ var sinRotation = Math.sin(helpers.toRadians(me.options.ticks.maxRotation));
tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
var labelCapacity = innerWidth / (tickLabelWidth);
// Start as small as possible
- this.tickUnit = 'millisecond';
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
- this.displayFormat = this.options.time.displayFormats[this.tickUnit];
+ me.tickUnit = 'millisecond';
+ me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
+ me.displayFormat = me.options.time.displayFormats[me.tickUnit];
var unitDefinitionIndex = 0;
var unitDefinition = time.units[unitDefinitionIndex];
// While we aren't ideal and we don't have units left
while (unitDefinitionIndex < time.units.length) {
// Can we scale this unit. If `false` we can scale infinitely
- this.unitScale = 1;
+ me.unitScale = 1;
- if (helpers.isArray(unitDefinition.steps) && Math.ceil(this.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
+ if (helpers.isArray(unitDefinition.steps) && Math.ceil(me.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
// Use one of the prefedined steps
for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
- if (unitDefinition.steps[idx] >= Math.ceil(this.scaleSizeInUnits / labelCapacity)) {
- this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, unitDefinition.steps[idx]);
+ if (unitDefinition.steps[idx] >= Math.ceil(me.scaleSizeInUnits / labelCapacity)) {
+ me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, unitDefinition.steps[idx]);
break;
}
}
break;
- } else if ((unitDefinition.maxStep === false) || (Math.ceil(this.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
+ } else if ((unitDefinition.maxStep === false) || (Math.ceil(me.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
// We have a max step. Scale this unit
- this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, Math.ceil(this.scaleSizeInUnits / labelCapacity));
+ me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, Math.ceil(me.scaleSizeInUnits / labelCapacity));
break;
} else {
// Move to the next unit up
++unitDefinitionIndex;
unitDefinition = time.units[unitDefinitionIndex];
- this.tickUnit = unitDefinition.name;
- var leadingUnitBuffer = this.firstTick.diff(this.getMomentStartOf(this.firstTick), this.tickUnit, true);
- var trailingUnitBuffer = this.getMomentStartOf(this.lastTick.clone().add(1, this.tickUnit)).diff(this.lastTick, this.tickUnit, true);
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
- this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
+ me.tickUnit = unitDefinition.name;
+ var leadingUnitBuffer = me.firstTick.diff(me.getMomentStartOf(me.firstTick), me.tickUnit, true);
+ var trailingUnitBuffer = me.getMomentStartOf(me.lastTick.clone().add(1, me.tickUnit)).diff(me.lastTick, me.tickUnit, true);
+ me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
+ me.displayFormat = me.options.time.displayFormats[unitDefinition.name];
}
}
}
var roundedStart;
// Only round the first tick if we have no hard minimum
- if (!this.options.time.min) {
- this.firstTick = this.getMomentStartOf(this.firstTick);
- roundedStart = this.firstTick;
+ if (!me.options.time.min) {
+ me.firstTick = me.getMomentStartOf(me.firstTick);
+ roundedStart = me.firstTick;
} else {
- roundedStart = this.getMomentStartOf(this.firstTick);
+ roundedStart = me.getMomentStartOf(me.firstTick);
}
// Only round the last tick if we have no hard maximum
- if (!this.options.time.max) {
- var roundedEnd = this.getMomentStartOf(this.lastTick);
- if (roundedEnd.diff(this.lastTick, this.tickUnit, true) !== 0) {
- // Do not use end of because we need this to be in the next time unit
- this.lastTick = this.getMomentStartOf(this.lastTick.add(1, this.tickUnit));
+ if (!me.options.time.max) {
+ var roundedEnd = me.getMomentStartOf(me.lastTick);
+ if (roundedEnd.diff(me.lastTick, me.tickUnit, true) !== 0) {
+ // Do not use end of because we need me to be in the next time unit
+ me.lastTick = me.getMomentStartOf(me.lastTick.add(1, me.tickUnit));
}
}
- this.smallestLabelSeparation = this.width;
+ me.smallestLabelSeparation = me.width;
- helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
- for (var i = 1; i < this.labelMoments[datasetIndex].length; i++) {
- this.smallestLabelSeparation = Math.min(this.smallestLabelSeparation, this.labelMoments[datasetIndex][i].diff(this.labelMoments[datasetIndex][i - 1], this.tickUnit, true));
+ helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
+ for (var i = 1; i < me.labelMoments[datasetIndex].length; i++) {
+ me.smallestLabelSeparation = Math.min(me.smallestLabelSeparation, me.labelMoments[datasetIndex][i].diff(me.labelMoments[datasetIndex][i - 1], me.tickUnit, true));
}
- }, this);
+ }, me);
// Tick displayFormat override
- if (this.options.time.displayFormat) {
- this.displayFormat = this.options.time.displayFormat;
+ if (me.options.time.displayFormat) {
+ me.displayFormat = me.options.time.displayFormat;
}
// first tick. will have been rounded correctly if options.time.min is not specified
- this.ticks.push(this.firstTick.clone());
+ me.ticks.push(me.firstTick.clone());
// For every unit in between the first and last moment, create a moment and add it to the ticks tick
- for (var i = 1; i <= this.scaleSizeInUnits; ++i) {
- var newTick = roundedStart.clone().add(i, this.tickUnit);
+ for (var i = 1; i <= me.scaleSizeInUnits; ++i) {
+ var newTick = roundedStart.clone().add(i, me.tickUnit);
// Are we greater than the max time
- if (this.options.time.max && newTick.diff(this.lastTick, this.tickUnit, true) >= 0) {
+ if (me.options.time.max && newTick.diff(me.lastTick, me.tickUnit, true) >= 0) {
break;
}
- if (i % this.unitScale === 0) {
- this.ticks.push(newTick);
+ if (i % me.unitScale === 0) {
+ me.ticks.push(newTick);
}
}
// Always show the right tick
- var diff = this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit);
- if (diff !== 0 || this.scaleSizeInUnits === 0) {
+ var diff = me.ticks[me.ticks.length - 1].diff(me.lastTick, me.tickUnit);
+ if (diff !== 0 || me.scaleSizeInUnits === 0) {
// this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
// but the last tick was not rounded.
- if (this.options.time.max) {
- this.ticks.push(this.lastTick.clone());
- this.scaleSizeInUnits = this.lastTick.diff(this.ticks[0], this.tickUnit, true);
+ if (me.options.time.max) {
+ me.ticks.push(me.lastTick.clone());
+ me.scaleSizeInUnits = me.lastTick.diff(me.ticks[0], me.tickUnit, true);
} else {
- this.ticks.push(this.lastTick.clone());
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
+ me.ticks.push(me.lastTick.clone());
+ me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
}
}
- this.ctx.restore();
+ me.ctx.restore();
},
// Get tooltip label
getLabelForIndex: function(index, datasetIndex) {
- var label = this.chart.data.labels && index < this.chart.data.labels.length ? this.chart.data.labels[index] : '';
+ var me = this;
+ var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
- if (typeof this.chart.data.datasets[datasetIndex].data[0] === 'object') {
- label = this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
+ if (typeof me.chart.data.datasets[datasetIndex].data[0] === 'object') {
+ label = me.getRightValue(me.chart.data.datasets[datasetIndex].data[index]);
}
// Format nicely
- if (this.options.time.tooltipFormat) {
- label = this.parseTime(label).format(this.options.time.tooltipFormat);
+ if (me.options.time.tooltipFormat) {
+ label = me.parseTime(label).format(me.options.time.tooltipFormat);
}
return label;
@@ -317,47 +321,51 @@ module.exports = function(Chart) {
}
},
convertTicksToLabels: function() {
- this.tickMoments = this.ticks;
- this.ticks = this.ticks.map(this.tickFormatFunction, this);
+ var me = this;
+ me.tickMoments = me.ticks;
+ me.ticks = me.ticks.map(me.tickFormatFunction, me);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
- var labelMoment = value && value.isValid && value.isValid() ? value : this.getLabelMoment(datasetIndex, index);
+ var me = this;
+ var labelMoment = value && value.isValid && value.isValid() ? value : me.getLabelMoment(datasetIndex, index);
if (labelMoment) {
- var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
+ var offset = labelMoment.diff(me.firstTick, me.tickUnit, true);
- var decimal = offset / this.scaleSizeInUnits;
+ var decimal = offset / me.scaleSizeInUnits;
- if (this.isHorizontal()) {
- var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
- var valueWidth = innerWidth / Math.max(this.ticks.length - 1, 1);
- var valueOffset = (innerWidth * decimal) + this.paddingLeft;
+ if (me.isHorizontal()) {
+ var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
+ var valueWidth = innerWidth / Math.max(me.ticks.length - 1, 1);
+ var valueOffset = (innerWidth * decimal) + me.paddingLeft;
- return this.left + Math.round(valueOffset);
+ return me.left + Math.round(valueOffset);
} else {
- var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
- var valueHeight = innerHeight / Math.max(this.ticks.length - 1, 1);
- var heightOffset = (innerHeight * decimal) + this.paddingTop;
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ var valueHeight = innerHeight / Math.max(me.ticks.length - 1, 1);
+ var heightOffset = (innerHeight * decimal) + me.paddingTop;
- return this.top + Math.round(heightOffset);
+ return me.top + Math.round(heightOffset);
}
}
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.tickMoments[index], null, null, includeOffset);
},
getValueForPixel: function(pixel) {
- var innerDimension = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
- var offset = (pixel - (this.isHorizontal() ? this.left + this.paddingLeft : this.top + this.paddingTop)) / innerDimension;
- offset *= this.scaleSizeInUnits;
- return this.firstTick.clone().add(moment.duration(offset, this.tickUnit).asSeconds(), 'seconds');
+ var me = this;
+ var innerDimension = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
+ var offset = (pixel - (me.isHorizontal() ? me.left + me.paddingLeft : me.top + me.paddingTop)) / innerDimension;
+ offset *= me.scaleSizeInUnits;
+ return me.firstTick.clone().add(moment.duration(offset, me.tickUnit).asSeconds(), 'seconds');
},
parseTime: function(label) {
- if (typeof this.options.time.parser === 'string') {
- return moment(label, this.options.time.parser);
+ var me = this;
+ if (typeof me.options.time.parser === 'string') {
+ return moment(label, me.options.time.parser);
}
- if (typeof this.options.time.parser === 'function') {
- return this.options.time.parser(label);
+ if (typeof me.options.time.parser === 'function') {
+ return me.options.time.parser(label);
}
// Date objects
if (typeof label.getMonth === 'function' || typeof label === 'number') {
@@ -368,12 +376,12 @@ module.exports = function(Chart) {
return label;
}
// Custom parsing (return an instance of moment)
- if (typeof this.options.time.format !== 'string' && this.options.time.format.call) {
+ if (typeof me.options.time.format !== 'string' && me.options.time.format.call) {
console.warn("options.time.format is deprecated and replaced by options.time.parser. See http://nnnick.github.io/Chart.js/docs-v2/#scales-time-scale");
- return this.options.time.format(label);
+ return me.options.time.format(label);
}
// Moment format parsing
- return moment(label, this.options.time.format);
+ return moment(label, me.options.time.format);
}
});
Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig); | true |
Other | chartjs | Chart.js | 37249e4375dde042d573f1a18aabe188aa2de1fa.json | Fix an incorrect test setup | test/controller.line.tests.js | @@ -192,7 +192,7 @@ describe('Line controller tests', function() {
chartArea: {
bottom: 200,
left: xScale.left,
- right: 200,
+ right: xScale.left + 200,
top: 0
},
data: data, | false |
Other | chartjs | Chart.js | d61745a31155843fd0583f3c6c0a08673e0d4a93.json | Handle transitioning NaNs | src/core/core.element.js | @@ -38,7 +38,7 @@
// Init if doesn't exist
else if (!this._view[key]) {
- if (typeof value === 'number') {
+ if (typeof value === 'number' && isNaN(this._view[key]) === false) {
this._view[key] = value * ease;
} else {
this._view[key] = value || null;
@@ -61,14 +61,13 @@
}
// Number transitions
else if (typeof value === 'number') {
- var startVal = this._start[key] !== undefined ? this._start[key] : 0;
+ var startVal = this._start[key] !== undefined && isNaN(this._start[key]) === false ? this._start[key] : 0;
this._view[key] = ((this._model[key] - startVal) * ease) + startVal;
}
// Everything else
else {
this._view[key] = value;
}
-
}, this);
if (ease === 1) { | true |
Other | chartjs | Chart.js | d61745a31155843fd0583f3c6c0a08673e0d4a93.json | Handle transitioning NaNs | src/scales/scale.radialLinear.js | @@ -272,7 +272,10 @@
return index * angleMultiplier - (Math.PI / 2);
},
getDistanceFromCenterForValue: function(value) {
- if (value === null) return 0; // null always in center
+ if (value === null || value === undefined || isNaN(value)) {
+ return 0; // null always in center
+ }
+
// Take into account half font size + the yPadding of the top value
var scalingFactor = this.drawingArea / (this.max - this.min);
if (this.options.reverse) { | true |
Other | chartjs | Chart.js | 05523b01b0207fd6d6ce00a45d8c6f773df4137d.json | Refactor the line drawing code. Tests are broken. | src/elements/element.line.js | @@ -31,87 +31,91 @@
Chart.elements.Line = Chart.Element.extend({
- draw: function() {
-
- var vm = this._view;
+ lineToNextPoint: function(previousPoint, point, nextPoint) {
var ctx = this._chart.ctx;
- var first = this._children[0];
- var last = this._children[this._children.length - 1];
-
- ctx.save();
-
- // Draw the background first (so the border is always on top)
- helpers.each(this._children, function(point, index) {
- var previous = helpers.previousItem(this._children, index);
- var next = helpers.nextItem(this._children, index);
-
- // First point moves to it's starting position no matter what
- if (!index) {
- ctx.moveTo(point._view.x, vm.scaleZero);
- }
-
- // Skip this point, draw to scaleZero, move to next point, and draw to next point
- if (point._view.skip && !this.loop) {
- ctx.lineTo(previous._view.x, vm.scaleZero);
- ctx.moveTo(next._view.x, vm.scaleZero);
- return;
- }
-
- // The previous line was skipped, so just draw a normal straight line to the point
- if (previous._view.skip) {
- ctx.lineTo(point._view.x, point._view.y);
- return;
+ if (point._view.skip) {
+ if (this.loop) {
+ // Go to center
+ ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
+ } else {
+ ctx.lineTo(previousPoint._view.x, this._view.scaleZero);
+ ctx.moveTo(next._view.x, this._view.scaleZero);
}
-
- // Draw a bezier to point
- if (vm.tension > 0 && index) {
- //ctx.lineTo(point._view.x, point._view.y);
+ } else if (previousPoint._view.skip) {
+ ctx.lineTo(point._view.x, point._view.y);
+ } else {
+ // Line between points
+ //if (point !== nextPoint) {
ctx.bezierCurveTo(
- previous._view.controlPointNextX,
- previous._view.controlPointNextY,
+ previousPoint._view.controlPointNextX,
+ previousPoint._view.controlPointNextY,
point._view.controlPointPreviousX,
point._view.controlPointPreviousY,
point._view.x,
point._view.y
);
- return;
- }
+ //} else {
+ // Drawing to the last point in the line
- // Draw a straight line to the point
- ctx.lineTo(point._view.x, point._view.y);
+ //}
+ }
+ },
- }, this);
+ draw: function() {
- // For radial scales, loop back around to the first point
- if (this._loop) {
- // Draw a bezier line
- if (vm.tension > 0 && !first._view.skip) {
- ctx.bezierCurveTo(
- last._view.controlPointNextX,
- last._view.controlPointNextY,
- first._view.controlPointPreviousX,
- first._view.controlPointPreviousY,
- first._view.x,
- first._view.y
- );
- return;
- }
- // Draw a straight line
- ctx.lineTo(first._view.x, first._view.y);
- }
+ var vm = this._view;
+ var ctx = this._chart.ctx;
+ var first = this._children[0];
+ var last = this._children[this._children.length - 1];
+
+ ctx.save();
// If we had points and want to fill this line, do so.
if (this._children.length > 0 && vm.fill) {
- //Round off the line by going to the base of the chart, back to the start, then fill.
- ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
- ctx.lineTo(this._children[0]._view.x, vm.scaleZero);
+ // Draw the background first (so the border is always on top)
+ ctx.beginPath();
+
+ helpers.each(this._children, function(point, index) {
+ var previous = helpers.previousItem(this._children, index/*, this._loop*/);
+ var next = helpers.nextItem(this._children, index/*, this._loop*/);
+
+ // First point moves to it's starting position no matter what
+ if (index === 0) {
+ ctx.moveTo(point._view.x, vm.scaleZero);
+ ctx.lineTo(point._view.x, point._view.y);
+ } else {
+ this.lineToNextPoint(previous, point, next);
+ }
+ }, this);
+
+ // For radial scales, loop back around to the first point
+ if (this._loop) {
+ if (!first._view.skip) {
+ // Draw a bezier line
+ ctx.bezierCurveTo(
+ last._view.controlPointNextX,
+ last._view.controlPointNextY,
+ first._view.controlPointPreviousX,
+ first._view.controlPointPreviousY,
+ first._view.x,
+ first._view.y
+ );
+ } else {
+ // Go to center
+ ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
+ }
+ } else {
+ //Round off the line by going to the base of the chart, back to the start, then fill.
+ ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
+ ctx.lineTo(this._children[0]._view.x, vm.scaleZero);
+ }
+
ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor;
ctx.closePath();
ctx.fill();
}
-
// Now draw the line between all the points with any borders
ctx.lineCap = vm.borderCapStyle || Chart.defaults.global.elements.line.borderCapStyle;
@@ -130,49 +134,16 @@
var previous = helpers.previousItem(this._children, index);
var next = helpers.nextItem(this._children, index);
- if (!index) {
- ctx.moveTo(point._view.x, vm.scaleZero);
- }
-
- // Skip this point and move to the next points zeroPoint
- if (point._view.skip && !this.loop) {
- ctx.moveTo(next._view.x, vm.scaleZero);
- return;
- }
-
- // Previous point was skipped, just move to the point
- if (previous._view.skip) {
- ctx.moveTo(point._view.x, point._view.y);
- return;
- }
-
- // If First point, move to the point ahead of time (so a line doesn't get drawn up the left axis)
- if (!index) {
+ if (index === 0) {
ctx.moveTo(point._view.x, point._view.y);
+ } else {
+ this.lineToNextPoint(previous, point, next);
}
-
- // Draw a bezier line to the point
- if (vm.tension > 0 && index) {
- ctx.bezierCurveTo(
- previous._view.controlPointNextX,
- previous._view.controlPointNextY,
- point._view.controlPointPreviousX,
- point._view.controlPointPreviousY,
- point._view.x,
- point._view.y
- );
- return;
- }
-
- // Draw a straight line to the point
- ctx.lineTo(point._view.x, point._view.y);
-
}, this);
- if (this._loop && !first._view.skip) {
-
- // Draw a bezier line to the first point
- if (vm.tension > 0) {
+ if (this._loop) {
+ if (!first._view.skip) {
+ // Draw a bezier line
ctx.bezierCurveTo(
last._view.controlPointNextX,
last._view.controlPointNextY,
@@ -181,11 +152,10 @@
first._view.x,
first._view.y
);
- return;
+ } else {
+ // Go to center
+ ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
}
-
- // Draw a straight line to the first point
- ctx.lineTo(first._view.x, first._view.y);
}
ctx.stroke(); | false |
Other | chartjs | Chart.js | 3d15e1ff54045e7f449139a2fc8e70e29d558fd2.json | Update doc for options.ticks.maxTicksLimit | docs/01-Scales.md | @@ -209,6 +209,9 @@ The radial linear scale extends the core scale class with the following tick tem
//Number - The backdrop padding to the side of the label in pixels
backdropPaddingX: 2,
+
+ //Number - Limit the maximum number of ticks
+ maxTicksLimit: 11,
},
pointLabels: { | false |
Other | chartjs | Chart.js | 178880bace3a9091db8bd2bc3ac55b6c48552a70.json | Update doc for options.ticks.maxTicksLimit | docs/01-Scales.md | @@ -49,6 +49,7 @@ Chart.defaults.scale = {
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
+ maxTicksLimit: 11,
maxRotation: 90,
minRotation: 20,
mirror: false, | false |
Other | chartjs | Chart.js | a5e382ab8af7064812300fb8c31856efd2755b7b.json | add composer file
add composer file | composer.json | @@ -0,0 +1,26 @@
+{
+ "name": "nnnick/chartjs",
+ "type": "library",
+ "description": "Simple HTML5 charts using the canvas element.",
+ "keywords": [
+ "chart",
+ "js"
+ ],
+ "homepage": "http://www.chartjs.org/",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "NICK DOWNIE",
+ "email": "hello@nickdownie.com"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "minimum-stability": "stable",
+ "extra": {
+ "branch-alias": {
+ "release/2.0": "v2.0-dev"
+ }
+ }
+} | false |
Other | chartjs | Chart.js | 8324b35506459407cbfeacbbc5e66b2655823cba.json | Update linear scale + tests | src/scales/scale.linear.js | @@ -42,11 +42,21 @@
this.min = null;
this.max = null;
- var positiveValues = [];
- var negativeValues = [];
-
if (this.options.stacked) {
+ var valuesPerType = {};
+
helpers.each(this.data.datasets, function(dataset) {
+ if (valuesPerType[dataset.type] === undefined) {
+ valuesPerType[dataset.type] = {
+ positiveValues: [],
+ negativeValues: [],
+ };
+ }
+
+ // Store these per type
+ var positiveValues = valuesPerType[dataset.type].positiveValues;
+ var negativeValues = valuesPerType[dataset.type].negativeValues;
+
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
@@ -71,9 +81,11 @@
}
}, this);
- var values = positiveValues.concat(negativeValues);
- this.min = helpers.min(values);
- this.max = helpers.max(values);
+ helpers.each(valuesPerType, function(valuesForType) {
+ var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
+ this.min = Math.min(this.min, helpers.min(values));
+ this.max = Math.max(this.max, helpers.max(values));
+ }, this);
} else {
helpers.each(this.data.datasets, function(dataset) { | true |
Other | chartjs | Chart.js | 8324b35506459407cbfeacbbc5e66b2655823cba.json | Update linear scale + tests | test/scale.linear.tests.js | @@ -188,13 +188,19 @@ describe('Linear Scale', function() {
var mockData = {
datasets: [{
yAxisID: scaleID,
- data: [10, 5, 0, -5, 78, -100]
+ data: [10, 5, 0, -5, 78, -100],
+ type: 'bar'
}, {
yAxisID: 'second scale',
data: [-1000, 1000],
}, {
yAxisID: scaleID,
- data: [150, 0, 0, -100, -10, 9]
+ data: [150, 0, 0, -100, -10, 9],
+ type: 'bar'
+ }, {
+ yAxisID: scaleID,
+ data: [10, 10, 10, 10, 10, 10],
+ type: 'line'
}]
};
| true |
Other | chartjs | Chart.js | 53d13f70268105515cdb56c5ebe593a3c5bebadb.json | Try beta Chrome (#6933)
* Try beta chrome
* Update path | .travis.yml | @@ -3,7 +3,7 @@ node_js:
- lts/*
before_install:
- - "export CHROME_BIN=/usr/bin/google-chrome"
+ - "export CHROME_BIN=/usr/bin/google-chrome-beta"
services:
- xvfb
@@ -20,7 +20,7 @@ sudo: required
dist: bionic
addons:
- chrome: stable
+ chrome: beta
firefox: latest
# IMPORTANT: scripts require GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables | false |
Other | chartjs | Chart.js | d04cdfc21fdb15948184bfe3a6f242a0ceec2e08.json | Add the ability to add a title to the legend (#6906)
* Add the ability to add a title to the legend
- Legend title can be specified
- Font & color options added
- Padding option added
- Positioning option added
- Legend title sample file added | docs/configuration/legend.md | @@ -19,6 +19,7 @@ The legend configuration is passed into the `options.legend` namespace. The glob
| `labels` | `object` | | See the [Legend Label Configuration](#legend-label-configuration) section below.
| `rtl` | `boolean` | | `true` for rendering the legends from right to left.
| `textDirection` | `string` | canvas' default | This will force the text direction `'rtl'|'ltr` on the canvas for rendering the legend, regardless of the css specified on the canvas
+| `title` | `object` | | See the [Legend Title Configuration](#legend-title-configuration) section below.
## Position
@@ -55,6 +56,21 @@ The legend label configuration is nested below the legend configuration using th
| `filter` | `function` | `null` | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#legend-item-interface) and the chart data.
| `usePointStyle` | `boolean` | `false` | Label style will match corresponding point style (size is based on the mimimum value between boxWidth and fontSize).
+## Legend Title Configuration
+
+The legend title configuration is nested below the legend configuration using the `title` key.
+
+| Name | Type | Default | Description
+| ---- | ---- | ------- | -----------
+| `display` | `boolean` | `false` | Is the legend title displayed.
+| `fontSize` | `number` | `12` | Font size of text.
+| `fontStyle` | `string` | `'normal'` | Font style of text.
+| `fontColor` | `Color` | `'#666'` | Color of text.
+| `fontFamily` | `string` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Font family of legend text.
+| `lineHeight` | `number` | | Line height of the text. If unset, is computed from the font size.
+| `padding` | <code>number|object</code> | `0` | Padding around the title. If specified as a number, it applies evenly to all sides.
+| `text` | `string` | | The string title.
+
## Legend Item Interface
Items passed to the legend `onClick` function are the ones returned from `labels.generateLabels`. These items must implement the following interface. | true |
Other | chartjs | Chart.js | d04cdfc21fdb15948184bfe3a6f242a0ceec2e08.json | Add the ability to add a title to the legend (#6906)
* Add the ability to add a title to the legend
- Legend title can be specified
- Font & color options added
- Padding option added
- Positioning option added
- Legend title sample file added | samples/legend/title.html | @@ -0,0 +1,153 @@
+<!doctype html>
+<html>
+
+<head>
+ <title>Legend Positions</title>
+ <script src="../../dist/Chart.min.js"></script>
+ <script src="../utils.js"></script>
+ <style>
+ canvas {
+ -moz-user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+ }
+ .chart-container {
+ width: 500px;
+ margin-left: 40px;
+ margin-right: 40px;
+ }
+ .container {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ justify-content: center;
+ }
+ </style>
+</head>
+
+<body>
+ <div class="container">
+ <div class="chart-container">
+ <canvas id="chart-legend-top-start"></canvas>
+ </div>
+ <div class="chart-container">
+ <canvas id="chart-legend-top-center"></canvas>
+ </div>
+ <div class="chart-container">
+ <canvas id="chart-legend-top-end"></canvas>
+ </div>
+ <div class="chart-container">
+ <canvas id="chart-legend-left-start"></canvas>
+ </div>
+ <div class="chart-container">
+ <canvas id="chart-legend-left-center"></canvas>
+ </div>
+ <div class="chart-container">
+ <canvas id="chart-legend-left-end"></canvas>
+ </div>
+ </div>
+ <script>
+ var color = Chart.helpers.color;
+ function createConfig(legendPosition, titlePosition, align, colorName) {
+ return {
+ type: 'line',
+ data: {
+ labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
+ datasets: [{
+ label: 'My First dataset',
+ data: [
+ randomScalingFactor(),
+ randomScalingFactor(),
+ randomScalingFactor(),
+ randomScalingFactor(),
+ randomScalingFactor(),
+ randomScalingFactor(),
+ randomScalingFactor()
+ ],
+ backgroundColor: color(window.chartColors[colorName]).alpha(0.5).rgbString(),
+ borderColor: window.chartColors[colorName],
+ borderWidth: 1
+ }]
+ },
+ options: {
+ responsive: true,
+ legend: {
+ align: align,
+ position: legendPosition,
+ title: {
+ display: true,
+ text: 'Legend Title',
+ position: titlePosition,
+ }
+ },
+ scales: {
+ x: {
+ display: true,
+ scaleLabel: {
+ display: true,
+ labelString: 'Month'
+ }
+ },
+ y: {
+ display: true,
+ scaleLabel: {
+ display: true,
+ labelString: 'Value'
+ }
+ }
+ },
+ title: {
+ display: true,
+ text: 'Legend Title Position: ' + titlePosition
+ }
+ }
+ };
+ }
+
+ window.onload = function() {
+ [{
+ id: 'chart-legend-top-start',
+ align: 'start',
+ legendPosition: 'top',
+ titlePosition: 'start',
+ color: 'red'
+ }, {
+ id: 'chart-legend-top-center',
+ align: 'center',
+ legendPosition: 'top',
+ titlePosition: 'center',
+ color: 'orange'
+ }, {
+ id: 'chart-legend-top-end',
+ align: 'end',
+ legendPosition: 'top',
+ titlePosition: 'end',
+ color: 'yellow'
+ }, {
+ id: 'chart-legend-left-start',
+ align: 'start',
+ legendPosition: 'left',
+ titlePosition: 'start',
+ color: 'green'
+ }, {
+ id: 'chart-legend-left-center',
+ align: 'center',
+ legendPosition: 'left',
+ titlePosition: 'center',
+ color: 'blue'
+ }, {
+ id: 'chart-legend-left-end',
+ align: 'end',
+ legendPosition: 'left',
+ titlePosition: 'end',
+ color: 'purple'
+ }].forEach(function(details) {
+ var ctx = document.getElementById(details.id).getContext('2d');
+ var config = createConfig(details.legendPosition, details.titlePosition, details.align, details.color);
+ new Chart(ctx, config);
+ });
+ };
+ </script>
+</body>
+
+</html> | true |
Other | chartjs | Chart.js | d04cdfc21fdb15948184bfe3a6f242a0ceec2e08.json | Add the ability to add a title to the legend (#6906)
* Add the ability to add a title to the legend
- Legend title can be specified
- Font & color options added
- Padding option added
- Positioning option added
- Legend title sample file added | samples/samples.js | @@ -163,6 +163,9 @@
items: [{
title: 'Positioning',
path: 'legend/positioning.html'
+ }, {
+ title: 'Legend Title',
+ path: 'legend/title.html'
}, {
title: 'Point style',
path: 'legend/point-style.html' | true |
Other | chartjs | Chart.js | d04cdfc21fdb15948184bfe3a6f242a0ceec2e08.json | Add the ability to add a title to the legend (#6906)
* Add the ability to add a title to the legend
- Legend title can be specified
- Font & color options added
- Padding option added
- Positioning option added
- Legend title sample file added | src/plugins/plugin.legend.js | @@ -72,6 +72,12 @@ defaults._set('legend', {
};
}, this);
}
+ },
+
+ title: {
+ display: false,
+ position: 'center',
+ text: '',
}
});
@@ -210,21 +216,21 @@ class Legend extends Element {
beforeFit() {}
fit() {
- var me = this;
- var opts = me.options;
- var labelOpts = opts.labels;
- var display = opts.display;
-
- var ctx = me.ctx;
+ const me = this;
+ const opts = me.options;
+ const labelOpts = opts.labels;
+ const display = opts.display;
- var labelFont = helpers.options._parseFont(labelOpts);
- var fontSize = labelFont.size;
+ const ctx = me.ctx;
+ const labelFont = helpers.options._parseFont(labelOpts);
+ const fontSize = labelFont.size;
// Reset hit boxes
- var hitboxes = me.legendHitBoxes = [];
+ const hitboxes = me.legendHitBoxes = [];
- var minSize = me._minSize;
- var isHorizontal = me.isHorizontal();
+ const minSize = me._minSize;
+ const isHorizontal = me.isHorizontal();
+ const titleHeight = me._computeTitleHeight();
if (isHorizontal) {
minSize.width = me.maxWidth; // fill all the width
@@ -242,18 +248,16 @@ class Legend extends Element {
ctx.font = labelFont.string;
if (isHorizontal) {
- // Labels
-
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
- var lineWidths = me.lineWidths = [0];
- var totalHeight = 0;
+ const lineWidths = me.lineWidths = [0];
+ let totalHeight = titleHeight;
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
me.legendItems.forEach(function(legendItem, i) {
- var boxWidth = getBoxWidth(labelOpts, fontSize);
- var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
+ const boxWidth = getBoxWidth(labelOpts, fontSize);
+ const width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
if (i === 0 || lineWidths[lineWidths.length - 1] + width + 2 * labelOpts.padding > minSize.width) {
totalHeight += fontSize + labelOpts.padding;
@@ -274,19 +278,20 @@ class Legend extends Element {
minSize.height += totalHeight;
} else {
- var vPadding = labelOpts.padding;
- var columnWidths = me.columnWidths = [];
- var columnHeights = me.columnHeights = [];
- var totalWidth = labelOpts.padding;
- var currentColWidth = 0;
- var currentColHeight = 0;
-
+ const vPadding = labelOpts.padding;
+ const columnWidths = me.columnWidths = [];
+ const columnHeights = me.columnHeights = [];
+ let totalWidth = labelOpts.padding;
+ let currentColWidth = 0;
+ let currentColHeight = 0;
+
+ let heightLimit = minSize.height - titleHeight;
me.legendItems.forEach(function(legendItem, i) {
- var boxWidth = getBoxWidth(labelOpts, fontSize);
- var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
+ const boxWidth = getBoxWidth(labelOpts, fontSize);
+ const itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
// If too tall, go to new column
- if (i > 0 && currentColHeight + fontSize + 2 * vPadding > minSize.height) {
+ if (i > 0 && currentColHeight + fontSize + 2 * vPadding > heightLimit) {
totalWidth += currentColWidth + labelOpts.padding;
columnWidths.push(currentColWidth); // previous column width
columnHeights.push(currentColHeight);
@@ -326,26 +331,27 @@ class Legend extends Element {
// Actually draw the legend on the canvas
draw() {
- var me = this;
- var opts = me.options;
- var labelOpts = opts.labels;
- var defaultColor = defaults.color;
- var lineDefault = defaults.elements.line;
- var legendHeight = me.height;
- var columnHeights = me.columnHeights;
- var legendWidth = me.width;
- var lineWidths = me.lineWidths;
+ const me = this;
+ const opts = me.options;
+ const labelOpts = opts.labels;
+ const defaultColor = defaults.color;
+ const lineDefault = defaults.elements.line;
+ const legendHeight = me.height;
+ const columnHeights = me.columnHeights;
+ const legendWidth = me.width;
+ const lineWidths = me.lineWidths;
if (!opts.display) {
return;
}
- var rtlHelper = getRtlHelper(opts.rtl, me.left, me._minSize.width);
- var ctx = me.ctx;
- var fontColor = valueOrDefault(labelOpts.fontColor, defaults.fontColor);
- var labelFont = helpers.options._parseFont(labelOpts);
- var fontSize = labelFont.size;
- var cursor;
+ me._drawTitle();
+ const rtlHelper = getRtlHelper(opts.rtl, me.left, me._minSize.width);
+ const ctx = me.ctx;
+ const fontColor = valueOrDefault(labelOpts.fontColor, defaults.fontColor);
+ const labelFont = helpers.options._parseFont(labelOpts);
+ const fontSize = labelFont.size;
+ let cursor;
// Canvas setup
ctx.textAlign = rtlHelper.textAlign('left');
@@ -429,17 +435,18 @@ class Legend extends Element {
};
// Horizontal
- var isHorizontal = me.isHorizontal();
+ const isHorizontal = me.isHorizontal();
+ const titleHeight = this._computeTitleHeight();
if (isHorizontal) {
cursor = {
x: me.left + alignmentOffset(legendWidth, lineWidths[0]),
- y: me.top + labelOpts.padding,
+ y: me.top + labelOpts.padding + titleHeight,
line: 0
};
} else {
cursor = {
x: me.left + labelOpts.padding,
- y: me.top + alignmentOffset(legendHeight, columnHeights[0]),
+ y: me.top + alignmentOffset(legendHeight, columnHeights[0]) + titleHeight,
line: 0
};
}
@@ -490,6 +497,95 @@ class Legend extends Element {
helpers.rtl.restoreTextDirection(me.ctx, opts.textDirection);
}
+ _drawTitle() {
+ const me = this;
+ const opts = me.options;
+ const titleOpts = opts.title;
+ const titleFont = helpers.options._parseFont(titleOpts);
+ const titlePadding = helpers.options.toPadding(titleOpts.padding);
+
+ if (!titleOpts.display) {
+ return;
+ }
+
+ const rtlHelper = getRtlHelper(opts.rtl, me.left, me.minSize.width);
+ const ctx = me.ctx;
+ const fontColor = valueOrDefault(titleOpts.fontColor, defaults.fontColor);
+ const position = titleOpts.position;
+ let x, textAlign;
+
+ const halfFontSize = titleFont.size / 2;
+ let y = me.top + titlePadding.top + halfFontSize;
+
+ // These defaults are used when the legend is vertical.
+ // When horizontal, they are computed below.
+ let left = me.left;
+ let maxWidth = me.width;
+
+ if (this.isHorizontal()) {
+ // Move left / right so that the title is above the legend lines
+ maxWidth = Math.max(...me.lineWidths);
+ switch (opts.align) {
+ case 'start':
+ // left is already correct in this case
+ break;
+ case 'end':
+ left = me.right - maxWidth;
+ break;
+ default:
+ left = ((me.left + me.right) / 2) - (maxWidth / 2);
+ break;
+ }
+ } else {
+ // Move down so that the title is above the legend stack in every alignment
+ const maxHeight = Math.max(...me.columnHeights);
+ switch (opts.align) {
+ case 'start':
+ // y is already correct in this case
+ break;
+ case 'end':
+ y += me.height - maxHeight;
+ break;
+ default: // center
+ y += (me.height - maxHeight) / 2;
+ break;
+ }
+ }
+
+ // Now that we know the left edge of the inner legend box, compute the correct
+ // X coordinate from the title alignment
+ switch (position) {
+ case 'start':
+ x = left;
+ textAlign = 'left';
+ break;
+ case 'end':
+ x = left + maxWidth;
+ textAlign = 'right';
+ break;
+ default:
+ x = left + (maxWidth / 2);
+ textAlign = 'center';
+ break;
+ }
+
+ // Canvas setup
+ ctx.textAlign = rtlHelper.textAlign(textAlign);
+ ctx.textBaseline = 'middle';
+ ctx.strokeStyle = fontColor;
+ ctx.fillStyle = fontColor;
+ ctx.font = titleFont.string;
+
+ ctx.fillText(titleOpts.text, x, y);
+ }
+
+ _computeTitleHeight() {
+ const titleOpts = this.options.title;
+ const titleFont = helpers.options._parseFont(titleOpts);
+ const titlePadding = helpers.options.toPadding(titleOpts.padding);
+ return titleOpts.display ? titleFont.lineHeight + titlePadding.height : 0;
+ }
+
/**
* @private
*/ | true |
Other | chartjs | Chart.js | d04cdfc21fdb15948184bfe3a6f242a0ceec2e08.json | Add the ability to add a title to the legend (#6906)
* Add the ability to add a title to the legend
- Legend title can be specified
- Font & color options added
- Padding option added
- Positioning option added
- Legend title sample file added | test/specs/plugin.legend.tests.js | @@ -20,6 +20,12 @@ describe('Legend block tests', function() {
boxWidth: 40,
padding: 10,
generateLabels: jasmine.any(Function)
+ },
+
+ title: {
+ display: false,
+ position: 'center',
+ text: '',
}
});
}); | true |
Other | chartjs | Chart.js | 547aa515440def05a3c2ab998919faead7d102f5.json | Draw active points last (#6944) | src/controllers/controller.line.js | @@ -164,16 +164,26 @@ export default DatasetController.extend({
const meta = me._cachedMeta;
const points = meta.data || [];
const area = chart.chartArea;
- const ilen = points.length;
- let i = 0;
+ const active = [];
+ let ilen = points.length;
+ let i, point;
if (me._showLine) {
meta.dataset.draw(ctx, area);
}
+
// Draw the points
- for (; i < ilen; ++i) {
- points[i].draw(ctx, area);
+ for (i = 0; i < ilen; ++i) {
+ point = points[i];
+ if (point.active) {
+ active.push(point);
+ } else {
+ point.draw(ctx, area);
+ }
+ }
+ for (i = 0, ilen = active.length; i < ilen; ++i) {
+ active[i].draw(ctx, area);
}
},
}); | true |
Other | chartjs | Chart.js | 547aa515440def05a3c2ab998919faead7d102f5.json | Draw active points last (#6944) | src/core/core.datasetController.js | @@ -1006,6 +1006,7 @@ helpers.extend(DatasetController.prototype, {
* @private
*/
_setStyle(element, index, mode, active) {
+ element.active = active;
this._resolveAnimations(index, mode, active).update(element, {options: this.getStyle(index, active)});
},
| true |
Other | chartjs | Chart.js | 8d7d5571cfc99e9ebd3466e9a7c40157e46e9ce3.json | Update moment to 2.24 in samples (#6948) | samples/scales/time/combo.html | @@ -3,7 +3,7 @@
<head>
<title>Line Chart - Combo Time Scale</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/moment@2.24.0/moment.min.js"></script>
<script src="../../../dist/Chart.min.js"></script>
<script src="../../utils.js"></script>
<style> | true |
Other | chartjs | Chart.js | 8d7d5571cfc99e9ebd3466e9a7c40157e46e9ce3.json | Update moment to 2.24 in samples (#6948) | samples/scales/time/financial.html | @@ -3,7 +3,7 @@
<head>
<title>Line Chart</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/moment@2.24.0/moment.min.js"></script>
<script src="../../../dist/Chart.min.js"></script>
<script src="../../utils.js"></script>
<style> | true |
Other | chartjs | Chart.js | 8d7d5571cfc99e9ebd3466e9a7c40157e46e9ce3.json | Update moment to 2.24 in samples (#6948) | samples/scales/time/line-point-data.html | @@ -3,7 +3,7 @@
<head>
<title>Time Scale Point Data</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/moment@2.24.0/moment.min.js"></script>
<script src="../../../dist/Chart.min.js"></script>
<script src="../../utils.js"></script>
<style> | true |
Other | chartjs | Chart.js | 8d7d5571cfc99e9ebd3466e9a7c40157e46e9ce3.json | Update moment to 2.24 in samples (#6948) | samples/scales/time/line.html | @@ -3,7 +3,7 @@
<head>
<title>Line Chart</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/moment@2.24.0/moment.min.js"></script>
<script src="../../../dist/Chart.min.js"></script>
<script src="../../utils.js"></script>
<style> | true |
Other | chartjs | Chart.js | 404c1a08c7ac4fae4a3711c850ca610815349116.json | Fix broken config in log scatter sample (#6937) | samples/scales/logarithmic/scatter.html | @@ -137,7 +137,7 @@
type: 'logarithmic',
position: 'bottom',
ticks: {
- userCallback: function(tick) {
+ callback: function(tick) {
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.math.log10(tick))));
if (remain === 1 || remain === 2 || remain === 5) {
return tick.toString() + 'Hz';
@@ -153,7 +153,7 @@
y: {
type: 'linear',
ticks: {
- userCallback: function(tick) {
+ callback: function(tick) {
return tick.toString() + 'dB';
}
}, | false |
Other | chartjs | Chart.js | a0dd9566c39348028f41d77db4e8c4f653c644b0.json | Upgrade Ubuntu on Travis to match GitHub actions (#6932) | .travis.yml | @@ -17,6 +17,7 @@ script:
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls || true
sudo: required
+dist: bionic
addons:
chrome: stable | false |
Other | chartjs | Chart.js | 2dd0c2f8feb8eef45e0b077ffa9a648d0c1229c6.json | Remove futile optimization (#6928) | src/controllers/controller.bubble.js | @@ -125,9 +125,8 @@ module.exports = DatasetController.extend({
const firstOpts = me._resolveDataElementOptions(start, mode);
const sharedOptions = me._getSharedOptions(mode, points[start], firstOpts);
const includeOptions = me._includeOptions(mode, sharedOptions);
- let i;
- for (i = 0; i < points.length; i++) {
+ for (let i = 0; i < points.length; i++) {
const point = points[i];
const index = start + i;
const parsed = !reset && me._getParsed(index);
@@ -140,8 +139,7 @@ module.exports = DatasetController.extend({
};
if (includeOptions) {
- properties.options = i === 0 ? firstOpts
- : me._resolveDataElementOptions(i, mode);
+ properties.options = me._resolveDataElementOptions(i, mode);
if (reset) {
properties.options.radius = 0; | true |
Other | chartjs | Chart.js | 2dd0c2f8feb8eef45e0b077ffa9a648d0c1229c6.json | Remove futile optimization (#6928) | src/controllers/controller.line.js | @@ -98,9 +98,8 @@ module.exports = DatasetController.extend({
const firstOpts = me._resolveDataElementOptions(start, mode);
const sharedOptions = me._getSharedOptions(mode, points[start], firstOpts);
const includeOptions = me._includeOptions(mode, sharedOptions);
- let i;
- for (i = 0; i < points.length; ++i) {
+ for (let i = 0; i < points.length; ++i) {
const index = start + i;
const point = points[i];
const parsed = me._getParsed(index);
@@ -113,8 +112,7 @@ module.exports = DatasetController.extend({
};
if (includeOptions) {
- properties.options = i === 0 ? firstOpts
- : me._resolveDataElementOptions(index, mode);
+ properties.options = me._resolveDataElementOptions(index, mode);
}
me._updateElement(point, index, properties, mode); | true |
Other | chartjs | Chart.js | 9cb65d2c97136dab4e6ed8f44f3d3d5dd2cda88b.json | Add API to change data visibility (#6907) | docs/developers/api.md | @@ -147,3 +147,21 @@ Extensive examples of usage are available in the [Chart.js tests](https://github
var meta = myChart.getDatasetMeta(0);
var x = meta.data[0].x;
```
+
+## setDatasetVisibility(datasetIndex, visibility)
+
+Sets the visibility for a given dataset. This can be used to build a chart legend in HTML. During click on one of the HTML items, you can call `setDatasetVisibility` to change the appropriate dataset.
+
+```javascript
+chart.setDatasetVisibility(1, false); // hides dataset at index 1
+chart.update(); // chart now renders with dataset hidden
+```
+
+## setDataVisibility(datasetIndex, index, visibility)
+
+Like [setDatasetVisibility](#setdatasetvisibility) except that it hides only a single item in the dataset. **Note** this only applies to polar area and doughnut charts at the moment. It will have no affect on line, bar, radar, or scatter charts.
+
+```javascript
+chart.setDataVisibility(0, 2, false); // hides the item in dataset 0, at index 2
+chart.update(); // chart now renders with item hidden
+```
\ No newline at end of file | true |
Other | chartjs | Chart.js | 9cb65d2c97136dab4e6ed8f44f3d3d5dd2cda88b.json | Add API to change data visibility (#6907) | src/core/core.controller.js | @@ -810,6 +810,19 @@ class Chart {
return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
}
+ setDatasetVisibility(datasetIndex, visible) {
+ const meta = this.getDatasetMeta(datasetIndex);
+ meta.hidden = !visible;
+ }
+
+ setDataVisibility(datasetIndex, index, visible) {
+ const meta = this.getDatasetMeta(datasetIndex);
+
+ if (meta.data[index]) {
+ meta.data[index].hidden = !visible;
+ }
+ }
+
/**
* @private
*/ | true |
Other | chartjs | Chart.js | 9cb65d2c97136dab4e6ed8f44f3d3d5dd2cda88b.json | Add API to change data visibility (#6907) | test/specs/core.controller.tests.js | @@ -1347,4 +1347,39 @@ describe('Chart', function() {
expect(metasets[3].order).toEqual(3);
});
});
+
+ describe('data visibility', function() {
+ it('should hide a dataset', function() {
+ var chart = acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [0, 1, 2]
+ }],
+ labels: ['a', 'b', 'c']
+ }
+ });
+
+ chart.setDatasetVisibility(0, false);
+
+ var meta = chart.getDatasetMeta(0);
+ expect(meta.hidden).toBe(true);
+ });
+
+ it('should hide a single data item', function() {
+ var chart = acquireChart({
+ type: 'polarArea',
+ data: {
+ datasets: [{
+ data: [1, 2, 3]
+ }]
+ }
+ });
+
+ chart.setDataVisibility(0, 1, false);
+
+ var meta = chart.getDatasetMeta(0);
+ expect(meta.data[1].hidden).toBe(true);
+ });
+ });
}); | true |
Other | chartjs | Chart.js | ac85ce41db282368de50cf7dfdb9cf386cbfbf62.json | Handle font sizes that are set as strings (#6921) | src/helpers/helpers.options.js | @@ -90,8 +90,13 @@ export function toPadding(value) {
* @private
*/
export function _parseFont(options) {
- var size = valueOrDefault(options.fontSize, defaults.fontSize);
- var font = {
+ let size = valueOrDefault(options.fontSize, defaults.fontSize);
+
+ if (typeof size === 'string') {
+ size = parseInt(size, 10);
+ }
+
+ const font = {
family: valueOrDefault(options.fontFamily, defaults.fontFamily),
lineHeight: toLineHeight(valueOrDefault(options.lineHeight, defaults.lineHeight), size),
size: size, | true |
Other | chartjs | Chart.js | ac85ce41db282368de50cf7dfdb9cf386cbfbf62.json | Handle font sizes that are set as strings (#6921) | test/specs/helpers.options.tests.js | @@ -113,6 +113,21 @@ describe('Chart.helpers.options', function() {
weight: null
});
});
+ it ('should handle a string font size', function() {
+ expect(parseFont({
+ fontFamily: 'bla',
+ lineHeight: 8,
+ fontSize: '21',
+ fontStyle: 'zzz'
+ })).toEqual({
+ family: 'bla',
+ lineHeight: 8 * 21,
+ size: 21,
+ string: 'zzz 21px bla',
+ style: 'zzz',
+ weight: null
+ });
+ });
it('should return null as a font string if fontSize or fontFamily are missing', function() {
const fontFamily = Chart.defaults.fontFamily;
const fontSize = Chart.defaults.fontSize; | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.