@siyahi/ui 0.1.9-next.3 → 0.1.9-next.4
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.
|
@@ -3,11 +3,13 @@ import { ChartFrame, seriesFill } from "../../../lib/chart-frame.js";
|
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { Bar, BarChart, Cell } from "recharts";
|
|
5
5
|
//#region src/components/registry/charts/bar-chart-card.tsx
|
|
6
|
+
const DOWN_FROM_ZERO = ["auto", 0];
|
|
6
7
|
/** Values over an ordered axis as bars: one series, or several grouped or stacked. */
|
|
7
8
|
function BarChartCard({ stacked = false, selected = null, onSelect, ...props }) {
|
|
8
9
|
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
9
10
|
chart: BarChart,
|
|
10
11
|
...props,
|
|
12
|
+
yDomain: props.yDomain ?? (props.data.some((row) => props.series.some(({ key }) => Number(row[key]) > 0)) ? void 0 : DOWN_FROM_ZERO),
|
|
11
13
|
stackOffset: stacked ? "sign" : void 0,
|
|
12
14
|
children: props.series.map((item, index) => {
|
|
13
15
|
const { key, label, color, negativeColor } = item;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ChartColor, ChartSeries, ChartSeriesItem, NumericXProps, SeriesChartProps } from "./chart-series.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
|
-
import { AreaChart, BarChart, LineChart } from "recharts";
|
|
3
|
+
import { AreaChart, BarChart, LineChart, YAxisProps } from "recharts";
|
|
4
4
|
//#region src/lib/chart-frame.d.ts
|
|
5
|
-
interface ChartFrameProps<T extends object, K extends keyof T> extends SeriesChartProps<T, K>, NumericXProps {
|
|
5
|
+
interface ChartFrameProps<T extends object, K extends keyof T> extends Omit<SeriesChartProps<T, K>, "yDomain">, NumericXProps {
|
|
6
6
|
chart: typeof AreaChart | typeof BarChart | typeof LineChart;
|
|
7
|
+
/** The value axis' range: a page's fixed one, or a card's rule such as bars reaching zero. */
|
|
8
|
+
yDomain?: YAxisProps["domain"];
|
|
7
9
|
/** One Bar, Area or Line per series. */
|
|
8
10
|
children: ReactNode;
|
|
9
11
|
/**
|
|
@@ -57,7 +57,10 @@ export interface SeriesChartProps<T extends object, K extends keyof T> {
|
|
|
57
57
|
valueFormatter?: (value: number) => string;
|
|
58
58
|
/** The y axis, when its ticks should be shorter than the tooltip's figures: moneyCompact against money. */
|
|
59
59
|
yTickFormatter?: (value: number) => string;
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* A fixed range for the value axis, such as [0, 100] for a percentage. By default it fits the data; a bar
|
|
62
|
+
* chart's always reaches zero.
|
|
63
|
+
*/
|
|
61
64
|
yDomain?: [number, number];
|
|
62
65
|
/** Where the value axis puts its ticks, such as [0, 25, 50, 75, 100]. */
|
|
63
66
|
yTicks?: readonly number[];
|