UNPKG

zz-chart

Version:

Alauda Chart components by Alauda Frontend Team

38 lines 1.62 kB
export function axisAutoSize(u, values, axisIdx, cycleNum) { const axis = u.axes[axisIdx]; if (cycleNum > 1) return axis._size; let axisSize = axis.ticks.size + axis.gap; const longestVal = (values ?? []).reduce((acc, val) => (val.length > acc.length ? val : acc), ''); if (longestVal !== '') { u.ctx.font = axis.font[0]; axisSize += u.ctx.measureText(longestVal).width / devicePixelRatio; } return Math.ceil(axisSize + 2); } export function autoPadRight(right = 8) { return (self, _side, _sidesWithAxes, cycleNum) => { const xAxis = self.axes[0]; const xVals = xAxis._values; if (xVals != null) { // bail out, force convergence if (cycleNum > 2) return self._padding[1]; const xSplits = xAxis._splits; const rightSplit = xSplits[xSplits.length - 1]; const rightSplitCoord = self.valToPos(rightSplit, 'x'); const leftPlotEdge = self.bbox.left / devicePixelRatio; const rightPlotEdge = leftPlotEdge + self.bbox.width / devicePixelRatio; const rightChartEdge = rightPlotEdge + self._padding[1]; const pxPerChar = right; const rightVal = xVals[xVals.length - 1] + ''; const valHalfWidth = pxPerChar * (rightVal.length / 2); const rightValEdge = leftPlotEdge + rightSplitCoord + valHalfWidth; if (rightValEdge >= rightChartEdge) { return rightValEdge - rightPlotEdge; } } return right; }; } //# sourceMappingURL=axis.js.map