Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide core.helpers monolith #5959

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions samples/advanced/data-labelling.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<button id="randomizeData">Randomize Data</button>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var barChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
Expand Down Expand Up @@ -84,7 +84,7 @@
var fontSize = 16;
var fontStyle = 'normal';
var fontFamily = 'Helvetica Neue';
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);
ctx.font = Chart.helpers.canvas.fontString(fontSize, fontStyle, fontFamily);

// Just naively convert to string for now
var dataString = dataset.data[index].toString();
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/bar/horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<button id="removeData">Remove Data</button>
<script>
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var horizontalBarChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/bar/vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<button id="removeData">Remove Data</button>
<script>
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var barChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/bubble.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var DEFAULT_DATASET_SIZE = 7;

var addedCount = 0;
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var bubbleChartData = {
animation: {
duration: 10000
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/polar-area.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
};

var chartColors = window.chartColors;
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
data: {
datasets: [{
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/radar-skip-points.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
return Math.round(Math.random() * 100);
};

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
type: 'radar',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/radar.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
return Math.round(Math.random() * 100);
};

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
type: 'radar',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/scatter/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<button id="randomizeData">Randomize Data</button>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
function generateData() {
var data = [];
for (var i = 0; i < 7; i++) {
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/scatter/multi-axis.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<button id="randomizeData">Randomize Data</button>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var scatterChartData = {
datasets: [{
label: 'My First dataset',
Expand Down
2 changes: 1 addition & 1 deletion samples/legend/point-style.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
</div>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
function createConfig(colorName) {
return {
type: 'line',
Expand Down
2 changes: 1 addition & 1 deletion samples/legend/positioning.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
</div>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
function createConfig(legendPosition, colorName) {
return {
type: 'line',
Expand Down
4 changes: 2 additions & 2 deletions samples/scales/logarithmic/scatter.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<canvas id="canvas"></canvas>
</div>
<script>
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var scatterChartData = {
datasets: [{
borderColor: window.chartColors.red,
Expand Down Expand Up @@ -137,7 +137,7 @@
position: 'bottom',
ticks: {
userCallback: function(tick) {
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(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';
}
Expand Down
2 changes: 1 addition & 1 deletion samples/scales/time/combo.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
return moment().add(days, 'd').format(timeFormat);
}

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
type: 'bar',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/scales/time/financial.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
ctx.canvas.width = 1000;
ctx.canvas.height = 300;

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var cfg = {
type: 'bar',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/scales/time/line-point-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
return moment().add(days, 'd').format();
}

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
type: 'line',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/scales/time/line.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
return moment().add(days, 'd').format(timeFormat);
}

var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var config = {
type: 'line',
data: {
Expand Down
2 changes: 1 addition & 1 deletion samples/tooltips/custom-points.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
});
}
};
var color = Chart.helpers.color;
var color = Chart.helpers.canvas.color;
var lineChartData = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
Expand Down
3 changes: 0 additions & 3 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ var Chart = require('./core/core')();

Chart.helpers = require('./helpers/index');

// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
require('./core/core.helpers')(Chart);

Chart.Animation = require('./core/core.animation');
Chart.animationService = require('./core/core.animations');
Chart.controllers = require('./controllers/index');
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/controller.bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ module.exports = DatasetController.extend({
radius: model.radius
};

model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.canvas.getHoverColor(options.backgroundColor));
model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.canvas.getHoverColor(options.borderColor));
model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
model.radius = options.radius + options.hoverRadius;
},
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ module.exports = DatasetController.extend({
}

if (lineModel.cubicInterpolationMode === 'monotone') {
helpers.splineCurveMonotone(points);
helpers.math.splineCurveMonotone(points);
} else {
for (i = 0, ilen = points.length; i < ilen; ++i) {
point = points[i];
model = point._model;
controlPoints = helpers.splineCurve(
helpers.previousItem(points, i)._model,
controlPoints = helpers.math.splineCurve(
helpers.math.previousItem(points, i)._model,
model,
helpers.nextItem(points, i)._model,
helpers.math.nextItem(points, i)._model,
lineModel.tension
);
model.controlPointPreviousX = controlPoints.previous.x;
Expand Down Expand Up @@ -344,8 +344,8 @@ module.exports = DatasetController.extend({
radius: model.radius
};

model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.canvas.getHoverColor(model.backgroundColor));
model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.canvas.getHoverColor(model.borderColor));
model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
}
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/controller.radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ module.exports = DatasetController.extend({

for (i = 0, ilen = points.length; i < ilen; i++) {
model = points[i]._model;
controlPoints = helpers.splineCurve(
helpers.previousItem(points, i, true)._model,
controlPoints = helpers.math.splineCurve(
helpers.math.previousItem(points, i, true)._model,
model,
helpers.nextItem(points, i, true)._model,
helpers.math.nextItem(points, i, true)._model,
model.tension
);

Expand All @@ -165,8 +165,8 @@ module.exports = DatasetController.extend({
};

model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.canvas.getHoverColor(model.backgroundColor));
model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.canvas.getHoverColor(model.borderColor));
model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
}
});
4 changes: 2 additions & 2 deletions src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
},

cancelAnimation: function(chart) {
var index = helpers.findIndex(this.animations, function(animation) {
var index = helpers.utility.findIndex(this.animations, function(animation) {
return animation.chart === chart;
});

Expand All @@ -67,7 +67,7 @@ module.exports = {
// Skip animation frame requests until the active one is executed.
// This can happen when processing mouse events, e.g. 'mousemove'
// and 'mouseout' events will trigger multiple renders.
me.request = helpers.requestAnimFrame.call(window, function() {
me.request = helpers.canvas.requestAnimFrame.call(window, function() {
me.request = null;
me.startDigest();
});
Expand Down
12 changes: 6 additions & 6 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(Chart) {
data.datasets = data.datasets || [];
data.labels = data.labels || [];

config.options = helpers.configMerge(
config.options = helpers.utility.configMerge(
defaults.global,
defaults[config.type],
config.options || {});
Expand All @@ -52,7 +52,7 @@ module.exports = function(Chart) {
layouts.removeBox(chart, scale);
});

newOptions = helpers.configMerge(
newOptions = helpers.utility.configMerge(
Chart.defaults.global,
Chart.defaults[chart.config.type],
newOptions);
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = function(Chart) {
// Before init plugin notification
plugins.notify(me, 'beforeInit');

helpers.retinaScale(me, me.options.devicePixelRatio);
helpers.dom.retinaScale(me, me.options.devicePixelRatio);

me.bindEvents();

Expand Down Expand Up @@ -180,8 +180,8 @@ module.exports = function(Chart) {
// the canvas display style uses the same integer values to avoid blurring effect.

// Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
var newWidth = Math.max(0, Math.floor(helpers.dom.getMaximumWidth(canvas)));
var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.dom.getMaximumHeight(canvas)));

if (me.width === newWidth && me.height === newHeight) {
return;
Expand All @@ -192,7 +192,7 @@ module.exports = function(Chart) {
canvas.style.width = newWidth + 'px';
canvas.style.height = newHeight + 'px';

helpers.retinaScale(me, options.devicePixelRatio);
helpers.dom.retinaScale(me, options.devicePixelRatio);

if (!silent) {
// Notify any plugins about the resize
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ helpers.extend(DatasetController.prototype, {
var index = element._index;
var custom = element.custom || {};
var valueOrDefault = helpers.valueAtIndexOrDefault;
var getHoverColor = helpers.getHoverColor;
var getHoverColor = helpers.canvas.getHoverColor;
var model = element._model;

element.$previousStyle = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ helpers.extend(Element.prototype, {
},

hasValue: function() {
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
return helpers.math.isNumber(this._model.x) && helpers.math.isNumber(this._model.y);
}
});

Expand Down
Loading