* Calculate points location for each series.
(seriesModel: BoxplotSeriesModel, offset: number, boxWidth: number)
| 117 | * Calculate points location for each series. |
| 118 | */ |
| 119 | function layoutSingleSeries(seriesModel: BoxplotSeriesModel, offset: number, boxWidth: number) { |
| 120 | const coordSys = seriesModel.coordinateSystem; |
| 121 | const data = seriesModel.getData(); |
| 122 | const halfWidth = boxWidth / 2; |
| 123 | const cDimIdx = seriesModel.getWhiskerBoxesLayout() === 'horizontal' ? 0 : 1; |
| 124 | const vDimIdx = 1 - cDimIdx; |
| 125 | const coordDims = ['x', 'y']; |
| 126 | const cDim = data.mapDimension(coordDims[cDimIdx]); |
| 127 | const vDims = data.mapDimensionsAll(coordDims[vDimIdx]); |
| 128 | |
| 129 | if (cDim == null || vDims.length < 5) { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | for (let dataIndex = 0; dataIndex < data.count(); dataIndex++) { |
| 134 | const axisDimVal = data.get(cDim, dataIndex) as number; |
| 135 | |
| 136 | const median = getPoint(axisDimVal, vDims[2], dataIndex); |
| 137 | const end1 = getPoint(axisDimVal, vDims[0], dataIndex); |
| 138 | const end2 = getPoint(axisDimVal, vDims[1], dataIndex); |
| 139 | const end4 = getPoint(axisDimVal, vDims[3], dataIndex); |
| 140 | const end5 = getPoint(axisDimVal, vDims[4], dataIndex); |
| 141 | |
| 142 | const ends: number[][] = []; |
| 143 | addBodyEnd(ends, end2, false); |
| 144 | addBodyEnd(ends, end4, true); |
| 145 | |
| 146 | ends.push(end1, end2, end5, end4); |
| 147 | layEndLine(ends, end1); |
| 148 | layEndLine(ends, end5); |
| 149 | layEndLine(ends, median); |
| 150 | |
| 151 | data.setItemLayout(dataIndex, { |
| 152 | initBaseline: median[vDimIdx], |
| 153 | ends: ends |
| 154 | } as BoxplotItemLayout); |
| 155 | } |
| 156 | |
| 157 | function getPoint(axisDimVal: number, dim: string, dataIndex: number) { |
| 158 | const val = data.get(dim, dataIndex) as number; |
| 159 | const p = []; |
| 160 | p[cDimIdx] = axisDimVal; |
| 161 | p[vDimIdx] = val; |
| 162 | let point; |
| 163 | if (isNaN(axisDimVal) || isNaN(val)) { |
| 164 | point = [NaN, NaN]; |
| 165 | } |
| 166 | else { |
| 167 | point = coordSys.dataToPoint(p); |
| 168 | point[cDimIdx] += offset; |
| 169 | } |
| 170 | return point; |
| 171 | } |
| 172 | |
| 173 | function addBodyEnd(ends: number[][], point: number[], start?: boolean) { |
| 174 | const point1 = point.slice(); |
| 175 | const point2 = point.slice(); |
| 176 | point1[cDimIdx] += halfWidth; |
no test coverage detected
searching dependent graphs…