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

Method _computeLabelItems

src/core/core.scale.js:1155–1334  ·  view source on GitHub ↗

* @private

(chartArea)

Source from the content-addressed store, hash-verified

1153 * @private
1154 */
1155 _computeLabelItems(chartArea) {
1156 const axis = this.axis;
1157 const options = this.options;
1158 const {position, ticks: optionTicks} = options;
1159 const isHorizontal = this.isHorizontal();
1160 const ticks = this.ticks;
1161 const {align, crossAlign, padding, mirror} = optionTicks;
1162 const tl = getTickMarkLength(options.grid);
1163 const tickAndPadding = tl + padding;
1164 const hTickAndPadding = mirror ? -padding : tickAndPadding;
1165 const rotation = -toRadians(this.labelRotation);
1166 const items = [];
1167 let i, ilen, tick, label, x, y, textAlign, pixel, font, lineHeight, lineCount, textOffset;
1168 let textBaseline = 'middle';
1169
1170 if (position === 'top') {
1171 y = this.bottom - hTickAndPadding;
1172 textAlign = this._getXAxisLabelAlignment();
1173 } else if (position === 'bottom') {
1174 y = this.top + hTickAndPadding;
1175 textAlign = this._getXAxisLabelAlignment();
1176 } else if (position === 'left') {
1177 const ret = this._getYAxisLabelAlignment(tl);
1178 textAlign = ret.textAlign;
1179 x = ret.x;
1180 } else if (position === 'right') {
1181 const ret = this._getYAxisLabelAlignment(tl);
1182 textAlign = ret.textAlign;
1183 x = ret.x;
1184 } else if (axis === 'x') {
1185 if (position === 'center') {
1186 y = ((chartArea.top + chartArea.bottom) / 2) + tickAndPadding;
1187 } else if (isObject(position)) {
1188 const positionAxisID = Object.keys(position)[0];
1189 const value = position[positionAxisID];
1190 y = this.chart.scales[positionAxisID].getPixelForValue(value) + tickAndPadding;
1191 }
1192 textAlign = this._getXAxisLabelAlignment();
1193 } else if (axis === 'y') {
1194 if (position === 'center') {
1195 x = ((chartArea.left + chartArea.right) / 2) - tickAndPadding;
1196 } else if (isObject(position)) {
1197 const positionAxisID = Object.keys(position)[0];
1198 const value = position[positionAxisID];
1199 x = this.chart.scales[positionAxisID].getPixelForValue(value);
1200 }
1201 textAlign = this._getYAxisLabelAlignment(tl).textAlign;
1202 }
1203
1204 if (axis === 'y') {
1205 if (align === 'start') {
1206 textBaseline = 'top';
1207 } else if (align === 'end') {
1208 textBaseline = 'bottom';
1209 }
1210 }
1211
1212 const labelSizes = this._getLabelSizes();

Callers 1

getLabelItemsMethod · 0.95

Calls 14

isHorizontalMethod · 0.95
_getLabelSizesMethod · 0.95
getPixelForTickMethod · 0.95
getContextMethod · 0.95
getTickMarkLengthFunction · 0.85
toRadiansFunction · 0.85
isObjectFunction · 0.85
isArrayFunction · 0.85
toPaddingFunction · 0.85

Tested by

no test coverage detected