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

Function getGroupedMetas

src/controllers/controller.bar.ts:103–118  ·  view source on GitHub ↗

* Returns the grouped metasets of the given type on the index scale, in sorted order. * A hidden metaset is kept when its stack still has visible bars, so that it holds the * position of that stack: hiding a dataset must not reorder the stacks. * @private

(chart: Chart, iScale: BarScale, type: string, hasBar: (meta: BarMeta) => boolean)

Source from the content-addressed store, hash-verified

101 * @private
102 */
103function getGroupedMetas(chart: Chart, iScale: BarScale, type: string, hasBar: (meta: BarMeta) => boolean): BarMeta[] {
104 const axisID = iScale.axis + 'AxisID';
105 // @ts-expect-error `_getSortedDatasetMetas` is `@private` in core.controller.js, which tsc reads as `private`
106 const metasets: BarMeta[] = chart._getSortedDatasetMetas()
107 .filter(meta => meta[axisID] === iScale.id && meta.type === type && meta.controller.options.grouped);
108
109 if (iScale.options.stacked === false) {
110 return metasets.filter(meta => meta.visible);
111 }
112 if (metasets.every(meta => meta.visible)) {
113 return metasets;
114 }
115
116 const visibleStacks = new Set(metasets.filter(meta => meta.visible && hasBar(meta)).map(meta => meta.stack));
117 return metasets.filter(meta => meta.visible || (meta.stack !== undefined && visibleStacks.has(meta.stack)));
118}
119
120/**
121 * Returns the first parsed item of the meta whose index-axis value is `value`.

Callers 1

_getStacksMethod · 0.85

Calls 2

hasMethod · 0.80

Tested by

no test coverage detected