From 48840c5d61b07ccfd1374b9b94f474aa4d5d92d3 Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Tue, 3 Oct 2023 12:43:04 +0200 Subject: [PATCH] feat: Support Gantt plots with time scale. --- ui/src/plot.tsx | 8 ++++---- website/widgets/plots/interval.md | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ui/src/plot.tsx b/ui/src/plot.tsx index 0f35851982..de7915b2b5 100644 --- a/ui/src/plot.tsx +++ b/ui/src/plot.tsx @@ -492,9 +492,9 @@ export const } const - isF = (x: any): x is number => typeof x === 'number', - isB = (x: any): x is boolean => typeof x === 'boolean', - isS = (x: any): x is string => typeof x === 'string', + isF = (x: unknown): x is number => typeof x === 'number', + isB = (x: unknown): x is boolean => typeof x === 'boolean', + isS = (x: unknown): x is string => typeof x === 'string', split = (s: S) => s.trim().split(/\s+/g), parseInts = (s: S) => split(s).map(s => parseInt(s, 10)), convertToDates = (ds: any[], f: S) => { @@ -939,7 +939,7 @@ const const type = getCoordType(marks) as any, - transpose = space === SpaceT.CD, + transpose = space === SpaceT.CD || space === SpaceT.TD, actions: CoordinateActions[] | undefined = transpose ? [['transpose']] : undefined if (transpose) for (const mark of marks) transposeMark(mark) diff --git a/website/widgets/plots/interval.md b/website/widgets/plots/interval.md index 0d7bd916e4..0294395a61 100644 --- a/website/widgets/plots/interval.md +++ b/website/widgets/plots/interval.md @@ -139,7 +139,7 @@ q.page['example'] = ui.plot_card( ## Range -Make a column plot with each bar representing high/low (or start/end) values. Transposing this produces a Gantt plot. +Make a column plot with each bar representing high/low (or start/end) values. ```py from h2o_wave import data @@ -158,6 +158,27 @@ q.page['example'] = ui.plot_card( ) ``` +## Gantt + +Make a Gantt plot with each bar representing high/low (or start/end) values. + +```py +from h2o_wave import data + +q.page['example'] = ui.plot_card( + box='1 1 4 5', + title='Interval, range', + data=data('profession max min', 5, rows=[ + ('medicine', '2022-01-01', '2020-01-01'), + ('fire fighting', '2021-06-01', '2021-01-01'), + ('pedagogy', '2020-06-01', '2022-01-01'), + ('psychology', '2021-01-01', '2022-01-01'), + ('computer science', '2020-01-01', '2022-01-01'), + ]), + plot=ui.plot([ui.mark(type='interval', y='=profession', x_scale='time', x0='=min', x='=max')]) +) +``` + ## Polar Make a rose plot (a bar plot in polar coordinates).