Explore: allow changing the graph type (#40522)

* explore: allow switching graph-styles

* refactor: simplify code

* adjust test to test a case that can really happen

* better generate-options approach

* explore: graph styles: remove url functionality

* not-stacked-bars should be filled
This commit is contained in:
Gábor Farkas
2021-10-26 15:51:59 +02:00
committed by GitHub
parent fe11a31175
commit 2c3b35df64
11 changed files with 174 additions and 6 deletions
+19
View File
@@ -201,6 +201,25 @@ export const safeStringifyValue = (value: any, space?: number) => {
return '';
};
export const EXPLORE_GRAPH_STYLES = ['lines', 'bars', 'points', 'stacked_lines', 'stacked_bars'] as const;
export type ExploreGraphStyle = typeof EXPLORE_GRAPH_STYLES[number];
const DEFAULT_GRAPH_STYLE: ExploreGraphStyle = 'lines';
// we use this function to take any kind of data we loaded
// from an external source (URL, localStorage, whatever),
// and extract the graph-style from it, or return the default
// graph-style if we are not able to do that.
// it is important that this function is able to take any form of data,
// (be it objects, or arrays, or booleans or whatever),
// and produce a best-effort graphStyle.
// note that typescript makes sure we make no mistake in this function.
// we do not rely on ` as ` or ` any `.
export const toGraphStyle = (data: unknown): ExploreGraphStyle => {
const found = EXPLORE_GRAPH_STYLES.find((v) => v === data);
return found ?? DEFAULT_GRAPH_STYLE;
};
export function parseUrlState(initial: string | undefined): ExploreUrlState {
const parsed = safeParseJson(initial);
const errorResult: any = {