Socket
Socket
Sign inDemoInstall

chart.js

Package Overview
Dependencies
Maintainers
3
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chart.js - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

4

bower.json
{
"name": "Chart.js",
"version": "2.1.0",
"version": "2.1.1",
"description": "Simple HTML5 Charts using the canvas element",
"homepage": "https://github.com/nnnick/Chart.js",
"homepage": "https://github.com/chartjs/Chart.js",
"author": "nnnick",

@@ -7,0 +7,0 @@ "license": "MIT",

@@ -154,3 +154,3 @@ ---

*labels*.padding | Number | 10 | Padding between rows of colored boxes
*labels*.generateLabels: | Function | `function(data) { }` | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. Styles that can be returned are `fillStyle`, `strokeStyle`, `lineCap`, `lineDash`, `lineDashOffset`, `lineWidth`, `lineJoin`. Return a `hidden` attribute to indicate that the label refers to something that is not visible. A strikethrough style will be given to the text in this case.
*labels*.generateLabels: | Function | `function(chart) { }` | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. Styles that can be returned are `fillStyle`, `strokeStyle`, `lineCap`, `lineDash`, `lineDashOffset`, `lineWidth`, `lineJoin`. Return a `hidden` attribute to indicate that the label refers to something that is not visible. A strikethrough style will be given to the text in this case.

@@ -157,0 +157,0 @@ The global options for tooltips are defined in `Chart.defaults.global.tooltips`.

@@ -95,3 +95,3 @@ ---

*animation*.animateScale | Boolean | false | If true, will animate scaling the Doughnut from the centre.
*legend*.*labels*.generateLabels | Function | `function(data) {} ` | Returns labels for each the legend
*legend*.*labels*.generateLabels | Function | `function(chart) {} ` | Returns a label for each item to be displayed on the legend.
*legend*.onClick | Function | function(event, legendItem) {} ` | Handles clicking an individual legend item

@@ -98,0 +98,0 @@

@@ -79,5 +79,5 @@ var gulp = require('gulp'),

.pipe(gulp.dest(outDir))
.pipe(streamify(uglify({
preserveComments: 'some'
})))
.pipe(streamify(uglify()))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
.pipe(streamify(concat('Chart.bundle.min.js')))

@@ -93,5 +93,5 @@ .pipe(gulp.dest(outDir));

.pipe(gulp.dest(outDir))
.pipe(streamify(uglify({
preserveComments: 'some'
})))
.pipe(streamify(uglify()))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
.pipe(streamify(concat('Chart.min.js')))

@@ -98,0 +98,0 @@ .pipe(gulp.dest(outDir));

@@ -5,3 +5,3 @@ {

"description": "Simple HTML5 charts using the canvas element.",
"version": "2.1.0",
"version": "2.1.1",
"license": "MIT",

@@ -8,0 +8,0 @@ "main": "src/chart.js",

@@ -19,3 +19,3 @@ # Chart.js

```
CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0/Chart.js
CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.min.js

@@ -22,0 +22,0 @@ ## Documentation

@@ -206,2 +206,3 @@ "use strict";

borderWidth: this.getPointBorderWidth(point, index),
tension: meta.dataset._model ? meta.dataset._model.tension : 0,
// Tooltip

@@ -208,0 +209,0 @@ hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().pointHitRadius, index, this.chart.options.elements.point.hitRadius)

@@ -578,3 +578,3 @@ "use strict";

this.tooltip._active = this.tooltipActive;
this.tooltip.update();
this.tooltip.update(true);
}

@@ -581,0 +581,0 @@

@@ -6,2 +6,3 @@ "use strict";

var helpers = Chart.helpers;
var noop = helpers.noop;

@@ -54,5 +55,6 @@ // Base class for all dataset controllers (line, bar, etc)

// Handle the number of data points changing
var meta = this.getMeta();
var numData = this.getDataset().data.length;
var numMetaData = meta.data.length;
var meta = this.getMeta(),
md = meta.data,
numData = this.getDataset().data.length,
numMetaData = md.length;

@@ -62,3 +64,3 @@ // Make sure that we handle number of datapoints changing

