47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import * as App from "kryon/app";
|
|
import { StyleTokenColor } from "kryon/drawing_props";
|
|
import { ExampleBounds, InstallPlotStyles } from "kryon/examples/optional_scene_styles";
|
|
import { Rectangle } from "kryon/geometry";
|
|
import { Gap } from "kryon/layout";
|
|
import { Session } from "kryon/session";
|
|
import { ThemeMetricRole } from "kryon/theme";
|
|
import { Box } from "kryon/tsx/box";
|
|
import { Column } from "kryon/tsx/layout";
|
|
import { Text } from "kryon/tsx/text";
|
|
import { PlotMode } from "plot/PlotWidget";
|
|
import { Plot } from "plot/tsx/plot";
|
|
|
|
function DrawExample(session: Session, bounds: Rectangle, key: u64): void {
|
|
const values: [float32, float32, float32, float32, float32, float32, float32, float32] = [3, 5, 4, 8, 6, 9, 8, 11];
|
|
<Plot session={session} values={nativeSlice(values)} props={{key: key, bounds: bounds, semantic_label: "Eight example values",
|
|
scale_min: 0, scale_max: 12, mode: PlotMode.PlotBars}}/>;
|
|
}
|
|
|
|
export function SetExampleOptions(_disabled: boolean, _reducedMotion: boolean): void {
|
|
}
|
|
|
|
export function Frame(frame: App.Frame): void {
|
|
const session: Session = {slot: frame.slot, epoch: frame.epoch};
|
|
const viewport = frame.viewport;
|
|
<Box session={session} props={{bounds: viewport, fill: StyleTokenColor("canvas")}}/>;
|
|
<Column session={session} props={{bounds: viewport, padding: Gap(ThemeMetricRole.ThemeMetricSpace6),
|
|
gap: Gap(ThemeMetricRole.ThemeMetricSpace4), gap_override: true}}>
|
|
<Text session={session} props={{bounds: {height: 36}, text: "Plot · bars", size: s32(23)}}/>
|
|
{DrawStandalone(session, viewport)}
|
|
</Column>;
|
|
}
|
|
|
|
function DrawStandalone(session: Session, viewport: Rectangle): void {
|
|
InstallPlotStyles(StyleTokenColor("canvas").r < u8(128));
|
|
DrawExample(session, ExampleBounds(viewport), u64(0));
|
|
}
|
|
|
|
export function GalleryFrame(frame: App.Frame): void {
|
|
const session: Session = {slot: frame.slot, epoch: frame.epoch};
|
|
DrawExample(session, ExampleBounds(frame.viewport), u64(600));
|
|
}
|
|
|
|
export function main(): s32 {
|
|
return App.Run({title: "plotbars"}, Frame);
|
|
}
|