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
10 changes: 7 additions & 3 deletions src/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import {DatasetController} from 'chart.js';
import {valueOrDefault, isNullOrUndef} from 'chart.js/helpers';
import {valueOrDefault, toFont, isNullOrUndef} from 'chart.js/helpers';
import {layout} from './layout';

/**
Expand Down Expand Up @@ -228,11 +228,15 @@ export default class SankeyController extends DatasetController {
* @private
*/
_drawLabel(label, y, height, ctx, textX) {
const lines = isNullOrUndef(label) ? [] : this.toTextLines(label);
const me = this;
const font = toFont(me.options.font, me.chart.options.font);
const lines = isNullOrUndef(label) ? [] : me.toTextLines(label);
const linesLength = lines.length;
const middle = y + height / 2;
const padding = 7.5;
const textHeight = 15;
const textHeight = font.lineHeight;

ctx.font = font.string;

if (linesLength > 1) {
const top = middle - (textHeight * linesLength / 2) + padding;
Expand Down
Binary file modified test/fixtures/labels-multiline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion types/index.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
Chart,
ChartComponent,
DatasetController,
Element
Element,
FontSpec
} from 'chart.js';

declare module 'chart.js' {
Expand Down Expand Up @@ -30,6 +31,7 @@ declare module 'chart.js' {
nodeWidth?: number /* defaults to 10 */
color?: string /* defaults to 'black' */
borderColor?: string /* defaults to 'black' */
font: FontSpec /* defaults to chart.options.font */
}

type FromToElement = {
Expand Down