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

Method _calculateBarIndexPixels

src/controllers/controller.bar.js:636–666  ·  src/controllers/controller.bar.js::BarController._calculateBarIndexPixels

* @private

(index, ruler)

Source from the content-addressed store, hash-verified

634 * @private
635 */
636 _calculateBarIndexPixels(index, ruler) {
637 const scale = ruler.scale;
638 const options = this.options;
639 const skipNull = options.skipNull;
640 const maxBarThickness = valueOrDefault(options.maxBarThickness, Infinity);
641 let center, size;
642 const axisCount = this._getAxisCount();
643 if (ruler.grouped) {
644 const stackCount = skipNull ? this._getStackCount(index) : ruler.stackCount;
645 const range = options.barThickness === class="st">'flex'
646 ? computeFlexCategoryTraits(index, ruler, options, stackCount * axisCount)
647 : computeFitCategoryTraits(index, ruler, options, stackCount * axisCount);
648 const axisID = this.chart.options.indexAxis === class="st">'x' ? this.getDataset().xAxisID : this.getDataset().yAxisID;
649 const axisNumber = this._getAxis().indexOf(valueOrDefault(axisID, this.getFirstScaleIdForIndexAxis()));
650 const stackIndex = this._getStackIndex(this.index, this._cachedMeta.stack, skipNull ? index : undefined) + axisNumber;
651 center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
652 size = Math.min(maxBarThickness, range.chunk * range.ratio);
653 } else {
654 class="cm">// For non-grouped bar charts, exact pixel values are used
655 center = scale.getPixelForValue(this.getParsed(index)[scale.axis], index);
656 size = Math.min(maxBarThickness, ruler.min * ruler.ratio);
657 }
658
659
660 return {
661 base: center - size / 2,
662 head: center + size / 2,
663 center,
664 size
665 };
666 }
667
668 draw() {
669 const meta = this._cachedMeta;

Callers 1

updateElementsMethod · 0.95

Calls 11

_getAxisCountMethod · 0.95
_getStackCountMethod · 0.95
_getAxisMethod · 0.95
_getStackIndexMethod · 0.95
valueOrDefaultFunction · 0.85
computeFitCategoryTraitsFunction · 0.85
getDatasetMethod · 0.80
getParsedMethod · 0.80
getPixelForValueMethod · 0.65

Tested by

no test coverage detected