| `font` | `Font` | Yes | `defaults.font` | See [Fonts](../general/fonts.md)
| `major` | `object` | | `{}` | [Major ticks configuration](./styling.mdx#major-tick-configuration).
| `padding` | `number` | | `0` | Sets the offset of the tick labels from the axis
+| `textStrokeColor` | `string` | `` | The color of the stroke around the text.
+| `textStrokeWidth` | `number` | `0` | Stroke width around the text.
| `z` | `number` | | `0` | z-index of tick layer. Useful when ticks are drawn on chart area. Values <= 0 are drawn under datasets, > 0 on top.
For example, in this chart the text will all be red except for the labels in the legend.
```javascript
-Chart.defaults.font.color = 'red';
+Chart.defaults.font.size = 16;
let chart = new Chart(ctx, {
type: 'line',
data: data,
labels: {
// This more specific font property overrides the global property
font: {
- color: 'black'
+ size: 14
}
}
}
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
-| `color` | `Color` | `'#666'` | Default font color for all text.
| `family` | `string` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Default font family for all text, follows CSS font-family options.
| `size` | `number` | `12` | Default font size (in px) for text. Does not apply to radialLinear scale point labels.
| `style` | `string` | `'normal'` | Default font style. Does not apply to tooltip title or footer. Does not apply to chart title. Follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit).
| `weight` | `string` | `undefined` | Default font weight (boldness). (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)).
| `lineHeight` | <code>number|string</code> | `1.2` | Height of an individual line of text (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height)).
-| `lineWidth` | `number` | `0` | Stroke width around the text. Currently only supported by [ticks](../axes/styling#tick-configuration).
-| `strokeStyle` | `string` | `` | The color of the stroke around the text. Currently only supported by [ticks](../axes/styling#tick-configuration).
## Missing Fonts
* `global` namespace was removed from `defaults`. So `Chart.defaults.global` is now `Chart.defaults`
* Dataset controller defaults were relocate to `controllers`. For example `Chart.defaults.line` is now `Chart.defaults.controllers.line`
* `default` prefix was removed from defaults. For example `Chart.defaults.global.defaultColor` is now `Chart.defaults.color`
-* `defaultColor` was renamed to `color`
-* `defaultFontColor` was renamed to `font.color`
+* `defaultColor` was split to `color`, `borderColor` and `backgroundColor`
+* `defaultFontColor` was renamed to `color`
* `defaultFontFamily` was renamed to `font.family`
* `defaultFontSize` was renamed to `font.size`
* `defaultFontStyle` was renamed to `font.style`
major: {
enabled: true
},
+ color: (context) => context.tick && context.tick.major && '#FF0000',
font: function(context) {
if (context.tick && context.tick.major) {
return {
- style: 'bold',
- color: '#FF0000'
+ style: 'bold'
};
}
}
*/
export class Defaults {
constructor() {
- this.color = 'rgba(0,0,0,0.1)';
+ this.backgroundColor = 'rgba(0,0,0,0.1)';
+ this.borderColor = 'rgba(0,0,0,0.1)';
+ this.color = '#666';
+ this.controllers = {};
this.elements = {};
this.events = [
'mousemove',
'touchmove'
];
this.font = {
- color: '#666',
family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
size: 12,
style: 'normal',
lineHeight: 1.2,
- weight: null,
- lineWidth: 0,
- strokeStyle: undefined
+ weight: null
+ };
+ this.hover = {
+ onHover: null
};
this.interaction = {
mode: 'nearest',
intersect: true
};
- this.hover = {
- onHover: null
- };
this.maintainAspectRatio = true;
this.onHover = null;
this.onClick = null;
- this.responsive = true;
- this.showLine = true;
this.plugins = {};
+ this.responsive = true;
this.scale = undefined;
this.scales = {};
- this.controllers = {};
+ this.showLine = true;
}
/**
// grid line settings
gridLines: {
display: true,
- color: 'rgba(0,0,0,0.1)',
lineWidth: 1,
drawBorder: true,
drawOnChartArea: true,
}
});
+defaults.route('scale.ticks', 'color', '', 'color');
+defaults.route('scale.gridLines', 'color', '', 'borderColor');
+defaults.route('scale.scaleLabel', 'color', '', 'color');
+
/**
* Returns a new array containing numItems from arr
* @param {any[]} arr
rotation,
label,
font,
+ color: optionTicks.color,
textOffset,
textAlign,
textBaseline,
for (i = 0, ilen = items.length; i < ilen; ++i) {
const item = items[i];
const tickFont = item.font;
- const useStroke = tickFont.lineWidth > 0 && tickFont.strokeStyle !== '';
+ const useStroke = optionTicks.textStrokeWidth > 0 && optionTicks.textStrokeColor !== '';
// Make sure we draw text in the correct color and font
ctx.save();
ctx.translate(item.x, item.y);
ctx.rotate(item.rotation);
ctx.font = tickFont.string;
- ctx.fillStyle = tickFont.color;
+ ctx.fillStyle = item.color;
ctx.textAlign = item.textAlign;
ctx.textBaseline = item.textBaseline;
if (useStroke) {
- ctx.strokeStyle = tickFont.strokeStyle;
- ctx.lineWidth = tickFont.lineWidth;
+ ctx.strokeStyle = optionTicks.textStrokeColor;
+ ctx.lineWidth = optionTicks.textStrokeWidth;
}
const label = item.label;
ctx.rotate(rotation);
ctx.textAlign = textAlign;
ctx.textBaseline = 'middle';
- ctx.fillStyle = scaleLabelFont.color;
+ ctx.fillStyle = scaleLabel.color;
ctx.font = scaleLabelFont.string;
ctx.fillText(scaleLabel.labelString, 0, 0);
ctx.restore();
function routeDefaults(scope, routes) {
Object.keys(routes).forEach(property => {
+ const propertyParts = property.split('.');
+ const sourceName = propertyParts.pop();
+ const sourceScope = [scope].concat(propertyParts).join('.');
const parts = routes[property].split('.');
const targetName = parts.pop();
const targetScope = parts.join('.');
- defaults.route(scope, property, targetScope, targetName);
+ defaults.route(sourceScope, sourceName, targetScope, targetName);
});
}
* @type {any}
*/
ArcElement.defaultRoutes = {
- backgroundColor: 'color'
+ backgroundColor: 'backgroundColor'
};
* @type {any}
*/
BarElement.defaultRoutes = {
- backgroundColor: 'color',
- borderColor: 'color'
+ backgroundColor: 'backgroundColor',
+ borderColor: 'borderColor'
};
* @type {any}
*/
LineElement.defaultRoutes = {
- backgroundColor: 'color',
- borderColor: 'color'
+ backgroundColor: 'backgroundColor',
+ borderColor: 'borderColor'
};
* @type {any}
*/
PointElement.defaultRoutes = {
- backgroundColor: 'color',
- borderColor: 'color'
+ backgroundColor: 'backgroundColor',
+ borderColor: 'borderColor'
};
}
const font = {
- color: valueOrDefault(options.color, fallback.color),
family: valueOrDefault(options.family, fallback.family),
lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size),
- lineWidth: valueOrDefault(options.lineWidth, fallback.lineWidth),
size,
style: valueOrDefault(options.style, fallback.style),
weight: valueOrDefault(options.weight, fallback.weight),
- strokeStyle: valueOrDefault(options.strokeStyle, fallback.strokeStyle),
string: ''
};
const rtlHelper = getRtlAdapter(opts.rtl, me.left, me._minSize.width);
const ctx = me.ctx;
const labelFont = toFont(labelOpts.font, me.chart.options.font);
- const fontColor = labelFont.color;
+ const fontColor = labelOpts.color;
const fontSize = labelFont.size;
let cursor;
// Canvas setup
ctx.textAlign = rtlHelper.textAlign(textAlign);
ctx.textBaseline = 'middle';
- ctx.strokeStyle = titleFont.color;
- ctx.fillStyle = titleFont.color;
+ ctx.strokeStyle = titleOpts.color;
+ ctx.fillStyle = titleOpts.color;
ctx.font = titleFont.string;
ctx.fillText(titleOpts.text, x, y);
ctx.save();
- ctx.fillStyle = fontOpts.color;
+ ctx.fillStyle = opts.color;
ctx.font = fontOpts.string;
ctx.translate(titleX, titleY);
position: 'top',
text: '',
weight: 2000 // by default greater than legend (1000) to be above
+ },
+
+ defaultRoutes: {
+ color: 'color'
}
};
titleFont = options.titleFont;
titleSpacing = options.titleSpacing;
- ctx.fillStyle = options.titleFont.color;
+ ctx.fillStyle = options.titleColor;
ctx.font = titleFont.string;
for (i = 0; i < length; ++i) {
pt.x = getAlignedX(me, bodyAlignForCalculation);
// Before body lines
- ctx.fillStyle = bodyFont.color;
+ ctx.fillStyle = options.bodyColor;
each(me.beforeBody, fillLineOfText);
xLinePadding = displayColors && bodyAlignForCalculation !== 'right'
footerFont = options.footerFont;
- ctx.fillStyle = options.footerFont.color;
+ ctx.fillStyle = options.footerColor;
ctx.font = footerFont.string;
for (i = 0; i < length; ++i) {
custom: null,
position: 'average',
backgroundColor: 'rgba(0,0,0,0.8)',
+ titleColor: '#fff',
titleFont: {
style: 'bold',
- color: '#fff',
},
titleSpacing: 2,
titleMarginBottom: 6,
titleAlign: 'left',
+ bodyColor: '#fff',
bodySpacing: 2,
bodyFont: {
- color: '#fff',
},
bodyAlign: 'left',
+ footerColor: '#fff',
footerSpacing: 2,
footerMarginTop: 6,
footerFont: {
- color: '#fff',
style: 'bold',
},
footerAlign: 'left',
};
},
labelTextColor() {
- return this.options.bodyFont.color;
+ return this.options.bodyColor;
},
labelPointStyle(tooltipItem) {
const meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex);
const context = scale.getContext(i);
const plFont = toFont(resolve([pointLabelOpts.font], context, i), scale.chart.options.font);
ctx.font = plFont.string;
- ctx.fillStyle = plFont.color;
+ ctx.fillStyle = pointLabelOpts.color;
const angle = toDegrees(scale.getIndexAngle(i));
ctx.textAlign = getTextAlignForAngle(angle);
);
}
- ctx.fillStyle = tickFont.color;
+ ctx.fillStyle = tickOpts.color;
ctx.fillText(tick.label, 0, -offset);
});
angleLines: {
display: true,
- color: 'rgba(0,0,0,0.1)',
lineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
}
}
};
+
+RadialLinearScale.defaultRoutes = {
+ 'angleLines.color': 'borderColor',
+ 'pointLabels.color': 'color',
+ 'ticks.color': 'color'
+};
expect(meta.data[i].x).toBeCloseToPixel(expected.x);
expect(meta.data[i].y).toBeCloseToPixel(expected.y);
expect(meta.data[i].options).toEqual(jasmine.objectContaining({
- backgroundColor: Chart.defaults.color,
- borderColor: Chart.defaults.color,
+ backgroundColor: Chart.defaults.backgroundColor,
+ borderColor: Chart.defaults.borderColor,
borderWidth: 1,
hitRadius: 1,
radius: expected.r
tension: 0.1,
},
point: {
- backgroundColor: Chart.defaults.color,
+ backgroundColor: Chart.defaults.backgroundColor,
borderWidth: 1,
- borderColor: Chart.defaults.color,
+ borderColor: Chart.defaults.borderColor,
hitRadius: 1,
hoverRadius: 4,
hoverBorderWidth: 1,
expect(meta.data[i].x).toBeCloseToPixel(expected.x);
expect(meta.data[i].y).toBeCloseToPixel(expected.y);
expect(meta.data[i].options).toEqual(jasmine.objectContaining({
- backgroundColor: Chart.defaults.color,
+ backgroundColor: Chart.defaults.backgroundColor,
borderWidth: 1,
- borderColor: Chart.defaults.color,
+ borderColor: Chart.defaults.borderColor,
hitRadius: 1,
radius: 3,
pointStyle: 'circle',
expect(meta.data[i].controlPointNextX).toBeCloseToPixel(expected.cpnx);
expect(meta.data[i].controlPointNextY).toBeCloseToPixel(expected.cpny);
expect(meta.data[i].options).toEqual(jasmine.objectContaining({
- backgroundColor: Chart.defaults.color,
+ backgroundColor: Chart.defaults.backgroundColor,
borderWidth: 1,
- borderColor: Chart.defaults.color,
+ borderColor: Chart.defaults.borderColor,
hitRadius: 1,
radius: 3,
pointStyle: 'circle',
it('should resolve data element options to the default color', function() {
var data0 = [0, 1, 2, 3, 4, 5];
- var oldColor = Chart.defaults.color;
- Chart.defaults.color = 'red';
+ var oldColor = Chart.defaults.borderColor;
+ Chart.defaults.borderColor = 'red';
var chart = acquireChart({
type: 'line',
data: {
expect(meta.data[0].options.borderColor).toBe('red');
// Reset old shared state
- Chart.defaults.color = oldColor;
+ Chart.defaults.borderColor = oldColor;
});
describe('_resolveOptions', function() {
it('should provide default scale label options', function() {
expect(Chart.defaults.scale.scaleLabel).toEqual({
- // display property
+ color: Chart.defaults.color,
display: false,
-
- // actual label
labelString: '',
-
- // top/bottom padding
padding: {
top: 4,
bottom: 4
-const {toLineHeight, toPadding, toFont, resolve, toTRBLCorners} = Chart.helpers; // from '../../src/helpers/helpers.options';
+const {toLineHeight, toPadding, toFont, resolve, toTRBLCorners} = Chart.helpers;
describe('Chart.helpers.options', function() {
describe('toLineHeight', function() {
const defaultFont = Object.assign({}, Chart.defaults.font);
Object.assign(Chart.defaults.font, {
- color: 'bar',
family: 'foobar',
size: 42,
style: 'xxxyyy',
});
expect(toFont({})).toEqual({
- color: 'bar',
family: 'foobar',
lineHeight: 63,
size: 42,
string: 'xxxyyy 42px foobar',
style: 'xxxyyy',
- weight: null,
- lineWidth: 0,
- strokeStyle: undefined
+ weight: null
});
Object.assign(Chart.defaults.font, defaultFont);
});
it ('should return a font with given values', function() {
expect(toFont({
- color: 'asd',
family: 'bla',
lineHeight: 8,
size: 21,
style: 'zzz'
})).toEqual({
- color: 'asd',
family: 'bla',
lineHeight: 8 * 21,
size: 21,
string: 'zzz 21px bla',
style: 'zzz',
- weight: null,
- lineWidth: 0,
- strokeStyle: undefined
+ weight: null
});
});
it ('should handle a string font size', function() {
expect(toFont({
- color: 'asd',
family: 'bla',
lineHeight: 8,
size: '21',
style: 'zzz'
})).toEqual({
- color: 'asd',
family: 'bla',
lineHeight: 8 * 21,
size: 21,
string: 'zzz 21px bla',
style: 'zzz',
- weight: null,
- lineWidth: 0,
- strokeStyle: undefined
+ weight: null
});
});
it('should return null as a font string if size or family are missing', function() {
it('Should have the correct default config', function() {
expect(Chart.defaults.plugins.title).toEqual({
align: 'center',
+ color: Chart.defaults.color,
display: false,
position: 'top',
fullWidth: true,
expect(tooltip.options.yPadding).toEqual(6);
expect(tooltip.xAlign).toEqual('left');
expect(tooltip.yAlign).toEqual('center');
+ expect(tooltip.options.bodyColor).toEqual('#fff');
expect(tooltip.options.bodyFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: defaults.font.style,
size: defaults.font.size,
bodySpacing: 2,
}));
+ expect(tooltip.options.titleColor).toEqual('#fff');
expect(tooltip.options.titleFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
titleMarginBottom: 6,
}));
+ expect(tooltip.options.footerColor).toEqual('#fff');
expect(tooltip.options.footerFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
afterBody: [],
footer: [],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
expect(tooltip.yAlign).toEqual('center');
expect(tooltip.options.bodyFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: defaults.font.style,
size: defaults.font.size,
}));
expect(tooltip.options.titleFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
}));
expect(tooltip.options.footerFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
expect(tooltip.labelTextColors).toEqual(['#fff']);
expect(tooltip.labelColors).toEqual([{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]);
expect(tooltip.x).toBeCloseToPixel(267);
expect(tooltip.yAlign).toEqual('center');
expect(tooltip.options.bodyFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: defaults.font.style,
size: defaults.font.size,
}));
expect(tooltip.options.titleFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
}));
expect(tooltip.options.footerFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
footer: ['beforeFooter', 'footer', 'afterFooter'],
labelTextColors: ['labelTextColor', 'labelTextColor'],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}],
labelPointStyles: [{
pointStyle: 'labelPointStyle',
afterBody: [],
footer: [],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
afterBody: [],
footer: [],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
afterBody: [],
footer: [],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
afterBody: [],
footer: [],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
expect(tooltip.yAlign).toEqual('top');
expect(tooltip.options.bodyFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: defaults.font.style,
size: defaults.font.size,
}));
expect(tooltip.options.titleFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
}));
expect(tooltip.options.footerFont).toEqual(jasmine.objectContaining({
- color: '#fff',
family: defaults.font.family,
style: 'bold',
size: defaults.font.size,
footer: ['beforeFooter', 'newline', 'footer', 'newline', 'afterFooter', 'newline'],
labelTextColors: ['labelTextColor', 'labelTextColor'],
labelColors: [{
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}, {
- borderColor: defaults.color,
- backgroundColor: defaults.color
+ borderColor: defaults.borderColor,
+ backgroundColor: defaults.backgroundColor
}]
}));
},
ticks: {
+ color: Chart.defaults.color,
showLabelBackdrop: true,
backdropColor: 'rgba(255,255,255,0.75)',
backdropPaddingY: 2,
},
pointLabels: {
+ color: Chart.defaults.color,
display: true,
font: {
size: 10