kaze-design-system 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -95,6 +95,7 @@ const LineChart = forwardRef(
|
|
|
95
95
|
showLegend = true,
|
|
96
96
|
showDots = false,
|
|
97
97
|
yAxisWidth = 48,
|
|
98
|
+
startAtZero = true,
|
|
98
99
|
formatValue = defaultFormat,
|
|
99
100
|
"aria-label": ariaLabel,
|
|
100
101
|
className,
|
|
@@ -146,7 +147,7 @@ const LineChart = forwardRef(
|
|
|
146
147
|
lo = 0;
|
|
147
148
|
hi = 1;
|
|
148
149
|
}
|
|
149
|
-
const scale = niceScale(lo, hi, 5);
|
|
150
|
+
const scale = niceScale(lo, hi, 5, startAtZero);
|
|
150
151
|
const yOf = linearScale([scale.min, scale.max], [PAD_TOP + plotH, PAD_TOP]);
|
|
151
152
|
const xOf = (i) => padLeft + (n <= 1 ? plotW / 2 : i / (n - 1) * plotW);
|
|
152
153
|
const labelStep = Math.max(1, Math.ceil(X_LABEL_MIN_GAP / (n <= 1 ? plotW : plotW / (n - 1))));
|
package/dist/lib/chartScale.js
CHANGED
|
@@ -6,9 +6,9 @@ function niceStep(rawStep) {
|
|
|
6
6
|
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
7
7
|
return nice * base;
|
|
8
8
|
}
|
|
9
|
-
function niceScale(dataMin, dataMax, tickCount = 5) {
|
|
10
|
-
let lo = Math.min(dataMin, 0);
|
|
11
|
-
let hi = Math.max(dataMax, 0);
|
|
9
|
+
function niceScale(dataMin, dataMax, tickCount = 5, includeZero = true) {
|
|
10
|
+
let lo = includeZero ? Math.min(dataMin, 0) : dataMin;
|
|
11
|
+
let hi = includeZero ? Math.max(dataMax, 0) : dataMax;
|
|
12
12
|
if (lo === hi) {
|
|
13
13
|
hi = lo + 1;
|
|
14
14
|
}
|
|
@@ -32,6 +32,8 @@ export interface LineChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "ch
|
|
|
32
32
|
showDots?: boolean;
|
|
33
33
|
/** Width reserved for y axis labels in px (default: 48) */
|
|
34
34
|
yAxisWidth?: number;
|
|
35
|
+
/** Include zero in the y axis (default: true). Set false to fit the data range, e.g. a price or balance line */
|
|
36
|
+
startAtZero?: boolean;
|
|
35
37
|
/** Format values for y axis and tooltip */
|
|
36
38
|
formatValue?: (value: number) => string;
|
|
37
39
|
/** Accessible description of the chart (required) */
|
|
@@ -9,10 +9,10 @@ export interface NiceScale {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Compute axis bounds and evenly spaced ticks that cover [min, max].
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* By default zero is included so bars and areas have a meaningful baseline;
|
|
13
|
+
* pass `includeZero: false` to fit the data range (e.g. a portfolio value line).
|
|
14
14
|
*/
|
|
15
|
-
export declare function niceScale(dataMin: number, dataMax: number, tickCount?: number): NiceScale;
|
|
15
|
+
export declare function niceScale(dataMin: number, dataMax: number, tickCount?: number, includeZero?: boolean): NiceScale;
|
|
16
16
|
/** Linear map from a domain to a range. */
|
|
17
17
|
export declare function linearScale(domain: [number, number], range: [number, number]): (value: number) => number;
|
|
18
18
|
/** Default compact number formatter for axis labels (1,200 / 1.2万 style is left to callers). */
|