Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ docs/index.md
bower_components/

coverage/*

nbproject/*
110 changes: 69 additions & 41 deletions Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
},
onClick: null,
defaultColor: 'rgba(0,0,0,0.1)',
defaultFontColor: '#666',
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
defaultFontSize: 12,
defaultFontStyle: 'normal',
showLines: true,

// Element defaults defined in element extensions
elements: {},
Expand Down Expand Up @@ -180,7 +185,7 @@
helpers.extend = function(base) {
var len = arguments.length;
var additionalArgs = [];
for(var i = 1; i < len; i++) {
for (var i = 1; i < len; i++) {
additionalArgs.push(arguments[i]);
}
helpers.each(additionalArgs, function(extensionObject) {
Expand Down Expand Up @@ -314,7 +319,8 @@
return arrayToSearch.indexOf(item);
} else {
for (var i = 0; i < arrayToSearch.length; i++) {
if (arrayToSearch[i] === item) return i;
if (arrayToSearch[i] === item)
return i;
}
return -1;
}
Expand Down Expand Up @@ -394,6 +400,9 @@
helpers.isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
helpers.almostEquals = function(x, y, epsilon) {
return Math.abs(x - y) < epsilon;
};
helpers.max = function(array) {
return array.reduce(function(max, value) {
if (!isNaN(value)) {
Expand Down Expand Up @@ -803,7 +812,8 @@
};
helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
// Create the events object if it's not already present
if (!chartInstance.events) chartInstance.events = {};
if (!chartInstance.events)
chartInstance.events = {};

helpers.each(arrayOfEvents, function(eventName) {
chartInstance.events[eventName] = function() {
Expand Down Expand Up @@ -978,7 +988,6 @@
// Insert the iframe so that contentWindow is available
node.insertBefore(hiddenIframe, node.firstChild);

var timer = 0;
(hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
if (callback) {
callback();
Expand All @@ -999,6 +1008,17 @@
}
return Array.isArray(obj);
};
helpers.pushAllIfDefined = function(element, array) {
if (typeof element == "undefined") {
return;
}

if (helpers.isArray(element)) {
array.push.apply(array, element);
} else {
array.push(element);
}
};
helpers.isDatasetVisible = function(dataset) {
return !dataset.hidden;
};
Expand Down Expand Up @@ -2223,10 +2243,10 @@

labels: {
boxWidth: 40,
fontSize: 12,
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
fontSize: Chart.defaults.global.defaultFontSize,
fontStyle: Chart.defaults.global.defaultFontStyle,
fontColor: Chart.defaults.global.defaultFontColor,
fontFamily: Chart.defaults.global.defaultFontFamily,
padding: 10,
// Generates labels shown in the legend
// Valid properties to return:
Expand Down Expand Up @@ -2549,10 +2569,10 @@

// scale label
scaleLabel: {
fontColor: '#666',
fontFamily: 'Helvetica Neue',
fontSize: 12,
fontStyle: 'normal',
fontColor: Chart.defaults.global.defaultFontColor,
fontFamily: Chart.defaults.global.defaultFontFamily,
fontSize: Chart.defaults.global.defaultFontSize,
fontStyle: Chart.defaults.global.defaultFontStyle,

// actual label
labelString: '',
Expand All @@ -2564,10 +2584,10 @@
// label settings
ticks: {
beginAtZero: false,
fontSize: 12,
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
fontSize: Chart.defaults.global.defaultFontSize,
fontStyle: Chart.defaults.global.defaultFontStyle,
fontColor: Chart.defaults.global.defaultFontColor,
fontFamily: Chart.defaults.global.defaultFontFamily,
maxRotation: 90,
mirror: false,
padding: 10,
Expand Down Expand Up @@ -3248,9 +3268,9 @@
position: 'top',
fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)

fontColor: '#666',
fontFamily: 'Helvetica Neue',
fontSize: 12,
fontColor: Chart.defaults.global.defaultFontColor,
fontFamily: Chart.defaults.global.defaultFontFamily,
fontSize: Chart.defaults.global.defaultFontSize,
fontStyle: 'bold',
padding: 10,

Expand Down Expand Up @@ -3445,21 +3465,21 @@
custom: null,
mode: 'single',
backgroundColor: "rgba(0,0,0,0.8)",
titleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
titleFontSize: 12,
titleFontFamily: Chart.defaults.global.defaultFontFamily,
titleFontSize: Chart.defaults.global.defaultFontSize,
titleFontStyle: "bold",
titleSpacing: 2,
titleMarginBottom: 6,
titleColor: "#fff",
titleAlign: "left",
bodyFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
bodyFontSize: 12,
bodyFontStyle: "normal",
bodyFontFamily: Chart.defaults.global.defaultFontFamily,
bodyFontSize: Chart.defaults.global.defaultFontSize,
bodyFontStyle: Chart.defaults.global.defaultFontStyle,
bodySpacing: 2,
bodyColor: "#fff",
bodyAlign: "left",
footerFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
footerFontSize: 12,
footerFontFamily: Chart.defaults.global.defaultFontFamily,
footerFontSize: Chart.defaults.global.defaultFontSize,
footerFontStyle: "bold",
footerSpacing: 2,
footerMarginTop: 6,
Expand Down Expand Up @@ -3594,11 +3614,9 @@
var lines = [];

helpers.each(tooltipItems, function(bodyItem) {
var beforeLabel = this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data) || '';
var bodyLabel = this._options.tooltips.callbacks.label.call(this, bodyItem, data) || '';
var afterLabel = this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data) || '';

lines.push(beforeLabel + bodyLabel + afterLabel);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data), lines);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.label.call(this, bodyItem, data), lines);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data), lines);
}, this);

return lines;
Expand Down Expand Up @@ -5722,11 +5740,11 @@

if (this.isHorizontal()) {
maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
Math.ceil(this.width / 50));
Math.ceil(this.width / 50));
} else {
// The factor of 2 used to scale the font size has been experimentally determined.
maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
Math.ceil(this.height / (2 * this.options.ticks.fontSize)));
Math.ceil(this.height / (2 * this.options.ticks.fontSize)));
}

// Make sure we always have at least 2 ticks
Expand All @@ -5736,12 +5754,24 @@
// "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
// for details.

var niceRange = helpers.niceNum(this.max - this.min, false);
var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
var spacing;
var fixedStepSizeSet = this.options.ticks.fixedStepSize && this.options.ticks.fixedStepSize > 0;
if (fixedStepSizeSet) {
spacing = this.options.ticks.fixedStepSize;
} else {
var niceRange = helpers.niceNum(this.max - this.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 numSpaces = (niceMax - niceMin) / spacing;

var numSpaces = Math.ceil((niceMax - niceMin) / spacing);
// If very close to our rounded value, use it.
if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
numSpaces = Math.round(numSpaces);
} else {
numSpaces = Math.ceil(numSpaces);
}

// Put the values into the ticks array
this.ticks.push(this.options.ticks.min !== undefined ? this.options.ticks.min : niceMin);
Expand Down Expand Up @@ -5773,11 +5803,9 @@
this.ticksAsNumbers = this.ticks.slice(); // do after we potentially reverse the ticks
this.zeroLineIndex = this.ticks.indexOf(0);
},

getLabelForIndex: function(index, datasetIndex) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
},

// Utils
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
// This must be called after fit has been run so that
Expand Down Expand Up @@ -6036,16 +6064,16 @@

pointLabels: {
//String - Point label font declaration
fontFamily: "'Arial'",
fontFamily: Chart.defaults.global.defaultFontFamily,

//String - Point label font weight
fontStyle: "normal",
fontStyle: Chart.defaults.global.defaultFontStyle,

//Number - Point label font size in pixels
fontSize: 10,

//String - Point label font colour
fontColor: "#666",
fontColor: Chart.defaults.global.defaultFontColor,

//Function - Used to convert point labels
callback: function(label) {
Expand Down
10 changes: 5 additions & 5 deletions Chart.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion docs/01-Scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ The linear scale extends the core scale class with the following tick template:
}
```

### Logarithmic Scale
It also provides additional configuration options:

Name | Type | Default | Description
--- |:---:| --- | ---
*ticks*.fixedStepSize | Number | - | User defined fixed step size for the scale. If set, the scale ticks will be enumerated by multiple of fixedStepSize, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.

#### Logarithmic Scale
The logarithmic scale is used to display logarithmic data of course. It can be placed on either the x or y axis.

The log scale extends the core scale class with the following tick template:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"color": "git://github.com/chartjs/color",
"gulp": "3.5.x",
"gulp": "3.9.x",
"gulp-concat": "~2.1.x",
"gulp-connect": "~2.0.5",
"gulp-html-validator": "^0.0.2",
Expand Down
20 changes: 16 additions & 4 deletions src/core/core.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
helpers.extend = function(base) {
var len = arguments.length;
var additionalArgs = [];
for(var i = 1; i < len; i++) {
for (var i = 1; i < len; i++) {
additionalArgs.push(arguments[i]);
}
helpers.each(additionalArgs, function(extensionObject) {
Expand Down Expand Up @@ -184,7 +184,8 @@
return arrayToSearch.indexOf(item);
} else {
for (var i = 0; i < arrayToSearch.length; i++) {
if (arrayToSearch[i] === item) return i;
if (arrayToSearch[i] === item)
return i;
}
return -1;
}
Expand Down Expand Up @@ -676,7 +677,8 @@
};
helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
// Create the events object if it's not already present
if (!chartInstance.events) chartInstance.events = {};
if (!chartInstance.events)
chartInstance.events = {};

helpers.each(arrayOfEvents, function(eventName) {
chartInstance.events[eventName] = function() {
Expand Down Expand Up @@ -851,7 +853,6 @@
// Insert the iframe so that contentWindow is available
node.insertBefore(hiddenIframe, node.firstChild);

var timer = 0;
(hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
if (callback) {
callback();
Expand All @@ -872,6 +873,17 @@
}
return Array.isArray(obj);
};
helpers.pushAllIfDefined = function(element, array) {
if (typeof element == "undefined") {
return;
}

if (helpers.isArray(element)) {
array.push.apply(array, element);
} else {
array.push(element);
}
};
helpers.isDatasetVisible = function(dataset) {
return !dataset.hidden;
};
Expand Down
8 changes: 3 additions & 5 deletions src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@
var lines = [];

helpers.each(tooltipItems, function(bodyItem) {
var beforeLabel = this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data) || '';
var bodyLabel = this._options.tooltips.callbacks.label.call(this, bodyItem, data) || '';
var afterLabel = this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data) || '';

lines.push(beforeLabel + bodyLabel + afterLabel);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data), lines);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.label.call(this, bodyItem, data), lines);
helpers.pushAllIfDefined(this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data), lines);
}, this);

return lines;
Expand Down
Loading