feat(坐标轴): 支持显示纵轴单位
All checks were successful
Package component / package (push) Successful in 4m18s

This commit is contained in:
李启源
2026-08-18 10:06:36 +08:00
parent 5c71c28429
commit 233b9b0aa2
10 changed files with 78 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ export interface ScientificAxisLabelOptions {
axisMin?: number
axisMax?: number
topTickValue?: number
unit?: string
}
/** @deprecated Use ScientificAxisLabelOptions. */
@@ -71,9 +72,11 @@ export function formatScientificAxisLabel(
const scaledValue = exponent === null ? value : value / 10 ** exponent
const formattedValue = formatYAxisNumber(scaledValue)
const topTickValue = options.topTickValue ?? options.axisMax
return exponent !== null && value === topTickValue
? `${formatExponent(exponent)} ${formattedValue}`
: formattedValue
if (value !== topTickValue) return formattedValue
const unit = options.unit?.trim()
const unitLabel = unit ? `(${unit}) ` : ''
const exponentLabel = exponent === null ? '' : `${formatExponent(exponent)} `
return `${exponentLabel}${unitLabel}${formattedValue}`
}
/** Return the shared E-style multiplier for an axis, or null for a plain axis. */