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

Method _computeGridLineItems

src/core/core.scale.js:1021–1150  ·  view source on GitHub ↗

* @private

(chartArea)

Source from the content-addressed store, hash-verified

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