caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

120 lines
3.4 KiB
TypeScript

/**
* A daily bar series rendered with plain RN Views (no chart lib). Each day is a
* vertical bar whose height is proportional to the largest value in the window;
* a sparse subset of day labels is shown on the axis to avoid crowding. Used
* for cost-over-time and credit-burn-over-time.
*/
import { StyleSheet, Text, View } from "react-native";
import { colors } from "@/components/me/theme";
import type { AnalyticsPoint } from "@/lib/types";
import { formatDay, toPercent } from "./format";
interface TimeSeriesBarsProps {
points: AnalyticsPoint[];
/** Fill colour for the bars (defaults to accent). */
color?: string;
/** Formats a bucket value for the peak-day caption (e.g. USD or count). */
formatValue: (value: number) => string;
/** Caption noun for the peak day, e.g. "spend" or "burn". */
peakLabel?: string;
emptyLabel?: string;
}
const CHART_HEIGHT = 120;
/** Show at most this many axis labels, evenly spaced across the window. */
const MAX_AXIS_LABELS = 4;
export function TimeSeriesBars({
points,
color,
formatValue,
peakLabel = "peak",
emptyLabel = "No activity in this window yet.",
}: TimeSeriesBarsProps) {
if (points.length === 0) {
return (
<View style={styles.card}>
<Text style={styles.empty}>{emptyLabel}</Text>
</View>
);
}
const max = points.reduce((acc, p) => Math.max(acc, p.value), 0);
const peak = points.reduce(
(acc, p) => (p.value > acc.value ? p : acc),
points[0],
);
const labelStride = Math.max(1, Math.ceil(points.length / MAX_AXIS_LABELS));
return (
<View style={styles.card}>
<View style={styles.chart}>
{points.map((point, index) => {
const heightPct = toPercent(point.value, max);
return (
<View key={`${point.date}-${index}`} style={styles.column}>
<View style={styles.barArea}>
<View
style={[
styles.bar,
{
height: max > 0 ? `${Math.max(heightPct, 1)}%` : 2,
backgroundColor: color ?? colors.accent,
},
]}
/>
</View>
<Text style={styles.axisLabel} numberOfLines={1}>
{index % labelStride === 0 ? formatDay(point.date) : ""}
</Text>
</View>
);
})}
</View>
<Text style={styles.caption}>
{max > 0
? `${peakLabel === "peak" ? "Peak" : `Peak ${peakLabel}`}: ${formatValue(
peak.value,
)} on ${formatDay(peak.date)}`
: "No activity in this window yet."}
</Text>
</View>
);
}
const styles = StyleSheet.create({
card: {
backgroundColor: colors.card,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 12,
padding: 14,
gap: 8,
},
chart: {
flexDirection: "row",
alignItems: "flex-end",
height: CHART_HEIGHT,
gap: 2,
},
column: { flex: 1, alignItems: "center", height: "100%" },
barArea: {
flex: 1,
width: "100%",
justifyContent: "flex-end",
alignItems: "stretch",
},
bar: { width: "100%", borderRadius: 3, minHeight: 2 },
axisLabel: {
color: colors.muted,
fontSize: 9,
marginTop: 4,
height: 12,
},
caption: { color: colors.muted, fontSize: 11 },
empty: { color: colors.muted, fontSize: 13, paddingVertical: 12 },
});