// Remove excess bars for data points that have been removed
meta.data.splice(numData, numMetaData - numData);
md.splice(numData, numMetaData - numData);
} else if (numData > numMetaData) {

@@ -73,12 +75,11 @@ // Add new elements

// Controllers should implement the following
addElements: helpers.noop,
addElementAndReset: helpers.noop,
draw: helpers.noop,
removeHoverStyle: helpers.noop,
setHoverStyle: helpers.noop,
update: helpers.noop
addElements: noop,
addElementAndReset: noop,
draw: noop,
removeHoverStyle: noop,
setHoverStyle: noop,
update: noop
});
Chart.DatasetController.extend = helpers.inherits;
};

@@ -6,2 +6,3 @@ "use strict";

var helpers = Chart.helpers;
var noop = helpers.noop;

@@ -18,9 +19,10 @@ Chart.defaults.global.legend = {

var index = legendItem.datasetIndex;
var meta = this.chart.getDatasetMeta(index);
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
// See controller.isDatasetVisible comment
meta.hidden = meta.hidden === null? !this.chart.data.datasets[index].hidden : null;
meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
// We hid a dataset ... rerender the chart
this.chart.update();
ci.update();
},

@@ -80,3 +82,3 @@

beforeUpdate: helpers.noop,
beforeUpdate: noop,
update: function(maxWidth, maxHeight, margins) {

@@ -110,7 +112,7 @@

},
afterUpdate: helpers.noop,
afterUpdate: noop,
//
beforeSetDimensions: helpers.noop,
beforeSetDimensions: noop,
setDimensions: function() {

@@ -143,7 +145,7 @@ // Set the unconstrained dimension before label rotation

},
afterSetDimensions: helpers.noop,
afterSetDimensions: noop,
//
beforeBuildLabels: helpers.noop,
beforeBuildLabels: noop,
buildLabels: function() {

@@ -155,40 +157,43 @@ this.legendItems = this.options.labels.generateLabels.call(this, this.chart);

},
afterBuildLabels: helpers.noop,
afterBuildLabels: noop,
//
beforeFit: helpers.noop,
beforeFit: noop,
fit: function() {
var opts = this.options;
var labelOpts = opts.labels;
var display = opts.display;
var ctx = this.ctx;
var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize);
var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle);
var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily);
var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
var globalDefault = Chart.defaults.global,
itemOrDefault = helpers.getValueOrDefault,
fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
// Reset hit boxes
this.legendHitBoxes = [];
var hitboxes = this.legendHitBoxes = [];
// Width
if (this.isHorizontal()) {
this.minSize.width = this.maxWidth; // fill all the width
} else {
this.minSize.width = this.options.display ? 10 : 0;
}
var minSize = this.minSize;
var isHorizontal = this.isHorizontal();
// height
if (this.isHorizontal()) {
this.minSize.height = this.options.display ? 10 : 0;
if (isHorizontal) {
minSize.width = this.maxWidth; // fill all the width
minSize.height = display ? 10 : 0;
} else {
this.minSize.height = this.maxHeight; // fill all the height
minSize.width = display ? 10 : 0;
minSize.height = this.maxHeight; // fill all the height
}
// Increase sizes here
if (this.options.display) {
if (this.isHorizontal()) {
if (display) {
if (isHorizontal) {
// Labels
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
this.lineWidths = [0];
var totalHeight = this.legendItems.length ? fontSize + (this.options.labels.padding) : 0;
var lineWidths = this.lineWidths = [0];
var totalHeight = this.legendItems.length ? fontSize + (labelOpts.padding) : 0;

@@ -200,10 +205,10 @@ ctx.textAlign = "left";

helpers.each(this.legendItems, function(legendItem, i) {
var width = this.options.labels.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
if (this.lineWidths[this.lineWidths.length - 1] + width + this.options.labels.padding >= this.width) {
totalHeight += fontSize + (this.options.labels.padding);
this.lineWidths[this.lineWidths.length] = this.left;
var width = labelOpts.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= this.width) {
totalHeight += fontSize + (labelOpts.padding);
lineWidths[lineWidths.length] = this.left;
}
// Store the hitbox width and height here. Final position will be updated in `draw`
this.legendHitBoxes[i] = {
hitboxes[i] = {
left: 0,

@@ -215,6 +220,6 @@ top: 0,

this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding;
lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
}, this);
this.minSize.height += totalHeight;
minSize.height += totalHeight;

@@ -226,7 +231,6 @@ } else {

this.width = this.minSize.width;
this.height = this.minSize.height;
this.width = minSize.width;
this.height = minSize.height;
},
afterFit: helpers.noop,
afterFit: noop,

@@ -240,15 +244,22 @@ // Shared Methods

draw: function() {
if (this.options.display) {
var ctx = this.ctx;
var cursor = {
x: this.left + ((this.width - this.lineWidths[0]) / 2),
y: this.top + this.options.labels.padding,
line: 0
};
var opts = this.options;
var labelOpts = opts.labels;
var globalDefault = Chart.defaults.global,
lineDefault = globalDefault.elements.line,
legendWidth = this.width,
lineWidths = this.lineWidths;
var fontColor = helpers.getValueOrDefault(this.options.labels.fontColor, Chart.defaults.global.defaultFontColor);
var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize);
var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle);
var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily);
var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
if (opts.display) {
var ctx = this.ctx,
cursor = {
x: this.left + ((legendWidth - lineWidths[0]) / 2),
y: this.top + labelOpts.padding,
line: 0
},
itemOrDefault = helpers.getValueOrDefault,
fontColor = itemOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor),
fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);

@@ -265,10 +276,15 @@ // Horizontal

var boxWidth = labelOpts.boxWidth,
hitboxes = this.legendHitBoxes;
helpers.each(this.legendItems, function(legendItem, i) {
var textWidth = ctx.measureText(legendItem.text).width;
var width = this.options.labels.boxWidth + (fontSize / 2) + textWidth;
var textWidth = ctx.measureText(legendItem.text).width,
width = boxWidth + (fontSize / 2) + textWidth,
x = cursor.x,
y = cursor.y;
if (cursor.x + width >= this.width) {
cursor.y += fontSize + (this.options.labels.padding);
if (x + width >= legendWidth) {
y = cursor.y += fontSize + (labelOpts.padding);
cursor.line++;
cursor.x = this.left + ((this.width - this.lineWidths[cursor.line]) / 2);
x = cursor.x = this.left + ((legendWidth - lineWidths[cursor.line]) / 2);
}

@@ -279,29 +295,25 @@

var itemOrDefault = function(item, defaulVal) {
return item !== undefined ? item : defaulVal;
};
ctx.fillStyle = itemOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
ctx.lineCap = itemOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
ctx.lineJoin = itemOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
ctx.lineWidth = itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
ctx.fillStyle = itemOrDefault(legendItem.fillStyle, Chart.defaults.global.defaultColor);
ctx.lineCap = itemOrDefault(legendItem.lineCap, Chart.defaults.global.elements.line.borderCapStyle);
ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, Chart.defaults.global.elements.line.borderDashOffset);
ctx.lineJoin = itemOrDefault(legendItem.lineJoin, Chart.defaults.global.elements.line.borderJoinStyle);
ctx.lineWidth = itemOrDefault(legendItem.lineWidth, Chart.defaults.global.elements.line.borderWidth);
ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, Chart.defaults.global.defaultColor);
if (ctx.setLineDash) {
// IE 9 and 10 do not support line dash
ctx.setLineDash(itemOrDefault(legendItem.lineDash, Chart.defaults.global.elements.line.borderDash));
ctx.setLineDash(itemOrDefault(legendItem.lineDash, lineDefault.borderDash));
}
// Draw the box
ctx.strokeRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize);
ctx.fillRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize);
ctx.strokeRect(x, y, boxWidth, fontSize);
ctx.fillRect(x, y, boxWidth, fontSize);
ctx.restore();
this.legendHitBoxes[i].left = cursor.x;
this.legendHitBoxes[i].top = cursor.y;
hitboxes[i].left = x;
hitboxes[i].top = y;
// Fill the actual label
ctx.fillText(legendItem.text, this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y);
ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y);

@@ -312,8 +324,8 @@ if (legendItem.hidden) {

ctx.lineWidth = 2;
ctx.moveTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y + (fontSize / 2));
ctx.lineTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x + textWidth, cursor.y + (fontSize / 2));
ctx.moveTo(boxWidth + (fontSize / 2) + x, y + (fontSize / 2));
ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2));
ctx.stroke();
}
cursor.x += width + (this.options.labels.padding);
cursor.x += width + (labelOpts.padding);
}, this);

