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

Method _computeGridLineItems

src/core/core.scale.js:1013–1142  ·  view source on GitHub ↗

* @private

(chartArea)

Source from the content-addressed store, hash-verified

1011 * @private
1012 */
1013 _computeGridLineItems(chartArea) {
1014 const axis = this.axis;
1015 const chart = this.chart;
1016 const options = this.options;
1017 const {grid, position, border} = options;
1018 const offset = grid.offset;
1019 const isHorizontal = this.isHorizontal();
1020 const ticks = this.ticks;
1021 const ticksLength = ticks.length + (offset ? 1 : 0);
1022 const tl = getTickMarkLength(grid);
1023 const items = [];
1024
1025 const borderOpts = border.setContext(this.getContext());
1026 const axisWidth = borderOpts.display ? borderOpts.width : 0;
1027 const axisHalfWidth = axisWidth / 2;
1028 const alignBorderValue = function(pixel) {
1029 return _alignPixel(chart, pixel, axisWidth);
1030 };
1031 let borderValue, i, lineValue, alignedLineValue;
1032 let tx1, ty1, tx2, ty2, x1, y1, x2, y2;
1033
1034 if (position === 'top') {
1035 borderValue = alignBorderValue(this.bottom);
1036 ty1 = this.bottom - tl;
1037 ty2 = borderValue - axisHalfWidth;
1038 y1 = alignBorderValue(chartArea.top) + axisHalfWidth;
1039 y2 = chartArea.bottom;
1040 } else if (position === 'bottom') {
1041 borderValue = alignBorderValue(this.top);
1042 y1 = chartArea.top;
1043 y2 = alignBorderValue(chartArea.bottom) - axisHalfWidth;
1044 ty1 = borderValue + axisHalfWidth;
1045 ty2 = this.top + tl;
1046 } else if (position === 'left') {
1047 borderValue = alignBorderValue(this.right);
1048 tx1 = this.right - tl;
1049 tx2 = borderValue - axisHalfWidth;
1050 x1 = alignBorderValue(chartArea.left) + axisHalfWidth;
1051 x2 = chartArea.right;
1052 } else if (position === 'right') {
1053 borderValue = alignBorderValue(this.left);
1054 x1 = chartArea.left;
1055 x2 = alignBorderValue(chartArea.right) - axisHalfWidth;
1056 tx1 = borderValue + axisHalfWidth;
1057 tx2 = this.left + tl;
1058 } else if (axis === 'x') {
1059 if (position === 'center') {
1060 borderValue = alignBorderValue((chartArea.top + chartArea.bottom) / 2 + 0.5);
1061 } else if (isObject(position)) {
1062 const positionAxisID = Object.keys(position)[0];
1063 const value = position[positionAxisID];
1064 borderValue = alignBorderValue(this.chart.scales[positionAxisID].getPixelForValue(value));
1065 }
1066
1067 y1 = chartArea.top;
1068 y2 = chartArea.bottom;
1069 ty1 = borderValue + axisHalfWidth;
1070 ty2 = ty1 + tl;

Callers 1

drawGridMethod · 0.95

Calls 9

isHorizontalMethod · 0.95
getContextMethod · 0.95
getTickMarkLengthFunction · 0.85
isObjectFunction · 0.85
valueOrDefaultFunction · 0.85
getPixelForGridLineFunction · 0.85
_alignPixelFunction · 0.85
setContextMethod · 0.80
getPixelForValueMethod · 0.65

Tested by

no test coverage detected