Skip to content

Commit

Permalink
Add support for canvas image
Browse files Browse the repository at this point in the history
  • Loading branch information
typpo committed Nov 14, 2021
1 parent 68ec248 commit aef804d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18,605 deletions.
1 change: 1 addition & 0 deletions dist/chartjs-plugin-annotation.esm.js
Expand Up @@ -5,6 +5,7 @@
* Released under the MIT License
*/
import ChartJsV3, { Element, defaults, Chart, Animations } from 'chart.js-v3';
import { Image } from 'canvas';

const {distanceBetweenPoints} = ChartJsV3.helpers;
const callHandler = ChartJsV3.helpers.callback;
Expand Down
12 changes: 6 additions & 6 deletions dist/chartjs-plugin-annotation.js
Expand Up @@ -5,10 +5,10 @@
* Released under the MIT License
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('chart.js-v3')) :
typeof define === 'function' && define.amd ? define(['chart.js-v3'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['chartjs-plugin-annotation'] = factory(global.ChartJsV3));
}(this, (function (ChartJsV3) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('chart.js-v3'), require('canvas')) :
typeof define === 'function' && define.amd ? define(['chart.js-v3', 'canvas'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['chartjs-plugin-annotation'] = factory(global.ChartJsV3, global.canvas));
}(this, (function (ChartJsV3, canvas) { 'use strict';

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

Expand Down Expand Up @@ -550,7 +550,7 @@ function drawLabel(ctx, line, chartArea) {
);
textYPosition += label.font.size + label.yPadding;
}
} else if (label.content instanceof Image) {
} else if (label.content instanceof canvas.Image) {
const x = -(width / 2) + label.xPadding;
const y = -(height / 2) + label.yPadding;
ctx.drawImage(label.content, x, y, width - (2 * label.xPadding), height - (2 * label.yPadding));
Expand Down Expand Up @@ -595,7 +595,7 @@ function getImageSize(size, value) {
const widthCache = new Map();
function measureLabel(ctx, label) {
const content = label.content;
if (content instanceof Image) {
if (content instanceof canvas.Image) {
return {
width: getImageSize(content.width, label.width) + 2 * label.xPadding,
height: getImageSize(content.height, label.height) + 2 * label.yPadding
Expand Down
2 changes: 1 addition & 1 deletion dist/chartjs-plugin-annotation.min.js

Large diffs are not rendered by default.

0 comments on commit aef804d

Please sign in to comment.