@@ -328,13 +340,17 @@ } else {

handleEvent: function(e) {
var position = helpers.getRelativePosition(e, this.chart.chart);
var position = helpers.getRelativePosition(e, this.chart.chart),
x = position.x,
y = position.y,
opts = this.options;
if (position.x >= this.left && position.x <= this.right && position.y >= this.top && position.y <= this.bottom) {
if (x >= this.left && x <= this.right && y >= this.top && y <= this.bottom) {
// See if we are touching one of the dataset boxes
for (var i = 0; i < this.legendHitBoxes.length; ++i) {
var hitBox = this.legendHitBoxes[i];
var lh = this.legendHitBoxes;
for (var i = 0; i < lh.length; ++i) {
var hitBox = lh[i];
if (position.x >= hitBox.left && position.x <= hitBox.left + hitBox.width && position.y >= hitBox.top && position.y <= hitBox.top + hitBox.height) {
if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
// Touching an element
if (this.options.onClick) {
this.options.onClick.call(this, e, this.legendItems[i]);
if (opts.onClick) {
opts.onClick.call(this, e, this.legendItems[i]);
}

@@ -341,0 +357,0 @@ break;

@@ -11,4 +11,5 @@ "use strict";

register: function(plugin) {
if (Chart.plugins.indexOf(plugin) === -1) {
Chart.plugins.push(plugin);
var p = Chart.plugins;
if (p.indexOf(plugin) === -1) {
p.push(plugin);
}

@@ -19,5 +20,6 @@ },

remove: function(plugin) {
var idx = Chart.plugins.indexOf(plugin);
var p = Chart.plugins;
var idx = p.indexOf(plugin);
if (idx !== -1) {
Chart.plugins.splice(idx, 1);
p.splice(idx, 1);
}

@@ -36,2 +38,3 @@ },

var noop = helpers.noop;
Chart.PluginBase = Chart.Element.extend({

@@ -41,22 +44,22 @@ // Plugin methods. All functions are passed the chart instance

// Called at start of chart init
beforeInit: helpers.noop,
beforeInit: noop,
// Called at end of chart init
afterInit: helpers.noop,
afterInit: noop,
// Called at start of update
beforeUpdate: helpers.noop,
beforeUpdate: noop,
// Called at end of update
afterUpdate: helpers.noop,
afterUpdate: noop,
// Called at start of draw
beforeDraw: helpers.noop,
beforeDraw: noop,
// Called at end of draw
afterDraw: helpers.noop,
afterDraw: noop,
// Called during destroy
destroy: helpers.noop,
destroy: noop,
});
};

@@ -19,2 +19,3 @@ "use strict";

var noop = helpers.noop;
Chart.Title = Chart.Element.extend({

@@ -32,3 +33,3 @@

beforeUpdate: helpers.noop,
beforeUpdate: noop,
update: function(maxWidth, maxHeight, margins) {

@@ -63,7 +64,7 @@

},
afterUpdate: helpers.noop,
afterUpdate: noop,
//
beforeSetDimensions: helpers.noop,
beforeSetDimensions: noop,
setDimensions: function() {

@@ -96,57 +97,41 @@ // Set the unconstrained dimension before label rotation

},
afterSetDimensions: helpers.noop,
afterSetDimensions: noop,
//
beforeBuildLabels: helpers.noop,
buildLabels: helpers.noop,
afterBuildLabels: helpers.noop,
beforeBuildLabels: noop,
buildLabels: noop,
afterBuildLabels: noop,
//
beforeFit: helpers.noop,
beforeFit: noop,
fit: function() {
var ctx = this.ctx;
var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize);
var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle);
var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily);
var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
var ctx = this.ctx,
valueOrDefault = helpers.getValueOrDefault,
opts = this.options,
globalDefaults = Chart.defaults.global,
display = opts.display,
fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
minSize = this.minSize;
// Width
if (this.isHorizontal()) {
this.minSize.width = this.maxWidth; // fill all the width
minSize.width = this.maxWidth; // fill all the width
minSize.height = display ? fontSize + (opts.padding * 2) : 0;
} else {
this.minSize.width = 0;
minSize.width = display ? fontSize + (opts.padding * 2) : 0;
minSize.height = this.maxHeight; // fill all the height
}
// height
if (this.isHorizontal()) {
this.minSize.height = 0;
} else {
this.minSize.height = this.maxHeight; // fill all the height
}
this.width = minSize.width;
this.height = minSize.height;
// Increase sizes here
if (this.isHorizontal()) {
// Title
if (this.options.display) {
this.minSize.height += fontSize + (this.options.padding * 2);
}
} else {
if (this.options.display) {
this.minSize.width += fontSize + (this.options.padding * 2);
}
}
this.width = this.minSize.width;
this.height = this.minSize.height;
},
afterFit: helpers.noop,
afterFit: noop,
// Shared Methods
isHorizontal: function() {
return this.options.position === "top" || this.options.position === "bottom";
var pos = this.options.position;
return pos === "top" || pos === "bottom";
},

@@ -156,13 +141,17 @@

draw: function() {
if (this.options.display) {
var ctx = this.ctx;
var titleX, titleY;
var ctx = this.ctx,
valueOrDefault = helpers.getValueOrDefault,
opts = this.options,
globalDefaults = Chart.defaults.global;
var fontColor = helpers.getValueOrDefault(this.options.fontColor, Chart.defaults.global.defaultFontColor);
var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize);
var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle);
var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily);
var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
if (opts.display) {
var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
rotation = 0,
titleX,
titleY;
ctx.fillStyle = fontColor; // render in correct colour
ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
ctx.font = titleFont;

@@ -172,25 +161,17 @@

if (this.isHorizontal()) {
// Title
ctx.textAlign = "center";
ctx.textBaseline = 'middle';
titleX = this.left + ((this.right - this.left) / 2); // midpoint of the width
titleY = this.top + ((this.bottom - this.top) / 2); // midpoint of the height
ctx.fillText(this.options.text, titleX, titleY);
} else {
// Title
titleX = this.options.position === 'left' ? this.left + (fontSize / 2) : this.right - (fontSize / 2);
titleX = opts.position === 'left' ? this.left + (fontSize / 2) : this.right - (fontSize / 2);
titleY = this.top + ((this.bottom - this.top) / 2);
var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
}
ctx.save();
ctx.translate(titleX, titleY);
ctx.rotate(rotation);
ctx.textAlign = "center";
ctx.textBaseline = 'middle';
ctx.fillText(this.options.text, 0, 0);
ctx.restore();
}
ctx.save();
ctx.translate(titleX, titleY);
ctx.rotate(rotation);
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(opts.text, 0, 0);
ctx.restore();
}

@@ -197,0 +178,0 @@ }

@@ -5,6 +5,7 @@ "use strict";

var helpers = Chart.helpers;
var helpers = Chart.helpers,
globalOpts = Chart.defaults.global;
Chart.defaults.global.elements.arc = {
backgroundColor: Chart.defaults.global.defaultColor,
globalOpts.elements.arc = {
backgroundColor: globalOpts.defaultColor,
borderColor: "#fff",

@@ -25,3 +26,2 @@ borderWidth: 2

inRange: function(chartX, chartY) {
var vm = this._view;

@@ -31,5 +31,7 @@

var pointRelativePosition = helpers.getAngleFromPoint(vm, {
x: chartX,
y: chartY
});
x: chartX,
y: chartY
}),
angle = pointRelativePosition.angle,
distance = pointRelativePosition.distance;

@@ -42,12 +44,12 @@ //Sanitise angle range

}
while (pointRelativePosition.angle > endAngle) {
pointRelativePosition.angle -= 2.0 * Math.PI;
while (angle > endAngle) {
angle -= 2.0 * Math.PI;
}
while (pointRelativePosition.angle < startAngle) {
pointRelativePosition.angle += 2.0 * Math.PI;
while (angle < startAngle) {
angle += 2.0 * Math.PI;
}
//Check if within the range of the open/close angle
var betweenAngles = (pointRelativePosition.angle >= startAngle && pointRelativePosition.angle <= endAngle),
withinRadius = (pointRelativePosition.distance >= vm.innerRadius && pointRelativePosition.distance <= vm.outerRadius);
var betweenAngles = (angle >= startAngle && angle <= endAngle),
withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);

@@ -71,11 +73,12 @@ return (betweenAngles && withinRadius);

var ctx = this._chart.ctx;
var vm = this._view;
var ctx = this._chart.ctx,
vm = this._view,
sA = vm.startAngle,
eA = vm.endAngle;
ctx.beginPath();
ctx.arc(vm.x, vm.y, vm.outerRadius, vm.startAngle, vm.endAngle);
ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
ctx.arc(vm.x, vm.y, vm.innerRadius, vm.endAngle, vm.startAngle, true);
ctx.closePath();

@@ -82,0 +85,0 @@ ctx.strokeStyle = vm.borderColor;

@@ -5,10 +5,11 @@ "use strict";

var helpers = Chart.helpers;
var helpers = Chart.helpers,
globalOpts = Chart.defaults.global;
Chart.defaults.global.elements.point = {
globalOpts.elements.point = {
radius: 3,
pointStyle: 'circle',
backgroundColor: Chart.defaults.global.defaultColor,
backgroundColor: globalOpts.defaultColor,
borderWidth: 1,
borderColor: Chart.defaults.global.defaultColor,
borderColor: globalOpts.defaultColor,
// Hover

@@ -24,18 +25,7 @@ hitRadius: 1,

var vm = this._view;
if (vm) {
var hoverRange = vm.hitRadius + vm.radius;
return ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(hoverRange, 2));
} else {
return false;
}
return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
},
inLabelRange: function(mouseX) {
var vm = this._view;
if (vm) {
return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2));
} else {
return false;
}
return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
},

@@ -51,7 +41,7 @@ tooltipPosition: function() {

draw: function() {
var vm = this._view;
var vm = this._view,
x = vm.x,
y = vm.y;
var ctx = this._chart.ctx;
if (vm.skip) {

@@ -61,4 +51,5 @@ return;

if (typeof vm.pointStyle === 'object' && ((vm.pointStyle.toString() === '[object HTMLImageElement]') || (vm.pointStyle.toString() === '[object HTMLCanvasElement]'))) {
ctx.drawImage(vm.pointStyle, vm.x - vm.pointStyle.width / 2, vm.y - vm.pointStyle.height / 2);
var pointStyle = vm.pointStyle;
if (typeof pointStyle === 'object' && ((pointStyle.toString() === '[object HTMLImageElement]') || (pointStyle.toString() === '[object HTMLCanvasElement]'))) {
ctx.drawImage(pointStyle, x - pointStyle.width / 2, y - pointStyle.height / 2);
return;

@@ -76,19 +67,20 @@ }

var xOffset;
var yOffset;
var xOffset,
yOffset;
switch (vm.pointStyle) {
switch (pointStyle) {
// Default includes circle
default: ctx.beginPath();
ctx.arc(vm.x, vm.y, radius, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
break;
default:
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
break;
case 'triangle':
ctx.beginPath();
ctx.beginPath();
var edgeLength = 3 * radius / Math.sqrt(3);
var height = edgeLength * Math.sqrt(3) / 2;
ctx.moveTo(vm.x - edgeLength / 2, vm.y + height / 3);
ctx.lineTo(vm.x + edgeLength / 2, vm.y + height / 3);
ctx.lineTo(vm.x, vm.y - 2 * height / 3);
ctx.moveTo(x - edgeLength / 2, y + height / 3);
ctx.lineTo(x + edgeLength / 2, y + height / 3);
ctx.lineTo(x, y - 2 * height / 3);
ctx.closePath();

@@ -98,7 +90,7 @@ ctx.fill();

case 'rect':
ctx.fillRect(vm.x - 1 / Math.SQRT2 * radius, vm.y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
ctx.strokeRect(vm.x - 1 / Math.SQRT2 * radius, vm.y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
ctx.fillRect(x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
ctx.strokeRect(x - 1 / Math.SQRT2 * radius, y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
break;
case 'rectRot':
ctx.translate(vm.x, vm.y);
ctx.translate(x, y);
ctx.rotate(Math.PI / 4);

@@ -110,43 +102,43 @@ ctx.fillRect(-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);

case 'cross':
ctx.beginPath();
ctx.moveTo(vm.x, vm.y + radius);
ctx.lineTo(vm.x, vm.y - radius);
ctx.moveTo(vm.x - radius, vm.y);
ctx.lineTo(vm.x + radius, vm.y);
ctx.beginPath();
ctx.moveTo(x, y + radius);
ctx.lineTo(x, y - radius);
ctx.moveTo(x - radius, y);
ctx.lineTo(x + radius, y);
ctx.closePath();
break;
case 'crossRot':
ctx.beginPath();
ctx.beginPath();
xOffset = Math.cos(Math.PI / 4) * radius;
yOffset = Math.sin(Math.PI / 4) * radius;
ctx.moveTo(vm.x - xOffset, vm.y - yOffset);
ctx.lineTo(vm.x + xOffset, vm.y + yOffset);
ctx.moveTo(vm.x - xOffset, vm.y + yOffset);
ctx.lineTo(vm.x + xOffset, vm.y - yOffset);
ctx.moveTo(x - xOffset, y - yOffset);
ctx.lineTo(x + xOffset, y + yOffset);
ctx.moveTo(x - xOffset, y + yOffset);
ctx.lineTo(x + xOffset, y - yOffset);
ctx.closePath();
break;
case 'star':
ctx.beginPath();
ctx.moveTo(vm.x, vm.y + radius);
ctx.lineTo(vm.x, vm.y - radius);
ctx.moveTo(vm.x - radius, vm.y);
ctx.lineTo(vm.x + radius, vm.y);
ctx.beginPath();
ctx.moveTo(x, y + radius);
ctx.lineTo(x, y - radius);
ctx.moveTo(x - radius, y);
ctx.lineTo(x + radius, y);
xOffset = Math.cos(Math.PI / 4) * radius;
yOffset = Math.sin(Math.PI / 4) * radius;
ctx.moveTo(vm.x - xOffset, vm.y - yOffset);
ctx.lineTo(vm.x + xOffset, vm.y + yOffset);
ctx.moveTo(vm.x - xOffset, vm.y + yOffset);
ctx.lineTo(vm.x + xOffset, vm.y - yOffset);
ctx.moveTo(x - xOffset, y - yOffset);
ctx.lineTo(x + xOffset, y + yOffset);
ctx.moveTo(x - xOffset, y + yOffset);
ctx.lineTo(x + xOffset, y - yOffset);
ctx.closePath();
break;
case 'line':
ctx.beginPath();
ctx.moveTo(vm.x - radius, vm.y);
ctx.lineTo(vm.x + radius, vm.y);
ctx.beginPath();
ctx.moveTo(x - radius, y);
ctx.lineTo(x + radius, y);
ctx.closePath();
break;
case 'dash':
ctx.beginPath();
ctx.moveTo(vm.x, vm.y);
ctx.lineTo(vm.x + radius, vm.y);
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + radius, y);
ctx.closePath();

@@ -153,0 +145,0 @@ break;

@@ -5,8 +5,9 @@ "use strict";

var helpers = Chart.helpers;
var helpers = Chart.helpers,
globalOpts = Chart.defaults.global;
Chart.defaults.global.elements.rectangle = {
backgroundColor: Chart.defaults.global.defaultColor,
globalOpts.elements.rectangle = {
backgroundColor: globalOpts.defaultColor,
borderWidth: 0,
borderColor: Chart.defaults.global.defaultColor,
borderColor: globalOpts.defaultColor,
borderSkipped: 'bottom'

@@ -17,3 +18,2 @@ };

draw: function() {
var ctx = this._chart.ctx;

@@ -37,3 +37,2 @@ var vm = this._view;

ctx.beginPath();
ctx.fillStyle = vm.backgroundColor;

@@ -79,22 +78,11 @@ ctx.strokeStyle = vm.borderColor;

var vm = this._view;
var inRange = false;
if (vm) {
if (vm.y < vm.base) {
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base);
} else {
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y);
}
}
return inRange;
return vm ?
(vm.y < vm.base ?
(mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base) :
(mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y)) :
false;
},
inLabelRange: function(mouseX) {
var vm = this._view;
if (vm) {
return (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2);
} else {
return false;
}
return vm ? (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) : false;
},

@@ -101,0 +89,0 @@ tooltipPosition: function() {

@@ -310,2 +310,3 @@ /*global window: false */

convertTicksToLabels: function() {
this.tickMoments = this.ticks;
this.ticks = this.ticks.map(this.tickFormatFunction, this);

@@ -336,2 +337,5 @@ },

},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.tickMoments[index], null, null, includeOffset);
},
getValueForPixel: function(pixel) {

@@ -338,0 +342,0 @@ var innerDimension = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);

@@ -111,4 +111,16 @@ // Test the rectangle element

}, {
name: 'save',
args: []
}, {
name: 'translate',
args: [300, 66]
}, {
name: 'rotate',
args: [0]
}, {
name: 'fillText',
args: ['My title', 300, 66]
args: ['My title', 0, 0]
}, {
name: 'restore',
args: []
}]);

@@ -115,0 +127,0 @@ });

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc