* Calculate offset and box width for each series.
(baseAxis: Axis, seriesCount: number)
| 74 | * Calculate offset and box width for each series. |
| 75 | */ |
| 76 | function calculateBase(baseAxis: Axis, seriesCount: number): BaseCalculationResult { |
| 77 | const boxWidthList: BaseCalculationResult['boxOffsetList'] = []; |
| 78 | const boxOffsetList: BaseCalculationResult['boxWidthList'] = []; |
| 79 | const boundList: Record<BoxplotSeriesModel['seriesIndex'], number[]> = []; |
| 80 | |
| 81 | const bandWidth = calcBandWidth( |
| 82 | baseAxis, |
| 83 | {fromStat: {key: makeAxisStatKey(SERIES_TYPE_BOXPLOT)}, min: 1}, |
| 84 | ).w; |
| 85 | |
| 86 | eachSeriesOnAxisOnKey(baseAxis, makeAxisStatKey(SERIES_TYPE_BOXPLOT), function (seriesModel: BoxplotSeriesModel) { |
| 87 | let boxWidthBound = seriesModel.get('boxWidth'); |
| 88 | if (!isArray(boxWidthBound)) { |
| 89 | boxWidthBound = [boxWidthBound, boxWidthBound]; |
| 90 | } |
| 91 | boundList[seriesModel.seriesIndex] = [ |
| 92 | parsePercent(boxWidthBound[0], bandWidth) || 0, |
| 93 | parsePercent(boxWidthBound[1], bandWidth) || 0 |
| 94 | ]; |
| 95 | }); |
| 96 | |
| 97 | const availableWidth = bandWidth * 0.8 - 2; |
| 98 | const boxGap = availableWidth / seriesCount * 0.3; |
| 99 | const boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount; |
| 100 | let base = boxWidth / 2 - availableWidth / 2; |
| 101 | |
| 102 | eachSeriesOnAxisOnKey(baseAxis, makeAxisStatKey(SERIES_TYPE_BOXPLOT), function (seriesModel) { |
| 103 | const seriesIndex = seriesModel.seriesIndex; |
| 104 | boxOffsetList[seriesIndex] = base; |
| 105 | base += boxGap + boxWidth; |
| 106 | |
| 107 | boxWidthList[seriesIndex] = mathMin(mathMax(boxWidth, boundList[seriesIndex][0]), boundList[seriesIndex][1]); |
| 108 | }); |
| 109 | |
| 110 | return { |
| 111 | boxOffsetList, |
| 112 | boxWidthList, |
| 113 | }; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Calculate points location for each series. |
no test coverage detected
searching dependent graphs…