MCPcopy
hub / github.com/chartjs/Chart.js / getCanvas

Function getCanvas

src/core/core.controller.js:51–64  ·  view source on GitHub ↗

* Chart.js can take a string id of a canvas element, a 2d context, or a canvas element itself. * Attempt to unwrap the item passed into the chart constructor so that it is a canvas element (if possible).

(item)

Source from the content-addressed store, hash-verified

49 * Attempt to unwrap the item passed into the chart constructor so that it is a canvas element (if possible).
50 */
51function getCanvas(item) {
52 if (_isDomSupported() && typeof item === 'string') {
53 item = document.getElementById(item);
54 } else if (item && item.length) {
55 // Support for array based queries (such as jQuery)
56 item = item[0];
57 }
58
59 if (item && item.canvas) {
60 // Support for any object associated to a canvas (including a context2d)
61 item = item.canvas;
62 }
63 return item;
64}
65
66const instances = {};
67const getChart = (key) => {

Callers 2

getChartFunction · 0.85
constructorMethod · 0.85

Calls 1

_isDomSupportedFunction · 0.85

Tested by

no test coverage detected