MCPcopy Create free account
hub / github.com/chartjs/Chart.js / BasePlatform

Class BasePlatform

src/platform/platform.base.js:9–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7 * Abstract class that allows abstracting platform dependencies away from the chart.
8 */
9export default class BasePlatform {
10 /**
11 * Called at chart construction time, returns a context2d instance implementing
12 * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
13 * @param {HTMLCanvasElement} canvas - The canvas from which to acquire context (platform specific)
14 * @param {number} [aspectRatio] - The chart options
15 */
16 acquireContext(canvas, aspectRatio) {} // eslint-disable-line no-unused-vars
17
18 /**
19 * Called at chart destruction time, releases any resources associated to the context
20 * previously returned by the acquireContext() method.
21 * @param {CanvasRenderingContext2D} context - The context2d instance
22 * @returns {boolean} true if the method succeeded, else false
23 */
24 releaseContext(context) { // eslint-disable-line no-unused-vars
25 return false;
26 }
27
28 /**
29 * Registers the specified listener on the given chart.
30 * @param {Chart} chart - Chart from which to listen for event
31 * @param {string} type - The ({@link ChartEvent}) type to listen for
32 * @param {function} listener - Receives a notification (an object that implements
33 * the {@link ChartEvent} interface) when an event of the specified type occurs.
34 */
35 addEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars
36
37 /**
38 * Removes the specified listener previously registered with addEventListener.
39 * @param {Chart} chart - Chart from which to remove the listener
40 * @param {string} type - The ({@link ChartEvent}) type to remove
41 * @param {function} listener - The listener function to remove from the event target.
42 */
43 removeEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars
44
45 /**
46 * @returns {number} the current devicePixelRatio of the device this platform is connected to.
47 */
48 getDevicePixelRatio() {
49 return 1;
50 }
51
52 /**
53 * Returns the maximum size in pixels of given canvas element.
54 * @param {HTMLCanvasElement} element
55 * @param {number} [width] - content width of parent element
56 * @param {number} [height] - content height of parent element
57 * @param {number} [aspectRatio] - aspect ratio to maintain
58 */
59 getMaximumSize(element, width, height, aspectRatio) {
60 width = Math.max(0, width || element.width);
61 height = height || element.height;
62 return {
63 width,
64 height: Math.max(0, aspectRatio ? Math.floor(width / aspectRatio) : height)
65 };
66 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected