From 61ebd8d4b9778c150625b796dbdf4499d0790a0f Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Thu, 7 Oct 2021 16:44:03 -0500 Subject: [PATCH 1/3] feat(types): improve generic types in specs, and spec prop types --- .../layout/types/viewmodel_types.ts | 4 +- .../src/chart_types/goal_chart/specs/index.ts | 48 ++--- .../src/chart_types/heatmap/specs/heatmap.ts | 86 ++++---- .../heatmap/state/selectors/heatmap_spec.ts | 4 +- .../partition_chart/specs/index.ts | 108 +++++----- .../src/chart_types/wordcloud/specs/index.ts | 51 ++--- .../chart_types/xy_chart/specs/area_series.ts | 53 +++++ .../xy_chart/specs/area_series.tsx | 46 ----- .../src/chart_types/xy_chart/specs/axis.ts | 36 ++++ .../src/chart_types/xy_chart/specs/axis.tsx | 35 ---- .../chart_types/xy_chart/specs/bar_series.ts | 53 +++++ .../chart_types/xy_chart/specs/bar_series.tsx | 46 ----- .../xy_chart/specs/bubble_series.ts | 52 +++++ .../xy_chart/specs/bubble_series.tsx | 46 ----- .../xy_chart/specs/histogram_bar_series.ts | 53 +++++ .../xy_chart/specs/histogram_bar_series.tsx | 46 ----- .../xy_chart/specs/line_annotation.ts | 52 +++++ .../xy_chart/specs/line_annotation.tsx | 40 ---- .../chart_types/xy_chart/specs/line_series.ts | 53 +++++ .../xy_chart/specs/line_series.tsx | 45 ----- .../xy_chart/specs/rect_annotation.ts | 33 +++ .../xy_chart/specs/rect_annotation.tsx | 38 ---- .../src/chart_types/xy_chart/utils/specs.ts | 85 ++++---- packages/charts/src/specs/constants.ts | 53 +++-- packages/charts/src/specs/group_by.ts | 53 +++-- packages/charts/src/specs/settings.tsx | 56 ++---- packages/charts/src/specs/small_multiples.ts | 30 +-- packages/charts/src/state/spec_factory.ts | 190 ++++++++++++++---- packages/charts/src/utils/accessor.ts | 13 +- packages/charts/src/utils/common.tsx | 3 +- 30 files changed, 832 insertions(+), 679 deletions(-) create mode 100644 packages/charts/src/chart_types/xy_chart/specs/area_series.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/area_series.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/axis.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/axis.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/bar_series.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/bar_series.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/bubble_series.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/bubble_series.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/line_annotation.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/line_annotation.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/line_series.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/line_series.tsx create mode 100644 packages/charts/src/chart_types/xy_chart/specs/rect_annotation.ts delete mode 100644 packages/charts/src/chart_types/xy_chart/specs/rect_annotation.tsx diff --git a/packages/charts/src/chart_types/goal_chart/layout/types/viewmodel_types.ts b/packages/charts/src/chart_types/goal_chart/layout/types/viewmodel_types.ts index 4699e2b4447..408e8bd1066 100644 --- a/packages/charts/src/chart_types/goal_chart/layout/types/viewmodel_types.ts +++ b/packages/charts/src/chart_types/goal_chart/layout/types/viewmodel_types.ts @@ -58,8 +58,6 @@ export type ShapeViewModel = { }; const commonDefaults = { - specType: SpecType.Series, - subtype: GoalSubtype.Goal, base: 0, actual: 50, ticks: [0, 25, 50, 75, 100], @@ -85,6 +83,8 @@ export const defaultGoalSpec = { /** @internal */ export const nullGoalViewModel = { ...commonDefaults, + specType: SpecType.Series, + subtype: GoalSubtype.Goal, bands: [], ticks: [], labelMajor: '', diff --git a/packages/charts/src/chart_types/goal_chart/specs/index.ts b/packages/charts/src/chart_types/goal_chart/specs/index.ts index ab0e1036505..70e81ee4363 100644 --- a/packages/charts/src/chart_types/goal_chart/specs/index.ts +++ b/packages/charts/src/chart_types/goal_chart/specs/index.ts @@ -6,13 +6,13 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { Color } from '../../../common/colors'; import { Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { specComponentFactory } from '../../../state/spec_factory'; import { LabelAccessor, RecursivePartial } from '../../../utils/common'; import { Config } from '../layout/types/config_types'; import { defaultGoalSpec } from '../layout/types/viewmodel_types'; @@ -36,11 +36,6 @@ export type BandFillColorAccessor = (input: BandFillColorAccessorInput) => Color /** @alpha */ export type GoalLabelAccessor = LabelAccessor; -const defaultProps = { - chartType: ChartType.Goal, - ...defaultGoalSpec, -}; - /** @alpha */ export interface GoalSpec extends Spec { specType: typeof SpecType.Series; @@ -67,28 +62,19 @@ export interface GoalSpec extends Spec { bandLabels: string[]; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @alpha */ -export const Goal: React.FunctionComponent = getConnect()( - specComponentFactory< - GoalSpec, - | 'chartType' - | 'subtype' - | 'base' - | 'target' - | 'actual' - | 'bands' - | 'bandLabels' - | 'ticks' - | 'bandFillColor' - | 'tickValueFormatter' - | 'labelMajor' - | 'labelMinor' - | 'centralMajor' - | 'centralMinor' - | 'angleStart' - | 'angleEnd' - >(defaultProps), +/** + * Add Goal spec to chart + * @alpha + */ +export const Goal = specComponentFactory()( + { + specType: SpecType.Series, + chartType: ChartType.Goal, + }, + { + ...defaultGoalSpec, + }, ); + +/** @public */ +export type GoalProps = ComponentProps; diff --git a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts index 36a8fe96f79..0bb20d65c8f 100644 --- a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts +++ b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts @@ -6,35 +6,21 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps, useRef } from 'react'; import { ChartType } from '../..'; import { Color } from '../../../common/colors'; import { Predicate } from '../../../common/predicate'; import { ScaleType } from '../../../scales/constants'; -import { SeriesScales, Spec } from '../../../specs'; +import { BaseDatum, SeriesScales, Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; import { Accessor, AccessorFn } from '../../../utils/accessor'; -import { Datum, RecursivePartial } from '../../../utils/common'; +import { RecursivePartial } from '../../../utils/common'; import { config } from '../layout/config/config'; import { Config } from '../layout/types/config_types'; import { X_SCALE_DEFAULT } from './scale_defaults'; -const defaultProps = { - chartType: ChartType.Heatmap, - specType: SpecType.Series, - data: [], - xAccessor: ({ x }: { x: string | number }) => x, - yAccessor: ({ y }: { y: string | number }) => y, - xScaleType: X_SCALE_DEFAULT.type, - valueAccessor: ({ value }: { value: string | number }) => value, - valueFormatter: (value: number) => `${value}`, - xSortPredicate: Predicate.AlphaAsc, - ySortPredicate: Predicate.AlphaAsc, - config, -}; - /** @public */ export type HeatmapScaleType = | typeof ScaleType.Linear @@ -59,13 +45,13 @@ export interface HeatmapBandsColorScale { } /** @alpha */ -export interface HeatmapSpec extends Spec { +export interface HeatmapSpec extends Spec { specType: typeof SpecType.Series; chartType: typeof ChartType.Heatmap; - data: Datum[]; + data: D[]; colorScale: HeatmapBandsColorScale; - xAccessor: Accessor | AccessorFn; - yAccessor: Accessor | AccessorFn; + xAccessor: keyof D | AccessorFn; + yAccessor: keyof D | AccessorFn; valueAccessor: Accessor | AccessorFn; valueFormatter: (value: number) => string; xSortPredicate: Predicate; @@ -76,20 +62,42 @@ export interface HeatmapSpec extends Spec { name?: string; } -/** @alpha */ -export const Heatmap: React.FunctionComponent< - Pick & Partial> -> = getConnect()( - specComponentFactory< - HeatmapSpec, - | 'xAccessor' - | 'yAccessor' - | 'valueAccessor' - | 'data' - | 'ySortPredicate' - | 'xSortPredicate' - | 'valueFormatter' - | 'config' - | 'xScaleType' - >(defaultProps), -); +/** + * Adds heatmap spec to chart specs + * @alpha + */ +export const Heatmap = function ( + props: SFProps< + HeatmapSpec, + keyof typeof buildProps.current['overrides'], + keyof typeof buildProps.current['defaults'], + keyof typeof buildProps.current['optionals'], + keyof typeof buildProps.current['requires'] + >, +) { + const buildProps = useRef( + buildSFProps>()( + { + chartType: ChartType.Heatmap, + specType: SpecType.Series, + }, + { + data: [], + // xAccessor: ({ x }: { x: string | number }) => x, + // yAccessor: ({ y }: { y: string | number }) => y, + valueAccessor: ({ value }) => value, + xScaleType: X_SCALE_DEFAULT.type, + valueFormatter: (value) => `${value}`, + xSortPredicate: Predicate.AlphaAsc, + ySortPredicate: Predicate.AlphaAsc, + config, + }, + ), + ); + const { defaults, overrides } = buildProps.current; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type HeatmapProps = ComponentProps; diff --git a/packages/charts/src/chart_types/heatmap/state/selectors/heatmap_spec.ts b/packages/charts/src/chart_types/heatmap/state/selectors/heatmap_spec.ts index a34755931ef..4f11040d143 100644 --- a/packages/charts/src/chart_types/heatmap/state/selectors/heatmap_spec.ts +++ b/packages/charts/src/chart_types/heatmap/state/selectors/heatmap_spec.ts @@ -13,7 +13,7 @@ import { getSpecsFromStore } from '../../../../state/utils'; import { HeatmapSpec } from '../../specs/heatmap'; /** @internal */ -export function getSpecOrNull(state: GlobalChartState): HeatmapSpec | null { - const specs = getSpecsFromStore(state.specs, ChartType.Heatmap, SpecType.Series); +export function getSpecOrNull(state: GlobalChartState): HeatmapSpec | null { + const specs = getSpecsFromStore>(state.specs, ChartType.Heatmap, SpecType.Series); return specs.length > 0 ? specs[0] : null; } diff --git a/packages/charts/src/chart_types/partition_chart/specs/index.ts b/packages/charts/src/chart_types/partition_chart/specs/index.ts index 83a351fed1a..633396af841 100644 --- a/packages/charts/src/chart_types/partition_chart/specs/index.ts +++ b/packages/charts/src/chart_types/partition_chart/specs/index.ts @@ -6,26 +6,19 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { Pixels } from '../../../common/geometry'; -import { Spec } from '../../../specs'; +import { BaseDatum, Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; // kept as unshortened import on separate line otherwise import circularity emerges -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; import { IndexedAccessorFn } from '../../../utils/accessor'; -import { - Datum, - LabelAccessor, - RecursivePartial, - ShowAccessor, - ValueAccessor, - ValueFormatter, -} from '../../../utils/common'; +import { LabelAccessor, RecursivePartial, ShowAccessor, ValueAccessor, ValueFormatter } from '../../../utils/common'; import { config, percentFormatter } from '../layout/config'; import { Config, FillFontSizeRange, FillLabelConfig } from '../layout/types/config_types'; -import { NodeColorAccessor, ShapeTreeNode, ValueGetter } from '../layout/types/viewmodel_types'; -import { AGGREGATE_KEY, NodeSorter, PrimitiveValue } from '../layout/utils/group_by_rollup'; +import { NodeColorAccessor, ValueGetter } from '../layout/types/viewmodel_types'; +import { AGGREGATE_KEY, NodeSorter } from '../layout/utils/group_by_rollup'; interface ExtendedFillLabelConfig extends FillLabelConfig, FillFontSizeRange {} @@ -33,8 +26,8 @@ interface ExtendedFillLabelConfig extends FillLabelConfig, FillFontSizeRange {} * Specification for a given layer in the partition chart * @public */ -export interface Layer { - groupByRollup: IndexedAccessorFn; +export interface Layer { + groupByRollup: IndexedAccessorFn; sortPredicate?: NodeSorter | null; nodeLabel?: LabelAccessor; fillLabel?: Partial; @@ -42,58 +35,65 @@ export interface Layer { shape?: { fillColor: string | NodeColorAccessor }; } -const defaultProps = { - chartType: ChartType.Partition, - specType: SpecType.Series, - config, - valueAccessor: (d: Datum) => (typeof d === 'number' ? d : 0), - valueGetter: (n: ShapeTreeNode): number => n[AGGREGATE_KEY], - valueFormatter: (d: number): string => String(d), - percentFormatter, - topGroove: 20, - smallMultiples: null, - layers: [ - { - groupByRollup: (d: Datum, i: number) => i, - nodeLabel: (d: PrimitiveValue) => String(d), - showAccessor: () => true, - fillLabel: {}, - }, - ], -}; - /** * Specifies the partition chart * @public */ -export interface PartitionSpec extends Spec { +export interface PartitionSpec extends Spec { specType: typeof SpecType.Series; chartType: typeof ChartType.Partition; config: RecursivePartial; - data: Datum[]; - valueAccessor: ValueAccessor; + data: D[]; + valueAccessor: ValueAccessor; valueFormatter: ValueFormatter; valueGetter: ValueGetter; percentFormatter: ValueFormatter; topGroove: Pixels; smallMultiples: string | null; - layers: Layer[]; + layers: Layer[]; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; +const buildProps = buildSFProps>()( + { + chartType: ChartType.Partition, + specType: SpecType.Series, + }, + { + config, + valueAccessor: (d) => (typeof d === 'number' ? d : 0), + valueGetter: (n) => n[AGGREGATE_KEY], + valueFormatter: (d) => String(d), + percentFormatter, + topGroove: 20, + smallMultiples: null, + layers: [ + { + groupByRollup: (d, i) => i, + nodeLabel: (d) => String(d), + showAccessor: () => true, + fillLabel: {}, + }, + ], + }, +); + +/** + * Adds partition spec to chart specs + * @public + */ +export const Partition = function ( + props: SFProps< + PartitionSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; /** @public */ -export const Partition: React.FunctionComponent = getConnect()( - specComponentFactory< - PartitionSpec, - | 'valueAccessor' - | 'valueGetter' - | 'valueFormatter' - | 'layers' - | 'config' - | 'percentFormatter' - | 'topGroove' - | 'smallMultiples' - >(defaultProps), -); +export type PartitionProp = ComponentProps; diff --git a/packages/charts/src/chart_types/wordcloud/specs/index.ts b/packages/charts/src/chart_types/wordcloud/specs/index.ts index beeb51028d6..90a77bd687b 100644 --- a/packages/charts/src/chart_types/wordcloud/specs/index.ts +++ b/packages/charts/src/chart_types/wordcloud/specs/index.ts @@ -6,13 +6,13 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { FontStyle } from '../../../common/text_utils'; import { Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { specComponentFactory } from '../../../state/spec_factory'; import { RecursivePartial } from '../../../utils/common'; import { config } from '../layout/config/config'; import { @@ -23,13 +23,6 @@ import { Configs as WordcloudConfigs, } from '../layout/types/viewmodel_types'; -const defaultProps = { - chartType: ChartType.Wordcloud, - specType: SpecType.Series, - ...defaultWordcloudSpec, - config, -}; - export { WordModel, WeightFn, OutOfRoomCallback, WordcloudConfigs }; /** @alpha */ @@ -53,28 +46,20 @@ export interface WordcloudSpec extends Spec { outOfRoomCallback: OutOfRoomCallback; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @alpha */ -export const Wordcloud: React.FunctionComponent = getConnect()( - specComponentFactory< - WordcloudSpec, - | 'chartType' - | 'startAngle' - | 'config' - | 'endAngle' - | 'angleCount' - | 'padding' - | 'fontWeight' - | 'fontFamily' - | 'fontStyle' - | 'minFontSize' - | 'maxFontSize' - | 'spiral' - | 'exponent' - | 'data' - | 'weightFn' - | 'outOfRoomCallback' - >(defaultProps), +/** + * Adds wordcloud spec to chart + * @alpha + */ +export const Wordcloud = specComponentFactory()( + { + specType: SpecType.Series, + chartType: ChartType.Wordcloud, + }, + { + ...defaultWordcloudSpec, + config, + }, ); + +/** @public */ +export type WordcloudProps = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/area_series.ts b/packages/charts/src/chart_types/xy_chart/specs/area_series.ts new file mode 100644 index 00000000000..b74b2fa79d2 --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/area_series.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { ScaleType } from '../../../scales/constants'; +import { SpecType } from '../../../specs/constants'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; +import { AreaSeriesSpec, HistogramModeAlignments, DEFAULT_GLOBAL_ID, SeriesType, BaseDatum } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Series, + seriesType: SeriesType.Area, + }, + { + groupId: DEFAULT_GLOBAL_ID, + xScaleType: ScaleType.Linear, + yScaleType: ScaleType.Linear, + // xAccessor: 'x', + // yAccessors: ['y'], + hideInLegend: false, + histogramModeAlignment: HistogramModeAlignments.Center, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const AreaSeries = function ( + props: SFProps< + AreaSeriesSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type AreaSeriesProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/area_series.tsx b/packages/charts/src/chart_types/xy_chart/specs/area_series.tsx deleted file mode 100644 index 0e5231faf04..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/area_series.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { ScaleType } from '../../../scales/constants'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { AreaSeriesSpec, HistogramModeAlignments, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Series, - seriesType: SeriesType.Area, - groupId: DEFAULT_GLOBAL_ID, - xScaleType: ScaleType.Linear, - yScaleType: ScaleType.Linear, - xAccessor: 'x', - yAccessors: ['y'], - hideInLegend: false, - histogramModeAlignment: HistogramModeAlignments.Center, -}; - -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @public */ -export const AreaSeries: React.FunctionComponent = getConnect()( - specComponentFactory< - AreaSeriesSpec, - | 'seriesType' - | 'groupId' - | 'xScaleType' - | 'yScaleType' - | 'xAccessor' - | 'yAccessors' - | 'hideInLegend' - | 'histogramModeAlignment' - >(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/axis.ts b/packages/charts/src/chart_types/xy_chart/specs/axis.ts new file mode 100644 index 00000000000..7b5ce12da7a --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/axis.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { SpecType } from '../../../specs/constants'; +import { specComponentFactory } from '../../../state/spec_factory'; +import { Position } from '../../../utils/common'; +import { AxisSpec, DEFAULT_GLOBAL_ID } from '../utils/specs'; + +/** + * Add axis spec to chart + * @public + */ +export const Axis = specComponentFactory()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Axis, + }, + { + groupId: DEFAULT_GLOBAL_ID, + hide: false, + showOverlappingTicks: false, + showOverlappingLabels: false, + position: Position.Left, + }, +); + +/** @public */ +export type AxisProps = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/axis.tsx b/packages/charts/src/chart_types/xy_chart/specs/axis.tsx deleted file mode 100644 index d80e8c469d0..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/axis.tsx +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { Position } from '../../../utils/common'; -import { AxisSpec, DEFAULT_GLOBAL_ID } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Axis, - groupId: DEFAULT_GLOBAL_ID, - hide: false, - showOverlappingTicks: false, - showOverlappingLabels: false, - position: Position.Left, -}; - -type SpecRequired = Pick; -type SpecOptionals = Partial>; - -/** @public */ -export const Axis: React.FunctionComponent = getConnect()( - specComponentFactory( - defaultProps, - ), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/bar_series.ts b/packages/charts/src/chart_types/xy_chart/specs/bar_series.ts new file mode 100644 index 00000000000..55cd5b2431e --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/bar_series.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { ScaleType } from '../../../scales/constants'; +import { SpecType } from '../../../specs/constants'; +import { useSpecFactory, SFProps, buildSFProps } from '../../../state/spec_factory'; +import { BarSeriesSpec, BaseDatum, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Series, + seriesType: SeriesType.Bar, + }, + { + groupId: DEFAULT_GLOBAL_ID, + xScaleType: ScaleType.Ordinal, + yScaleType: ScaleType.Linear, + // xAccessor: 'x', + // yAccessors: ['y'], + hideInLegend: false, + enableHistogramMode: false, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const BarSeries = function ( + props: SFProps< + BarSeriesSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type BarSeriesProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/bar_series.tsx b/packages/charts/src/chart_types/xy_chart/specs/bar_series.tsx deleted file mode 100644 index 7006236bc77..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/bar_series.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { ScaleType } from '../../../scales/constants'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { BarSeriesSpec, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Series, - seriesType: SeriesType.Bar, - groupId: DEFAULT_GLOBAL_ID, - xScaleType: ScaleType.Ordinal, - yScaleType: ScaleType.Linear, - xAccessor: 'x', - yAccessors: ['y'], - hideInLegend: false, - enableHistogramMode: false, -}; - -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @public */ -export const BarSeries: React.FunctionComponent = getConnect()( - specComponentFactory< - BarSeriesSpec, - | 'seriesType' - | 'groupId' - | 'xScaleType' - | 'yScaleType' - | 'xAccessor' - | 'yAccessors' - | 'hideInLegend' - | 'enableHistogramMode' - >(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/bubble_series.ts b/packages/charts/src/chart_types/xy_chart/specs/bubble_series.ts new file mode 100644 index 00000000000..5d1eb05751e --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/bubble_series.ts @@ -0,0 +1,52 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { ScaleType } from '../../../scales/constants'; +import { SpecType } from '../../../specs/constants'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; +import { BaseDatum, BubbleSeriesSpec, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Series, + seriesType: SeriesType.Bubble, + }, + { + groupId: DEFAULT_GLOBAL_ID, + xScaleType: ScaleType.Ordinal, + yScaleType: ScaleType.Linear, + // xAccessor: 'x', + // yAccessors: ['y'], + hideInLegend: false, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const BubbleSeries = function ( + props: SFProps< + BubbleSeriesSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type BubbleSeriesProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/bubble_series.tsx b/packages/charts/src/chart_types/xy_chart/specs/bubble_series.tsx deleted file mode 100644 index ee37e0d0521..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/bubble_series.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { ScaleType } from '../../../scales/constants'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { BubbleSeriesSpec, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Series, - seriesType: SeriesType.Bubble, - groupId: DEFAULT_GLOBAL_ID, - xScaleType: ScaleType.Ordinal, - yScaleType: ScaleType.Linear, - xAccessor: 'x', - yAccessors: ['y'], - hideInLegend: false, -}; -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** - * @alpha - * - * This series type uses a spatial index that is incompatible with other series types. This will - * be fixed once an update has been made to the tooltip design. - * - * When used alone with other `BubbleSeries` the spatial index will be used. However when - * mixed with other series types, the linear index will be used. This will affect highlighting - * of points when using the `markSizeAccessor`. - */ -export const BubbleSeries: React.FunctionComponent = getConnect()( - specComponentFactory< - BubbleSeriesSpec, - 'seriesType' | 'groupId' | 'xScaleType' | 'yScaleType' | 'xAccessor' | 'yAccessors' | 'hideInLegend' - >(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.ts b/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.ts new file mode 100644 index 00000000000..8a65cc23d0c --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { ScaleType } from '../../../scales/constants'; +import { SpecType } from '../../../specs/constants'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; +import { HistogramBarSeriesSpec, DEFAULT_GLOBAL_ID, SeriesType, BaseDatum } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Series, + seriesType: SeriesType.Bar, + }, + { + groupId: DEFAULT_GLOBAL_ID, + xScaleType: ScaleType.Linear, + yScaleType: ScaleType.Linear, + // xAccessor: 'x', + // yAccessors: ['y'], + hideInLegend: false, + enableHistogramMode: true as const, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const HistogramBarSeries = function ( + props: SFProps< + HistogramBarSeriesSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type HistogramBarSeriesProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx b/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx deleted file mode 100644 index bd0d7e20b3a..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { ScaleType } from '../../../scales/constants'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { HistogramBarSeriesSpec, DEFAULT_GLOBAL_ID, SeriesType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Series, - seriesType: SeriesType.Bar, - groupId: DEFAULT_GLOBAL_ID, - xScaleType: ScaleType.Linear, - yScaleType: ScaleType.Linear, - xAccessor: 'x', - yAccessors: ['y'], - hideInLegend: false, - enableHistogramMode: true as const, -}; - -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @public */ -export const HistogramBarSeries: React.FunctionComponent = getConnect()( - specComponentFactory< - HistogramBarSeriesSpec, - | 'seriesType' - | 'groupId' - | 'xScaleType' - | 'yScaleType' - | 'xAccessor' - | 'yAccessors' - | 'hideInLegend' - | 'enableHistogramMode' - >(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/line_annotation.ts b/packages/charts/src/chart_types/xy_chart/specs/line_annotation.ts new file mode 100644 index 00000000000..9f11d02b643 --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/line_annotation.ts @@ -0,0 +1,52 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { SpecType } from '../../../specs/constants'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; +import { DEFAULT_ANNOTATION_LINE_STYLE } from '../../../utils/themes/merge_utils'; +import { LineAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType, BaseDatum } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Annotation, + }, + { + groupId: DEFAULT_GLOBAL_ID, + annotationType: AnnotationType.Line, + style: DEFAULT_ANNOTATION_LINE_STYLE, + hideLines: false, + hideTooltips: false, + hideLinesTooltips: true, + zIndex: 1, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const LineAnnotation = function ( + props: SFProps< + LineAnnotationSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type LineAnnotationProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/line_annotation.tsx b/packages/charts/src/chart_types/xy_chart/specs/line_annotation.tsx deleted file mode 100644 index e7f445de0bd..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/line_annotation.tsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; -import { DEFAULT_ANNOTATION_LINE_STYLE } from '../../../utils/themes/merge_utils'; -import { LineAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Annotation, - groupId: DEFAULT_GLOBAL_ID, - annotationType: AnnotationType.Line, - style: DEFAULT_ANNOTATION_LINE_STYLE, - hideLines: false, - hideTooltips: false, - hideLinesTooltips: true, - zIndex: 1, -}; - -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial< - Omit< - LineAnnotationSpec, - 'chartType' | 'specType' | 'seriesType' | 'id' | 'dataValues' | 'domainType' | 'annotationType' - > ->; - -/** @public */ -export const LineAnnotation: React.FunctionComponent = getConnect()( - specComponentFactory(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/line_series.ts b/packages/charts/src/chart_types/xy_chart/specs/line_series.ts new file mode 100644 index 00000000000..0659fb0f94e --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/line_series.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { ScaleType } from '../../../scales/constants'; +import { SpecType } from '../../../specs/constants'; +import { SFProps, buildSFProps, useSpecFactory } from '../../../state/spec_factory'; +import { LineSeriesSpec, DEFAULT_GLOBAL_ID, HistogramModeAlignments, SeriesType, BaseDatum } from '../utils/specs'; + +const buildProps = buildSFProps>()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Series, + seriesType: SeriesType.Line, + }, + { + groupId: DEFAULT_GLOBAL_ID, + xScaleType: ScaleType.Ordinal, + yScaleType: ScaleType.Linear, + // xAccessor: 'x', + // yAccessors: ['y'], + hideInLegend: false, + histogramModeAlignment: HistogramModeAlignments.Center, + }, +); + +/** + * Adds bar series to chart specs + * @public + */ +export const LineSeries = function ( + props: SFProps< + LineSeriesSpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; + +/** @public */ +export type LineSeriesProp = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/line_series.tsx b/packages/charts/src/chart_types/xy_chart/specs/line_series.tsx deleted file mode 100644 index 3bde107fe9c..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/line_series.tsx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { ScaleType } from '../../../scales/constants'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { LineSeriesSpec, DEFAULT_GLOBAL_ID, HistogramModeAlignments, SeriesType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Series, - seriesType: SeriesType.Line, - groupId: DEFAULT_GLOBAL_ID, - xScaleType: ScaleType.Ordinal, - yScaleType: ScaleType.Linear, - xAccessor: 'x', - yAccessors: ['y'], - hideInLegend: false, - histogramModeAlignment: HistogramModeAlignments.Center, -}; -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @public */ -export const LineSeries: React.FunctionComponent = getConnect()( - specComponentFactory< - LineSeriesSpec, - | 'seriesType' - | 'groupId' - | 'xScaleType' - | 'yScaleType' - | 'xAccessor' - | 'yAccessors' - | 'hideInLegend' - | 'histogramModeAlignment' - >(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.ts b/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.ts new file mode 100644 index 00000000000..59f28af53db --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ComponentProps } from 'react'; + +import { ChartType } from '../..'; +import { SpecType } from '../../../specs/constants'; +import { specComponentFactory } from '../../../state/spec_factory'; +import { DEFAULT_ANNOTATION_RECT_STYLE } from '../../../utils/themes/merge_utils'; +import { RectAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } from '../utils/specs'; + +/** @public */ +export const RectAnnotation = specComponentFactory()( + { + chartType: ChartType.XYAxis, + specType: SpecType.Annotation, + }, + { + groupId: DEFAULT_GLOBAL_ID, + annotationType: AnnotationType.Rectangle, + zIndex: -1, + style: DEFAULT_ANNOTATION_RECT_STYLE, + outside: false, + }, +); + +/** @public */ +export type RectAnnotationProps = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.tsx b/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.tsx deleted file mode 100644 index 1d2a2601799..00000000000 --- a/packages/charts/src/chart_types/xy_chart/specs/rect_annotation.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; - -import { ChartType } from '../..'; -import { SpecType } from '../../../specs/constants'; -import { specComponentFactory, getConnect } from '../../../state/spec_factory'; -import { DEFAULT_ANNOTATION_RECT_STYLE } from '../../../utils/themes/merge_utils'; -import { RectAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } from '../utils/specs'; - -const defaultProps = { - chartType: ChartType.XYAxis, - specType: SpecType.Annotation, - groupId: DEFAULT_GLOBAL_ID, - annotationType: AnnotationType.Rectangle, - zIndex: -1, - style: DEFAULT_ANNOTATION_RECT_STYLE, - outside: false, -}; - -/** @public */ -export const RectAnnotation: React.FunctionComponent< - Pick & - Partial< - Omit< - RectAnnotationSpec, - 'chartType' | 'specType' | 'seriesType' | 'id' | 'dataValues' | 'domainType' | 'annotationType' - > - > -> = getConnect()( - specComponentFactory(defaultProps), -); diff --git a/packages/charts/src/chart_types/xy_chart/utils/specs.ts b/packages/charts/src/chart_types/xy_chart/utils/specs.ts index b30231657a5..62773bfeb4f 100644 --- a/packages/charts/src/chart_types/xy_chart/utils/specs.ts +++ b/packages/charts/src/chart_types/xy_chart/utils/specs.ts @@ -17,8 +17,8 @@ import { ScaleType } from '../../../scales/constants'; import { LogScaleOptions } from '../../../scales/scale_continuous'; import { Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { Accessor, AccessorFormat, AccessorFn } from '../../../utils/accessor'; -import { RecursivePartial, Position, Datum } from '../../../utils/common'; +import { AccessorFormat, AccessorFn } from '../../../utils/accessor'; +import { RecursivePartial, Position } from '../../../utils/common'; import { CurveType } from '../../../utils/curves'; import { OrdinalDomain } from '../../../utils/domain'; import { AxisId, GroupId } from '../../../utils/ids'; @@ -400,7 +400,7 @@ export interface DisplayValueSpec { } /** @public */ -export interface SeriesSpec extends Spec { +export interface SeriesSpec extends Spec { specType: typeof SpecType.Series; chartType: typeof ChartType.XYAxis; /** @@ -419,7 +419,7 @@ export interface SeriesSpec extends Spec { */ useDefaultGroupDomain?: boolean | string; /** An array of data */ - data: Datum[]; + data: D[]; /** The type of series you are looking to render */ seriesType: SeriesType; /** Set colors for specific series */ @@ -483,23 +483,23 @@ export type SeriesColorAccessorFn = (seriesIdentifier: XYChartSeriesIdentifier) export type SeriesColorAccessor = string | SeriesColorsArray | SeriesColorAccessorFn; /** @public */ -export interface SeriesAccessors { +export interface SeriesAccessors { /** The field name of the x value on Datum object */ - xAccessor: Accessor | AccessorFn; + xAccessor: keyof D | AccessorFn; /** An array of field names one per y metric value */ - yAccessors: (Accessor | AccessorFn)[]; + yAccessors: (keyof D | AccessorFn)[]; /** An optional accessor of the y0 value: base point for area/bar charts */ - y0Accessors?: (Accessor | AccessorFn)[]; + y0Accessors?: (keyof D | AccessorFn)[]; /** An array of fields thats indicates the datum series membership */ - splitSeriesAccessors?: (Accessor | AccessorFn)[]; + splitSeriesAccessors?: (keyof D | AccessorFn)[]; /** An array of fields thats indicates the stack membership */ - stackAccessors?: (Accessor | AccessorFn)[]; + stackAccessors?: (keyof D | AccessorFn)[]; /** * Field name of mark size metric on `Datum` * * Only used with line/area series */ - markSizeAccessor?: Accessor | AccessorFn; + markSizeAccessor?: keyof D | AccessorFn; } /** @public */ @@ -536,27 +536,36 @@ export interface SeriesScales { yNice?: boolean; } +type MarkFormatter = Type extends 'bar' + ? // eslint-disable-next-line @typescript-eslint/ban-types + {} // these options are to be empty thus {} + : { + /** + * A function called to format every single mark value + * + * Only used with line/area series + */ + markFormat?: TickFormatter; + }; + /** @public */ -export type BasicSeriesSpec = SeriesSpec & - SeriesAccessors & - SeriesScales & { - /** - * A function called to format every single mark value - * - * Only used with line/area series - */ - markFormat?: TickFormatter; - }; +export type BasicSeriesSpec = SeriesSpec & + SeriesAccessors & + SeriesScales & + MarkFormatter; /** @public */ -export type SeriesSpecs = Array; +export type SeriesSpecs = BasicSeriesSpec> = Array; + +/** @internal */ +export type BaseDatum = Record | unknown; /** * This spec describe the dataset configuration used to display a bar series. * @public */ -export type BarSeriesSpec = BasicSeriesSpec & +export type BarSeriesSpec = BasicSeriesSpec & Postfixes & { /** @defaultValue `bar` {@link (SeriesType:type) | SeriesType.Bar} */ seriesType: typeof SeriesType.Bar; @@ -588,7 +597,7 @@ export type BarSeriesSpec = BasicSeriesSpec & * A histogram bar series is identical to a bar series except that stackAccessors are not allowed. * @public */ -export type HistogramBarSeriesSpec = Omit & { +export type HistogramBarSeriesSpec = Omit, 'stackAccessors'> & { enableHistogramMode: true; }; @@ -616,7 +625,7 @@ export type FitConfig = { * This spec describe the dataset configuration used to display a line series. * @public */ -export type LineSeriesSpec = BasicSeriesSpec & +export type LineSeriesSpec = BasicSeriesSpec & HistogramConfig & { /** @defaultValue `line` {@link (SeriesType:type) | SeriesType.Line} */ seriesType: typeof SeriesType.Line; @@ -637,7 +646,7 @@ export type LineSeriesSpec = BasicSeriesSpec & * * @alpha */ -export type BubbleSeriesSpec = BasicSeriesSpec & { +export type BubbleSeriesSpec = BasicSeriesSpec & { /** @defaultValue `bubble` {@link (SeriesType:type) | SeriesType.Bubble} */ seriesType: typeof SeriesType.Bubble; bubbleSeriesStyle?: RecursivePartial; @@ -651,7 +660,7 @@ export type BubbleSeriesSpec = BasicSeriesSpec & { * This spec describe the dataset configuration used to display an area series. * @public */ -export type AreaSeriesSpec = BasicSeriesSpec & +export type AreaSeriesSpec = BasicSeriesSpec & HistogramConfig & Postfixes & { /** @defaultValue `area` {@link (SeriesType:type) | SeriesType.Area} */ @@ -789,11 +798,11 @@ export type AnnotationDomainType = $Values; * The descriptive object of a line annotation * @public */ -export interface LineAnnotationDatum { +export interface LineAnnotationDatum { /** * The value on the x or y axis accordingly to the domainType configured */ - dataValue: any; + dataValue: D; /** * A textual description of the annotation */ @@ -805,9 +814,9 @@ export interface LineAnnotationDatum { } /** @public */ -export type LineAnnotationSpec = BaseAnnotationSpec< +export type LineAnnotationSpec = BaseAnnotationSpec< typeof AnnotationType.Line, - LineAnnotationDatum, + LineAnnotationDatum, LineAnnotationStyle > & { domainType: AnnotationDomainType; @@ -927,7 +936,7 @@ export type AnnotationPortalSettings = TooltipPortalSettings<'chart'> & { /** @public */ export interface BaseAnnotationSpec< T extends typeof AnnotationType.Rectangle | typeof AnnotationType.Line, - D extends RectAnnotationDatum | LineAnnotationDatum, + D extends RectAnnotationDatum | LineAnnotationDatum, S extends RectAnnotationStyle | LineAnnotationStyle > extends Spec, AnnotationPortalSettings { @@ -962,10 +971,10 @@ export interface BaseAnnotationSpec< } /** @public */ -export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; +export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; /** @internal */ -export function isLineAnnotation(spec: AnnotationSpec): spec is LineAnnotationSpec { +export function isLineAnnotation(spec: AnnotationSpec): spec is LineAnnotationSpec { return spec.annotationType === AnnotationType.Line; } @@ -975,22 +984,22 @@ export function isRectAnnotation(spec: AnnotationSpec): spec is RectAnnotationSp } /** @internal */ -export function isBarSeriesSpec(spec: BasicSeriesSpec): spec is BarSeriesSpec { +export function isBarSeriesSpec(spec: BasicSeriesSpec): spec is BarSeriesSpec { return spec.seriesType === SeriesType.Bar; } /** @internal */ -export function isBubbleSeriesSpec(spec: BasicSeriesSpec): spec is BubbleSeriesSpec { +export function isBubbleSeriesSpec(spec: BasicSeriesSpec): spec is BubbleSeriesSpec { return spec.seriesType === SeriesType.Bubble; } /** @internal */ -export function isLineSeriesSpec(spec: BasicSeriesSpec): spec is LineSeriesSpec { +export function isLineSeriesSpec(spec: BasicSeriesSpec): spec is LineSeriesSpec { return spec.seriesType === SeriesType.Line; } /** @internal */ -export function isAreaSeriesSpec(spec: BasicSeriesSpec): spec is AreaSeriesSpec { +export function isAreaSeriesSpec(spec: BasicSeriesSpec): spec is AreaSeriesSpec { return spec.seriesType === SeriesType.Area; } diff --git a/packages/charts/src/specs/constants.ts b/packages/charts/src/specs/constants.ts index 1cedd906136..2011972d7ba 100644 --- a/packages/charts/src/specs/constants.ts +++ b/packages/charts/src/specs/constants.ts @@ -10,6 +10,7 @@ import { $Values } from 'utility-types'; import { ChartType } from '../chart_types'; import { BOTTOM, CENTER, LEFT, MIDDLE, RIGHT, TOP } from '../common/constants'; +import { buildSFProps } from '../state/spec_factory'; import { Position } from '../utils/common'; import { LIGHT_THEME } from '../utils/themes/light_theme'; import { SettingsSpec } from './settings'; @@ -159,27 +160,37 @@ export const DEFAULT_TOOLTIP_CONFIG = { showNullValues: false, }; -/** @public */ -export const DEFAULT_SETTINGS_SPEC: SettingsSpec = { - id: '__global__settings___', - chartType: ChartType.Global, - specType: SpecType.Settings, - rendering: 'canvas' as const, - rotation: 0 as const, - animateData: true, - resizeDebounce: 10, - debug: false, - tooltip: DEFAULT_TOOLTIP_CONFIG, - pointerUpdateTrigger: PointerUpdateTrigger.X, - externalPointerEvents: { - tooltip: { - visible: false, +/** @internal */ +export const settingsBuildProps = buildSFProps()( + { + id: '__global__settings___' as const, + chartType: ChartType.Global, + specType: SpecType.Settings, + }, + { + rendering: 'canvas' as const, + rotation: 0 as const, + animateData: true, + resizeDebounce: 10, + debug: false, + tooltip: DEFAULT_TOOLTIP_CONFIG, + pointerUpdateTrigger: PointerUpdateTrigger.X, + externalPointerEvents: { + tooltip: { + visible: false, + }, }, + baseTheme: LIGHT_THEME, + brushAxis: BrushAxis.X, + minBrushDelta: 2, + ariaUseDefaultSummary: true, + ariaLabelHeadingLevel: 'p', + ...DEFAULT_LEGEND_CONFIG, }, - baseTheme: LIGHT_THEME, - brushAxis: BrushAxis.X, - minBrushDelta: 2, - ariaUseDefaultSummary: true, - ariaLabelHeadingLevel: 'p', - ...DEFAULT_LEGEND_CONFIG, +); + +/** @public */ +export const DEFAULT_SETTINGS_SPEC: SettingsSpec = { + ...settingsBuildProps.defaults, + ...settingsBuildProps.overrides, }; diff --git a/packages/charts/src/specs/group_by.ts b/packages/charts/src/specs/group_by.ts index 8a72f3dd328..d6370d9e287 100644 --- a/packages/charts/src/specs/group_by.ts +++ b/packages/charts/src/specs/group_by.ts @@ -6,16 +6,16 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; -import { Spec } from '.'; +import { BaseDatum, Spec } from '.'; import { ChartType } from '../chart_types'; import { Predicate } from '../common/predicate'; -import { getConnect, specComponentFactory } from '../state/spec_factory'; +import { buildSFProps, SFProps, useSpecFactory } from '../state/spec_factory'; import { SpecType } from './constants'; /** @public */ -export type GroupByAccessor = (spec: Spec, datum: any) => string | number; +export type GroupByAccessor = (spec: Spec, datum: D) => string | number; /** @alpha */ export type GroupBySort = Predicate; @@ -23,14 +23,14 @@ export type GroupBySort = Predicate; * Title formatter that handles any value returned from the GroupByAccessor * @public */ -export type GroupByFormatter = (value: ReturnType) => string; +export type GroupByFormatter = (value: ReturnType>) => string; /** @alpha */ -export interface GroupBySpec extends Spec { +export interface GroupBySpec extends Spec { /** * Function to return a unique value __by__ which to group the data */ - by: GroupByAccessor; + by: GroupByAccessor; /** * Sort predicate used to sort grouped data */ @@ -40,19 +40,34 @@ export interface GroupBySpec extends Spec { * * Only for displayed values, not used in sorting or other internal computations. */ - format?: GroupByFormatter; + format?: GroupByFormatter; } -const DEFAULT_GROUP_BY_PROPS = { - chartType: ChartType.Global, - specType: SpecType.IndexOrder, -}; -type DefaultGroupByProps = 'chartType' | 'specType'; +const buildProps = buildSFProps>()( + { + chartType: ChartType.Global, + specType: SpecType.IndexOrder, + }, + {}, +); -/** @alpha */ -export type GroupByProps = Pick; +/** + * Add GroupBy spec to chart + * @public + */ +export const GroupBy = function ( + props: SFProps< + GroupBySpec, + keyof typeof buildProps['overrides'], + keyof typeof buildProps['defaults'], + keyof typeof buildProps['optionals'], + keyof typeof buildProps['requires'] + >, +) { + const { defaults, overrides } = buildProps; + useSpecFactory>({ ...defaults, ...props, ...overrides }); + return null; +}; -/** @alpha */ -export const GroupBy: React.FunctionComponent = getConnect()( - specComponentFactory(DEFAULT_GROUP_BY_PROPS), -); +/** @public */ +export type GroupByProps = ComponentProps; diff --git a/packages/charts/src/specs/settings.tsx b/packages/charts/src/specs/settings.tsx index f2bd1ac208e..ae91ea9dbc3 100644 --- a/packages/charts/src/specs/settings.tsx +++ b/packages/charts/src/specs/settings.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import React, { ComponentType, ReactChild } from 'react'; +import { ComponentProps, ComponentType, ReactChild } from 'react'; import { CustomXDomain, GroupByAccessor, Spec, TooltipStickTo } from '.'; import { Cell } from '../chart_types/heatmap/layout/types/viewmodel_types'; @@ -21,7 +21,7 @@ import { TooltipPortalSettings } from '../components'; import { CustomTooltip } from '../components/tooltip/types'; import { ScaleContinuousType, ScaleOrdinalType } from '../scales'; import { LegendPath } from '../state/actions/legend'; -import { getConnect, specComponentFactory } from '../state/spec_factory'; +import { SFProps, useSpecFactory } from '../state/spec_factory'; import { Accessor } from '../utils/accessor'; import { HorizontalAlignment, @@ -38,12 +38,12 @@ import { PartialTheme, Theme } from '../utils/themes/theme'; import { BinAgg, BrushAxis, - DEFAULT_SETTINGS_SPEC, DEFAULT_TOOLTIP_CONFIG, Direction, PointerEventType, PointerUpdateTrigger, TooltipType, + settingsBuildProps, } from './constants'; /** @public */ @@ -174,7 +174,7 @@ export type BasicListener = () => undefined | void; /** @public */ export type RectAnnotationEvent = { id: SpecId; datum: RectAnnotationDatum }; /** @public */ -export type LineAnnotationEvent = { id: SpecId; datum: LineAnnotationDatum }; +export type LineAnnotationEvent = { id: SpecId; datum: LineAnnotationDatum }; /** @public */ export type AnnotationClickListener = (annotations: { rects: RectAnnotationEvent[]; @@ -681,38 +681,26 @@ export interface OrderBy { direction?: Direction; } -/** @public */ -export type DefaultSettingsProps = - | 'id' - | 'chartType' - | 'specType' - | 'rendering' - | 'rotation' - | 'resizeDebounce' - | 'pointerUpdateDebounce' - | 'pointerUpdateTrigger' - | 'animateData' - | 'debug' - | 'tooltip' - | 'theme' - | 'brushAxis' - | 'minBrushDelta' - | 'externalPointerEvents' - | 'showLegend' - | 'showLegendExtra' - | 'legendPosition' - | 'legendMaxDepth' - | 'ariaUseDefaultSummary' - | 'ariaLabelHeadingLevel' - | 'ariaTableCaption'; - -/** @public */ -export type SettingsSpecProps = Partial>; +/** + * Adds settings spec to chart specs + * @public + */ +export const Settings = function ( + props: SFProps< + SettingsSpec, + keyof typeof settingsBuildProps['overrides'], + keyof typeof settingsBuildProps['defaults'], + keyof typeof settingsBuildProps['optionals'], + keyof typeof settingsBuildProps['requires'] + >, +) { + const { defaults, overrides } = settingsBuildProps; + useSpecFactory({ ...defaults, ...props, ...overrides }); + return null; +}; /** @public */ -export const Settings: React.FunctionComponent = getConnect()( - specComponentFactory(DEFAULT_SETTINGS_SPEC), -); +export type SettingsProp = ComponentProps; /** @internal */ export function isPointerOutEvent(event: PointerEvent | null | undefined): event is PointerOutEvent { diff --git a/packages/charts/src/specs/small_multiples.ts b/packages/charts/src/specs/small_multiples.ts index 91433c12c0d..1bc9dac91cc 100644 --- a/packages/charts/src/specs/small_multiples.ts +++ b/packages/charts/src/specs/small_multiples.ts @@ -6,12 +6,12 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { Spec } from '.'; import { ChartType } from '../chart_types'; import { Ratio } from '../common/geometry'; -import { getConnect, specComponentFactory } from '../state/spec_factory'; +import { specComponentFactory } from '../state/spec_factory'; import { SpecType } from './constants'; /** @@ -70,16 +70,18 @@ export interface SmallMultiplesSpec extends Spec { style?: Partial; } -const DEFAULT_SMALL_MULTIPLES_PROPS = { - id: '__global__small_multiples___', - chartType: ChartType.Global, - specType: SpecType.SmallMultiples, -}; - -/** @alpha */ -export type SmallMultiplesProps = Partial>; - -/** @alpha */ -export const SmallMultiples: React.FunctionComponent = getConnect()( - specComponentFactory(DEFAULT_SMALL_MULTIPLES_PROPS), +/** + * Add small multiples spec to chart + * @alpha + */ +export const SmallMultiples = specComponentFactory()( + { + id: '__global__small_multiples___', + chartType: ChartType.Global, + specType: SpecType.SmallMultiples, + }, + {}, ); + +/** @public */ +export type SmallMultiplesProps = ComponentProps; diff --git a/packages/charts/src/state/spec_factory.ts b/packages/charts/src/state/spec_factory.ts index b65f89e2417..6b648d7992a 100644 --- a/packages/charts/src/state/spec_factory.ts +++ b/packages/charts/src/state/spec_factory.ts @@ -6,59 +6,161 @@ * Side Public License, v 1. */ -import { useEffect } from 'react'; -import { connect } from 'react-redux'; -import { Dispatch, bindActionCreators } from 'redux'; +import { FC, useEffect, useMemo } from 'react'; +import { useDispatch } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { OptionalKeys, RequiredKeys } from 'utility-types'; -import { Spec } from '../specs'; -import { upsertSpec, removeSpec } from './actions/specs'; +import { Spec as Spec } from '../specs'; +import { upsertSpec as upsertSpecAction, removeSpec as removeSpecAction } from './actions/specs'; /** @internal */ export interface DispatchProps { - upsertSpec: (spec: Spec) => void; - removeSpec: (id: string) => void; + upsertSpec: typeof upsertSpecAction; + removeSpec: typeof removeSpecAction; } -/** @internal */ -export function specComponentFactory( - defaultProps: Pick, -) { - /* eslint-disable no-shadow, react-hooks/exhaustive-deps, unicorn/consistent-function-scoping */ - const SpecInstance = (props: U & DispatchProps) => { - const { removeSpec, upsertSpec, ...SpecInstance } = props; - useEffect(() => { - upsertSpec(SpecInstance); - }); - useEffect( - () => () => { - removeSpec(props.id); - }, - [], - ); - return null; - }; - /* eslint-enable */ - SpecInstance.defaultProps = defaultProps; - return SpecInstance; -} +/** + * Used inside custom spec component to link component to state as new spec + * @internal + */ +export function useSpecFactory(props: Props) { + const dispatch = useDispatch(); + const { upsertSpec, removeSpec } = useMemo( + () => ({ + upsertSpec: bindActionCreators(upsertSpecAction, dispatch), + removeSpec: bindActionCreators(removeSpecAction, dispatch), + }), + [dispatch], + ); -const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => - bindActionCreators( - { - upsertSpec, - removeSpec, + useEffect(() => { + upsertSpec(props); + }); + useEffect( + () => () => { + removeSpec(props.id); }, - dispatch, + [], // eslint-disable-line react-hooks/exhaustive-deps ); +} + +/** + * Creates spec component factory given overrides and default props. + * + * To use this you must pass the Spec type via empty function call... + * + * ```ts + * const MyThing = specComponentFactory()(overrides, defaults) + * ``` + * + * > IMPORTANT: Both `overrides` and `defaults` should __NOT__ have explicit types. + * > The types are determined automatically from thier implicitly defined types, while still + * > enforing that the types are derived from the defined `Spec`. + * @internal + */ +export const specComponentFactory = () => < + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys, + Optionals extends SFOptionalKeys, + Requires extends SFRequiredKeys +>( + overrides: SFOverrides, + defaults: SFDefaults, +): FC> => { + return (props) => { + // @ts-ignore - All Spec keys are guaranteed to be included + useSpecFactory({ ...defaults, ...props, ...overrides }); + return null; + }; +}; + +/** + * Takes in prop overrides and defaults with enforced types. + * Determines implicit types of optional and required props. + * + * To use this you must pass the Spec type via empty function call... + * + * ```ts + * const MyThingBuildProps = buildSFProps()(overrides, defaults) + * ``` + * + * > IMPORTANT: Both `overrides` and `defaults` should __NOT__ have explicit types. + * > The types are determined automatically from thier implicitly defined types, while still + * > enforing that the types are derived from the defined `Spec`. + * @internal + */ +export const buildSFProps = () => < + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys, + Optionals extends SFOptionalKeys, + Requires extends SFRequiredKeys +>( + overrides: SFOverrides, + defaults: SFDefaults, +): BuildProps => ({ + overrides, + defaults, + optionals: {} as Pick, // used to transfer type only + requires: {} as Pick, // used to transfer type only +}); + +/* +------------------------------------------------------------ + Reused types to maintain single source of truth +------------------------------------------------------------ +*/ + +/** + * Resulting props for spec given overrides, defaults, optionals and required props + * @internal + */ +export type SFProps< + S extends Spec, + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys, + Optionals extends SFOptionalKeys, + Requires extends SFRequiredKeys +> = Pick & Partial>; /** @internal */ -export function getConnect() { - /** - * Redux assumes shallowEqual for all connected components - * - * This causes an issue where the specs are cleared and memoized spec components will never be - * re-rendered and thus never re-upserted to the state. Setting pure to false solves this issue - * and doesn't cause traditional performance degradations. - */ - return connect(null, mapDispatchToProps, null, { pure: false }); +export interface BuildProps< + S extends Spec, + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys, + Optionals extends SFOptionalKeys, + Requires extends SFRequiredKeys +> { + overrides: SFOverrides; + defaults: SFDefaults; + /** @deprecated typing only do not use as value */ + optionals: Pick; + /** @deprecated typing only do not use as value */ + requires: Pick; } + +/** All specs __must__ provide these as overrides */ +type RequiredSpecProps = keyof Pick; + +/* Types defining keys */ +type SFOverrideKeys = keyof S; +type SFDefaultKeys = keyof Omit; +type SFOptionalKeys< + S extends Spec, + Overrides extends keyof S, + Defaults extends keyof Omit +> = OptionalKeys>; +type SFRequiredKeys< + S extends Spec, + Overrides extends keyof S, + Defaults extends keyof Omit, + Optionals extends SFOptionalKeys +> = RequiredKeys>; + +/* Object types defined from key types above */ +type SFOverrides = Required>; +type SFDefaults< + S extends Spec, + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys +> = Required>; diff --git a/packages/charts/src/utils/accessor.ts b/packages/charts/src/utils/accessor.ts index ecb8b617f05..25e98190beb 100644 --- a/packages/charts/src/utils/accessor.ts +++ b/packages/charts/src/utils/accessor.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { BaseDatum } from '../chart_types/specs'; import { Datum } from './common'; /** @@ -13,12 +14,12 @@ import { Datum } from './common'; * @param datum - the datum * @public */ -export interface UnaryAccessorFn { +export interface UnaryAccessorFn { /** * Name used as accessor field name in place of function reference */ fieldName?: string; - (datum: Datum): Return; + (datum: D): Return; } /** @@ -27,19 +28,21 @@ export interface UnaryAccessorFn { * @param index - the index in the array * @public */ -export type BinaryAccessorFn = (datum: Datum, index: number) => Return; +export type BinaryAccessorFn = (datum: D, index: number) => Return; /** * An accessor function * @public */ -export type AccessorFn = UnaryAccessorFn; +export type AccessorFn = UnaryAccessorFn; /** * An indexed accessor function * @public */ -export type IndexedAccessorFn = UnaryAccessorFn | BinaryAccessorFn; +export type IndexedAccessorFn = + | UnaryAccessorFn + | BinaryAccessorFn; /** * A key accessor string diff --git a/packages/charts/src/utils/common.tsx b/packages/charts/src/utils/common.tsx index d2c5addf0c5..c952e2b882e 100644 --- a/packages/charts/src/utils/common.tsx +++ b/packages/charts/src/utils/common.tsx @@ -13,6 +13,7 @@ import { v1 as uuidV1 } from 'uuid'; import { PrimitiveValue } from '../chart_types/partition_chart/layout/utils/group_by_rollup'; import { Color, Colors } from '../common/colors'; import { Degrees, Radian } from '../common/geometry'; +import { BaseDatum } from '../specs'; import { AdditiveNumber } from './accessor'; import { Point } from './point'; @@ -448,7 +449,7 @@ export function getUniqueValues(fullArray: T[], uniqueProperty: keyof T, filt /** @public */ export type ValueFormatter = (value: number) => string; /** @public */ -export type ValueAccessor = (d: Datum) => AdditiveNumber; +export type ValueAccessor = (d: D) => AdditiveNumber; /** @public */ export type LabelAccessor = (value: T) => string; /** @public */ From c63295dcf9227f107c2dc79c255e69e4d36ebf34 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 13 Oct 2021 18:03:50 -0500 Subject: [PATCH 2/3] feat(settings): expose global charts context for settings --- .../server/generate/vrt_page_template.js | 16 +++++------ packages/charts/src/specs/context.ts | 26 +++++++++++++++++ packages/charts/src/specs/index.ts | 1 + packages/charts/src/specs/settings.tsx | 28 +++++++++++-------- packages/charts/src/utils/common.test.ts | 11 ++++++++ packages/charts/src/utils/common.tsx | 9 ++++++ 6 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 packages/charts/src/specs/context.ts diff --git a/integration/server/generate/vrt_page_template.js b/integration/server/generate/vrt_page_template.js index 4915989a36f..2b8481ceaab 100644 --- a/integration/server/generate/vrt_page_template.js +++ b/integration/server/generate/vrt_page_template.js @@ -41,8 +41,7 @@ ReactDOM.render(, document.getElementById('story-root') as HTMLElemen function pageTemplate(imports, routes, urls) { return ` -import React, { Suspense } from 'react'; -import { ThemeIdProvider, BackgroundIdProvider } from '../../storybook/use_base_theme'; +import React, { Suspense, useMemo } from 'react'; import { useGlobalsParameters } from '../server/mocks/use_global_parameters'; export function VRTPage() { @@ -52,6 +51,7 @@ export function VRTPage() { setParams, } = useGlobalsParameters(); const urlParams = new URL(window.location.toString()).searchParams; + const contextValue = useMemo(() => getContext(themeId, backgroundId), [themeId, backgroundId]); ${imports.join('\n ')} const path = urlParams.get('path'); @@ -68,13 +68,11 @@ export function VRTPage() { ); } return ( - - - Loading...}> - ${routes.join('\n ')} - - - + + Loading...}> + ${routes.join('\n ')} + + ); } diff --git a/packages/charts/src/specs/context.ts b/packages/charts/src/specs/context.ts new file mode 100644 index 00000000000..fa6f9ca8e5c --- /dev/null +++ b/packages/charts/src/specs/context.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { createContext, useContext } from 'react'; + +import { SettingsProps } from './settings'; + +/** @internal */ +export interface EchContext { + settings?: SettingsProps; +} +const ElasticChartsContext = createContext({}); + +/** + * Context used to control elastic chart options globally + * @public + */ +export const ElasticChartsProvider = ElasticChartsContext.Provider; + +/** @internal */ +export const useChartsContext = () => useContext(ElasticChartsContext); diff --git a/packages/charts/src/specs/index.ts b/packages/charts/src/specs/index.ts index 274af649d59..fa24cd923ae 100644 --- a/packages/charts/src/specs/index.ts +++ b/packages/charts/src/specs/index.ts @@ -22,4 +22,5 @@ export * from './group_by'; export * from './small_multiples'; export * from './settings'; export * from './constants'; +export * from './context'; export * from '../chart_types/specs'; diff --git a/packages/charts/src/specs/settings.tsx b/packages/charts/src/specs/settings.tsx index ae91ea9dbc3..a2b2a8ddb48 100644 --- a/packages/charts/src/specs/settings.tsx +++ b/packages/charts/src/specs/settings.tsx @@ -24,6 +24,7 @@ import { LegendPath } from '../state/actions/legend'; import { SFProps, useSpecFactory } from '../state/spec_factory'; import { Accessor } from '../utils/accessor'; import { + getArrayOf, HorizontalAlignment, LayoutDirection, Position, @@ -45,6 +46,7 @@ import { TooltipType, settingsBuildProps, } from './constants'; +import { useChartsContext } from './context'; /** @public */ export interface LayerValue { @@ -685,22 +687,26 @@ export interface OrderBy { * Adds settings spec to chart specs * @public */ -export const Settings = function ( - props: SFProps< - SettingsSpec, - keyof typeof settingsBuildProps['overrides'], - keyof typeof settingsBuildProps['defaults'], - keyof typeof settingsBuildProps['optionals'], - keyof typeof settingsBuildProps['requires'] - >, -) { +export const Settings = function ({ + theme: userTheme = [], + ...props +}: SFProps< + SettingsSpec, + keyof typeof settingsBuildProps['overrides'], + keyof typeof settingsBuildProps['defaults'], + keyof typeof settingsBuildProps['optionals'], + keyof typeof settingsBuildProps['requires'] +>) { const { defaults, overrides } = settingsBuildProps; - useSpecFactory({ ...defaults, ...props, ...overrides }); + const { theme: contextTheme = [], ...contextSettings } = useChartsContext()?.settings ?? {}; + const theme = [...getArrayOf(userTheme), ...getArrayOf(contextTheme)]; + + useSpecFactory({ ...defaults, ...contextSettings, ...props, theme, ...overrides }); return null; }; /** @public */ -export type SettingsProp = ComponentProps; +export type SettingsProps = ComponentProps; /** @internal */ export function isPointerOutEvent(event: PointerEvent | null | undefined): event is PointerOutEvent { diff --git a/packages/charts/src/utils/common.test.ts b/packages/charts/src/utils/common.test.ts index df75353cc67..37e34ba3973 100644 --- a/packages/charts/src/utils/common.test.ts +++ b/packages/charts/src/utils/common.test.ts @@ -20,6 +20,7 @@ import { isUniqueArray, isDefined, isDefinedFrom, + getArrayOf, } from './common'; describe('common utilities', () => { @@ -1131,4 +1132,14 @@ describe('#isDefinedFrom', () => { ); expect(result).toEqual(values.slice(0, 3)); }); + + describe('#getArrayOf', () => { + const obj = { a: 'test' }; + it('should return array from single value', () => { + expect(getArrayOf(obj)).toEqual([obj]); + }); + it('should return array from array of values', () => { + expect(getArrayOf([obj])).toEqual([obj]); + }); + }); }); diff --git a/packages/charts/src/utils/common.tsx b/packages/charts/src/utils/common.tsx index c952e2b882e..19dddf15119 100644 --- a/packages/charts/src/utils/common.tsx +++ b/packages/charts/src/utils/common.tsx @@ -274,6 +274,15 @@ export function isArrayOrSet(value: any): value is Array | Set { return Array.isArray(value) || value instanceof Set; } +/** + * Returns an array of values given single value or array of values + * @internal + */ +export function getArrayOf(value?: T | T[]): T[] { + if (!value) return []; + return Array.isArray(value) ? value : [value]; +} + /** @internal */ export function isNil(value: any): value is null | undefined { return value === null || value === undefined; From 675509b2b29df4e1c900c48ad55bf3d54945b862 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 13 Oct 2021 18:10:49 -0500 Subject: [PATCH 3/3] chore: fix storybook usage --- .../{use_base_theme.ts => context_utils.ts} | 49 +++++++----- .../lines/1_x_continuous.story.tsx | 3 +- .../annotations/lines/2_x_ordinal.story.tsx | 3 +- .../annotations/lines/3_x_time.story.tsx | 3 +- .../annotations/lines/4_y_domain.story.tsx | 3 +- .../annotations/lines/5_styling.story.tsx | 3 +- .../6_test_single_bar_histogram.story.tsx | 3 +- .../lines/7_tooltip_options.story.tsx | 3 +- .../lines/8_advanced_markers.story.tsx | 3 +- .../rects/1_linear_bar_chart.story.tsx | 3 +- .../rects/2_ordinal_bar_chart.story.tsx | 3 +- .../rects/3_linear_line_chart.story.tsx | 3 +- .../annotations/rects/4_styling.story.tsx | 3 +- .../rects/5_tooltip_options.story.tsx | 3 +- .../annotations/rects/6_zero_domain.story.tsx | 3 +- .../rects/7_with_group_id.story.tsx | 3 +- .../annotations/rects/8_outside.story.tsx | 1 - .../rects/9_click_handler.story.tsx | 1 - .../area/10_stacked_same_naming.story.tsx | 3 +- .../stories/area/11_test_linear.story.tsx | 3 +- storybook/stories/area/12_test_time.story.tsx | 4 +- storybook/stories/area/13_band_area.story.tsx | 3 +- .../stories/area/14_stacked_band.story.tsx | 3 +- .../stories/area/15_stacked_grouped.story.tsx | 3 +- .../16_test_stacked_with_missing.story.tsx | 4 +- storybook/stories/area/17_negative.story.tsx | 3 +- .../area/18_negative_positive.story.tsx | 3 +- .../stories/area/19_negative_band.story.tsx | 1 - storybook/stories/area/1_basic.story.tsx | 3 +- .../area/21_with_time_timeslip.story.tsx | 3 +- storybook/stories/area/2_with_time.story.tsx | 1 - .../stories/area/3_with_linear.story.tsx | 3 +- storybook/stories/area/4_with_log.story.tsx | 3 +- .../stories/area/5_with_4_axes.story.tsx | 4 +- .../area/6_with_axis_and_legend.story.tsx | 3 +- storybook/stories/area/7_stacked.story.tsx | 3 +- .../area/8_stacked_percentage.story.tsx | 3 +- .../area/8_stacked_percentage_zeros.story.tsx | 3 +- .../area/9_stacked_separate_specs.story.tsx | 4 +- .../axes/10_one_domain_bound.story.tsx | 3 +- .../axes/11_fit_domain_extent.story.tsx | 3 +- .../stories/axes/12_duplicate_ticks.story.tsx | 3 +- .../axes/13_label_formatting.story.tsx | 3 +- storybook/stories/axes/1_basic.story.tsx | 3 +- .../axes/2_tick_label_rotation.story.tsx | 3 +- .../stories/axes/3_axis_4_axes.story.tsx | 3 +- storybook/stories/axes/4_multi_axis.story.tsx | 3 +- .../axes/5_multi_axis_bar_lines.story.tsx | 3 +- .../axes/6_different_tooltip.story.tsx | 3 +- .../6a_different_tooltip_formatter.story.tsx | 1 - .../stories/axes/7_many_tick_labels.story.tsx | 3 +- .../stories/axes/8_custom_domain.story.tsx | 1 - .../axes/9_custom_mixed_domain.story.tsx | 3 +- .../stories/bar/10_axis_and_legend.story.tsx | 3 +- .../11_stacked_with_axis_and_legend.story.tsx | 3 +- .../bar/12_stacked_as_percentage.story.tsx | 3 +- storybook/stories/bar/13_clustered.story.tsx | 1 - .../bar/14_clustered_multiple.story.tsx | 3 +- .../stories/bar/15_time_clustered.story.tsx | 3 +- .../stories/bar/17_time_stacked.story.tsx | 3 +- .../stories/bar/18_bar_chart_1y0g.story.tsx | 3 +- .../stories/bar/19_bar_chart_1y1g.story.tsx | 3 +- storybook/stories/bar/1_basic.story.tsx | 4 +- .../stories/bar/20_bar_chart_1y2g.story.tsx | 3 +- .../stories/bar/21_bar_chart_2y0g.story.tsx | 3 +- .../stories/bar/22_barchart_2y1g.story.tsx | 3 +- .../stories/bar/23_bar_chart_2y2g.story.tsx | 3 +- .../bar/24_tooltip_visibility.story.tsx | 3 +- .../stories/bar/25_high_data_volume.story.tsx | 3 +- .../bar/26_single_data_linear.story.tsx | 3 +- .../bar/27_single_data_ordinal.story.tsx | 3 +- .../bar/28_single_data_clustered.story.tsx | 3 +- .../bar/29_single_data_stacked.story.tsx | 3 +- storybook/stories/bar/2_label_value.story.tsx | 1 - .../bar/30_stacked_to_extent.story.tsx | 3 +- ...1_negative_and_positive_x_values.story.tsx | 3 +- .../stories/bar/32_scale_to_extent.story.tsx | 3 +- storybook/stories/bar/33_band_bar.story.tsx | 3 +- .../stories/bar/34_test_linear.story.tsx | 3 +- storybook/stories/bar/35_test_time.story.tsx | 3 +- .../bar/36_test_linear_clustered.story.tsx | 3 +- .../bar/37_test_time_clustered.story.tsx | 3 +- .../bar/38_test_clustered_null_bars.story.tsx | 3 +- .../bar/39_test_stacked_null.story.tsx | 3 +- storybook/stories/bar/3_with_axis.story.tsx | 3 +- .../stories/bar/40_test_switch.story.tsx | 3 +- .../bar/41_test_histogram_linear.story.tsx | 1 - .../bar/42_test_histogram_ordinal.story.tsx | 1 - .../stories/bar/43_test_discover.story.tsx | 3 +- .../bar/44_test_single_histogram.story.tsx | 4 +- storybook/stories/bar/45_min_height.story.tsx | 3 +- .../stories/bar/46_test_min_height.story.tsx | 3 +- .../bar/47_stacked_only_grouped.story.tsx | 3 +- .../stories/bar/48_test_tooltip.story.tsx | 3 +- .../stories/bar/49_test_dual_axis.story.tsx | 3 +- storybook/stories/bar/4_ordinal.story.tsx | 3 +- .../bar/50_order_bins_by_sum.story.tsx | 1 - .../bar/51_label_value_advanced.story.tsx | 1 - .../bar/52_multi_group_same_domain.story.tsx | 3 +- ...se_domain_from_different_groupid.story.tsx | 3 +- .../bar/54_functional_accessors.story.tsx | 3 +- .../stories/bar/55_tooltip_boundary.story.tsx | 3 +- .../bar/56_test_use_dfl_gdomain.story.tsx | 3 +- .../bar/57_test_rect_border_bars.story.tsx | 1 - storybook/stories/bar/5_linear.story.tsx | 3 +- .../bar/6_linear_no_linear_interval.story.tsx | 1 - .../stories/bar/7_with_time_xaxis.story.tsx | 3 +- .../stories/bar/8_with_log_yaxis.story.tsx | 3 +- .../stories/bar/9_with_stacked_log.story.tsx | 3 +- storybook/stories/bubble/1_simple.story.tsx | 1 - storybook/stories/bubble/2_ordinal.story.tsx | 1 - storybook/stories/bubble/3_multiple.story.tsx | 1 - storybook/stories/bubble/4_mixed.story.tsx | 1 - storybook/stories/debug/1_basic.story.tsx | 4 +- .../stories/debug/2_debug_state.story.tsx | 1 - .../stories/goal/10_band_in_band.story.tsx | 3 +- storybook/stories/goal/11_gaps.story.tsx | 3 +- storybook/stories/goal/12_range.story.tsx | 3 +- .../goal/13_confidence_level.story.tsx | 3 +- storybook/stories/goal/14_one_third.story.tsx | 3 +- .../stories/goal/15_half_circle.story.tsx | 3 +- .../stories/goal/16_two_thirds.story.tsx | 3 +- .../stories/goal/17_three_quarters.story.tsx | 3 +- .../stories/goal/17_total_circle.story.tsx | 3 +- .../stories/goal/17_very_small_gap.story.tsx | 3 +- .../stories/goal/18_side_gauge.story.tsx | 3 +- ...de_gauge_inverted_angle_relation.story.tsx | 4 +- .../goal/19_horizontal_negative.story.tsx | 3 +- .../goal/20_vertical_negative.story.tsx | 3 +- .../stories/goal/21_goal_negative.story.tsx | 3 +- .../goal/22_horizontal_plusminus.story.tsx | 3 +- .../goal/23_vertical_plusminus.story.tsx | 3 +- .../stories/goal/24_goal_plusminus.story.tsx | 3 +- .../goal/2_gauge_with_target.story.tsx | 3 +- .../goal/3_horizontal_bullet.story.tsx | 3 +- .../stories/goal/4_vertical_bullet.story.tsx | 3 +- storybook/stories/goal/5_minimal.story.tsx | 3 +- .../goal/6_minimal_horizontal.story.tsx | 3 +- .../stories/goal/7_horizontal_bar.story.tsx | 3 +- .../stories/goal/8_irregular_ticks.story.tsx | 3 +- .../stories/goal/9_minimal_band.story.tsx | 3 +- storybook/stories/grids/1_basic.story.tsx | 3 +- .../stories/grids/2_multiple_axes.story.tsx | 3 +- storybook/stories/grids/3_lines.story.tsx | 1 - storybook/stories/heatmap/1_basic.story.tsx | 1 - .../stories/heatmap/2_categorical.story.tsx | 1 - .../stories/icicle/01_unix_icicle.story.tsx | 3 +- .../stories/icicle/02_unix_flame.story.tsx | 1 - .../icicle/03_cpu_profile_flame.story.tsx | 3 +- .../10_brush_selection_bar.story.tsx | 3 +- .../10a_brush_selection_bar_hist.story.tsx | 1 - .../interactions/11_brush_time.story.tsx | 1 - .../interactions/12_brush_time_hist.story.tsx | 1 - .../13_brush_disabled_ordinal.story.tsx | 3 +- .../interactions/14_crosshair_time.story.tsx | 1 - .../interactions/15_render_change.story.tsx | 1 - .../16_cursor_update_action.story.tsx | 1 - .../interactions/17_png_export.story.tsx | 1 - .../interactions/1_bar_clicks.story.tsx | 1 - .../2_area_point_clicks.story.tsx | 1 - .../3_line_point_clicks.story.tsx | 1 - .../4_line_area_bar_clicks.story.tsx | 1 - .../4_sunburst_slice_clicks.story.tsx | 1 - .../5_clicks_legend_items_bar.story.tsx | 1 - .../6_clicks_legend_items_area.story.tsx | 1 - .../7_clicks_legend_items_line.story.tsx | 1 - .../8_clicks_legend_items_mixed.story.tsx | 1 - .../9_brush_selection_linear.story.tsx | 3 +- .../9a_brush_selection_linear.story.tsx | 1 - .../stories/legend/10_sunburst.story.tsx | 3 +- .../10_sunburst_repeated_label.story.tsx | 1 - .../legend/11_legend_actions.story.tsx | 1 - .../legend/12_legend_margins.story.tsx | 1 - .../stories/legend/13_inside_chart.story.tsx | 1 - .../stories/legend/14_single_series.story.tsx | 1 - .../stories/legend/1_legend_right.story.tsx | 4 +- .../stories/legend/2_legend_bottom.story.tsx | 3 +- .../stories/legend/3_legend_left.story.tsx | 4 +- .../stories/legend/4_legend_top.story.tsx | 3 +- .../stories/legend/5_changing_specs.story.tsx | 4 +- .../stories/legend/6_hide_legend.story.tsx | 3 +- .../stories/legend/7_display_values.story.tsx | 1 - .../stories/legend/8_spacing_buffer.story.tsx | 4 +- .../stories/legend/9_color_picker.story.tsx | 4 +- .../line/10_test_path_ordering.story.tsx | 1 - .../11_discontinuous_data_points.story.tsx | 3 +- .../line/12_orphan_data_points.story.tsx | 1 - .../line/13_line_mark_accessor.story.tsx | 1 - .../stories/line/14_point_shapes.story.tsx | 1 - .../line/15_test_negative_points.story.tsx | 3 +- storybook/stories/line/1_basic.story.tsx | 3 +- storybook/stories/line/2_w_axis.story.tsx | 1 - storybook/stories/line/3_ordinal.story.tsx | 3 +- storybook/stories/line/4_linear.story.tsx | 3 +- .../line/5_w_axis_and_legend.story.tsx | 3 +- storybook/stories/line/6_curved.story.tsx | 3 +- storybook/stories/line/7_multiple.story.tsx | 3 +- storybook/stories/line/8_stacked.story.tsx | 3 +- .../stories/line/9_multi_series.story.tsx | 3 +- .../stories/mixed/1_bars_and_lines.story.tsx | 3 +- .../stories/mixed/2_lines_and_areas.story.tsx | 3 +- .../stories/mixed/3_areas_and_bars.story.tsx | 3 +- storybook/stories/mixed/4_test_bar.story.tsx | 3 +- .../stories/mixed/5_test_bar_time.story.tsx | 3 +- storybook/stories/mixed/6_fitting.story.tsx | 1 - .../stories/mixed/6_fitting_stacked.story.tsx | 1 - storybook/stories/mixed/7_marks.story.tsx | 1 - .../stories/mosaic/10_mosaic_simple.story.tsx | 1 - .../mosaic/20_mosaic_with_other.story.tsx | 3 +- .../stories/rotations/1_ordinal.story.tsx | 1 - .../rotations/2_negative_ordinal.story.tsx | 3 +- .../rotations/3_rotations_ordinal.story.tsx | 3 +- .../stories/rotations/4_90_ordinal.story.tsx | 3 +- .../stories/rotations/5_180_ordinal.story.tsx | 3 +- .../rotations/6_negative_linear.story.tsx | 3 +- .../rotations/7_rotations_linear.story.tsx | 3 +- .../rotations/8_90_deg_linear.story.tsx | 3 +- .../rotations/9_180_deg_linear.story.tsx | 3 +- .../scales/1_different_timezones.story.tsx | 4 +- .../stories/scales/2_local_tooltip.story.tsx | 4 +- .../stories/scales/3_utc_tooltip.story.tsx | 3 +- .../scales/4_specified_timezone.story.tsx | 4 +- .../scales/6_x_scale_fallback.story.tsx | 4 +- .../scales/7_log_scale_options.story.tsx | 3 +- .../stories/small_multiples/1_grid.story.tsx | 1 - .../2_vertical_areas.story.tsx | 1 - .../small_multiples/3_grid_lines.story.tsx | 1 - .../4_horizontal_bars.story.tsx | 4 +- .../small_multiples/4_vertical_bars.story.tsx | 3 +- .../5_histogram_bars.story.tsx | 3 +- .../6_heterogeneous_cartesians.story.tsx | 4 +- .../small_multiples/7_sunbursts.story.tsx | 1 - .../stories/streamgraph/1_basic.story.tsx | 3 +- .../stories/stylings/10_custom_bars.story.tsx | 3 +- .../stylings/11_custom_lines.story.tsx | 1 - .../stories/stylings/12_custom_area.story.tsx | 1 - .../stylings/13_custom_series_name.story.tsx | 4 +- .../13_custom_series_name_config.story.tsx | 4 +- ...14_custom_series_name_formatting.story.tsx | 4 +- .../stories/stylings/15_tick_label.story.tsx | 3 +- .../stylings/16_style_accessor.story.tsx | 1 - .../17_bar_series_color_variant.story.tsx | 1 - .../18_line_series_color_variant.story.tsx | 1 - .../19_area_series_color_variant.story.tsx | 1 - .../stories/stylings/1_chart_size.story.tsx | 11 ++- .../20_partition_background.story.tsx | 3 +- .../stylings/21_partition_labels.story.tsx | 3 +- .../stories/stylings/22_dark_theme.story.tsx | 1 - .../stylings/23_with_texture.story.tsx | 1 - .../24_texture_multiple_series.story.tsx | 1 - .../stories/stylings/2_margins.story.tsx | 1 - storybook/stories/stylings/3_axis.story.tsx | 1 - .../stylings/4_theme_styling.story.tsx | 1 - .../stylings/5_partial_custom_theme.story.tsx | 1 - .../stylings/6_partial_and_base.story.tsx | 1 - .../stylings/7_multiple_custom.story.tsx | 1 - .../8_custom_series_colors_array.story.tsx | 3 +- .../9_custom_series_colors_function.story.tsx | 3 +- .../stories/sunburst/10_2_slice.story.tsx | 3 +- .../stories/sunburst/11_small_large.story.tsx | 3 +- .../stories/sunburst/12_very_small.story.tsx | 3 +- storybook/stories/sunburst/13_empty.story.tsx | 3 +- .../stories/sunburst/14_full_zero.story.tsx | 3 +- .../stories/sunburst/15_single.story.tsx | 3 +- .../sunburst/15_single_sunburst.story.tsx | 3 +- .../sunburst/16_single_small.story.tsx | 3 +- .../sunburst/17_single_very_small.story.tsx | 3 +- .../stories/sunburst/18_no_sliced.story.tsx | 3 +- .../stories/sunburst/19_negative.story.tsx | 3 +- storybook/stories/sunburst/1_simple.story.tsx | 3 +- .../stories/sunburst/20_total_zero.story.tsx | 3 +- .../stories/sunburst/21_high_pie.story.tsx | 3 +- .../sunburst/22_counter_clockwise.story.tsx | 3 +- .../stories/sunburst/23_clockwise.story.tsx | 3 +- .../sunburst/24_linked_label.story.tsx | 3 +- .../stories/sunburst/25_no_labels.story.tsx | 3 +- .../stories/sunburst/26_percentage.story.tsx | 3 +- .../sunburst/27_heterogeneous_depth.story.tsx | 3 +- .../sunburst/28_not_a_number.story.tsx | 3 +- .../sunburst/29_custom_stroke.story.tsx | 3 +- .../sunburst/2_value_formatted.story.tsx | 3 +- .../sunburst/30_largest_circle.story.tsx | 3 +- .../sunburst/31_bold_link_value.story.tsx | 3 +- .../sunburst/32_custom_tooltip.story.tsx | 3 +- .../sunburst/33_ordered_slices.story.tsx | 3 +- .../sunburst/3_value_formatted_2.story.tsx | 3 +- .../stories/sunburst/4_fill_labels.story.tsx | 3 +- storybook/stories/sunburst/5_donut.story.tsx | 3 +- .../sunburst/6_pie_chart_labels.story.tsx | 3 +- .../6_pie_chart_linked_labels.story.tsx | 3 +- .../stories/sunburst/7_zero_slice.story.tsx | 3 +- .../sunburst/8_sunburst_two_layers.story.tsx | 3 +- .../9_sunburst_three_layers.story.tsx | 3 +- .../stories/test_cases/1_no_series.story.tsx | 4 +- .../2_chrome_path_bug_fix.story.tsx | 4 +- .../test_cases/3_no_axes_annotation.story.tsx | 3 +- .../4_filter_zero_values_log.story.tsx | 3 +- .../5_legend_scroll_bar_sizing.story.tsx | 4 +- .../6_a11y_custom_description.story.tsx | 1 - .../stories/treemap/10_three_layers.story.tsx | 3 +- .../stories/treemap/1_one_layer.story.tsx | 3 +- .../stories/treemap/2_one_layer_2.story.tsx | 3 +- storybook/stories/treemap/3_mid_two.story.tsx | 3 +- .../treemap/4_two_layer_stress.story.tsx | 3 +- .../stories/treemap/5_multicolor.story.tsx | 3 +- .../stories/treemap/6_custom_style.story.tsx | 3 +- .../stories/treemap/7_percentage.story.tsx | 3 +- .../stories/treemap/8_groove_text.story.tsx | 3 +- .../stories/treemap/9_zero_values.story.tsx | 3 +- storybook/stories/waffle/1_simple.story.tsx | 3 +- .../stories/wordcloud/1_wordcloud.story.tsx | 1 - storybook/story_wrapper.tsx | 75 ++++++++++--------- 312 files changed, 304 insertions(+), 629 deletions(-) rename storybook/{use_base_theme.ts => context_utils.ts} (60%) diff --git a/storybook/use_base_theme.ts b/storybook/context_utils.ts similarity index 60% rename from storybook/use_base_theme.ts rename to storybook/context_utils.ts index c5134fd097b..29835261fef 100644 --- a/storybook/use_base_theme.ts +++ b/storybook/context_utils.ts @@ -7,11 +7,10 @@ */ import { EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT } from '@elastic/eui/dist/eui_charts_theme'; -import { createContext, useContext } from 'react'; +import { createContext } from 'react'; import { $Values } from 'utility-types'; -import { Theme, LIGHT_THEME, DARK_THEME, DEFAULT_CHART_MARGINS } from '@elastic/charts'; -import { mergePartial } from '@elastic/charts/src/utils/common'; +import { LIGHT_THEME, DARK_THEME, DEFAULT_CHART_MARGINS, EchContext, PartialTheme, Theme } from '@elastic/charts'; import { storybookParameters } from './parameters'; @@ -34,11 +33,16 @@ const BackgroundContext = createContext(undefined); export const ThemeIdProvider = ThemeContext.Provider; export const BackgroundIdProvider = BackgroundContext.Provider; -const themeMap = { +const themeMap: Record = { + [ThemeId.EUILight]: EUI_CHARTS_THEME_LIGHT.theme, + [ThemeId.EUIDark]: EUI_CHARTS_THEME_DARK.theme, +}; + +const baseThemeMap: Record = { [ThemeId.Light]: LIGHT_THEME, [ThemeId.Dark]: DARK_THEME, - [ThemeId.EUILight]: mergePartial(LIGHT_THEME, EUI_CHARTS_THEME_LIGHT.theme, { mergeOptionalPartialValues: true }), - [ThemeId.EUIDark]: mergePartial(DARK_THEME, EUI_CHARTS_THEME_DARK.theme, { mergeOptionalPartialValues: true }), + [ThemeId.EUILight]: LIGHT_THEME, + [ThemeId.EUIDark]: DARK_THEME, }; const getBackground = (backgroundId?: string) => { @@ -49,21 +53,26 @@ const getBackground = (backgroundId?: string) => { return option?.background ?? option?.color; }; -export const useBaseTheme = (): Theme => { - const themeId = useContext(ThemeContext); - const backgroundId = useContext(BackgroundContext); - const theme = themeMap[themeId] ?? LIGHT_THEME; +export const getContext = (themeId: ThemeId, backgroundId: string): EchContext => { + const theme = themeMap[themeId] ?? {}; + const baseTheme = baseThemeMap[themeId] ?? LIGHT_THEME; const backgroundColor = getBackground(backgroundId); - return mergePartial( - theme, - { - // eui chart theme has no margin for some reason. This is just for consistency. - chartMargins: DEFAULT_CHART_MARGINS, - background: { - color: backgroundColor, - }, + return { + settings: { + baseTheme, + theme: [ + { + // eui chart theme has no margin for some reason. This is just for consistency. + chartMargins: DEFAULT_CHART_MARGINS, + background: { + color: backgroundColor, + }, + }, + theme, + ], }, - { mergeOptionalPartialValues: true }, - ); + }; }; + +export const useBaseTheme = () => LIGHT_THEME; diff --git a/storybook/stories/annotations/lines/1_x_continuous.story.tsx b/storybook/stories/annotations/lines/1_x_continuous.story.tsx index fc95184bc8b..cafc11af779 100644 --- a/storybook/stories/annotations/lines/1_x_continuous.story.tsx +++ b/storybook/stories/annotations/lines/1_x_continuous.story.tsx @@ -23,7 +23,6 @@ import { import { Icon } from '@elastic/charts/src/components/icons/icon'; import { Position } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../../use_base_theme'; import { getChartRotationKnob, arrayKnobs } from '../../utils/knobs'; function generateAnnotationData(values: any[]): LineAnnotationDatum[] { @@ -60,7 +59,7 @@ export const Example = () => { return ( - + { const dataValues = generateAnnotationData(arrayKnobs('annotation values', ['a', 'c'])); return ( - + { return ( - + { return ( - + { return ( - + { @@ -56,7 +55,7 @@ export const Example = () => { return ( - + { return ( - + { return ( - + { @@ -43,7 +42,7 @@ export const Example = () => { return ( - + { @@ -21,7 +20,7 @@ export const Example = () => { return ( - + { @@ -75,7 +74,7 @@ export const Example = () => { return ( - + diff --git a/storybook/stories/annotations/rects/4_styling.story.tsx b/storybook/stories/annotations/rects/4_styling.story.tsx index fd72fdfea75..cbe01940fff 100644 --- a/storybook/stories/annotations/rects/4_styling.story.tsx +++ b/storybook/stories/annotations/rects/4_styling.story.tsx @@ -13,7 +13,6 @@ import { Axis, Chart, LineSeries, RectAnnotation, ScaleType, Settings } from '@e import { Icon } from '@elastic/charts/src/components/icons/icon'; import { Position } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../../use_base_theme'; import { getChartRotationKnob } from '../../utils/knobs'; export const Example = () => { @@ -93,7 +92,7 @@ export const Example = () => { return ( - + { @@ -71,7 +70,7 @@ export const Example = () => { return ( - + { const minY = number('min y', 0); @@ -38,7 +37,7 @@ export const Example = () => { return ( - + { const enabled = boolean('enable annotation', true); @@ -49,7 +48,7 @@ export const Example = () => { style={{ fill: 'red' }} /> )} - + diff --git a/storybook/stories/annotations/rects/8_outside.story.tsx b/storybook/stories/annotations/rects/8_outside.story.tsx index bc1662793cf..9806400ff58 100644 --- a/storybook/stories/annotations/rects/8_outside.story.tsx +++ b/storybook/stories/annotations/rects/8_outside.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, LineSeries, Position, RectAnnotation, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../../use_base_theme'; import { getChartRotationKnob } from '../../utils/knobs'; const vGroups = { diff --git a/storybook/stories/annotations/rects/9_click_handler.story.tsx b/storybook/stories/annotations/rects/9_click_handler.story.tsx index 35c922c8e28..95b03d82fe5 100644 --- a/storybook/stories/annotations/rects/9_click_handler.story.tsx +++ b/storybook/stories/annotations/rects/9_click_handler.story.tsx @@ -26,7 +26,6 @@ import { } from '@elastic/charts'; import { Icon } from '@elastic/charts/src/components/icons/icon'; -import { useBaseTheme } from '../../../use_base_theme'; export const Example = () => { const onAnnotationClick = boolean('onAnnotationClick listener', true); diff --git a/storybook/stories/area/10_stacked_same_naming.story.tsx b/storybook/stories/area/10_stacked_same_naming.story.tsx index 851a9ef7ea8..f02aa627c35 100644 --- a/storybook/stories/area/10_stacked_same_naming.story.tsx +++ b/storybook/stories/area/10_stacked_same_naming.story.tsx @@ -11,13 +11,12 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, timeFormatter } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; const dateFormatter = timeFormatter('HH:mm'); export const Example = () => ( - + { @@ -28,7 +27,7 @@ export const Example = () => { ]; return ( - + { ]; return ( - + { const y1AccessorFormat = text('y1AccessorFormat', ''); return ( - + { return ( - + { const data1 = [ @@ -49,7 +48,7 @@ export const Example = () => { ]; return ( - + ( - + { ); return ( - + { return ( - + { const scaleType = select( diff --git a/storybook/stories/area/1_basic.story.tsx b/storybook/stories/area/1_basic.story.tsx index 5928f665af6..d650f8b53ac 100644 --- a/storybook/stories/area/1_basic.story.tsx +++ b/storybook/stories/area/1_basic.story.tsx @@ -11,13 +11,12 @@ import React from 'react'; import { AreaSeries, Chart, ScaleType, Settings } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const { data } = KIBANA_METRICS.metrics.kibana_os_load[0]; return ( - + { const yAxisTitle = 'CPU utilization'; return ( - + { const start = KIBANA_METRICS.metrics.kibana_os_load[0].data[0][0]; const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 20).map((d) => [(d[0] - start) / 30000, d[1]]); return ( - + { const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.map((d) => (d[1] < 7 ? [d[0], null] : [d[0], d[1] - 10])); return ( - + ( - + ( - + { const allMetrics = [...data3, ...data2, ...data1]; return ( - + { const stackedAsPercentage = boolean('stacked as percentage', true); return ( - + ( - + ( - + { const leftDomain = { @@ -26,7 +25,7 @@ export const Example = () => { return ( - + { @@ -49,7 +48,7 @@ export const Example = () => { return ( - + { const now = DateTime.fromISO('2019-01-11T00:00:00.000').setZone('utc+1').toMillis(); @@ -42,7 +41,7 @@ export const Example = () => { const duplicateTicksInAxis = boolean('Show duplicate ticks in x axis', false); return ( - + { const tickFormatBottom = text('tickFormat bottom', '0.0000'); @@ -25,7 +24,7 @@ export const Example = () => { return ( - + { const customStyle: RecursivePartial = { @@ -38,7 +37,7 @@ export const Example = () => { const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 60); return ( - + => ({ @@ -135,7 +134,7 @@ export const Example = () => { return ( - + ( - + { const seriesGroup2 = 'group2'; return ( - + {renderAxisWithOptions(Position.Top, seriesGroup1, false)} {renderAxisWithOptions(Position.Top, seriesGroup2, true)} {renderAxisWithOptions(Position.Left, seriesGroup1, false)} diff --git a/storybook/stories/axes/5_multi_axis_bar_lines.story.tsx b/storybook/stories/axes/5_multi_axis_bar_lines.story.tsx index 23ddfe88cc0..0af6e946c48 100644 --- a/storybook/stories/axes/5_multi_axis_bar_lines.story.tsx +++ b/storybook/stories/axes/5_multi_axis_bar_lines.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> ( - + { const showLegend = boolean('Show legend', true, 'Y axis'); diff --git a/storybook/stories/axes/7_many_tick_labels.story.tsx b/storybook/stories/axes/7_many_tick_labels.story.tsx index 2f1c6e49ee7..08fe7455ced 100644 --- a/storybook/stories/axes/7_many_tick_labels.story.tsx +++ b/storybook/stories/axes/7_many_tick_labels.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, RecursivePartial, AxisStyle } from '@elastic/charts'; import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const dg = new SeededDataGenerator(); @@ -26,7 +25,7 @@ export const Example = () => { return ( - + { const customXDomain = boolean('customize X domain', true, 'X axis'); diff --git a/storybook/stories/axes/9_custom_mixed_domain.story.tsx b/storybook/stories/axes/9_custom_mixed_domain.story.tsx index 86ea60f5b4a..b19a4401aea 100644 --- a/storybook/stories/axes/9_custom_mixed_domain.story.tsx +++ b/storybook/stories/axes/9_custom_mixed_domain.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { arrayKnobs } from '../utils/knobs'; export const Example = () => { @@ -29,7 +28,7 @@ export const Example = () => { return ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/11_stacked_with_axis_and_legend.story.tsx b/storybook/stories/bar/11_stacked_with_axis_and_legend.story.tsx index a51e5798a1e..bf70d86443e 100644 --- a/storybook/stories/bar/11_stacked_with_axis_and_legend.story.tsx +++ b/storybook/stories/bar/11_stacked_with_axis_and_legend.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/12_stacked_as_percentage.story.tsx b/storybook/stories/bar/12_stacked_as_percentage.story.tsx index d02741c3a8e..fc251f82fd8 100644 --- a/storybook/stories/bar/12_stacked_as_percentage.story.tsx +++ b/storybook/stories/bar/12_stacked_as_percentage.story.tsx @@ -11,14 +11,13 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, StackMode } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const stackedAsPercentage = boolean('stacked as percentage', true); const clusterBars = boolean('cluster', true); return ( - + { diff --git a/storybook/stories/bar/14_clustered_multiple.story.tsx b/storybook/stories/bar/14_clustered_multiple.story.tsx index bde103b8122..cf8ea9bda0e 100644 --- a/storybook/stories/bar/14_clustered_multiple.story.tsx +++ b/storybook/stories/bar/14_clustered_multiple.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/15_time_clustered.story.tsx b/storybook/stories/bar/15_time_clustered.story.tsx index 12b015a7c83..70cb3a35819 100644 --- a/storybook/stories/bar/15_time_clustered.story.tsx +++ b/storybook/stories/bar/15_time_clustered.story.tsx @@ -21,13 +21,12 @@ import { } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const formatter = timeFormatter(niceTimeFormatByDay(1)); return ( - + { const formatter = timeFormatter(niceTimeFormatByDay(1)); return ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/19_bar_chart_1y1g.story.tsx b/storybook/stories/bar/19_bar_chart_1y1g.story.tsx index 0d538286e50..49b03399ff3 100644 --- a/storybook/stories/bar/19_bar_chart_1y1g.story.tsx +++ b/storybook/stories/bar/19_bar_chart_1y1g.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/1_basic.story.tsx b/storybook/stories/bar/1_basic.story.tsx index 2ed200bf62b..7bf155fe45f 100644 --- a/storybook/stories/bar/1_basic.story.tsx +++ b/storybook/stories/bar/1_basic.story.tsx @@ -11,8 +11,6 @@ import React from 'react'; import { BarSeries, Chart, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const toggleSpec = boolean('toggle bar spec', true); const data1 = [ @@ -26,7 +24,7 @@ export const Example = () => { const specId = toggleSpec ? 'bars1' : 'bars2'; return ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/21_bar_chart_2y0g.story.tsx b/storybook/stories/bar/21_bar_chart_2y0g.story.tsx index b12896d0ea0..dd73c6b65f3 100644 --- a/storybook/stories/bar/21_bar_chart_2y0g.story.tsx +++ b/storybook/stories/bar/21_bar_chart_2y0g.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/22_barchart_2y1g.story.tsx b/storybook/stories/bar/22_barchart_2y1g.story.tsx index 1ef42acc01b..a8c355e0cf4 100644 --- a/storybook/stories/bar/22_barchart_2y1g.story.tsx +++ b/storybook/stories/bar/22_barchart_2y1g.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/23_bar_chart_2y2g.story.tsx b/storybook/stories/bar/23_bar_chart_2y2g.story.tsx index 0dea52d2962..8689823948e 100644 --- a/storybook/stories/bar/23_bar_chart_2y2g.story.tsx +++ b/storybook/stories/bar/23_bar_chart_2y2g.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> { const isVisibleFunction: FilterPredicate = (series) => series.splitAccessors.get('g1') === 'cloudflare.com'; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/25_high_data_volume.story.tsx b/storybook/stories/bar/25_high_data_volume.story.tsx index 86ceb60bdf8..f93b6614400 100644 --- a/storybook/stories/bar/25_high_data_volume.story.tsx +++ b/storybook/stories/bar/25_high_data_volume.story.tsx @@ -12,7 +12,6 @@ import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/ import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; import { TooltipType } from '@elastic/charts/src/specs/constants'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const dg = new SeededDataGenerator(); @@ -22,7 +21,7 @@ export const Example = () => { }; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/26_single_data_linear.story.tsx b/storybook/stories/bar/26_single_data_linear.story.tsx index 5c41bd537bc..0fb484458bb 100644 --- a/storybook/stories/bar/26_single_data_linear.story.tsx +++ b/storybook/stories/bar/26_single_data_linear.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, PartialTheme, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { @@ -35,7 +34,7 @@ export const Example = () => { }; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/27_single_data_ordinal.story.tsx b/storybook/stories/bar/27_single_data_ordinal.story.tsx index 8a9e1d68735..89c2f65ffc6 100644 --- a/storybook/stories/bar/27_single_data_ordinal.story.tsx +++ b/storybook/stories/bar/27_single_data_ordinal.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, PartialTheme, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { @@ -30,7 +29,7 @@ export const Example = () => { }; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/28_single_data_clustered.story.tsx b/storybook/stories/bar/28_single_data_clustered.story.tsx index b4bd3035955..5758da56e31 100644 --- a/storybook/stories/bar/28_single_data_clustered.story.tsx +++ b/storybook/stories/bar/28_single_data_clustered.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/29_single_data_stacked.story.tsx b/storybook/stories/bar/29_single_data_stacked.story.tsx index 7e2053f5b28..e83bc4d636e 100644 --- a/storybook/stories/bar/29_single_data_stacked.story.tsx +++ b/storybook/stories/bar/29_single_data_stacked.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/2_label_value.story.tsx b/storybook/stories/bar/2_label_value.story.tsx index f0ab405ff2e..ad8ca1aa652 100644 --- a/storybook/stories/bar/2_label_value.story.tsx +++ b/storybook/stories/bar/2_label_value.story.tsx @@ -22,7 +22,6 @@ import { } from '@elastic/charts'; import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob, getPositionKnob } from '../utils/knobs'; const dataGen = new SeededDataGenerator(); diff --git a/storybook/stories/bar/30_stacked_to_extent.story.tsx b/storybook/stories/bar/30_stacked_to_extent.story.tsx index 7260d0dcbc2..61b45c4b1d0 100644 --- a/storybook/stories/bar/30_stacked_to_extent.story.tsx +++ b/storybook/stories/bar/30_stacked_to_extent.story.tsx @@ -11,14 +11,13 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const fit = boolean('fit Y domain to data', true); return ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/32_scale_to_extent.story.tsx b/storybook/stories/bar/32_scale_to_extent.story.tsx index 243966fad84..2df3933ff63 100644 --- a/storybook/stories/bar/32_scale_to_extent.story.tsx +++ b/storybook/stories/bar/32_scale_to_extent.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Axis, Chart, DomainPaddingUnit, Position, ScaleType, Settings } from '@elastic/charts'; import { computeContinuousDataDomain } from '@elastic/charts/src/utils/domain'; -import { useBaseTheme } from '../../use_base_theme'; import { getKnobsFromEnum, getXYSeriesKnob } from '../utils/knobs'; const logDomains = (data: any[], customDomain: any) => { @@ -75,7 +74,7 @@ export const Example = () => { return ( - + { const useFunctions = boolean('use fn accessors', false); return ( - + { @@ -28,7 +27,7 @@ export const Example = () => { ]; return ( - + { ]; return ( - + { @@ -28,7 +27,7 @@ export const Example = () => { ]; return ( - + { ]; return ( - + { @@ -27,7 +26,7 @@ export const Example = () => { ]; return ( - + { @@ -27,7 +26,7 @@ export const Example = () => { ]; return ( - + { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/40_test_switch.story.tsx b/storybook/stories/bar/40_test_switch.story.tsx index eca1b7f9bea..a6ed5d8b08d 100644 --- a/storybook/stories/bar/40_test_switch.story.tsx +++ b/storybook/stories/bar/40_test_switch.story.tsx @@ -11,12 +11,11 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; // for testing purposes only export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/41_test_histogram_linear.story.tsx b/storybook/stories/bar/41_test_histogram_linear.story.tsx index 23d140ac2e6..3dcf58de284 100644 --- a/storybook/stories/bar/41_test_histogram_linear.story.tsx +++ b/storybook/stories/bar/41_test_histogram_linear.story.tsx @@ -27,7 +27,6 @@ import { } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; // for testing purposes only diff --git a/storybook/stories/bar/42_test_histogram_ordinal.story.tsx b/storybook/stories/bar/42_test_histogram_ordinal.story.tsx index 1c68f7da6c7..363f9533ce0 100644 --- a/storybook/stories/bar/42_test_histogram_ordinal.story.tsx +++ b/storybook/stories/bar/42_test_histogram_ordinal.story.tsx @@ -20,7 +20,6 @@ import { Settings, } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; // for testing purposes only diff --git a/storybook/stories/bar/43_test_discover.story.tsx b/storybook/stories/bar/43_test_discover.story.tsx index 5d0dd8fef1b..48c9dcc461b 100644 --- a/storybook/stories/bar/43_test_discover.story.tsx +++ b/storybook/stories/bar/43_test_discover.story.tsx @@ -20,7 +20,6 @@ import { timeFormatter, } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const TEST_DATASET_DISCOVER = { xAxisLabel: 'timestamp per 30 seconds', @@ -50,7 +49,7 @@ export const Example = () => { const useCustomMinInterval = boolean('use custom minInterval of 30s', true); return ( - + { const formatter = timeFormatter(niceTimeFormatByDay(1)); @@ -34,7 +32,7 @@ export const Example = () => { return ( - + { const minBarHeight = number('minBarHeight', 5); @@ -28,7 +27,7 @@ export const Example = () => { ]; return ( - + { @@ -38,7 +37,7 @@ export const Example = () => { ]; return ( - + { const data1 = [ @@ -71,7 +70,7 @@ export const Example = () => { ]; return ( - + { return (
- + { const stack13 = boolean('Stack bars1 and bars3', true); const stack24 = boolean('Stack bars2 and bars4', false); return ( - + diff --git a/storybook/stories/bar/4_ordinal.story.tsx b/storybook/stories/bar/4_ordinal.story.tsx index efb32329474..bdbf7933507 100644 --- a/storybook/stories/bar/4_ordinal.story.tsx +++ b/storybook/stories/bar/4_ordinal.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/50_order_bins_by_sum.story.tsx b/storybook/stories/bar/50_order_bins_by_sum.story.tsx index 047d185c74b..f86657dbda3 100644 --- a/storybook/stories/bar/50_order_bins_by_sum.story.tsx +++ b/storybook/stories/bar/50_order_bins_by_sum.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, BinAgg, Direction } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const data = [ { x1: 'b', x2: 2, g1: 'false', g2: 'Canada', y1: 19, y2: 22 }, diff --git a/storybook/stories/bar/51_label_value_advanced.story.tsx b/storybook/stories/bar/51_label_value_advanced.story.tsx index 306f90d0326..9e2d498b989 100644 --- a/storybook/stories/bar/51_label_value_advanced.story.tsx +++ b/storybook/stories/bar/51_label_value_advanced.story.tsx @@ -22,7 +22,6 @@ import { } from '@elastic/charts'; import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; const dataGen = new SeededDataGenerator(); diff --git a/storybook/stories/bar/52_multi_group_same_domain.story.tsx b/storybook/stories/bar/52_multi_group_same_domain.story.tsx index 3b24f65c314..8e9444c7b49 100644 --- a/storybook/stories/bar/52_multi_group_same_domain.story.tsx +++ b/storybook/stories/bar/52_multi_group_same_domain.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Settings, Chart, Position, ScaleType } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const data1 = [ @@ -49,7 +48,7 @@ export const Example = () => { return ( - + { const data1 = [ @@ -48,7 +47,7 @@ export const Example = () => { return ( - + diff --git a/storybook/stories/bar/54_functional_accessors.story.tsx b/storybook/stories/bar/54_functional_accessors.story.tsx index 13cf7bc8d7c..923cc5a8312 100644 --- a/storybook/stories/bar/54_functional_accessors.story.tsx +++ b/storybook/stories/bar/54_functional_accessors.story.tsx @@ -22,7 +22,6 @@ import { } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const xAccessorFn: AccessorFn = (d) => d.x; @@ -35,7 +34,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/55_tooltip_boundary.story.tsx b/storybook/stories/bar/55_tooltip_boundary.story.tsx index 151cd392104..8b8eb8ba13f 100644 --- a/storybook/stories/bar/55_tooltip_boundary.story.tsx +++ b/storybook/stories/bar/55_tooltip_boundary.story.tsx @@ -12,7 +12,6 @@ import React, { useRef } from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, TooltipProps } from '@elastic/charts'; import { getRandomNumberGenerator, SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); const rng = getRandomNumberGenerator(); @@ -66,7 +65,7 @@ export const Example = () => {
- + { return ( - + diff --git a/storybook/stories/bar/57_test_rect_border_bars.story.tsx b/storybook/stories/bar/57_test_rect_border_bars.story.tsx index 6bb51221a09..2a468b97794 100644 --- a/storybook/stories/bar/57_test_rect_border_bars.story.tsx +++ b/storybook/stories/bar/57_test_rect_border_bars.story.tsx @@ -10,7 +10,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { return ( diff --git a/storybook/stories/bar/5_linear.story.tsx b/storybook/stories/bar/5_linear.story.tsx index b85de5301fd..ea216f66f0d 100644 --- a/storybook/stories/bar/5_linear.story.tsx +++ b/storybook/stories/bar/5_linear.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, PartialTheme } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { @@ -33,7 +32,7 @@ export const Example = () => { }; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/bar/6_linear_no_linear_interval.story.tsx b/storybook/stories/bar/6_linear_no_linear_interval.story.tsx index 5169a1bd789..184d58b3709 100644 --- a/storybook/stories/bar/6_linear_no_linear_interval.story.tsx +++ b/storybook/stories/bar/6_linear_no_linear_interval.story.tsx @@ -10,7 +10,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( diff --git a/storybook/stories/bar/7_with_time_xaxis.story.tsx b/storybook/stories/bar/7_with_time_xaxis.story.tsx index a3409a58664..c05da969a77 100644 --- a/storybook/stories/bar/7_with_time_xaxis.story.tsx +++ b/storybook/stories/bar/7_with_time_xaxis.story.tsx @@ -21,13 +21,12 @@ import { } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const formatter = timeFormatter(niceTimeFormatByDay(1)); return ( - + ( - + ( - + ({ diff --git a/storybook/stories/bubble/3_multiple.story.tsx b/storybook/stories/bubble/3_multiple.story.tsx index a091c6aa280..ebedb0e4a54 100644 --- a/storybook/stories/bubble/3_multiple.story.tsx +++ b/storybook/stories/bubble/3_multiple.story.tsx @@ -13,7 +13,6 @@ import React from 'react'; import { Axis, Chart, BubbleSeries, Position, ScaleType, Settings, TooltipType } from '@elastic/charts'; import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); diff --git a/storybook/stories/bubble/4_mixed.story.tsx b/storybook/stories/bubble/4_mixed.story.tsx index ebe1cadbc74..56b301871f6 100644 --- a/storybook/stories/bubble/4_mixed.story.tsx +++ b/storybook/stories/bubble/4_mixed.story.tsx @@ -13,7 +13,6 @@ import React from 'react'; import { Axis, Chart, BubbleSeries, Position, ScaleType, Settings, LineSeries } from '@elastic/charts'; import { SeededDataGenerator, getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); const rng = getRandomNumberGenerator(); diff --git a/storybook/stories/debug/1_basic.story.tsx b/storybook/stories/debug/1_basic.story.tsx index 9f334d4083c..acb3d7ae76e 100644 --- a/storybook/stories/debug/1_basic.story.tsx +++ b/storybook/stories/debug/1_basic.story.tsx @@ -11,14 +11,12 @@ import React from 'react'; import { Chart, ScaleType, Settings, Position, Axis, BarSeries, AreaSeries, CurveType } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const debug = boolean('debug', true); return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/debug/2_debug_state.story.tsx b/storybook/stories/debug/2_debug_state.story.tsx index 5d423bfb546..4b31f1d79ba 100644 --- a/storybook/stories/debug/2_debug_state.story.tsx +++ b/storybook/stories/debug/2_debug_state.story.tsx @@ -26,7 +26,6 @@ import { } from '@elastic/charts'; import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const debug = boolean('debug', false); diff --git a/storybook/stories/goal/10_band_in_band.story.tsx b/storybook/stories/goal/10_band_in_band.story.tsx index 5aad312fa84..3b2ceb8fe52 100644 --- a/storybook/stories/goal/10_band_in_band.story.tsx +++ b/storybook/stories/goal/10_band_in_band.story.tsx @@ -13,7 +13,6 @@ import { BandFillColorAccessorInput } from '@elastic/charts/src/chart_types/goal import { GoalSubtype } from '@elastic/charts/src/chart_types/goal_chart/specs/constants'; import { Color } from '../../../packages/charts/src/common/colors'; -import { useBaseTheme } from '../../use_base_theme'; const subtype = GoalSubtype.Goal; @@ -26,7 +25,7 @@ const bandFillColor = (x: number): Color => colorMap[x]; export const Example = () => ( - + { return ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + { return ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + colorMap[x]; export const Example = () => ( - + { const integersOnlyRight = boolean('right axis show only intger values', false, 'right axis'); return ( - + { return ( - + { const [selection, setSelection] = useState<{ x: (string | number)[]; y: (string | number)[] } | undefined>(); diff --git a/storybook/stories/heatmap/2_categorical.story.tsx b/storybook/stories/heatmap/2_categorical.story.tsx index 64428613b6c..bcde3e552fd 100644 --- a/storybook/stories/heatmap/2_categorical.story.tsx +++ b/storybook/stories/heatmap/2_categorical.story.tsx @@ -13,7 +13,6 @@ import React from 'react'; import { Chart, Heatmap, Settings } from '@elastic/charts'; import { BABYNAME_DATA } from '@elastic/charts/src/utils/data_samples/babynames'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const data = boolean('filter dataset', true) diff --git a/storybook/stories/icicle/01_unix_icicle.story.tsx b/storybook/stories/icicle/01_unix_icicle.story.tsx index d1ef1ce7429..3eb8a9eaed8 100644 --- a/storybook/stories/icicle/01_unix_icicle.story.tsx +++ b/storybook/stories/icicle/01_unix_icicle.story.tsx @@ -10,7 +10,6 @@ import React from 'react'; import { Chart, Datum, Partition, PartitionLayout, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { config, getFlatData, getLayerSpec, maxDepth } from '../utils/hierarchical_input_utils'; import { viridis18 as palette } from '../utils/utils'; @@ -19,7 +18,7 @@ const color = palette.slice().reverse(); export const Example = () => { return ( - + { const clipText = boolean("Allow, and clip, texts that wouldn't otherwise fit", true); return ( - + { @@ -21,7 +20,7 @@ export const Example = () => { return ( - + ( diff --git a/storybook/stories/interactions/11_brush_time.story.tsx b/storybook/stories/interactions/11_brush_time.story.tsx index b8420606b62..f7658f5147a 100644 --- a/storybook/stories/interactions/11_brush_time.story.tsx +++ b/storybook/stories/interactions/11_brush_time.story.tsx @@ -24,7 +24,6 @@ import { Settings, } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { diff --git a/storybook/stories/interactions/12_brush_time_hist.story.tsx b/storybook/stories/interactions/12_brush_time_hist.story.tsx index dd6b865cb4d..784418d0314 100644 --- a/storybook/stories/interactions/12_brush_time_hist.story.tsx +++ b/storybook/stories/interactions/12_brush_time_hist.story.tsx @@ -23,7 +23,6 @@ import { } from '@elastic/charts'; import { isVerticalRotation } from '@elastic/charts/src/chart_types/xy_chart/state/utils/common'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { diff --git a/storybook/stories/interactions/13_brush_disabled_ordinal.story.tsx b/storybook/stories/interactions/13_brush_disabled_ordinal.story.tsx index 6cf2dcb4dff..5c25c4dec85 100644 --- a/storybook/stories/interactions/13_brush_disabled_ordinal.story.tsx +++ b/storybook/stories/interactions/13_brush_disabled_ordinal.story.tsx @@ -11,12 +11,11 @@ import React from 'react'; import { Axis, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => ( - + { diff --git a/storybook/stories/interactions/15_render_change.story.tsx b/storybook/stories/interactions/15_render_change.story.tsx index 5bb2343fc8e..d867956c262 100644 --- a/storybook/stories/interactions/15_render_change.story.tsx +++ b/storybook/stories/interactions/15_render_change.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const onRenderChange = action('onRenderChange'); diff --git a/storybook/stories/interactions/16_cursor_update_action.story.tsx b/storybook/stories/interactions/16_cursor_update_action.story.tsx index f43d066d1d6..0096a0befd3 100644 --- a/storybook/stories/interactions/16_cursor_update_action.story.tsx +++ b/storybook/stories/interactions/16_cursor_update_action.story.tsx @@ -27,7 +27,6 @@ import { import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; import { palettes } from '@elastic/charts/src/utils/themes/colors'; -import { useBaseTheme } from '../../use_base_theme'; import { getTooltipTypeKnob, getPlacementKnob } from '../utils/knobs'; const chartTypes: Record = { diff --git a/storybook/stories/interactions/17_png_export.story.tsx b/storybook/stories/interactions/17_png_export.story.tsx index da2432250a1..0108a0e9674 100644 --- a/storybook/stories/interactions/17_png_export.story.tsx +++ b/storybook/stories/interactions/17_png_export.story.tsx @@ -29,7 +29,6 @@ import { mocks } from '@elastic/charts/src/mocks/hierarchical'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; import { Color } from '../../../packages/charts/src/common/colors'; -import { useBaseTheme } from '../../use_base_theme'; import { productLookup, indexInterpolatedFillColor, interpolatorCET2s } from '../utils/utils'; export const Example = () => { diff --git a/storybook/stories/interactions/1_bar_clicks.story.tsx b/storybook/stories/interactions/1_bar_clicks.story.tsx index d137527b569..47345d94002 100644 --- a/storybook/stories/interactions/1_bar_clicks.story.tsx +++ b/storybook/stories/interactions/1_bar_clicks.story.tsx @@ -21,7 +21,6 @@ import { TooltipValueFormatter, } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const onElementListeners = { onElementClick: action('onElementClick'), diff --git a/storybook/stories/interactions/2_area_point_clicks.story.tsx b/storybook/stories/interactions/2_area_point_clicks.story.tsx index 10cb577aba4..7b8550fa117 100644 --- a/storybook/stories/interactions/2_area_point_clicks.story.tsx +++ b/storybook/stories/interactions/2_area_point_clicks.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const onElementListeners = { onElementClick: action('onElementClick'), diff --git a/storybook/stories/interactions/3_line_point_clicks.story.tsx b/storybook/stories/interactions/3_line_point_clicks.story.tsx index 78c114fe47c..e5b223fd34e 100644 --- a/storybook/stories/interactions/3_line_point_clicks.story.tsx +++ b/storybook/stories/interactions/3_line_point_clicks.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const onElementListeners = { onElementClick: action('onElementClick'), diff --git a/storybook/stories/interactions/4_line_area_bar_clicks.story.tsx b/storybook/stories/interactions/4_line_area_bar_clicks.story.tsx index c17c3beceff..0f870562346 100644 --- a/storybook/stories/interactions/4_line_area_bar_clicks.story.tsx +++ b/storybook/stories/interactions/4_line_area_bar_clicks.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { AreaSeries, Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const onElementListeners = { onElementClick: action('onElementClick'), diff --git a/storybook/stories/interactions/4_sunburst_slice_clicks.story.tsx b/storybook/stories/interactions/4_sunburst_slice_clicks.story.tsx index 3d0965842a4..1a69866f419 100644 --- a/storybook/stories/interactions/4_sunburst_slice_clicks.story.tsx +++ b/storybook/stories/interactions/4_sunburst_slice_clicks.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Chart, Position, Settings, Partition, PartitionLayout } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { indexInterpolatedFillColor, interpolatorCET2s, diff --git a/storybook/stories/interactions/5_clicks_legend_items_bar.story.tsx b/storybook/stories/interactions/5_clicks_legend_items_bar.story.tsx index 7d1abf14ede..d33875519ee 100644 --- a/storybook/stories/interactions/5_clicks_legend_items_bar.story.tsx +++ b/storybook/stories/interactions/5_clicks_legend_items_bar.story.tsx @@ -13,7 +13,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import { BARCHART_2Y2G } from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; const onLegendItemListeners = { onLegendItemOver: action('onLegendItemOver'), diff --git a/storybook/stories/interactions/6_clicks_legend_items_area.story.tsx b/storybook/stories/interactions/6_clicks_legend_items_area.story.tsx index b5709af2f21..2d16e9b0b28 100644 --- a/storybook/stories/interactions/6_clicks_legend_items_area.story.tsx +++ b/storybook/stories/interactions/6_clicks_legend_items_area.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( diff --git a/storybook/stories/interactions/7_clicks_legend_items_line.story.tsx b/storybook/stories/interactions/7_clicks_legend_items_line.story.tsx index 645262c6297..e8d83a78fe6 100644 --- a/storybook/stories/interactions/7_clicks_legend_items_line.story.tsx +++ b/storybook/stories/interactions/7_clicks_legend_items_line.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, CurveType, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( diff --git a/storybook/stories/interactions/8_clicks_legend_items_mixed.story.tsx b/storybook/stories/interactions/8_clicks_legend_items_mixed.story.tsx index 5c2132b20bf..533f469b3cd 100644 --- a/storybook/stories/interactions/8_clicks_legend_items_mixed.story.tsx +++ b/storybook/stories/interactions/8_clicks_legend_items_mixed.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( diff --git a/storybook/stories/interactions/9_brush_selection_linear.story.tsx b/storybook/stories/interactions/9_brush_selection_linear.story.tsx index c69cad30436..098cec6acf6 100644 --- a/storybook/stories/interactions/9_brush_selection_linear.story.tsx +++ b/storybook/stories/interactions/9_brush_selection_linear.story.tsx @@ -11,12 +11,11 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/interactions/9a_brush_selection_linear.story.tsx b/storybook/stories/interactions/9a_brush_selection_linear.story.tsx index 21f0feb92be..b3afa1645e6 100644 --- a/storybook/stories/interactions/9a_brush_selection_linear.story.tsx +++ b/storybook/stories/interactions/9a_brush_selection_linear.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, BrushAxis } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; import { getChartRotationKnob } from '../utils/knobs'; export const Example = () => { diff --git a/storybook/stories/legend/10_sunburst.story.tsx b/storybook/stories/legend/10_sunburst.story.tsx index 8272bc3b0cd..ccefaebd8c3 100644 --- a/storybook/stories/legend/10_sunburst.story.tsx +++ b/storybook/stories/legend/10_sunburst.story.tsx @@ -14,7 +14,6 @@ import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/c import { ShapeTreeNode } from '@elastic/charts/src/chart_types/partition_chart/layout/types/viewmodel_types'; import { mocks } from '@elastic/charts/src/mocks/hierarchical'; -import { useBaseTheme } from '../../use_base_theme'; import { discreteColor, colorBrewerCategoricalStark9, @@ -115,7 +114,7 @@ export const Example = () => { Example.parameters = { background: { default: 'white' }, markdown: `To flatten a hierarchical legend (like the rendered in a pie chart or a treemap when using a multi-layer configuration) you can -add the \`flatLegend\` prop into the \`\` component. +add the \`flatLegend\` prop into the \`\` component. To limit displayed hierarchy to a specific depth, you can use the \`legendMaxDepth\` prop. The first layer will have a depth of \`1\`.`, }; diff --git a/storybook/stories/legend/10_sunburst_repeated_label.story.tsx b/storybook/stories/legend/10_sunburst_repeated_label.story.tsx index 0e98a07ee1f..ab56f375365 100644 --- a/storybook/stories/legend/10_sunburst_repeated_label.story.tsx +++ b/storybook/stories/legend/10_sunburst_repeated_label.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Chart, LegendStrategy, Partition, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const flatLegend = boolean('flatLegend', false); diff --git a/storybook/stories/legend/11_legend_actions.story.tsx b/storybook/stories/legend/11_legend_actions.story.tsx index 7c7f4e9e030..524fa712f8b 100644 --- a/storybook/stories/legend/11_legend_actions.story.tsx +++ b/storybook/stories/legend/11_legend_actions.story.tsx @@ -37,7 +37,6 @@ import { } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; import { getPositionKnob, getEuiPopoverPositionKnob } from '../utils/knobs'; const getAction = (anchorPosition: PopoverAnchorPosition): LegendAction => ({ series, label }) => { diff --git a/storybook/stories/legend/12_legend_margins.story.tsx b/storybook/stories/legend/12_legend_margins.story.tsx index 93f08676ce9..bc0c74018d3 100644 --- a/storybook/stories/legend/12_legend_margins.story.tsx +++ b/storybook/stories/legend/12_legend_margins.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import { BARCHART_1Y1G } from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( diff --git a/storybook/stories/legend/13_inside_chart.story.tsx b/storybook/stories/legend/13_inside_chart.story.tsx index 7fb21a93612..c7cd703534b 100644 --- a/storybook/stories/legend/13_inside_chart.story.tsx +++ b/storybook/stories/legend/13_inside_chart.story.tsx @@ -24,7 +24,6 @@ import { import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); const data = dg.generateGroupedSeries(10, 20); diff --git a/storybook/stories/legend/14_single_series.story.tsx b/storybook/stories/legend/14_single_series.story.tsx index a4e872f3eec..0b4cf0f2c71 100644 --- a/storybook/stories/legend/14_single_series.story.tsx +++ b/storybook/stories/legend/14_single_series.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { BarSeries, Chart, ScaleType, Settings } from '@elastic/charts'; import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; import { getPositionKnob } from '../utils/knobs'; export const Example = () => { diff --git a/storybook/stories/legend/1_legend_right.story.tsx b/storybook/stories/legend/1_legend_right.story.tsx index ad25ce6ace5..35d6688fedd 100644 --- a/storybook/stories/legend/1_legend_right.story.tsx +++ b/storybook/stories/legend/1_legend_right.story.tsx @@ -11,15 +11,13 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const yAccessors = ['y1', 'y2']; const splitSeriesAccessors = ['g1', 'g2']; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/2_legend_bottom.story.tsx b/storybook/stories/legend/2_legend_bottom.story.tsx index 00fac5f2327..2f6318722e5 100644 --- a/storybook/stories/legend/2_legend_bottom.story.tsx +++ b/storybook/stories/legend/2_legend_bottom.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/3_legend_left.story.tsx b/storybook/stories/legend/3_legend_left.story.tsx index 0d33649cd2e..05759ffb9f1 100644 --- a/storybook/stories/legend/3_legend_left.story.tsx +++ b/storybook/stories/legend/3_legend_left.story.tsx @@ -11,11 +11,9 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/4_legend_top.story.tsx b/storybook/stories/legend/4_legend_top.story.tsx index b264b359e05..8894e4a7a74 100644 --- a/storybook/stories/legend/4_legend_top.story.tsx +++ b/storybook/stories/legend/4_legend_top.story.tsx @@ -11,11 +11,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/5_changing_specs.story.tsx b/storybook/stories/legend/5_changing_specs.story.tsx index 9858f5633ef..9695d82b97c 100644 --- a/storybook/stories/legend/5_changing_specs.story.tsx +++ b/storybook/stories/legend/5_changing_specs.story.tsx @@ -12,13 +12,11 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const splitSeries = boolean('split series', true) ? ['g1', 'g2'] : undefined; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/6_hide_legend.story.tsx b/storybook/stories/legend/6_hide_legend.story.tsx index fc8755cda94..2d182e16fe3 100644 --- a/storybook/stories/legend/6_hide_legend.story.tsx +++ b/storybook/stories/legend/6_hide_legend.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const hideBarSeriesInLegend = boolean('hide bar series in legend', false); @@ -19,7 +18,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/7_display_values.story.tsx b/storybook/stories/legend/7_display_values.story.tsx index 4b4f9e93a4c..5011b66bb32 100644 --- a/storybook/stories/legend/7_display_values.story.tsx +++ b/storybook/stories/legend/7_display_values.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, CurveType, Position, ScaleType, Settings } from '@elastic/charts'; import { TSVB_DATASET } from '@elastic/charts/src/utils/data_samples/test_dataset_tsvb'; -import { useBaseTheme } from '../../use_base_theme'; import { arrayKnobs } from '../utils/knobs'; export const Example = () => { diff --git a/storybook/stories/legend/8_spacing_buffer.story.tsx b/storybook/stories/legend/8_spacing_buffer.story.tsx index 6e0069e22c5..76ef08a96bc 100644 --- a/storybook/stories/legend/8_spacing_buffer.story.tsx +++ b/storybook/stories/legend/8_spacing_buffer.story.tsx @@ -11,8 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, PartialTheme } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const theme: PartialTheme = { legend: { @@ -26,7 +24,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/legend/9_color_picker.story.tsx b/storybook/stories/legend/9_color_picker.story.tsx index 3060c17dc0c..9c800dd2067 100644 --- a/storybook/stories/legend/9_color_picker.story.tsx +++ b/storybook/stories/legend/9_color_picker.story.tsx @@ -24,8 +24,6 @@ import { } from '@elastic/charts'; import { BARCHART_1Y1G } from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - const onChangeAction = action('onChange'); export const Example = () => { @@ -71,7 +69,7 @@ export const Example = () => { CustomColorPicker.displayName = 'CustomColorPicker'; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/line/10_test_path_ordering.story.tsx b/storybook/stories/line/10_test_path_ordering.story.tsx index 3e39ea5021f..b83cc72acec 100644 --- a/storybook/stories/line/10_test_path_ordering.story.tsx +++ b/storybook/stories/line/10_test_path_ordering.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Axis, LineSeries, Chart, Position, ScaleType, Settings, Direction } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; /** * Data to defined consistent order of series when using shuffle diff --git a/storybook/stories/line/11_discontinuous_data_points.story.tsx b/storybook/stories/line/11_discontinuous_data_points.story.tsx index 8d96adb58cb..832c2a79b0b 100644 --- a/storybook/stories/line/11_discontinuous_data_points.story.tsx +++ b/storybook/stories/line/11_discontinuous_data_points.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, CurveType, LineSeries, Position, ScaleType, Settings, Fit, AreaSeries } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const fitEnabled = boolean('enable fit function', false); @@ -19,7 +18,7 @@ export const Example = () => { const LineOrAreaSeries = isArea ? AreaSeries : LineSeries; return ( - + diff --git a/storybook/stories/line/12_orphan_data_points.story.tsx b/storybook/stories/line/12_orphan_data_points.story.tsx index 7ba7930d9e6..4fbe42ab4bf 100644 --- a/storybook/stories/line/12_orphan_data_points.story.tsx +++ b/storybook/stories/line/12_orphan_data_points.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, CurveType, LineSeries, Position, ScaleType, Settings, Fit, AreaSeries } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const fitEnabled = boolean('enable fit function', false); diff --git a/storybook/stories/line/13_line_mark_accessor.story.tsx b/storybook/stories/line/13_line_mark_accessor.story.tsx index 85f64ab03dd..6140b9392b7 100644 --- a/storybook/stories/line/13_line_mark_accessor.story.tsx +++ b/storybook/stories/line/13_line_mark_accessor.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Axis, Chart, Position, ScaleType, Settings, LineSeries } from '@elastic/charts'; import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; const rng = getRandomNumberGenerator(); const bubbleData = new Array(30).fill(0).map((_, i) => ({ diff --git a/storybook/stories/line/14_point_shapes.story.tsx b/storybook/stories/line/14_point_shapes.story.tsx index ea8c30a0ac1..8ca6d23fa9e 100644 --- a/storybook/stories/line/14_point_shapes.story.tsx +++ b/storybook/stories/line/14_point_shapes.story.tsx @@ -23,7 +23,6 @@ import { } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; import { renderEuiColorPicker } from '../legend/11_legend_actions.story'; const dateFormatter = timeFormatter(niceTimeFormatByDay(1)); diff --git a/storybook/stories/line/15_test_negative_points.story.tsx b/storybook/stories/line/15_test_negative_points.story.tsx index eeb2d0958f4..af257ade496 100644 --- a/storybook/stories/line/15_test_negative_points.story.tsx +++ b/storybook/stories/line/15_test_negative_points.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { LineSeries, Chart, ScaleType, Settings, Position, Axis } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const negative = boolean('use negative values', true); @@ -35,7 +34,7 @@ export const Example = () => { }); return ( - + diff --git a/storybook/stories/line/1_basic.story.tsx b/storybook/stories/line/1_basic.story.tsx index 45c19c35a24..c949f1704ec 100644 --- a/storybook/stories/line/1_basic.story.tsx +++ b/storybook/stories/line/1_basic.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Chart, LineSeries, ScaleType, Settings } from '@elastic/charts'; import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const toggleSpec = boolean('toggle line spec', true); @@ -23,7 +22,7 @@ export const Example = () => { return ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/mixed/2_lines_and_areas.story.tsx b/storybook/stories/mixed/2_lines_and_areas.story.tsx index 1c165880854..fdb608af05c 100644 --- a/storybook/stories/mixed/2_lines_and_areas.story.tsx +++ b/storybook/stories/mixed/2_lines_and_areas.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { AreaSeries, Axis, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/mixed/3_areas_and_bars.story.tsx b/storybook/stories/mixed/3_areas_and_bars.story.tsx index 06240997d8c..ebbc132f132 100644 --- a/storybook/stories/mixed/3_areas_and_bars.story.tsx +++ b/storybook/stories/mixed/3_areas_and_bars.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { AreaSeries, Axis, BarSeries, Chart, CurveType, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/mixed/4_test_bar.story.tsx b/storybook/stories/mixed/4_test_bar.story.tsx index 628ff075bae..56e5d0c6973 100644 --- a/storybook/stories/mixed/4_test_bar.story.tsx +++ b/storybook/stories/mixed/4_test_bar.story.tsx @@ -10,7 +10,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const data1 = [ @@ -38,7 +37,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/mixed/5_test_bar_time.story.tsx b/storybook/stories/mixed/5_test_bar_time.story.tsx index 3a56fcc56d3..ecf22aa8664 100644 --- a/storybook/stories/mixed/5_test_bar_time.story.tsx +++ b/storybook/stories/mixed/5_test_bar_time.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; import { timeFormatter } from '@elastic/charts/src/utils/data/formatters'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const start = DateTime.fromISO('2019-01-01T00:00:00.000', { zone: 'utc' }); @@ -42,7 +41,7 @@ export const Example = () => { return ( - + { const dataTypes = { diff --git a/storybook/stories/mixed/6_fitting_stacked.story.tsx b/storybook/stories/mixed/6_fitting_stacked.story.tsx index 61c1476eecc..5212855485f 100644 --- a/storybook/stories/mixed/6_fitting_stacked.story.tsx +++ b/storybook/stories/mixed/6_fitting_stacked.story.tsx @@ -13,7 +13,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, CurveType, Position, ScaleType, Settings, Fit, StackMode } from '@elastic/charts'; import { getRandomNumberGenerator, getRNGSeed } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const randomizeBoundingData = getRNGSeed() ? false : boolean('randomize bounding data', false); diff --git a/storybook/stories/mixed/7_marks.story.tsx b/storybook/stories/mixed/7_marks.story.tsx index fc954df4921..ec728e31f59 100644 --- a/storybook/stories/mixed/7_marks.story.tsx +++ b/storybook/stories/mixed/7_marks.story.tsx @@ -14,7 +14,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils'; -import { useBaseTheme } from '../../use_base_theme'; const getRandomNumber = getRandomNumberGenerator(); const data1 = new Array(100).fill(0).map((_, x) => ({ diff --git a/storybook/stories/mosaic/10_mosaic_simple.story.tsx b/storybook/stories/mosaic/10_mosaic_simple.story.tsx index 452a7443144..1060b9f7078 100644 --- a/storybook/stories/mosaic/10_mosaic_simple.story.tsx +++ b/storybook/stories/mosaic/10_mosaic_simple.story.tsx @@ -23,7 +23,6 @@ import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/c import { mocks } from '@elastic/charts/src/mocks/hierarchical'; import { keepDistinct } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../use_base_theme'; import { countryLookup, colorBrewerCategoricalPastel12B, regionLookup } from '../utils/utils'; const productLookup: Record = { diff --git a/storybook/stories/mosaic/20_mosaic_with_other.story.tsx b/storybook/stories/mosaic/20_mosaic_with_other.story.tsx index 1e26452a111..adbdf9a853e 100644 --- a/storybook/stories/mosaic/20_mosaic_with_other.story.tsx +++ b/storybook/stories/mosaic/20_mosaic_with_other.story.tsx @@ -21,7 +21,6 @@ import { } from '@elastic/charts'; import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/config'; -import { useBaseTheme } from '../../use_base_theme'; import { countryLookup } from '../utils/utils'; const categoricalColors = ['rgb(110,110,110)', 'rgb(123,123,123)', 'darkgrey', 'lightgrey']; @@ -42,7 +41,7 @@ const data = [ export const Example = () => { return ( - + ( diff --git a/storybook/stories/rotations/2_negative_ordinal.story.tsx b/storybook/stories/rotations/2_negative_ordinal.story.tsx index adb656cb365..c67649dbd63 100644 --- a/storybook/stories/rotations/2_negative_ordinal.story.tsx +++ b/storybook/stories/rotations/2_negative_ordinal.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/3_rotations_ordinal.story.tsx b/storybook/stories/rotations/3_rotations_ordinal.story.tsx index 07fd60fc1ce..99ea6d90052 100644 --- a/storybook/stories/rotations/3_rotations_ordinal.story.tsx +++ b/storybook/stories/rotations/3_rotations_ordinal.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/4_90_ordinal.story.tsx b/storybook/stories/rotations/4_90_ordinal.story.tsx index 4a50cf527ed..f430c88ce35 100644 --- a/storybook/stories/rotations/4_90_ordinal.story.tsx +++ b/storybook/stories/rotations/4_90_ordinal.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/5_180_ordinal.story.tsx b/storybook/stories/rotations/5_180_ordinal.story.tsx index bd233337ef2..d127f622f79 100644 --- a/storybook/stories/rotations/5_180_ordinal.story.tsx +++ b/storybook/stories/rotations/5_180_ordinal.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/6_negative_linear.story.tsx b/storybook/stories/rotations/6_negative_linear.story.tsx index cffae527acd..560cf6af379 100644 --- a/storybook/stories/rotations/6_negative_linear.story.tsx +++ b/storybook/stories/rotations/6_negative_linear.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/7_rotations_linear.story.tsx b/storybook/stories/rotations/7_rotations_linear.story.tsx index 6dab2610f39..addb52e3c6b 100644 --- a/storybook/stories/rotations/7_rotations_linear.story.tsx +++ b/storybook/stories/rotations/7_rotations_linear.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/8_90_deg_linear.story.tsx b/storybook/stories/rotations/8_90_deg_linear.story.tsx index f06fdb831d0..925301ec49a 100644 --- a/storybook/stories/rotations/8_90_deg_linear.story.tsx +++ b/storybook/stories/rotations/8_90_deg_linear.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/rotations/9_180_deg_linear.story.tsx b/storybook/stories/rotations/9_180_deg_linear.story.tsx index 04ae1b2aff5..f56a11639a1 100644 --- a/storybook/stories/rotations/9_180_deg_linear.story.tsx +++ b/storybook/stories/rotations/9_180_deg_linear.story.tsx @@ -10,11 +10,10 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => ( - + diff --git a/storybook/stories/scales/1_different_timezones.story.tsx b/storybook/stories/scales/1_different_timezones.story.tsx index 385ff044139..929af11ecfe 100644 --- a/storybook/stories/scales/1_different_timezones.story.tsx +++ b/storybook/stories/scales/1_different_timezones.story.tsx @@ -12,8 +12,6 @@ import React from 'react'; import { Axis, Chart, LineSeries, Position, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - const today = Date.now(); const UTC_DATE = DateTime.fromISO('2019-01-01T00:00:00.000Z').toMillis(); const UTC_PLUS8_DATE = DateTime.fromISO('2019-01-01T00:00:00.000+08:00', { @@ -74,7 +72,7 @@ export const Example = () => { } return ( - + [UTC_DATE + DAY_INCREMENT_1 * i, i % 5]); export const Example = () => ( - + [UTC_DATE + DAY_INCREMEN export const Example = () => ( - + ( - + DateTime.fromMillis(d, { zone: 'utc-6' }).toISO()} /> { const includeString = boolean('include string is x data', true); return ( - + { return ( - + { return ( - + diff --git a/storybook/stories/small_multiples/4_vertical_bars.story.tsx b/storybook/stories/small_multiples/4_vertical_bars.story.tsx index 2bab0667fb2..5a5a9d3460f 100644 --- a/storybook/stories/small_multiples/4_vertical_bars.story.tsx +++ b/storybook/stories/small_multiples/4_vertical_bars.story.tsx @@ -28,7 +28,6 @@ import { import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; import { ColorVariant } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); const numOfDays = 7; @@ -75,7 +74,7 @@ export const Example = () => { return ( - + diff --git a/storybook/stories/small_multiples/5_histogram_bars.story.tsx b/storybook/stories/small_multiples/5_histogram_bars.story.tsx index 7d8b4cd141e..7434d9d9138 100644 --- a/storybook/stories/small_multiples/5_histogram_bars.story.tsx +++ b/storybook/stories/small_multiples/5_histogram_bars.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { ScaleType, Position, Chart, Axis, GroupBy, SmallMultiples, Settings, BarSeries } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; const data = [ { x: 30, split: 'Cloudy', y: 9 }, @@ -58,7 +57,7 @@ export const Example = () => { return ( - + { return ( - + diff --git a/storybook/stories/small_multiples/7_sunbursts.story.tsx b/storybook/stories/small_multiples/7_sunbursts.story.tsx index b3f6257ede5..bc8d48aaf66 100644 --- a/storybook/stories/small_multiples/7_sunbursts.story.tsx +++ b/storybook/stories/small_multiples/7_sunbursts.story.tsx @@ -25,7 +25,6 @@ import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/c import { mocks } from '@elastic/charts/src/mocks/hierarchical'; import { keepDistinct } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../use_base_theme'; import { colorBrewerCategoricalPastel12, countryLookup, productLookup, regionLookup } from '../utils/utils'; const data = mocks.sunburst; // .filter((d) => countryLookup[d.dest].continentCountry.slice(0, 2) === 'eu'); diff --git a/storybook/stories/streamgraph/1_basic.story.tsx b/storybook/stories/streamgraph/1_basic.story.tsx index f1b880c187e..928272387be 100644 --- a/storybook/stories/streamgraph/1_basic.story.tsx +++ b/storybook/stories/streamgraph/1_basic.story.tsx @@ -12,7 +12,6 @@ import React from 'react'; import { AreaSeries, Chart, ScaleType, StackMode, Axis, Position, CurveType, Settings } from '@elastic/charts'; import { BABYNAME_DATA } from '@elastic/charts/src/utils/data_samples/babynames'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const stackMode = select( @@ -25,7 +24,7 @@ export const Example = () => { ); return ( - + { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/stylings/11_custom_lines.story.tsx b/storybook/stories/stylings/11_custom_lines.story.tsx index 2f8744f7c97..921fe82fe66 100644 --- a/storybook/stories/stylings/11_custom_lines.story.tsx +++ b/storybook/stories/stylings/11_custom_lines.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { Axis, Chart, LineSeries, Position, ScaleType, Settings, LineSeriesStyle } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; function range(title: string, min: number, max: number, value: number, groupId?: string, step = 1) { return number( diff --git a/storybook/stories/stylings/12_custom_area.story.tsx b/storybook/stories/stylings/12_custom_area.story.tsx index 37d60235b9b..525b70e395c 100644 --- a/storybook/stories/stylings/12_custom_area.story.tsx +++ b/storybook/stories/stylings/12_custom_area.story.tsx @@ -11,7 +11,6 @@ import React from 'react'; import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, LineSeriesStyle, PartialTheme } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; function range(title: string, min: number, max: number, value: number, groupId?: string, step = 1) { return number( diff --git a/storybook/stories/stylings/13_custom_series_name.story.tsx b/storybook/stories/stylings/13_custom_series_name.story.tsx index d93cfd07975..1398d8b21b0 100644 --- a/storybook/stories/stylings/13_custom_series_name.story.tsx +++ b/storybook/stories/stylings/13_custom_series_name.story.tsx @@ -11,8 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, SeriesNameFn } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const customSeriesNamingFn: SeriesNameFn = ({ yAccessor, splitAccessors }) => { if (yAccessor === 'y1' && splitAccessors.get('g') === 'a') { @@ -24,7 +22,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/stylings/13_custom_series_name_config.story.tsx b/storybook/stories/stylings/13_custom_series_name_config.story.tsx index a33a51f1e67..834a7eab617 100644 --- a/storybook/stories/stylings/13_custom_series_name_config.story.tsx +++ b/storybook/stories/stylings/13_custom_series_name_config.story.tsx @@ -11,8 +11,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, SeriesNameConfigOptions } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const customSeriesNameOptions: SeriesNameConfigOptions = { names: [ @@ -32,7 +30,7 @@ export const Example = () => { }; return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/stylings/14_custom_series_name_formatting.story.tsx b/storybook/stories/stylings/14_custom_series_name_formatting.story.tsx index dde2cd53281..0f6b9a97b2a 100644 --- a/storybook/stories/stylings/14_custom_series_name_formatting.story.tsx +++ b/storybook/stories/stylings/14_custom_series_name_formatting.story.tsx @@ -12,8 +12,6 @@ import React from 'react'; import { Axis, BarSeries, Chart, Position, ScaleType, Settings, SeriesNameFn } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const start = DateTime.fromISO('2019-01-01T00:00:00.000', { zone: 'utc' }); const data = [ @@ -54,7 +52,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/stylings/15_tick_label.story.tsx b/storybook/stories/stylings/15_tick_label.story.tsx index ba89c23bc89..ce097b87b0b 100644 --- a/storybook/stories/stylings/15_tick_label.story.tsx +++ b/storybook/stories/stylings/15_tick_label.story.tsx @@ -21,7 +21,6 @@ import { AxisStyle, } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; function range(title: string, min: number, max: number, value: number, groupId?: string, step = 1) { return number( @@ -58,7 +57,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> { const hasThreshold = boolean('threshold', true); diff --git a/storybook/stories/stylings/17_bar_series_color_variant.story.tsx b/storybook/stories/stylings/17_bar_series_color_variant.story.tsx index e6911de3ae9..23fec0ead4e 100644 --- a/storybook/stories/stylings/17_bar_series_color_variant.story.tsx +++ b/storybook/stories/stylings/17_bar_series_color_variant.story.tsx @@ -13,7 +13,6 @@ import { Axis, BarSeries, Chart, Position, ScaleType, Settings, PartialTheme } f import { ColorVariant } from '@elastic/charts/src/utils/common'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const fillOption = select( diff --git a/storybook/stories/stylings/18_line_series_color_variant.story.tsx b/storybook/stories/stylings/18_line_series_color_variant.story.tsx index 7a3335f98ec..24881865a68 100644 --- a/storybook/stories/stylings/18_line_series_color_variant.story.tsx +++ b/storybook/stories/stylings/18_line_series_color_variant.story.tsx @@ -12,7 +12,6 @@ import { Axis, LineSeries, Chart, Position, ScaleType, Settings, PartialTheme } import { ColorVariant } from '@elastic/charts/src/utils/common'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const customTheme: PartialTheme = { diff --git a/storybook/stories/stylings/19_area_series_color_variant.story.tsx b/storybook/stories/stylings/19_area_series_color_variant.story.tsx index 30947699bf5..ef18162053e 100644 --- a/storybook/stories/stylings/19_area_series_color_variant.story.tsx +++ b/storybook/stories/stylings/19_area_series_color_variant.story.tsx @@ -12,7 +12,6 @@ import { Axis, AreaSeries, Chart, Position, ScaleType, Settings, PartialTheme } import { ColorVariant } from '@elastic/charts/src/utils/common'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const customTheme: PartialTheme = { diff --git a/storybook/stories/stylings/1_chart_size.story.tsx b/storybook/stories/stylings/1_chart_size.story.tsx index f3a85789e2c..10880b56ab9 100644 --- a/storybook/stories/stylings/1_chart_size.story.tsx +++ b/storybook/stories/stylings/1_chart_size.story.tsx @@ -12,7 +12,6 @@ import { BarSeries, Chart, ScaleType, Settings, PartialTheme } from '@elastic/ch import { SeededDataGenerator } from '@elastic/charts/src/mocks/utils'; import { TooltipType } from '@elastic/charts/src/specs/constants'; -import { useBaseTheme } from '../../use_base_theme'; const dg = new SeededDataGenerator(); const data2 = dg.generateSimpleSeries(40); @@ -29,7 +28,7 @@ export const Example = () => { return (
- + { /> - + { /> - + { /> - + { /> - + { }; return ( - + { @@ -24,7 +23,7 @@ export const Example = () => { }; return ( - + ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/stylings/9_custom_series_colors_function.story.tsx b/storybook/stories/stylings/9_custom_series_colors_function.story.tsx index 17ce0177718..d078f1a3910 100644 --- a/storybook/stories/stylings/9_custom_series_colors_function.story.tsx +++ b/storybook/stories/stylings/9_custom_series_colors_function.story.tsx @@ -21,7 +21,6 @@ import { } from '@elastic/charts'; import * as TestDatasets from '@elastic/charts/src/utils/data_samples/test_dataset'; -import { useBaseTheme } from '../../use_base_theme'; export const Example = () => { const barColor = color('barSeriesColor', '#000'); @@ -47,7 +46,7 @@ export const Example = () => { return ( - + Number(d).toFixed(2)} /> diff --git a/storybook/stories/sunburst/10_2_slice.story.tsx b/storybook/stories/sunburst/10_2_slice.story.tsx index d238c5f0132..f50c7ac422f 100644 --- a/storybook/stories/sunburst/10_2_slice.story.tsx +++ b/storybook/stories/sunburst/10_2_slice.story.tsx @@ -12,12 +12,11 @@ import { Chart, Datum, Partition, PartitionLayout, Settings } from '@elastic/cha import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/config'; import { mocks } from '@elastic/charts/src/mocks/hierarchical'; -import { useBaseTheme } from '../../use_base_theme'; import { indexInterpolatedFillColor, interpolatorCET2s, productLookup } from '../utils/utils'; export const Example = () => ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + { const showDebug = boolean('show table for debugging', false); return ( - + ( - + ({ ...s, exportVal: 0 }))} diff --git a/storybook/stories/sunburst/21_high_pie.story.tsx b/storybook/stories/sunburst/21_high_pie.story.tsx index 2e314f45d16..b624d4d8ba1 100644 --- a/storybook/stories/sunburst/21_high_pie.story.tsx +++ b/storybook/stories/sunburst/21_high_pie.story.tsx @@ -12,12 +12,11 @@ import { Chart, Datum, Partition, PartitionLayout, Settings } from '@elastic/cha import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/config'; import { mocks } from '@elastic/charts/src/mocks/hierarchical'; -import { useBaseTheme } from '../../use_base_theme'; import { countryLookup, indexInterpolatedFillColor, interpolatorCET2s } from '../utils/utils'; export const Example = () => ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + { @@ -24,7 +23,7 @@ export const Example = () => { }; return ( - + ( - + ( - + ( - + { }; return ( - + { return ( - + ( - + ( - + ( - + ( - + ( - + ( - + { const showDebug = boolean('show table for debugging', false); return ( - + ( - + = ({ msg }) => ( @@ -35,7 +33,7 @@ export const Example = () => { - : undefined} baseTheme={useBaseTheme()} /> + : undefined} /> ); }; diff --git a/storybook/stories/test_cases/2_chrome_path_bug_fix.story.tsx b/storybook/stories/test_cases/2_chrome_path_bug_fix.story.tsx index 40ff724fbc0..290a14879c1 100644 --- a/storybook/stories/test_cases/2_chrome_path_bug_fix.story.tsx +++ b/storybook/stories/test_cases/2_chrome_path_bug_fix.story.tsx @@ -11,8 +11,6 @@ import React from 'react'; import { AreaSeries, Chart, ScaleType, Settings } from '@elastic/charts'; -import { useBaseTheme } from '../../use_base_theme'; - export const Example = () => { const data = [ { g: 'css', x: 1614092400000, y: 13 }, @@ -69,7 +67,7 @@ export const Example = () => { return ( - + { const chartRotation = getChartRotationKnob(); return ( - + { const logMinLimit = number('logMinLimit', 0.001); return ( - + { return ( - + { const automatedSeries = boolean('Use the default generated series types of charts for screen readers', true); diff --git a/storybook/stories/treemap/10_three_layers.story.tsx b/storybook/stories/treemap/10_three_layers.story.tsx index 90a519a806f..67884f53039 100644 --- a/storybook/stories/treemap/10_three_layers.story.tsx +++ b/storybook/stories/treemap/10_three_layers.story.tsx @@ -17,7 +17,6 @@ import { mocks } from '@elastic/charts/src/mocks/hierarchical'; import { palettes } from '@elastic/charts/src/mocks/hierarchical/palettes'; import { keepDistinct } from '@elastic/charts/src/utils/common'; -import { useBaseTheme } from '../../use_base_theme'; import { countryLookup, productLookup, regionLookup } from '../utils/utils'; const interpolator = hueInterpolator(palettes.CET2s.map(([r, g, b]) => [r, g, b, 0.5])); @@ -32,7 +31,7 @@ const countryCount = countries.length; export const Example = () => ( - + d.sitc1, productDimension); @@ -26,7 +25,7 @@ const defaultFillColor = (colorMaker: any) => (d: any, i: number, a: any[]) => c export const Example = () => ( - + d.sitc1, productDimension); export const Example = () => ( - + d.region, regionDimension); const countryLookup = arrayToLookup((d: Datum) => d.country, countryDimension); @@ -25,7 +24,7 @@ const interpolatorTurbo = hueInterpolator(palettes.turbo.map(([r, g, b]) => [r, export const Example = () => ( - + d.sitc1, productDimension); const countryLookup = arrayToLookup((d: Datum) => d.country, countryDimension); @@ -25,7 +24,7 @@ const interpolatorTurbo = hueInterpolator(palettes.turbo.map(([r, g, b]) => [r, export const Example = () => ( - + d.country, countryDimension); @@ -37,7 +36,7 @@ export const Example = () => ( } } > - + d.country, countryDimension); @@ -29,7 +28,7 @@ const fillColor = ({ [MODEL_KEY]: model }: any) => { export const Example = () => ( - + d.region, regionDimension); const countryLookup = arrayToLookup((d: Datum) => d.country, countryDimension); @@ -31,7 +30,7 @@ export const Example = () => ( } } > - + d.region, regionDimension); const countryLookup = arrayToLookup((d: Datum) => d.country, countryDimension); @@ -26,7 +25,7 @@ const interpolatorTurbo = hueInterpolator(palettes.turbo.map(([r, g, b]) => [r, export const Example = () => ( - + d.sitc1, productDimension); @@ -26,7 +25,7 @@ const defaultFillColor = (colorMaker: any) => (d: any, i: number, a: any[]) => c export const Example = () => ( - + (i ? d : { ...d, exportVal: 0 }))} diff --git a/storybook/stories/waffle/1_simple.story.tsx b/storybook/stories/waffle/1_simple.story.tsx index c8e01a98a6a..68077cb68d3 100644 --- a/storybook/stories/waffle/1_simple.story.tsx +++ b/storybook/stories/waffle/1_simple.story.tsx @@ -13,14 +13,13 @@ import { Chart, Datum, Partition, PartitionLayout, Settings, ShapeTreeNode } fro import { config } from '@elastic/charts/src/chart_types/partition_chart/layout/config'; import { mocks } from '@elastic/charts/src/mocks/hierarchical'; -import { useBaseTheme } from '../../use_base_theme'; import { discreteColor, colorBrewerCategoricalStark9, productLookup } from '../utils/utils'; export const Example = () => { const showDebug = boolean('show table for debugging', false); return ( - + = (Story, context) => { - if (!Story) return
No Story
; +import { getContext, ThemeId } from './context_utils'; +export const StoryWrapper: DecoratorFunction = (Story, context) => { const themeId = context.globals?.theme ?? ThemeId.Light; const backgroundId = context.globals?.background; const markdown = context?.parameters?.markdown; + const contextValue = useMemo(() => getContext(themeId, backgroundId), [themeId, backgroundId]); - return ( - - - - - - - -

{context.kind}

-
-
- - - -

{context.name}

-
-
- - -
-
+ if (!Story) return
No Story
; - -
- -
-
+ return ( + + + + + + +

{context.kind}

+
+
- {markdown && ( - - {markdown} + + +

{context.name}

+
- )} -
-
-
+ + +
+
+ + +
+ +
+
+ + {markdown && ( + + {markdown} + + )} + + ); };