Borrow dashboard slices in TSX views and fully initialize example records
This commit is contained in:
1 parent
2ee81ee3b4
commit
a92a5f3c8b
3 files changed
+44
-28
No files matched your search
@@ -6,6 +6,9 @@
|
||||
|
||||
- Borrow band chart points and bands through native slice props.
|
||||
|
||||
- Borrow dashboard chart slices through TSX view props and fully initialize
|
||||
the dashboard example records.
|
||||
|
||||
- Align Plot with Kryon b0636e491's deterministic AVIF pin.
|
||||
|
||||
- Align band chart axes with shared plot bounds and both labelled gridlines.
|
||||
|
||||
@@ -10,14 +10,16 @@ function Beside(bounds: Rectangle): Rectangle {
|
||||
// The second panel uses the original strategy values with its own observed range.
|
||||
function Equity(session: Session, bounds: Rectangle): void {
|
||||
const selected: [Plot.XYPointValue, Plot.XYPointValue, Plot.XYPointValue, Plot.XYPointValue] = [
|
||||
{x: 1640995200, y: 100}, {x: 1648771200, y: 102.9},
|
||||
{x: 1664582400, missing: true}, {x: 1672444800, y: 110.37},
|
||||
{x: 1640995200, y: 100, missing: false}, {x: 1648771200, y: 102.9, missing: false},
|
||||
{x: 1664582400, y: 0, missing: true}, {x: 1672444800, y: 110.37, missing: false},
|
||||
];
|
||||
const benchmark: [Plot.XYPointValue, Plot.XYPointValue, Plot.XYPointValue] = [
|
||||
{x: 1640995200, y: 100}, {x: 1648771200, y: 163.7}, {x: 1672444800, y: 293.58},
|
||||
{x: 1640995200, y: 100, missing: false}, {x: 1648771200, y: 163.7, missing: false},
|
||||
{x: 1672444800, y: 293.58, missing: false},
|
||||
];
|
||||
const series: [Plot.XYSeries, Plot.XYSeries] = [
|
||||
{name: "Selected", points: nativeSlice(selected)}, {name: "Buy and hold", points: nativeSlice(benchmark)},
|
||||
{name: "Selected", color: u32(0), mark: Plot.XYMark.XYLine, points: nativeSlice(selected)},
|
||||
{name: "Buy and hold", color: u32(0), mark: Plot.XYMark.XYLine, points: nativeSlice(benchmark)},
|
||||
];
|
||||
<XYChart session={session} series={nativeSlice(series)} props={{key: u64(11), bounds: bounds,
|
||||
label: "Equity comparison", date_x: true, y_unit: "index", x_min: 1640995200, x_max: 1672444800}}/>;
|
||||
@@ -27,18 +29,25 @@ function Equity(session: Session, bounds: Rectangle): void {
|
||||
|
||||
function Returns(session: Session, bounds: Rectangle): void {
|
||||
const years: [string, string, string] = ["2020", "2022", "2025"];
|
||||
const strategy: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [{value: 4}, {value: 10.37}, {value: -6.43}];
|
||||
const hold: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [{value: -14.8}, {value: -64.2}, {value: -18.5}];
|
||||
const strategy: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [
|
||||
{value: 4, missing: false}, {value: 10.37, missing: false}, {value: -6.43, missing: false},
|
||||
];
|
||||
const hold: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [
|
||||
{value: -14.8, missing: false}, {value: -64.2, missing: false}, {value: -18.5, missing: false},
|
||||
];
|
||||
const returns: [Plot.BarSeries, Plot.BarSeries] = [
|
||||
{name: "Selected", values: nativeSlice(strategy)}, {name: "Buy and hold", values: nativeSlice(hold)},
|
||||
{name: "Selected", color: u32(0), values: nativeSlice(strategy)},
|
||||
{name: "Buy and hold", color: u32(0), values: nativeSlice(hold)},
|
||||
];
|
||||
<BarChart session={session} categories={nativeSlice(years)} series={nativeSlice(returns)} props={{key: u64(13), bounds: bounds,
|
||||
label: "Returns in down years", y_unit: "%"}}/>;
|
||||
let differences: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [{}, {}, {}];
|
||||
let differences: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [
|
||||
{value: 0, missing: false}, {value: 0, missing: false}, {value: 0, missing: false},
|
||||
];
|
||||
for (let index = s32(0); index < s32(3); index += s32(1)) {
|
||||
differences[index] = {value: strategy[index].value - hold[index].value};
|
||||
differences[index] = {value: strategy[index].value - hold[index].value, missing: false};
|
||||
}
|
||||
const delta: [Plot.BarSeries] = [{name: "Return difference", values: nativeSlice(differences)}];
|
||||
const delta: [Plot.BarSeries] = [{name: "Return difference", color: u32(0), values: nativeSlice(differences)}];
|
||||
<BarChart session={session} categories={nativeSlice(years)} series={nativeSlice(delta)} props={{key: u64(14), bounds: Beside(bounds),
|
||||
label: "Outperformance", y_unit: "pp", horizontal: true, hide_legend: true}}/>;
|
||||
}
|
||||
@@ -47,13 +56,14 @@ function Contributions(session: Session, bounds: Rectangle): void {
|
||||
const columns: [string, string, string] = ["2020", "2022", "2025"];
|
||||
const rows: [string, string] = ["Momentum", "Carry"];
|
||||
const cells: [Plot.ChartValue, Plot.ChartValue, Plot.ChartValue, Plot.ChartValue, Plot.ChartValue, Plot.ChartValue] = [
|
||||
{value: 6}, {value: -12}, {missing: true}, {}, {value: 5}, {value: -4.2},
|
||||
{value: 6, missing: false}, {value: -12, missing: false}, {value: 0, missing: true},
|
||||
{value: 0, missing: false}, {value: 5, missing: false}, {value: -4.2, missing: false},
|
||||
];
|
||||
<HeatmapChart session={session} columns={nativeSlice(columns)} rows={nativeSlice(rows)} cells={nativeSlice(cells)} props={{key: u64(15),
|
||||
bounds: bounds, label: "Trait returns", y_unit: "%"}}/>;
|
||||
const steps: [Plot.WaterfallStep, Plot.WaterfallStep, Plot.WaterfallStep, Plot.WaterfallStep] = [
|
||||
{label: "Start", value: 18.5, total: true}, {label: "Signals", value: 7.25},
|
||||
{label: "Costs", value: -4.38}, {label: "End", value: 21.37, total: true},
|
||||
{label: "Start", value: 18.5, total: true, missing: false}, {label: "Signals", value: 7.25, total: false, missing: false},
|
||||
{label: "Costs", value: -4.38, total: false, missing: false}, {label: "End", value: 21.37, total: true, missing: false},
|
||||
];
|
||||
<WaterfallChart session={session} steps={nativeSlice(steps)} props={{key: u64(16), bounds: Beside(bounds),
|
||||
label: "Return contributions", y_unit: "pp"}}/>;
|
||||
@@ -61,17 +71,20 @@ function Contributions(session: Session, bounds: Rectangle): void {
|
||||
|
||||
function Diagnostics(session: Session, bounds: Rectangle): void {
|
||||
const bars: [Plot.PriceBar64, Plot.PriceBar64, Plot.PriceBar64] = [
|
||||
{timestamp: s64(1640995200), open: 100, high: 118, low: 98, close: 111},
|
||||
{timestamp: s64(1641081600), open: 110, high: 115, low: 104, close: 106},
|
||||
{timestamp: s64(1641340800), open: 106, high: 125, low: 105, close: 121},
|
||||
{timestamp: s64(1640995200), open: 100, high: 118, low: 98, close: 111, volume: 0},
|
||||
{timestamp: s64(1641081600), open: 110, high: 115, low: 104, close: 106, volume: 0},
|
||||
{timestamp: s64(1641340800), open: 106, high: 125, low: 105, close: 121, volume: 0},
|
||||
];
|
||||
const allocation: [Plot.XYPointValue, Plot.XYPointValue, Plot.XYPointValue, Plot.XYPointValue] = [
|
||||
{x: 1640995200, y: 25}, {x: 1641081600, y: 60}, {x: 1641254400, y: 15}, {x: 1641340800, y: 15},
|
||||
{x: 1640995200, y: 25, missing: false}, {x: 1641081600, y: 60, missing: false},
|
||||
{x: 1641254400, y: 15, missing: false}, {x: 1641340800, y: 15, missing: false},
|
||||
];
|
||||
const trades: [Plot.XYPointValue, Plot.XYPointValue] = [
|
||||
{x: 1641081600, y: 60, missing: false}, {x: 1641254400, y: 15, missing: false},
|
||||
];
|
||||
const trades: [Plot.XYPointValue, Plot.XYPointValue] = [{x: 1641081600, y: 60}, {x: 1641254400, y: 15}];
|
||||
const marks: [Plot.XYSeries, Plot.XYSeries] = [
|
||||
{name: "Allocation", mark: Plot.XYMark.XYStep, points: nativeSlice(allocation)},
|
||||
{name: "Trade", mark: Plot.XYMark.XYPoint, points: nativeSlice(trades)},
|
||||
{name: "Allocation", color: u32(0), mark: Plot.XYMark.XYStep, points: nativeSlice(allocation)},
|
||||
{name: "Trade", color: u32(0), mark: Plot.XYMark.XYPoint, points: nativeSlice(trades)},
|
||||
];
|
||||
const hit = <TimeCandleChart64 session={session} bars={nativeSlice(bars)} props={{key: u64(17), label: "Price",
|
||||
bounds: bounds, x_min: 1640995200, x_max: 1641340800, y_unit: "USD"}}/>;
|
||||
|
||||
@@ -4,34 +4,34 @@ import { Session } from "kryon/session";
|
||||
export interface XYChartProps {
|
||||
session: Session;
|
||||
props: Native.ChartProps;
|
||||
series: Native.XYSeries[];
|
||||
series: NativeSlice<Native.XYSeries>;
|
||||
}
|
||||
|
||||
export interface BarChartProps {
|
||||
session: Session;
|
||||
props: Native.ChartProps;
|
||||
categories: string[];
|
||||
series: Native.BarSeries[];
|
||||
categories: NativeSlice<string>;
|
||||
series: NativeSlice<Native.BarSeries>;
|
||||
}
|
||||
|
||||
export interface HeatmapChartProps {
|
||||
session: Session;
|
||||
props: Native.ChartProps;
|
||||
columns: string[];
|
||||
rows: string[];
|
||||
cells: Native.ChartValue[];
|
||||
columns: NativeSlice<string>;
|
||||
rows: NativeSlice<string>;
|
||||
cells: NativeSlice<Native.ChartValue>;
|
||||
}
|
||||
|
||||
export interface WaterfallChartProps {
|
||||
session: Session;
|
||||
props: Native.ChartProps;
|
||||
steps: Native.WaterfallStep[];
|
||||
steps: NativeSlice<Native.WaterfallStep>;
|
||||
}
|
||||
|
||||
export interface TimeCandleChartProps<Bar> {
|
||||
session: Session;
|
||||
props: Native.ChartProps;
|
||||
bars: Bar[];
|
||||
bars: NativeSlice<Bar>;
|
||||
}
|
||||
|
||||
export function XYChart(widget: XYChartProps): Native.ChartHit {
|
||||
|
||||
Reference in new issue
Block a user