mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-14 04:06:49 +01:00
Refactoring using helpers.options.resolve (#5965)
This commit is contained in:
committed by
Simon Brunel
parent
dd3564aee5
commit
820debf452
@@ -12,6 +12,8 @@ var plugins = require('./core.plugins');
|
||||
var scaleService = require('../core/core.scaleService');
|
||||
var Tooltip = require('./core.tooltip');
|
||||
|
||||
var valueOrDefault = helpers.valueOrDefault;
|
||||
|
||||
module.exports = function(Chart) {
|
||||
|
||||
// Create a dictionary of chart types, to allow for extension of existing types
|
||||
@@ -265,7 +267,7 @@ module.exports = function(Chart) {
|
||||
helpers.each(items, function(item) {
|
||||
var scaleOptions = item.options;
|
||||
var id = scaleOptions.id;
|
||||
var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
|
||||
var scaleType = valueOrDefault(scaleOptions.type, item.dtype);
|
||||
|
||||
if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
|
||||
scaleOptions.position = item.dposition;
|
||||
@@ -510,9 +512,7 @@ module.exports = function(Chart) {
|
||||
}
|
||||
|
||||
var animationOptions = me.options.animation;
|
||||
var duration = typeof config.duration !== 'undefined'
|
||||
? config.duration
|
||||
: animationOptions && animationOptions.duration;
|
||||
var duration = valueOrDefault(config.duration, animationOptions && animationOptions.duration);
|
||||
var lazy = config.lazy;
|
||||
|
||||
if (plugins.notify(me, 'beforeRender') === false) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
var helpers = require('../helpers/index');
|
||||
|
||||
var resolve = helpers.options.resolve;
|
||||
|
||||
var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
|
||||
|
||||
/**
|
||||
@@ -245,9 +247,8 @@ helpers.extend(DatasetController.prototype, {
|
||||
var dataset = this.chart.data.datasets[element._datasetIndex];
|
||||
var index = element._index;
|
||||
var custom = element.custom || {};
|
||||
var valueOrDefault = helpers.valueAtIndexOrDefault;
|
||||
var getHoverColor = helpers.getHoverColor;
|
||||
var model = element._model;
|
||||
var getHoverColor = helpers.getHoverColor;
|
||||
|
||||
element.$previousStyle = {
|
||||
backgroundColor: model.backgroundColor,
|
||||
@@ -255,9 +256,9 @@ helpers.extend(DatasetController.prototype, {
|
||||
borderWidth: model.borderWidth
|
||||
};
|
||||
|
||||
model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
|
||||
model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
|
||||
model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
|
||||
model.backgroundColor = resolve([custom.hoverBackgroundColor, dataset.hoverBackgroundColor, getHoverColor(model.backgroundColor)], undefined, index);
|
||||
model.borderColor = resolve([custom.hoverBorderColor, dataset.hoverBorderColor, getHoverColor(model.borderColor)], undefined, index);
|
||||
model.borderWidth = resolve([custom.hoverBorderWidth, dataset.hoverBorderWidth, model.borderWidth], undefined, index);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,9 @@ var Element = require('./core.element');
|
||||
var helpers = require('../helpers/index');
|
||||
var Ticks = require('./core.ticks');
|
||||
|
||||
var valueOrDefault = helpers.valueOrDefault;
|
||||
var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
|
||||
|
||||
defaults._set('scale', {
|
||||
display: true,
|
||||
position: 'left',
|
||||
@@ -730,24 +733,24 @@ module.exports = Element.extend({
|
||||
|
||||
var parseFont = helpers.options._parseFont;
|
||||
var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
|
||||
var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, defaultFontColor);
|
||||
var tickFontColor = valueOrDefault(optionTicks.fontColor, defaultFontColor);
|
||||
var tickFont = parseFont(optionTicks);
|
||||
var lineHeight = tickFont.lineHeight;
|
||||
var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, defaultFontColor);
|
||||
var majorTickFontColor = valueOrDefault(optionMajorTicks.fontColor, defaultFontColor);
|
||||
var majorTickFont = parseFont(optionMajorTicks);
|
||||
var tickPadding = optionTicks.padding;
|
||||
var labelOffset = optionTicks.labelOffset;
|
||||
|
||||
var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
|
||||
|
||||
var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, defaultFontColor);
|
||||
var scaleLabelFontColor = valueOrDefault(scaleLabel.fontColor, defaultFontColor);
|
||||
var scaleLabelFont = parseFont(scaleLabel);
|
||||
var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
|
||||
var labelRotationRadians = helpers.toRadians(me.labelRotation);
|
||||
|
||||
var itemsToDraw = [];
|
||||
|
||||
var axisWidth = gridLines.drawBorder ? helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0, 0) : 0;
|
||||
var axisWidth = gridLines.drawBorder ? valueAtIndexOrDefault(gridLines.lineWidth, 0, 0) : 0;
|
||||
var alignPixel = helpers._alignPixel;
|
||||
var borderValue, tickStart, tickEnd;
|
||||
|
||||
@@ -786,8 +789,8 @@ module.exports = Element.extend({
|
||||
borderDash = gridLines.zeroLineBorderDash || [];
|
||||
borderDashOffset = gridLines.zeroLineBorderDashOffset || 0.0;
|
||||
} else {
|
||||
lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
|
||||
lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
|
||||
lineWidth = valueAtIndexOrDefault(gridLines.lineWidth, index);
|
||||
lineColor = valueAtIndexOrDefault(gridLines.color, index);
|
||||
borderDash = gridLines.borderDash || [];
|
||||
borderDashOffset = gridLines.borderDashOffset || 0.0;
|
||||
}
|
||||
@@ -961,7 +964,7 @@ module.exports = Element.extend({
|
||||
if (axisWidth) {
|
||||
// Draw the line at the edge of the axis
|
||||
var firstLineWidth = axisWidth;
|
||||
var lastLineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, ticks.length - 1, 0);
|
||||
var lastLineWidth = valueAtIndexOrDefault(gridLines.lineWidth, ticks.length - 1, 0);
|
||||
var x1, x2, y1, y2;
|
||||
|
||||
if (isHorizontal) {
|
||||
@@ -975,7 +978,7 @@ module.exports = Element.extend({
|
||||
}
|
||||
|
||||
context.lineWidth = axisWidth;
|
||||
context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
|
||||
context.strokeStyle = valueAtIndexOrDefault(gridLines.color, 0);
|
||||
context.beginPath();
|
||||
context.moveTo(x1, y1);
|
||||
context.lineTo(x2, y2);
|
||||
|
||||
@@ -4,6 +4,8 @@ var defaults = require('./core.defaults');
|
||||
var Element = require('./core.element');
|
||||
var helpers = require('../helpers/index');
|
||||
|
||||
var valueOrDefault = helpers.valueOrDefault;
|
||||
|
||||
defaults._set('global', {
|
||||
tooltips: {
|
||||
enabled: true,
|
||||
@@ -221,7 +223,6 @@ function createTooltipItem(element) {
|
||||
*/
|
||||
function getBaseModel(tooltipOpts) {
|
||||
var globalDefaults = defaults.global;
|
||||
var valueOrDefault = helpers.valueOrDefault;
|
||||
|
||||
return {
|
||||
// Positioning
|
||||
|
||||
Reference in New Issue
Block a user