Remove global from defaults (#6893)

This commit is contained in:
Jukka Kurkela
2020-01-03 21:07:38 +02:00
committed by Evert Timberg
parent 099e552e6d
commit f4792306e0
50 changed files with 478 additions and 498 deletions

View File

@@ -13,11 +13,9 @@ import {clipArea, unclipArea} from '../helpers/helpers.canvas';
import {valueOrDefault, isFinite, isArray, extend} from '../helpers/helpers.core';
import {_normalizeAngle} from '../helpers/helpers.math';
defaults._set('global', {
plugins: {
filler: {
propagate: true
}
defaults._set('plugins', {
filler: {
propagate: true
}
});
@@ -436,7 +434,7 @@ export default {
const {line, target, scale} = meta;
const lineOpts = line.options;
const fillOption = lineOpts.fill;
const color = lineOpts.backgroundColor || defaults.global.defaultColor;
const color = lineOpts.backgroundColor || defaults.color;
const {above = color, below = color} = fillOption || {};
if (target && line.points.length) {
clipArea(ctx, area);

View File

@@ -8,71 +8,69 @@ const layouts = require('../core/core.layouts');
const getRtlHelper = helpers.rtl.getRtlAdapter;
const valueOrDefault = helpers.valueOrDefault;
defaults._set('global', {
legend: {
display: true,
position: 'top',
align: 'center',
fullWidth: true,
reverse: false,
weight: 1000,
defaults._set('legend', {
display: true,
position: 'top',
align: 'center',
fullWidth: true,
reverse: false,
weight: 1000,
// a callback that will handle
onClick: function(e, legendItem) {
var index = legendItem.datasetIndex;
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
// a callback that will handle
onClick: function(e, legendItem) {
var index = legendItem.datasetIndex;
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
// See controller.isDatasetVisible comment
meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
// See controller.isDatasetVisible comment
meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
// We hid a dataset ... rerender the chart
ci.update();
},
// We hid a dataset ... rerender the chart
ci.update();
},
onHover: null,
onLeave: null,
onHover: null,
onLeave: null,
labels: {
boxWidth: 40,
padding: 10,
// Generates labels shown in the legend
// Valid properties to return:
// text : text to display
// fillStyle : fill of coloured box
// strokeStyle: stroke of coloured box
// hidden : if this legend item refers to a hidden item
// lineCap : cap style for line
// lineDash
// lineDashOffset :
// lineJoin :
// lineWidth :
generateLabels: function(chart) {
var datasets = chart.data.datasets;
var options = chart.options.legend || {};
var usePointStyle = options.labels && options.labels.usePointStyle;
labels: {
boxWidth: 40,
padding: 10,
// Generates labels shown in the legend
// Valid properties to return:
// text : text to display
// fillStyle : fill of coloured box
// strokeStyle: stroke of coloured box
// hidden : if this legend item refers to a hidden item
// lineCap : cap style for line
// lineDash
// lineDashOffset :
// lineJoin :
// lineWidth :
generateLabels: function(chart) {
var datasets = chart.data.datasets;
var options = chart.options.legend || {};
var usePointStyle = options.labels && options.labels.usePointStyle;
return chart._getSortedDatasetMetas().map(function(meta) {
var style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
return chart._getSortedDatasetMetas().map(function(meta) {
var style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
return {
text: datasets[meta.index].label,
fillStyle: style.backgroundColor,
hidden: !meta.visible,
lineCap: style.borderCapStyle,
lineDash: style.borderDash,
lineDashOffset: style.borderDashOffset,
lineJoin: style.borderJoinStyle,
lineWidth: style.borderWidth,
strokeStyle: style.borderColor,
pointStyle: style.pointStyle,
rotation: style.rotation,
return {
text: datasets[meta.index].label,
fillStyle: style.backgroundColor,
hidden: !meta.visible,
lineCap: style.borderCapStyle,
lineDash: style.borderDash,
lineDashOffset: style.borderDashOffset,
lineJoin: style.borderJoinStyle,
lineWidth: style.borderWidth,
strokeStyle: style.borderColor,
pointStyle: style.pointStyle,
rotation: style.rotation,
// Below is extra data used for toggling the datasets
datasetIndex: meta.index
};
}, this);
}
// Below is extra data used for toggling the datasets
datasetIndex: meta.index
};
}, this);
}
}
});
@@ -333,9 +331,8 @@ class Legend extends Element {
var me = this;
var opts = me.options;
var labelOpts = opts.labels;
var globalDefaults = defaults.global;
var defaultColor = globalDefaults.defaultColor;
var lineDefault = globalDefaults.elements.line;
var defaultColor = defaults.color;
var lineDefault = defaults.elements.line;
var legendHeight = me.height;
var columnHeights = me.columnHeights;
var legendWidth = me.width;
@@ -347,7 +344,7 @@ class Legend extends Element {
var rtlHelper = getRtlHelper(opts.rtl, me.left, me.minSize.width);
var ctx = me.ctx;
var fontColor = valueOrDefault(labelOpts.fontColor, globalDefaults.defaultFontColor);
var fontColor = valueOrDefault(labelOpts.fontColor, defaults.fontColor);
var labelFont = helpers.options._parseFont(labelOpts);
var fontSize = labelFont.size;
var cursor;
@@ -602,7 +599,7 @@ module.exports = {
var legend = chart.legend;
if (legendOpts) {
helpers.mergeIf(legendOpts, defaults.global.legend);
helpers.mergeIf(legendOpts, defaults.legend);
if (legend) {
layouts.configure(chart, legend, legendOpts);

View File

@@ -5,16 +5,14 @@ const Element = require('../core/core.element');
const helpers = require('../helpers/index');
const layouts = require('../core/core.layouts');
defaults._set('global', {
title: {
display: false,
fontStyle: 'bold',
fullWidth: true,
padding: 10,
position: 'top',
text: '',
weight: 2000 // by default greater than legend (1000) to be above
}
defaults._set('title', {
display: false,
fontStyle: 'bold',
fullWidth: true,
padding: 10,
position: 'top',
text: '',
weight: 2000 // by default greater than legend (1000) to be above
});
/**
@@ -148,7 +146,7 @@ class Title extends Element {
var right = me.right;
var maxWidth, titleX, titleY;
ctx.fillStyle = helpers.valueOrDefault(opts.fontColor, defaults.global.defaultFontColor); // render in correct colour
ctx.fillStyle = helpers.valueOrDefault(opts.fontColor, defaults.fontColor); // render in correct colour
ctx.font = fontOpts.string;
// Horizontal
@@ -221,7 +219,7 @@ module.exports = {
var titleBlock = chart.titleBlock;
if (titleOpts) {
helpers.mergeIf(titleOpts, defaults.global.title);
helpers.mergeIf(titleOpts, defaults.title);
if (titleBlock) {
layouts.configure(chart, titleBlock, titleOpts);