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

Class Legend

src/plugins/plugin.legend.js:41–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39const itemsEqual = (a, b) => a !== null && b !== null && a.datasetIndex === b.datasetIndex && a.index === b.index;
40
41export class Legend extends Element {
42
43 /**
44 * @param {{ ctx: any; options: any; chart: any; }} config
45 */
46 constructor(config) {
47 super();
48
49 this._added = false;
50
51 // Contains hit boxes for each dataset (in dataset order)
52 this.legendHitBoxes = [];
53
54 /**
55 * @private
56 */
57 this._hoveredItem = null;
58
59 // Are we in doughnut mode which has a different data type
60 this.doughnutMode = false;
61
62 this.chart = config.chart;
63 this.options = config.options;
64 this.ctx = config.ctx;
65 this.legendItems = undefined;
66 this.columnSizes = undefined;
67 this.lineWidths = undefined;
68 this.maxHeight = undefined;
69 this.maxWidth = undefined;
70 this.top = undefined;
71 this.bottom = undefined;
72 this.left = undefined;
73 this.right = undefined;
74 this.height = undefined;
75 this.width = undefined;
76 this._margins = undefined;
77 this.position = undefined;
78 this.weight = undefined;
79 this.fullSize = undefined;
80 }
81
82 update(maxWidth, maxHeight, margins) {
83 this.maxWidth = maxWidth;
84 this.maxHeight = maxHeight;
85 this._margins = margins;
86
87 this.setDimensions();
88 this.buildLabels();
89 this.fit();
90 }
91
92 setDimensions() {
93 if (this.isHorizontal()) {
94 this.width = this.maxWidth;
95 this.left = this._margins.left;
96 this.right = this.width;
97 } else {
98 this.height = this.maxHeight;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected