diff --git a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-grids-basic-visually-looks-correct-1-snap.png b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-grids-basic-visually-looks-correct-1-snap.png index 98f3b97596..21601db908 100644 Binary files a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-grids-basic-visually-looks-correct-1-snap.png and b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-grids-basic-visually-looks-correct-1-snap.png differ diff --git a/integration/tests/__image_snapshots__/heatmap-stories-test-ts-heatmap-stories-time-snap-with-dataset-3-1-snap.png b/integration/tests/__image_snapshots__/heatmap-stories-test-ts-heatmap-stories-time-snap-with-dataset-3-1-snap.png index 747e09e5de..8f309b8425 100644 Binary files a/integration/tests/__image_snapshots__/heatmap-stories-test-ts-heatmap-stories-time-snap-with-dataset-3-1-snap.png and b/integration/tests/__image_snapshots__/heatmap-stories-test-ts-heatmap-stories-time-snap-with-dataset-3-1-snap.png differ diff --git a/package.json b/package.json index b70b401439..beb3d84d29 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "@elastic/datemath": "^5.0.3", "@elastic/eui": "^41.3.0", "@mdx-js/loader": "^1.6.6", - "@microsoft/api-documenter": "^7.13.54", - "@microsoft/api-extractor": "^7.18.11", + "@microsoft/api-documenter": "^7.13.63", + "@microsoft/api-extractor": "^7.18.16", "@semantic-release/changelog": "^5.0.1", "@semantic-release/commit-analyzer": "^8.0.1", "@semantic-release/exec": "^5.0.0", diff --git a/packages/charts/api/charts.api.md b/packages/charts/api/charts.api.md index bb7f72cfc3..b06c57d671 100644 --- a/packages/charts/api/charts.api.md +++ b/packages/charts/api/charts.api.md @@ -5,23 +5,29 @@ ```ts import { $Values } from 'utility-types'; +import { ComponentProps } from 'react'; import { ComponentType } from 'react'; +import { FC } from 'react'; import { LegacyRef } from 'react'; +import { OptionalKeys } from 'utility-types'; import { default as React_2 } from 'react'; import { ReactChild } from 'react'; import { ReactNode } from 'react'; +import { RequiredKeys } from 'utility-types'; // @public (undocumented) export type A = number; +// Warning: (ae-forgotten-export) The symbol "DatumKey" needs to be exported by the entry point index.d.ts +// // @public -export type Accessor = AccessorObjectKey | AccessorArrayIndex; +export type Accessor = DatumKey | AccessorObjectKey | AccessorArrayIndex; // @public export type AccessorArrayIndex = number; // @public -export type AccessorFn = UnaryAccessorFn; +export type AccessorFn = UnaryAccessorFn; // @public export type AccessorObjectKey = string; @@ -80,7 +86,7 @@ export type AnnotationPortalSettings = TooltipPortalSettings<'chart'> & { }; // @public (undocumented) -export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; +export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; // @public (undocumented) export type AnnotationTooltipFormatter = (details?: string) => JSX.Element | null; @@ -116,14 +122,16 @@ export type AreaFitStyle = Visible & Opacity & { texture?: TexturedStyles; }; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "SFProps" needs to be exported by the entry point index.d.ts // +// @public +export const AreaSeries: (props: SFProps, "chartType" | "specType" | "seriesType", "groupId" | "xScaleType" | "yScaleType" | "hideInLegend" | "histogramModeAlignment", "sortIndex" | "fit" | "timeZone" | "name" | "color" | "curve" | "areaSeriesStyle" | "xNice" | "yNice" | "useDefaultGroupDomain" | "displayValueSettings" | "y0AccessorFormat" | "y1AccessorFormat" | "filterSeriesInTooltip" | "tickFormat" | "y0Accessors" | "splitSeriesAccessors" | "stackAccessors" | "markSizeAccessor" | "markFormat" | "stackMode" | "pointStyleAccessor", "data" | "id" | "xAccessor" | "yAccessors">) => null; + // @public (undocumented) -export const AreaSeries: React_2.FunctionComponent; +export type AreaSeriesProps = ComponentProps; // @public -export type AreaSeriesSpec = BasicSeriesSpec & HistogramConfig & Postfixes & { +export type AreaSeriesSpec = BasicSeriesSpec & HistogramConfig & Postfixes & { seriesType: typeof SeriesType.Area; curve?: CurveType; areaSeriesStyle?: RecursivePartial; @@ -170,15 +178,15 @@ export interface ArrayNode extends NodeDescriptor { [SORT_INDEX_KEY]: number; } -// Warning: (ae-forgotten-export) The symbol "SpecRequired" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionals" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export const Axis: React_2.FunctionComponent; +// @public +export const Axis: FC>; // @public (undocumented) export type AxisId = string; +// @public (undocumented) +export type AxisProps = ComponentProps; + // @public export interface AxisSpec extends Spec { // (undocumented) @@ -268,14 +276,14 @@ export interface BandFillColorAccessorInput { value: number; } -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// +// @public +export const BarSeries: (props: SFProps, "chartType" | "specType" | "seriesType", "groupId" | "xScaleType" | "yScaleType" | "hideInLegend" | "enableHistogramMode", "sortIndex" | "timeZone" | "name" | "color" | "barSeriesStyle" | "xNice" | "yNice" | "useDefaultGroupDomain" | "displayValueSettings" | "y0AccessorFormat" | "y1AccessorFormat" | "filterSeriesInTooltip" | "tickFormat" | "y0Accessors" | "splitSeriesAccessors" | "stackAccessors" | "markSizeAccessor" | "stackMode" | "styleAccessor" | "minBarHeight", "data" | "id" | "xAccessor" | "yAccessors">) => null; + // @public (undocumented) -export const BarSeries: React_2.FunctionComponent; +export type BarSeriesProps = ComponentProps; // @public -export type BarSeriesSpec = BasicSeriesSpec & Postfixes & { +export type BarSeriesSpec = BasicSeriesSpec & Postfixes & { seriesType: typeof SeriesType.Bar; enableHistogramMode?: boolean; barSeriesStyle?: RecursivePartial; @@ -301,11 +309,11 @@ export type BarStyleAccessor = (datum: DataSeriesDatum, seriesIdentifier: XYChar export type BarStyleOverride = RecursivePartial | Color | null; // @public (undocumented) -export interface BaseAnnotationSpec extends Spec, AnnotationPortalSettings { +export interface BaseAnnotationSpec, S extends RectAnnotationStyle | LineAnnotationStyle, D = never> extends Spec, AnnotationPortalSettings { annotationType: T; // (undocumented) chartType: typeof ChartType.XYAxis; - dataValues: D[]; + dataValues: AD[]; groupId: GroupId; hideTooltips?: boolean; // (undocumented) @@ -314,6 +322,9 @@ export interface BaseAnnotationSpec | any[]; + // @public (undocumented) export interface BasePointerEvent { // (undocumented) @@ -325,10 +336,10 @@ export interface BasePointerEvent { // @public (undocumented) export type BasicListener = () => undefined | void; +// Warning: (ae-forgotten-export) The symbol "MarkFormatter" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export type BasicSeriesSpec = SeriesSpec & SeriesAccessors & SeriesScales & { - markFormat?: TickFormatter; -}; +export type BasicSeriesSpec = SeriesSpec & SeriesAccessors & SeriesScales & MarkFormatter; // @public export const BinAgg: Readonly<{ @@ -355,14 +366,16 @@ export type BrushEndListener = (brushAreaEvent: BrushEvent) => void; // @public (undocumented) export type BrushEvent = XYBrushEvent | HeatmapBrushEvent; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts +// Warning: (ae-incompatible-release-tags) The symbol "BubbleSeries" is marked as @public, but its signature references "BubbleSeriesSpec" which is marked as @alpha // -// @alpha -export const BubbleSeries: React_2.FunctionComponent; +// @public +export const BubbleSeries: (props: SFProps, "chartType" | "specType" | "seriesType", "groupId" | "xScaleType" | "yScaleType" | "hideInLegend", "sortIndex" | "timeZone" | "name" | "color" | "bubbleSeriesStyle" | "xNice" | "yNice" | "useDefaultGroupDomain" | "displayValueSettings" | "y0AccessorFormat" | "y1AccessorFormat" | "filterSeriesInTooltip" | "tickFormat" | "y0Accessors" | "splitSeriesAccessors" | "stackAccessors" | "markSizeAccessor" | "markFormat" | "pointStyleAccessor", "data" | "id" | "xAccessor" | "yAccessors">) => null; + +// @public (undocumented) +export type BubbleSeriesProps = ComponentProps; // @alpha -export type BubbleSeriesSpec = BasicSeriesSpec & { +export type BubbleSeriesSpec = BasicSeriesSpec & { seriesType: typeof SeriesType.Bubble; bubbleSeriesStyle?: RecursivePartial; pointStyleAccessor?: PointStyleAccessor; @@ -503,7 +516,7 @@ export const ColorVariant: Readonly<{ export type ColorVariant = $Values; // @public -export type ComponentWithAnnotationDatum = ComponentType; +export type ComponentWithAnnotationDatum = ComponentType>; // @public export function computeRatioByGroups>(data: T[], groupAccessors: GroupKeysOrKeyFn, valueAccessor: (k: T) => number | null | undefined, ratioKeyName: string): (T & { @@ -751,9 +764,6 @@ export const DEFAULT_TOOLTIP_TYPE: "vertical"; // @public (undocumented) export function defaultPartitionValueFormatter(d: number): string; -// @public (undocumented) -export type DefaultSettingsProps = 'id' | 'chartType' | 'specType' | 'rendering' | 'rotation' | 'resizeDebounce' | 'pointerUpdateDebounce' | 'pointerUpdateTrigger' | 'animateData' | 'debug' | 'tooltip' | 'theme' | 'brushAxis' | 'minBrushDelta' | 'externalPointerEvents' | 'showLegend' | 'showLegendExtra' | 'legendPosition' | 'legendMaxDepth' | 'legendSize' | 'ariaUseDefaultSummary' | 'ariaLabelHeadingLevel' | 'ariaTableCaption' | 'allowBrushingLastHistogramBin'; - // @public (undocumented) export const DEPTH_KEY = "depth"; @@ -933,15 +943,17 @@ export interface GeometryValue { // @public (undocumented) export function getNodeName(node: ArrayNode): string; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// -// @alpha (undocumented) -export const Goal: React_2.FunctionComponent; +// @alpha +export const Goal: FC>; // @alpha (undocumented) export type GoalLabelAccessor = LabelAccessor; +// Warning: (ae-incompatible-release-tags) The symbol "GoalProps" is marked as @public, but its signature references "Goal" which is marked as @alpha +// +// @public (undocumented) +export type GoalProps = ComponentProps; + // @alpha (undocumented) export interface GoalSpec extends Spec { // (undocumented) @@ -1030,20 +1042,22 @@ export interface GroupBrushExtent { groupId: GroupId; } -// @alpha (undocumented) -export const GroupBy: React_2.FunctionComponent; +// Warning: (ae-incompatible-release-tags) The symbol "GroupBy" is marked as @public, but its signature references "GroupBySpec" which is marked as @alpha +// +// @public +export const GroupBy: (props: SFProps, "chartType" | "specType", never, "format", "id" | "sort" | "by">) => null; // @public (undocumented) -export type GroupByAccessor = (spec: Spec, datum: any) => string | number; +export type GroupByAccessor = (spec: Spec, datum: D) => string | number; // @public -export type GroupByFormatter = (value: ReturnType) => string; +export type GroupByFormatter = (value: ReturnType>) => string; // @public (undocumented) export type GroupByKeyFn = (data: T) => string; -// @alpha (undocumented) -export type GroupByProps = Pick; +// @public (undocumented) +export type GroupByProps = ComponentProps; // Warning: (ae-forgotten-export) The symbol "Predicate" needs to be exported by the entry point index.d.ts // @@ -1051,9 +1065,9 @@ export type GroupByProps = Pick; export type GroupBySort = Predicate; // @alpha (undocumented) -export interface GroupBySpec extends Spec { - by: GroupByAccessor; - format?: GroupByFormatter; +export interface GroupBySpec extends Spec { + by: GroupByAccessor; + format?: GroupByFormatter; sort: GroupBySort; } @@ -1063,11 +1077,8 @@ export type GroupId = string; // @public (undocumented) export type GroupKeysOrKeyFn = Array | GroupByKeyFn; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// -// @alpha (undocumented) -export const Heatmap: React_2.FunctionComponent; +// @alpha +export const Heatmap: (props: SFProps, "chartType" | "specType", "data" | "timeZone" | "valueAccessor" | "valueFormatter" | "xAccessor" | "yAccessor" | "xSortPredicate" | "ySortPredicate" | "xScale" | "xAxisLabelFormatter" | "xAxisTitle" | "yAxisTitle" | "xAxisLabelName" | "yAxisLabelName" | "yAxisLabelFormatter", "name" | "onBrushEnd" | "highlightedData", "id" | "colorScale">) => null; // @alpha (undocumented) export interface HeatmapBandsColorScale { @@ -1088,14 +1099,19 @@ export type HeatmapBrushEvent = { // @public (undocumented) export type HeatmapElementEvent = [Cell, SeriesIdentifier]; +// Warning: (ae-incompatible-release-tags) The symbol "HeatmapProps" is marked as @public, but its signature references "Heatmap" which is marked as @alpha +// +// @public (undocumented) +export type HeatmapProps = ComponentProps; + // @alpha (undocumented) -export interface HeatmapSpec extends Spec { +export interface HeatmapSpec extends Spec { // (undocumented) chartType: typeof ChartType.Heatmap; // (undocumented) colorScale: HeatmapBandsColorScale; // (undocumented) - data: Datum[]; + data: D[]; // (undocumented) highlightedData?: { x: Array; @@ -1112,13 +1128,13 @@ export interface HeatmapSpec extends Spec { // (undocumented) timeZone: string; // (undocumented) - valueAccessor: Accessor | AccessorFn; + valueAccessor: Accessor | AccessorFn; // (undocumented) - valueFormatter: (value: number) => string; + valueFormatter: ValueFormatter; // (undocumented) - xAccessor: Accessor | AccessorFn; + xAccessor: Accessor | AccessorFn; // (undocumented) - xAxisLabelFormatter: (value: string | number) => string; + xAxisLabelFormatter: LabelAccessor; // (undocumented) xAxisLabelName: string; // (undocumented) @@ -1128,9 +1144,9 @@ export interface HeatmapSpec extends Spec { // (undocumented) xSortPredicate: Predicate; // (undocumented) - yAccessor: Accessor | AccessorFn; + yAccessor: Accessor | AccessorFn; // (undocumented) - yAxisLabelFormatter: (value: string | number) => string; + yAxisLabelFormatter: LabelAccessor; // (undocumented) yAxisLabelName: string; // (undocumented) @@ -1222,14 +1238,14 @@ export const HIERARCHY_ROOT_KEY: Key; // @public (undocumented) export type HierarchyOfArrays = Array; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// +// @public +export const HistogramBarSeries: (props: SFProps, "chartType" | "specType" | "seriesType", "groupId" | "xScaleType" | "yScaleType" | "hideInLegend" | "enableHistogramMode", "sortIndex" | "timeZone" | "name" | "color" | "barSeriesStyle" | "xNice" | "yNice" | "useDefaultGroupDomain" | "displayValueSettings" | "y0AccessorFormat" | "y1AccessorFormat" | "filterSeriesInTooltip" | "tickFormat" | "y0Accessors" | "splitSeriesAccessors" | "markSizeAccessor" | "stackMode" | "styleAccessor" | "minBarHeight", "data" | "id" | "xAccessor" | "yAccessors">) => null; + // @public (undocumented) -export const HistogramBarSeries: React_2.FunctionComponent; +export type HistogramBarSeriesProps = ComponentProps; // @public -export type HistogramBarSeriesSpec = Omit & { +export type HistogramBarSeriesSpec = Omit, 'stackAccessors'> & { enableHistogramMode: true; }; @@ -1263,7 +1279,7 @@ export type HorizontalAlignment = $Values; // Warning: (ae-forgotten-export) The symbol "BinaryAccessorFn" needs to be exported by the entry point index.d.ts // // @public -export type IndexedAccessorFn = UnaryAccessorFn | BinaryAccessorFn; +export type IndexedAccessorFn = UnaryAccessorFn | BinaryAccessorFn; // @public (undocumented) export const INPUT_KEY = "inputIndex"; @@ -1405,15 +1421,12 @@ export interface LegendStyle { // @public (undocumented) export const LIGHT_THEME: Theme; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export const LineAnnotation: React_2.FunctionComponent; +// @public +export const LineAnnotation: (props: SFProps, "chartType" | "specType", "style" | "zIndex" | "groupId" | "hideLines" | "hideLinesTooltips" | "annotationType" | "hideTooltips", "offset" | "fallbackPlacements" | "placement" | "boundary" | "boundaryPadding" | "marker" | "customTooltip" | "markerBody" | "markerDimensions" | "markerPosition" | "customTooltipDetails", "id" | "dataValues" | "domainType">) => null; // @public -export interface LineAnnotationDatum { - dataValue: any; +export interface LineAnnotationDatum { + dataValue: D; details?: string; header?: string; } @@ -1421,14 +1434,17 @@ export interface LineAnnotationDatum { // @public (undocumented) export type LineAnnotationEvent = { id: SpecId; - datum: LineAnnotationDatum; + datum: LineAnnotationDatum; }; // @public (undocumented) -export type LineAnnotationSpec = BaseAnnotationSpec & { +export type LineAnnotationProps = ComponentProps; + +// @public (undocumented) +export type LineAnnotationSpec = BaseAnnotationSpec, LineAnnotationStyle, D> & { domainType: AnnotationDomainType; - marker?: ReactNode | ComponentWithAnnotationDatum; - markerBody?: ReactNode | ComponentWithAnnotationDatum; + marker?: ReactNode | ComponentWithAnnotationDatum; + markerBody?: ReactNode | ComponentWithAnnotationDatum; markerDimensions?: { width: number; height: number; @@ -1457,14 +1473,14 @@ export type LineFitStyle = Visible & Opacity & StrokeDashArray & { stroke: Color | typeof ColorVariant.Series; }; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// +// @public +export const LineSeries: (props: SFProps, "chartType" | "specType" | "seriesType", "groupId" | "xScaleType" | "yScaleType" | "hideInLegend" | "histogramModeAlignment", "sortIndex" | "fit" | "timeZone" | "name" | "color" | "curve" | "lineSeriesStyle" | "xNice" | "yNice" | "useDefaultGroupDomain" | "displayValueSettings" | "y0AccessorFormat" | "y1AccessorFormat" | "filterSeriesInTooltip" | "tickFormat" | "y0Accessors" | "splitSeriesAccessors" | "stackAccessors" | "markSizeAccessor" | "markFormat" | "pointStyleAccessor", "data" | "id" | "xAccessor" | "yAccessors">) => null; + // @public (undocumented) -export const LineSeries: React_2.FunctionComponent; +export type LineSeriesProps = ComponentProps; // @public -export type LineSeriesSpec = BasicSeriesSpec & HistogramConfig & { +export type LineSeriesSpec = BasicSeriesSpec & HistogramConfig & { seriesType: typeof SeriesType.Line; curve?: CurveType; lineSeriesStyle?: RecursivePartial; @@ -1584,11 +1600,10 @@ export function parentAccessor(n: ArrayEntry): ArrayNode; // @public (undocumented) export type PartialTheme = RecursivePartial; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "PartitionSpec" needs to be exported by the entry point index.d.ts // -// @public (undocumented) -export const Partition: React_2.FunctionComponent; +// @public +export const Partition: (props: SFProps, "chartType" | "specType", "animation" | "layout" | "valueAccessor" | "clockwiseSectors" | "specialFirstInnermostSector" | "drilldown" | "maxRowCount" | "fillOutside" | "radiusOutside" | "fillRectangleWidth" | "fillRectangleHeight" | "valueFormatter" | "valueGetter" | "percentFormatter" | "topGroove" | "smallMultiples" | "layers", never, "data" | "id">) => null; // Warning: (ae-forgotten-export) The symbol "StaticConfig" needs to be exported by the entry point index.d.ts // @@ -1615,13 +1630,13 @@ export interface PartitionFillLabel extends LabelConfig { } // @public -export interface PartitionLayer { +export interface PartitionLayer { // Warning: (ae-forgotten-export) The symbol "ExtendedFillLabelConfig" needs to be exported by the entry point index.d.ts // // (undocumented) fillLabel?: Partial; // (undocumented) - groupByRollup: IndexedAccessorFn; + groupByRollup: IndexedAccessorFn; // (undocumented) nodeLabel?: LabelAccessor; // (undocumented) @@ -1647,6 +1662,9 @@ export const PartitionLayout: Readonly<{ // @public (undocumented) export type PartitionLayout = $Values; +// @public (undocumented) +export type PartitionProps = ComponentProps; + // Warning: (ae-forgotten-export) The symbol "FillFontSizeRange" needs to be exported by the entry point index.d.ts // // @public (undocumented) @@ -1844,7 +1862,7 @@ export type Ratio = number; export type RawTextGetter = (node: ShapeTreeNode) => string; // @public (undocumented) -export const RectAnnotation: React_2.FunctionComponent & Partial>>; +export const RectAnnotation: FC>; // @public export interface RectAnnotationDatum { @@ -1863,6 +1881,9 @@ export type RectAnnotationEvent = { datum: RectAnnotationDatum; }; +// @public (undocumented) +export type RectAnnotationProps = ComponentProps; + // @public (undocumented) export type RectAnnotationSpec = BaseAnnotationSpec & { renderTooltip?: AnnotationTooltipFormatter; @@ -1969,13 +1990,13 @@ export interface SectorGeomSpecY { } // @public (undocumented) -export interface SeriesAccessors { - markSizeAccessor?: Accessor | AccessorFn; - splitSeriesAccessors?: (Accessor | AccessorFn)[]; - stackAccessors?: (Accessor | AccessorFn)[]; - xAccessor: Accessor | AccessorFn; - y0Accessors?: (Accessor | AccessorFn)[]; - yAccessors: (Accessor | AccessorFn)[]; +export interface SeriesAccessors { + markSizeAccessor?: Accessor | AccessorFn; + splitSeriesAccessors?: (Accessor | AccessorFn)[]; + stackAccessors?: (Accessor | AccessorFn)[]; + xAccessor: Accessor | AccessorFn; + y0Accessors?: (Accessor | AccessorFn)[]; + yAccessors: (Accessor | AccessorFn)[]; } // @public (undocumented) @@ -2029,11 +2050,11 @@ export interface SeriesScales { } // @public (undocumented) -export interface SeriesSpec extends Spec { +export interface SeriesSpec extends Spec { // (undocumented) chartType: typeof ChartType.XYAxis; color?: SeriesColorAccessor; - data: Datum[]; + data: D[]; // (undocumented) displayValueSettings?: DisplayValueSpec; filterSeriesInTooltip?: FilterPredicate; @@ -2053,7 +2074,7 @@ export interface SeriesSpec extends Spec { } // @public (undocumented) -export type SeriesSpecs = Array; +export type SeriesSpecs = BasicSeriesSpec> = Array; // @public (undocumented) export const SeriesType: Readonly<{ @@ -2066,8 +2087,16 @@ export const SeriesType: Readonly<{ // @public export type SeriesType = $Values; +// @public +export const Settings: (props: SFProps) => null; + +// Warning: (ae-forgotten-export) The symbol "BuildProps" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export const settingsBuildProps: BuildProps; + // @public (undocumented) -export const Settings: React_2.FunctionComponent; +export type SettingsProps = ComponentProps; // @public export interface SettingsSpec extends Spec, LegendSpec { @@ -2121,9 +2150,6 @@ export interface SettingsSpec extends Spec, LegendSpec { xDomain?: CustomXDomain; } -// @public (undocumented) -export type SettingsSpecProps = Partial>; - // @public (undocumented) export interface ShapeTreeNode extends TreeNode, SectorGeomSpecY { // (undocumented) @@ -2163,11 +2189,13 @@ export interface SimplePadding { outer: Pixels; } -// @alpha (undocumented) -export const SmallMultiples: React_2.FunctionComponent; +// @alpha +export const SmallMultiples: FC>; -// @alpha (undocumented) -export type SmallMultiplesProps = Partial>; +// Warning: (ae-incompatible-release-tags) The symbol "SmallMultiplesProps" is marked as @public, but its signature references "SmallMultiples" which is marked as @alpha +// +// @public (undocumented) +export type SmallMultiplesProps = ComponentProps; // @alpha (undocumented) export interface SmallMultiplesSpec extends Spec { @@ -2437,9 +2465,9 @@ export const TooltipType: Readonly<{ export type TooltipType = $Values; // @public -export interface TooltipValue { +export interface TooltipValue { color: Color; - datum?: unknown; + datum?: D; formattedMarkValue?: string | null; formattedValue: string; isHighlighted: boolean; @@ -2448,7 +2476,7 @@ export interface TooltipValue { markValue?: number | null; seriesIdentifier: SeriesIdentifier; value: any; - valueAccessor?: Accessor; + valueAccessor?: Accessor; } // @public @@ -2472,9 +2500,9 @@ export interface TreeNode extends AngleFromTo { } // @public -export interface UnaryAccessorFn { +export interface UnaryAccessorFn { // (undocumented) - (datum: Datum): Return; + (datum: D): Return; fieldName?: string; } @@ -2482,7 +2510,7 @@ export interface UnaryAccessorFn { export function useLegendAction(): [ref: LegacyRef, onClose: () => void]; // @public (undocumented) -export type ValueAccessor = (d: Datum) => AdditiveNumber; +export type ValueAccessor = (d: D) => AdditiveNumber; // @public (undocumented) export type ValueFormatter = (value: number) => string; @@ -2524,15 +2552,17 @@ export const WeightFn: Readonly<{ // @public (undocumented) export type WeightFn = $Values; -// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts -// -// @alpha (undocumented) -export const Wordcloud: React_2.FunctionComponent; +// @alpha +export const Wordcloud: FC>; // @public (undocumented) export type WordCloudElementEvent = [WordModel, SeriesIdentifier]; +// Warning: (ae-incompatible-release-tags) The symbol "WordcloudProps" is marked as @public, but its signature references "Wordcloud" which is marked as @alpha +// +// @public (undocumented) +export type WordcloudProps = ComponentProps; + // @alpha (undocumented) export interface WordcloudSpec extends Spec, WordcloudViewModel { // (undocumented) @@ -2598,7 +2628,7 @@ export interface XYBrushEvent { export type XYChartElementEvent = [GeometryValue, XYChartSeriesIdentifier]; // @public (undocumented) -export interface XYChartSeriesIdentifier extends SeriesIdentifier { +export interface XYChartSeriesIdentifier extends SeriesIdentifier { // (undocumented) seriesKeys: (string | number)[]; // (undocumented) @@ -2608,7 +2638,7 @@ export interface XYChartSeriesIdentifier extends SeriesIdentifier { // (undocumented) splitAccessors: Map; // (undocumented) - yAccessor: Accessor; + yAccessor: Accessor; } // @public 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 a84b195e6a..4180eb7dfb 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 @@ -60,8 +60,6 @@ export type ShapeViewModel = { }; const commonDefaults = { - specType: SpecType.Series, - subtype: GoalSubtype.Goal, base: 0, actual: 50, ticks: [0, 25, 50, 75, 100], @@ -88,6 +86,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 e6ba4c4c79..d45628ec03 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, ValueFormatter } from '../../../utils/common'; import { defaultGoalSpec } from '../layout/types/viewmodel_types'; import { GoalSubtype } from './constants'; @@ -35,11 +35,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; @@ -62,29 +57,19 @@ export interface GoalSpec extends Spec { tooltipValueFormatter: ValueFormatter; } -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' - | 'tooltipValueFormatter' - >(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/layout/viewmodel/viewmodel.ts b/packages/charts/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts index 90f8d6cc6f..2406a7e976 100644 --- a/packages/charts/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts +++ b/packages/charts/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts @@ -18,7 +18,7 @@ import { ScaleType } from '../../../../scales/constants'; import { LinearScale, OrdinalScale, RasterTimeScale } from '../../../../specs'; import { TextMeasure, withTextMeasure } from '../../../../utils/bbox/canvas_text_bbox_calculator'; import { addIntervalToTime } from '../../../../utils/chrono/elasticsearch'; -import { clamp } from '../../../../utils/common'; +import { clamp, Datum } from '../../../../utils/common'; import { Dimensions, horizontalPad, innerPad, pad } from '../../../../utils/dimensions'; import { Logger } from '../../../../utils/logger'; import { HeatmapStyle, Theme, Visible } from '../../../../utils/themes/theme'; @@ -34,6 +34,7 @@ import { ShapeViewModel, TextBox, } from '../types/viewmodel_types'; +import { BaseDatum } from './../../../xy_chart/utils/specs'; /** @public */ export interface HeatmapCellDatum { @@ -78,9 +79,9 @@ function estimatedNonOverlappingTickCount( }); } /** @internal */ -export function shapeViewModel( +export function shapeViewModel( textMeasure: TextMeasure, - spec: HeatmapSpec, + spec: HeatmapSpec, { heatmap: heatmapTheme, axes: { axisTitle }, background }: Theme, elementSizes: ChartElementSizes, heatmapTable: HeatmapTable, diff --git a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts index ea2cb333cc..624d199503 100644 --- a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts +++ b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts @@ -6,41 +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 { Spec } from '../../../specs'; +import { BaseDatum, 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 { ESCalendarInterval, ESFixedInterval } from '../../../utils/chrono/elasticsearch'; -import { Datum } from '../../../utils/common'; +import { Datum, LabelAccessor, stripUndefined, ValueFormatter } from '../../../utils/common'; import { Cell } from '../layout/types/viewmodel_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, - xScale: { type: X_SCALE_DEFAULT.type }, - valueAccessor: ({ value }: { value: string | number }) => value, - valueFormatter: (value: number) => `${value}`, - xSortPredicate: Predicate.AlphaAsc, - ySortPredicate: Predicate.AlphaAsc, - timeZone: 'UTC', - xAxisTitle: '', - yAxisTitle: '', - xAxisLabelName: 'X Value', - xAxisLabelFormatter: String, - yAxisLabelName: 'Y Value', - yAxisLabelFormatter: String, -}; - /** @public */ export type HeatmapScaleType = | typeof ScaleType.Linear @@ -91,15 +71,15 @@ export interface OrdinalScale { } /** @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; - valueAccessor: Accessor | AccessorFn; - valueFormatter: (value: number) => string; + xAccessor: Accessor | AccessorFn; + yAccessor: Accessor | AccessorFn; + valueAccessor: Accessor | AccessorFn; + valueFormatter: ValueFormatter; xSortPredicate: Predicate; ySortPredicate: Predicate; xScale: RasterTimeScale | OrdinalScale | LinearScale; @@ -109,33 +89,56 @@ export interface HeatmapSpec extends Spec { onBrushEnd?: (brushArea: HeatmapBrushEvent) => void; xAxisTitle: string; xAxisLabelName: string; - xAxisLabelFormatter: (value: string | number) => string; + xAxisLabelFormatter: LabelAccessor; yAxisTitle: string; yAxisLabelName: string; - yAxisLabelFormatter: (value: string | number) => string; + yAxisLabelFormatter: LabelAccessor; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; +/** + * 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( + // @ts-ignore - excessively deep types + buildSFProps>()( + { + chartType: ChartType.Heatmap, + specType: SpecType.Series, + }, + { + data: [], + valueAccessor: ({ value }) => value, + xScale: { type: X_SCALE_DEFAULT.type }, + valueFormatter: (value) => `${value}`, + xSortPredicate: Predicate.AlphaAsc, + ySortPredicate: Predicate.AlphaAsc, + // TODO: make accessors required + xAccessor: (d) => (d as any)?.x, + yAccessor: (d) => (d as any)?.y, + timeZone: 'UTC', + xAxisTitle: '', + yAxisTitle: '', + xAxisLabelName: 'X Value', + xAxisLabelFormatter: String, + yAxisLabelName: 'Y Value', + yAxisLabelFormatter: String, + }, + ), + ); + const { defaults, overrides } = buildProps.current; + useSpecFactory>({ ...defaults, ...stripUndefined(props), ...overrides }); + return null; +}; -/** @alpha */ -export const Heatmap: React.FunctionComponent = getConnect()( - specComponentFactory< - HeatmapSpec, - | 'xAccessor' - | 'yAccessor' - | 'valueAccessor' - | 'data' - | 'ySortPredicate' - | 'xSortPredicate' - | 'valueFormatter' - | 'xScale' - | 'timeZone' - | 'xAxisTitle' - | 'xAxisLabelName' - | 'xAxisLabelFormatter' - | 'yAxisTitle' - | 'yAxisLabelName' - | 'yAxisLabelFormatter' - >(defaultProps), -); +/** @public */ +export type HeatmapProps = ComponentProps; diff --git a/packages/charts/src/chart_types/heatmap/state/selectors/get_heatmap_table.ts b/packages/charts/src/chart_types/heatmap/state/selectors/get_heatmap_table.ts index 7a1a01b197..cde13c1168 100644 --- a/packages/charts/src/chart_types/heatmap/state/selectors/get_heatmap_table.ts +++ b/packages/charts/src/chart_types/heatmap/state/selectors/get_heatmap_table.ts @@ -31,7 +31,6 @@ export const getHeatmapTableSelector = createCustomCachedSelector( const resultData = data.reduce( (acc, curr, index) => { const x = getAccessorValue(curr, xAccessor); - const y = getAccessorValue(curr, yAccessor); const value = getAccessorValue(curr, valueAccessor); 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 89c4d5ea38..1332017e90 100644 --- a/packages/charts/src/chart_types/partition_chart/specs/index.ts +++ b/packages/charts/src/chart_types/partition_chart/specs/index.ts @@ -6,20 +6,27 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { Distance, Pixels, Radius } 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, ShowAccessor, ValueAccessor, ValueFormatter } from '../../../utils/common'; +import { + Datum, + LabelAccessor, + ShowAccessor, + ValueAccessor, + ValueFormatter, + stripUndefined, +} from '../../../utils/common'; import { FillFontSizeRange, FillLabelConfig } from '../../../utils/themes/partition'; import { percentFormatter } from '../layout/config'; import { AnimationConfig, PartitionLayout } 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 { NodeSorter, AGGREGATE_KEY } from '../layout/utils/group_by_rollup'; interface ExtendedFillLabelConfig extends FillLabelConfig, FillFontSizeRange { valueFormatter: ValueFormatter; @@ -29,8 +36,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; @@ -38,54 +45,21 @@ export interface Layer { shape?: { fillColor: string | NodeColorAccessor }; } -/** - * @todo: we really need these typed, but since `specComponentFactory` has the typing - * for optional and required props built-in, this is not currently possible. - */ -const defaultProps = { - chartType: ChartType.Partition, - specType: SpecType.Series, - 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: {}, - }, - ], - clockwiseSectors: true, - specialFirstInnermostSector: true, - layout: PartitionLayout.sunburst, - drilldown: false, - maxRowCount: 12, - fillOutside: false, - radiusOutside: 128, - fillRectangleWidth: Infinity, - fillRectangleHeight: Infinity, - animation: { duration: 0 }, -}; - /** * Specifies the partition chart * @public */ -export interface PartitionSpec extends Spec, AnimationConfig { +export interface PartitionSpec extends Spec, AnimationConfig { specType: typeof SpecType.Series; chartType: typeof ChartType.Partition; - data: Datum[]; - valueAccessor: ValueAccessor; + data: D[]; + valueAccessor: ValueAccessor; valueFormatter: ValueFormatter; valueGetter: ValueGetter; percentFormatter: ValueFormatter; topGroove: Pixels; smallMultiples: string | null; - layers: Layer[]; + layers: Layer[]; /** * Largest to smallest sectors are positioned in a clockwise order */ @@ -106,29 +80,56 @@ export interface PartitionSpec extends Spec, AnimationConfig { fillRectangleHeight: Distance; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; +const buildProps = buildSFProps()( + { + chartType: ChartType.Partition, + specType: SpecType.Series, + }, + { + valueAccessor: (d) => (typeof d === 'number' ? d : 0), + valueGetter: (n) => n[AGGREGATE_KEY], + valueFormatter: (d) => String(d), + percentFormatter, + topGroove: 20, + smallMultiples: '__global__small_multiples___', + layers: [ + { + groupByRollup: (_, i) => i, + nodeLabel: (d) => String(d), + showAccessor: () => true, + fillLabel: {}, + }, + ], + clockwiseSectors: true, + specialFirstInnermostSector: true, + layout: PartitionLayout.sunburst, + drilldown: false, + maxRowCount: 12, + fillOutside: false, + radiusOutside: 128, + fillRectangleWidth: Infinity, + fillRectangleHeight: Infinity, + animation: { duration: 0 }, + }, +); + +/** + * 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, ...stripUndefined(props), ...overrides }); + return null; +}; /** @public */ -export const Partition: React.FunctionComponent = getConnect()( - specComponentFactory< - PartitionSpec, - | 'valueAccessor' - | 'valueGetter' - | 'valueFormatter' - | 'percentFormatter' - | 'topGroove' - | 'smallMultiples' - | 'layers' - | 'clockwiseSectors' - | 'specialFirstInnermostSector' - | 'layout' - | 'drilldown' - | 'maxRowCount' - | 'fillOutside' - | 'radiusOutside' - | 'fillRectangleWidth' - | 'fillRectangleHeight' - | 'animation' - >(defaultProps), -); +export type PartitionProps = ComponentProps; diff --git a/packages/charts/src/chart_types/specs.ts b/packages/charts/src/chart_types/specs.ts index 1d0afcc8b7..ff029ddb4b 100644 --- a/packages/charts/src/chart_types/specs.ts +++ b/packages/charts/src/chart_types/specs.ts @@ -8,13 +8,21 @@ export { AreaSeries, + AreaSeriesProps, Axis, + AxisProps, BarSeries, + BarSeriesProps, BubbleSeries, + BubbleSeriesProps, HistogramBarSeries, + HistogramBarSeriesProps, LineAnnotation, + LineAnnotationProps, LineSeries, + LineSeriesProps, RectAnnotation, + RectAnnotationProps, } from './xy_chart/specs'; export * from './xy_chart/utils/specs'; diff --git a/packages/charts/src/chart_types/wordcloud/specs/index.ts b/packages/charts/src/chart_types/wordcloud/specs/index.ts index 42e286c526..95a7c839df 100644 --- a/packages/charts/src/chart_types/wordcloud/specs/index.ts +++ b/packages/charts/src/chart_types/wordcloud/specs/index.ts @@ -6,12 +6,12 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { specComponentFactory } from '../../../state/spec_factory'; import { WordModel, defaultWordcloudSpec, @@ -20,41 +20,27 @@ import { WordcloudViewModel, } from '../layout/types/viewmodel_types'; -const defaultProps = { - chartType: ChartType.Wordcloud, - specType: SpecType.Series, - ...defaultWordcloudSpec, -}; - export { WordModel, WeightFn, OutOfRoomCallback }; /** @alpha */ export interface WordcloudSpec extends Spec, WordcloudViewModel { - specType: typeof SpecType.Series; chartType: typeof ChartType.Wordcloud; + specType: typeof SpecType.Series; } -type SpecRequiredProps = Pick; -type SpecOptionalProps = Partial>; - -/** @alpha */ -export const Wordcloud: React.FunctionComponent = getConnect()( - specComponentFactory< - WordcloudSpec, - | 'chartType' - | 'startAngle' - | 'endAngle' - | 'angleCount' - | 'padding' - | 'fontWeight' - | 'fontFamily' - | 'fontStyle' - | 'minFontSize' - | 'maxFontSize' - | 'spiral' - | 'exponent' - | 'data' - | 'weightFn' - | 'outOfRoomCallback' - >(defaultProps), +/** + * Adds wordcloud spec to chart + * @alpha + */ +export const Wordcloud = specComponentFactory()( + { + chartType: ChartType.Wordcloud, + specType: SpecType.Series, + }, + { + ...defaultWordcloudSpec, + }, ); + +/** @public */ +export type WordcloudProps = ComponentProps; diff --git a/packages/charts/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx b/packages/charts/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx index 0ff1c96032..89f27cbc9f 100644 --- a/packages/charts/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx +++ b/packages/charts/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx @@ -43,6 +43,8 @@ describe('Annotation tooltips', () => { { x: 2, y: 3 }, { x: 4, y: 5 }, ]} + xAccessor="x" + yAccessors={['y']} xScaleType={ScaleType.Linear} /> { { x: 2, y: 3 }, { x: 4, y: 5 }, ]} + xAccessor="x" + yAccessors={['y']} xScaleType={ScaleType.Linear} /> ; +export type ComponentWithAnnotationDatum = ComponentType>; /** * The marker for an Annotation. Usually a JSX element 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 0000000000..a3a36c914c --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/area_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 { Datum, stripUndefined } from '../../../utils/common'; +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, + 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type AreaSeriesProps = 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 0e5231faf0..0000000000 --- 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.tsx b/packages/charts/src/chart_types/xy_chart/specs/axis.ts similarity index 62% rename from packages/charts/src/chart_types/xy_chart/specs/axis.tsx rename to packages/charts/src/chart_types/xy_chart/specs/axis.ts index 468c835cbd..a91448d627 100644 --- a/packages/charts/src/chart_types/xy_chart/specs/axis.tsx +++ b/packages/charts/src/chart_types/xy_chart/specs/axis.ts @@ -6,30 +6,32 @@ * Side Public License, v 1. */ -import React from 'react'; +import { ComponentProps } from 'react'; import { ChartType } from '../..'; import { SpecType } from '../../../specs/constants'; -import { getConnect, specComponentFactory } from '../../../state/spec_factory'; +import { specComponentFactory } from '../../../state/spec_factory'; import { Position } from '../../../utils/common'; import { AxisSpec, DEFAULT_GLOBAL_ID } from '../utils/specs'; -/** @public */ -export const Axis: React.FunctionComponent = getConnect()( - specComponentFactory< - AxisSpec, - 'groupId' | 'hide' | 'showOverlappingTicks' | 'showOverlappingLabels' | 'position' | 'timeAxisLayerCount' - >({ +/** + * 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, timeAxisLayerCount: 0, - }), + }, ); -type SpecRequired = Pick; -type SpecOptionals = Partial>; +/** @public */ +export type AxisProps = ComponentProps; 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 0000000000..866e810585 --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/bar_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 { useSpecFactory, SFProps, buildSFProps } from '../../../state/spec_factory'; +import { Datum, stripUndefined } from '../../../utils/common'; +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, + 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type BarSeriesProps = 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 7006236bc7..0000000000 --- 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 0000000000..d3ee9c5e94 --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/bubble_series.ts @@ -0,0 +1,51 @@ +/* + * 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 { Datum, stripUndefined } from '../../../utils/common'; +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, + 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type BubbleSeriesProps = 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 ee37e0d052..0000000000 --- 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 0000000000..031080a1be --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/histogram_bar_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 { Datum, stripUndefined } from '../../../utils/common'; +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, + 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type HistogramBarSeriesProps = 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 bd0d7e20b3..0000000000 --- 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/index.ts b/packages/charts/src/chart_types/xy_chart/specs/index.ts index a9dc880845..c7c0024398 100644 --- a/packages/charts/src/chart_types/xy_chart/specs/index.ts +++ b/packages/charts/src/chart_types/xy_chart/specs/index.ts @@ -6,11 +6,11 @@ * Side Public License, v 1. */ -export { AreaSeries } from './area_series'; -export { Axis } from './axis'; -export { BarSeries } from './bar_series'; -export { BubbleSeries } from './bubble_series'; -export { HistogramBarSeries } from './histogram_bar_series'; -export { LineAnnotation } from './line_annotation'; -export { LineSeries } from './line_series'; -export { RectAnnotation } from './rect_annotation'; +export * from './area_series'; +export * from './axis'; +export * from './bar_series'; +export * from './bubble_series'; +export * from './histogram_bar_series'; +export * from './line_annotation'; +export * from './line_series'; +export * from './rect_annotation'; 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 0000000000..4f878a0b2c --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/line_annotation.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 { SpecType } from '../../../specs/constants'; +import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; +import { stripUndefined } from '../../../utils/common'; +import { DEFAULT_ANNOTATION_LINE_STYLE } from '../../../utils/themes/merge_utils'; +import { LineAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type LineAnnotationProps = 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 e7f445de0b..0000000000 --- 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 0000000000..d9795767eb --- /dev/null +++ b/packages/charts/src/chart_types/xy_chart/specs/line_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 { SFProps, buildSFProps, useSpecFactory } from '../../../state/spec_factory'; +import { Datum, stripUndefined } from '../../../utils/common'; +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, + 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, ...stripUndefined(props), ...overrides }); + return null; +}; + +/** @public */ +export type LineSeriesProps = 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 3bde107fe9..0000000000 --- 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 0000000000..59f28af53d --- /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 1d2a260179..0000000000 --- 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/series.ts b/packages/charts/src/chart_types/xy_chart/utils/series.ts index 5fba386ce6..adf1a051e1 100644 --- a/packages/charts/src/chart_types/xy_chart/utils/series.ts +++ b/packages/charts/src/chart_types/xy_chart/utils/series.ts @@ -22,7 +22,7 @@ import { X_SCALE_DEFAULT } from '../scales/scale_defaults'; import { SmallMultiplesGroupBy } from '../state/selectors/get_specs'; import { applyFitFunctionToDataSeries } from './fit_function_utils'; import { groupBy } from './group_data_series'; -import { BasicSeriesSpec, SeriesNameConfigOptions, SeriesSpecs, SeriesType, StackMode } from './specs'; +import { BaseDatum, BasicSeriesSpec, SeriesNameConfigOptions, SeriesSpecs, SeriesType, StackMode } from './specs'; import { datumXSortPredicate, formatStackedDataSeriesValues } from './stacked_series_utils'; /** @internal */ @@ -59,8 +59,8 @@ export interface DataSeriesDatum { } /** @public */ -export interface XYChartSeriesIdentifier extends SeriesIdentifier { - yAccessor: Accessor; +export interface XYChartSeriesIdentifier extends SeriesIdentifier { + yAccessor: Accessor; splitAccessors: Map; // does the map have a size vs making it optional smVerticalAccessorValue?: string | number; smHorizontalAccessorValue?: string | number; @@ -68,7 +68,7 @@ export interface XYChartSeriesIdentifier extends SeriesIdentifier { } /** @internal */ -export type DataSeries = XYChartSeriesIdentifier & { +export type DataSeries = XYChartSeriesIdentifier & { groupId: GroupId; seriesType: SeriesType; data: DataSeriesDatum[]; @@ -95,7 +95,10 @@ export function getSeriesIndex(series: SeriesIdentifier[], target: SeriesIdentif * Returns string form of accessor. Uses index when accessor is a function. * @internal */ -export function getAccessorFieldName(accessor: Accessor | AccessorFn, index: number) { +export function getAccessorFieldName( + accessor: Accessor | AccessorFn, + index: number, +): Accessor | string { return typeof accessor === 'function' ? accessor.fieldName ?? `(index:${index})` : accessor; } @@ -252,13 +255,13 @@ export function getSeriesKey( * Get the array of values that forms a series key * @internal */ -function getSplitAccessors( - datum: Datum, - accessors: (Accessor | AccessorFn)[] = [], +function getSplitAccessors( + datum: D, + accessors: (Accessor | AccessorFn)[] = [], ): Map { const splitAccessors = new Map(); if (typeof datum === 'object' && datum !== null) { - accessors.forEach((accessor: Accessor | AccessorFn, index) => { + accessors.forEach((accessor, index) => { const value = getAccessorValue(datum, accessor); if (typeof value === 'string' || typeof value === 'number') { const accessorStr = getAccessorFieldName(accessor, index); @@ -273,13 +276,13 @@ function getSplitAccessors( * Extract y1 and y0 and mark properties from Datum. Casting them to numbers or null * @internal */ -export function extractYAndMarkFromDatum( - datum: Datum, - yAccessor: Accessor | AccessorFn, +export function extractYAndMarkFromDatum( + datum: D, + yAccessor: Accessor | AccessorFn, nonNumericValues: any[], bandedSpec: boolean, - y0Accessor?: Accessor | AccessorFn, - markSizeAccessor?: Accessor | AccessorFn, + y0Accessor?: Accessor | AccessorFn, + markSizeAccessor?: Accessor | AccessorFn, ): Pick { const mark = markSizeAccessor === undefined ? null : finiteOrNull(getAccessorValue(datum, markSizeAccessor), nonNumericValues); 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 046a6ed09e..9e971e6537 100644 --- a/packages/charts/src/chart_types/xy_chart/utils/specs.ts +++ b/packages/charts/src/chart_types/xy_chart/utils/specs.ts @@ -16,7 +16,7 @@ import { LogScaleOptions, ScaleContinuousType } from '../../../scales'; import { ScaleType } from '../../../scales/constants'; import { Spec } from '../../../specs'; import { SpecType } from '../../../specs/constants'; -import { Accessor, AccessorFormat, AccessorFn } from '../../../utils/accessor'; +import { AccessorFormat, AccessorFn, Accessor } from '../../../utils/accessor'; import { RecursivePartial, Position, Datum } from '../../../utils/common'; import { CurveType } from '../../../utils/curves'; import { OrdinalDomain } from '../../../utils/domain'; @@ -399,7 +399,7 @@ export interface DisplayValueSpec { } /** @public */ -export interface SeriesSpec extends Spec { +export interface SeriesSpec extends Spec { specType: typeof SpecType.Series; chartType: typeof ChartType.XYAxis; /** @@ -418,7 +418,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 */ @@ -482,23 +482,28 @@ 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: Accessor | AccessorFn; /** An array of field names one per y metric value */ - yAccessors: (Accessor | AccessorFn)[]; + yAccessors: (Accessor | AccessorFn)[]; /** An optional accessor of the y0 value: base point for area/bar charts */ - y0Accessors?: (Accessor | AccessorFn)[]; + y0Accessors?: (Accessor | AccessorFn)[]; /** An array of fields thats indicates the datum series membership */ - splitSeriesAccessors?: (Accessor | AccessorFn)[]; - /** An array of fields thats indicates the stack membership */ - stackAccessors?: (Accessor | AccessorFn)[]; + splitSeriesAccessors?: (Accessor | AccessorFn)[]; + /** + * An array of fields thats indicates the stack membership. + * Does not depend on datum at the moment. + * + * TODO pass datum to accessors when applicable + */ + stackAccessors?: (Accessor | AccessorFn)[]; /** * Field name of mark size metric on `Datum` * * Only used with line/area series */ - markSizeAccessor?: Accessor | AccessorFn; + markSizeAccessor?: Accessor | AccessorFn; } /** @public */ @@ -535,27 +540,39 @@ 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; + +/** + * Expected shape of unknown data row/datum + * @public + */ +export type BaseDatum = Record | any[]; /** * 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; @@ -587,7 +604,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; }; @@ -615,7 +632,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; @@ -636,7 +653,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; @@ -650,7 +667,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} */ @@ -796,11 +813,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 + * The value on the x or y axis according to the domainType configured */ - dataValue: any; + dataValue: D; /** * A textual description of the annotation */ @@ -812,16 +829,17 @@ export interface LineAnnotationDatum { } /** @public */ -export type LineAnnotationSpec = BaseAnnotationSpec< +export type LineAnnotationSpec = BaseAnnotationSpec< typeof AnnotationType.Line, - LineAnnotationDatum, - LineAnnotationStyle + LineAnnotationDatum, + LineAnnotationStyle, + D > & { domainType: AnnotationDomainType; /** Optional Custom marker icon centered on data value */ - marker?: ReactNode | ComponentWithAnnotationDatum; + marker?: ReactNode | ComponentWithAnnotationDatum; /** Optional marker body, always contained within chart area */ - markerBody?: ReactNode | ComponentWithAnnotationDatum; + markerBody?: ReactNode | ComponentWithAnnotationDatum; /** * Custom marker dimensions; will be computed internally * Any user-supplied values will be overwritten @@ -934,8 +952,9 @@ export type AnnotationPortalSettings = TooltipPortalSettings<'chart'> & { /** @public */ export interface BaseAnnotationSpec< T extends typeof AnnotationType.Rectangle | typeof AnnotationType.Line, - D extends RectAnnotationDatum | LineAnnotationDatum, - S extends RectAnnotationStyle | LineAnnotationStyle + AD extends RectAnnotationDatum | LineAnnotationDatum, + S extends RectAnnotationStyle | LineAnnotationStyle, + D = never > extends Spec, AnnotationPortalSettings { chartType: typeof ChartType.XYAxis; @@ -952,7 +971,7 @@ export interface BaseAnnotationSpec< /** * Data values defined with coordinates and details */ - dataValues: D[]; + dataValues: AD[]; /** * Custom annotation style */ @@ -969,10 +988,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; } @@ -982,21 +1001,21 @@ 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/components/__snapshots__/chart.test.tsx.snap b/packages/charts/src/components/__snapshots__/chart.test.tsx.snap index 85d2d80872..69c2ad65b4 100644 --- a/packages/charts/src/components/__snapshots__/chart.test.tsx.snap +++ b/packages/charts/src/components/__snapshots__/chart.test.tsx.snap @@ -55,12 +55,8 @@ exports[`Chart should render the legend name test 1`] = ` - - - - - - + +
diff --git a/packages/charts/src/components/accessibility/accessibility.test.tsx b/packages/charts/src/components/accessibility/accessibility.test.tsx index 6e3e1f9d42..0eedeb9042 100644 --- a/packages/charts/src/components/accessibility/accessibility.test.tsx +++ b/packages/charts/src/components/accessibility/accessibility.test.tsx @@ -26,7 +26,7 @@ describe('Accessibility', () => { const wrapper = mount( - + , ); expect(wrapper.find('dd').first().text()).toBe('bar chart'); @@ -35,8 +35,8 @@ describe('Accessibility', () => { const wrapper = mount( - - + + , ); expect(wrapper.find('dd').first().text()).toBe('Mixed chart: bar and line chart'); diff --git a/packages/charts/src/components/chart.test.tsx b/packages/charts/src/components/chart.test.tsx index c7f69b01c3..488a0a7bbd 100644 --- a/packages/charts/src/components/chart.test.tsx +++ b/packages/charts/src/components/chart.test.tsx @@ -12,6 +12,11 @@ import React from 'react'; import { Settings, BarSeries } from '../specs'; import { Chart } from './chart'; +interface Datum { + x: number; + y: number; +} + describe('Chart', () => { it("should render 'No data to display' without series", () => { const wrapper = mount(); @@ -31,17 +36,19 @@ describe('Chart', () => { const wrapper = mount( - + id="test" data={[]} xAccessor="x" yAccessors={['y']} /> , ); expect(wrapper.text()).toContain('No data to display'); }); it('should render the legend name test', () => { + // This is snapshot has a slight diff between local and ci runs, need to investigate + // See https://github.com/elastic/elastic-charts/runs/4706561347?check_suite_focus=true const wrapper = mount( - + , ); expect(wrapper.debug()).toMatchSnapshot(); diff --git a/packages/charts/src/components/error_boundary/error_boundary.tsx b/packages/charts/src/components/error_boundary/error_boundary.tsx index 47af7014c8..4284c53e9a 100644 --- a/packages/charts/src/components/error_boundary/error_boundary.tsx +++ b/packages/charts/src/components/error_boundary/error_boundary.tsx @@ -8,13 +8,13 @@ import React, { Component, ReactNode } from 'react'; -import { SettingsSpecProps } from '../../specs'; +import { SettingsSpec } from '../../specs/settings'; import { NoResults } from '../no_results'; import { isGracefulError } from './errors'; type ErrorBoundaryProps = { children: ReactNode; - renderFn?: SettingsSpecProps['noResults']; + renderFn?: SettingsSpec['noResults']; }; interface ErrorBoundaryState { diff --git a/packages/charts/src/components/legend/legend.test.tsx b/packages/charts/src/components/legend/legend.test.tsx index 4143dab187..656b5c588e 100644 --- a/packages/charts/src/components/legend/legend.test.tsx +++ b/packages/charts/src/components/legend/legend.test.tsx @@ -284,7 +284,14 @@ describe('Legend', () => { const wrapper = mount( - + , ); const legendItems = wrapper.find(LegendListItem); diff --git a/packages/charts/src/components/no_results.tsx b/packages/charts/src/components/no_results.tsx index a8987dc7ed..be217c0da1 100644 --- a/packages/charts/src/components/no_results.tsx +++ b/packages/charts/src/components/no_results.tsx @@ -8,10 +8,10 @@ import React, { FC, Suspense } from 'react'; -import { SettingsSpecProps } from '../specs'; +import { SettingsProps } from '../specs'; interface NoResultsProps { - renderFn?: SettingsSpecProps['noResults']; + renderFn?: SettingsProps['noResults']; } /** @internal */ diff --git a/packages/charts/src/index.ts b/packages/charts/src/index.ts index fe9cc86bdd..faa71afc1f 100644 --- a/packages/charts/src/index.ts +++ b/packages/charts/src/index.ts @@ -43,9 +43,9 @@ export { export { GeometryValue, BandedAccessorType } from './utils/geometry'; export { LegendPath, LegendPathElement } from './state/actions/legend'; export { CategoryKey } from './common/category'; +export { Layer as PartitionLayer, PartitionProps } from './chart_types/partition_chart/specs/index'; export { FillLabelConfig as PartitionFillLabel, PartitionStyle } from './utils/themes/partition'; export { PartitionLayout } from './chart_types/partition_chart/layout/types/config_types'; -export { Layer as PartitionLayer } from './chart_types/partition_chart/specs/index'; export * from './chart_types/goal_chart/specs/index'; export * from './chart_types/wordcloud/specs/index'; @@ -82,7 +82,7 @@ export { AnimKeyframe } from './chart_types/partition_chart/layout/types/config_ // heatmap export { Cell } from './chart_types/heatmap/layout/types/viewmodel_types'; -export { ColorBand, HeatmapBandsColorScale } from './chart_types/heatmap/specs/heatmap'; +export { ColorBand, HeatmapBandsColorScale, HeatmapProps } from './chart_types/heatmap/specs/heatmap'; // utilities export { diff --git a/packages/charts/src/specs/constants.ts b/packages/charts/src/specs/constants.ts index eb10f5e4fe..aad1d180e4 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'; @@ -161,27 +162,37 @@ export const DEFAULT_TOOLTIP_CONFIG = { }; /** @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, +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', + allowBrushingLastHistogramBin: true, + ...DEFAULT_LEGEND_CONFIG, }, - baseTheme: LIGHT_THEME, - brushAxis: BrushAxis.X, - minBrushDelta: 2, - ariaUseDefaultSummary: true, - ariaLabelHeadingLevel: 'p', - allowBrushingLastHistogramBin: true, - ...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 8a72f3dd32..71ddbbca02 100644 --- a/packages/charts/src/specs/group_by.ts +++ b/packages/charts/src/specs/group_by.ts @@ -6,16 +6,17 @@ * 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 { Datum, stripUndefined } from '../utils/common'; 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 +24,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 +41,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, ...stripUndefined(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 dd16e1af8c..d5161f3145 100644 --- a/packages/charts/src/specs/settings.tsx +++ b/packages/charts/src/specs/settings.tsx @@ -6,13 +6,13 @@ * 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'; import { PrimitiveValue } from '../chart_types/partition_chart/layout/utils/group_by_rollup'; import { LegendStrategy } from '../chart_types/partition_chart/layout/utils/highlighted_geoms'; -import { LineAnnotationDatum, RectAnnotationDatum } from '../chart_types/specs'; +import { BaseDatum, LineAnnotationDatum, RectAnnotationDatum } from '../chart_types/specs'; import { WordModel } from '../chart_types/wordcloud/layout/types/viewmodel_types'; import { XYChartSeriesIdentifier } from '../chart_types/xy_chart/utils/series'; import { Color } from '../common/colors'; @@ -21,15 +21,17 @@ 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 { + Datum, HorizontalAlignment, LayoutDirection, Position, Rendering, Rotation, VerticalAlignment, + stripUndefined, } from '../utils/common'; import { GeometryValue } from '../utils/geometry'; import { GroupId, SpecId } from '../utils/ids'; @@ -38,12 +40,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 +176,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[]; @@ -215,7 +217,7 @@ export type PointerEvent = PointerOverEvent | PointerOutEvent; * This interface describe the properties of single value shown in the tooltip * @public */ -export interface TooltipValue { +export interface TooltipValue { /** * The label of the tooltip value */ @@ -255,13 +257,13 @@ export interface TooltipValue { /** * The accessor linked to the current tooltip value */ - valueAccessor?: Accessor; + valueAccessor?: Accessor; /** * The datum associated with the current tooltip value * Maybe not available */ - datum?: unknown; + datum?: D; } /** @@ -678,40 +680,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' - | 'legendSize' - | 'ariaUseDefaultSummary' - | 'ariaLabelHeadingLevel' - | 'ariaTableCaption' - | 'allowBrushingLastHistogramBin'; - -/** @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, ...stripUndefined(props), ...overrides }); + return null; +}; /** @public */ -export const Settings: React.FunctionComponent = getConnect()( - specComponentFactory(DEFAULT_SETTINGS_SPEC), -); +export type SettingsProps = 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 91433c12c0..8a011f8484 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,19 @@ 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()( + { + chartType: ChartType.Global, + specType: SpecType.SmallMultiples, + }, + { + id: '__global__small_multiples___', + }, ); + +/** @public */ +export type SmallMultiplesProps = ComponentProps; diff --git a/packages/charts/src/state/spec_factory.ts b/packages/charts/src/state/spec_factory.ts index b65f89e241..c4021bff18 100644 --- a/packages/charts/src/state/spec_factory.ts +++ b/packages/charts/src/state/spec_factory.ts @@ -6,59 +6,162 @@ * 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 { stripUndefined } from '../utils/common'; +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 ); +} -/** @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 }); +/** + * 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, ...stripUndefined(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 + * @public + */ +export type SFProps< + S extends Spec, + Overrides extends SFOverrideKeys, + Defaults extends SFDefaultKeys, + Optionals extends SFOptionalKeys, + Requires extends SFRequiredKeys +> = Pick & Partial>; + +/** @public */ +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 ecb8b617f0..f57b179ce7 100644 --- a/packages/charts/src/utils/accessor.ts +++ b/packages/charts/src/utils/accessor.ts @@ -6,19 +6,19 @@ * Side Public License, v 1. */ -import { Datum } from './common'; +import { BaseDatum } from '../chart_types/specs'; /** * Accessor function * @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 +27,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 @@ -53,11 +55,22 @@ export type AccessorObjectKey = string; */ export type AccessorArrayIndex = number; +/** + * Need to check for array to exclude array prototype keys. + * + * TODO: tighten keyof types by removing string fallback. This will make it harder to satisfy the + * types for complex data values. + * + * Note: ignores symbols as keys + * @public + */ +export type DatumKey = D extends any[] ? number : Exclude | string; + /** * A datum accessor in form of object key accessor string/number * @public */ -export type Accessor = AccessorObjectKey | AccessorArrayIndex; +export type Accessor = DatumKey | AccessorObjectKey | AccessorArrayIndex; /** * Accessor format for _banded_ series as postfix string or accessor function @@ -70,8 +83,8 @@ export type AccessorFormat = string | ((value: string) => string); * @param accessor the spec accessor * @internal */ -export function getAccessorFn(accessor: Accessor): AccessorFn { - return (datum: Datum) => +export function getAccessorFn(accessor: Accessor): AccessorFn { + return (datum: D) => typeof datum === 'object' && datum !== null ? datum[accessor as keyof typeof datum] : undefined; } @@ -91,12 +104,17 @@ export function getAccessorFormatLabel(accessor: AccessorFormat, label: string): * Helper function to get accessor value from string, number or function * @internal */ -export function getAccessorValue(datum: Datum, accessor: Accessor | AccessorFn) { +export function getAccessorValue(datum: D, accessor: Accessor | AccessorFn) { if (typeof accessor === 'function') { return accessor(datum); } - return datum[accessor]; + try { + // @ts-ignore - could throw error if not proper key accessed + return datum[accessor]; + } catch { + return undefined; + } } /** diff --git a/packages/charts/src/utils/common.ts b/packages/charts/src/utils/common.ts index 00c4b9d1f7..3f64e3073e 100644 --- a/packages/charts/src/utils/common.ts +++ b/packages/charts/src/utils/common.ts @@ -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'; @@ -426,7 +427,7 @@ export function mergePartial( /** @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 */ @@ -626,3 +627,18 @@ export function getOppositeAlignment>(source: R): R { + return Object.keys(source).reduce((acc, key) => { + const val = source[key]; + if (val !== undefined) { + // @ts-ignore - building new R from {} + acc[key] = val; + } + return acc; + }, {} as R); +} diff --git a/storybook/stories/annotations/lines/8_advanced_markers.story.tsx b/storybook/stories/annotations/lines/8_advanced_markers.story.tsx index 6aa942962a..6bc6d192c1 100644 --- a/storybook/stories/annotations/lines/8_advanced_markers.story.tsx +++ b/storybook/stories/annotations/lines/8_advanced_markers.story.tsx @@ -134,6 +134,8 @@ export const Example = () => { ({ x: start.clone().add(i, 'd').valueOf(), y: maxMetric }))} diff --git a/storybook/stories/annotations/rects/6_zero_domain.story.tsx b/storybook/stories/annotations/rects/6_zero_domain.story.tsx index c7279d7464..e3ccb66e19 100644 --- a/storybook/stories/annotations/rects/6_zero_domain.story.tsx +++ b/storybook/stories/annotations/rects/6_zero_domain.story.tsx @@ -52,6 +52,8 @@ export const Example = () => { /> { yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y1', 'y2']} - splitSeriesAccessors={['g1', 'g2', 'g3']} + splitSeriesAccessors={['g1', 'g2']} data={TestDatasets.BARCHART_2Y2G} filterSeriesInTooltip={isVisibleFunction} /> diff --git a/storybook/stories/bar/49_test_dual_axis.story.tsx b/storybook/stories/bar/49_test_dual_axis.story.tsx index 53d0782ac9..dd35a4913a 100644 --- a/storybook/stories/bar/49_test_dual_axis.story.tsx +++ b/storybook/stories/bar/49_test_dual_axis.story.tsx @@ -56,6 +56,7 @@ export const Example = () => { groupId="2" xScaleType={ScaleType.Ordinal} xAccessor="x" + yAccessors={['y']} stackAccessors={stack13 ? ['y'] : undefined} data={[ { x: 'trousers', y: 39 }, @@ -69,6 +70,7 @@ export const Example = () => { id="bars4" xScaleType={ScaleType.Ordinal} xAccessor="x" + yAccessors={['y']} stackAccessors={stack24 ? ['y'] : undefined} data={[ { x: 'trousers', y: 39 }, diff --git a/storybook/stories/bar/58_data_values.story.tsx b/storybook/stories/bar/58_data_values.story.tsx index 3bb1c4231a..bd815f2100 100644 --- a/storybook/stories/bar/58_data_values.story.tsx +++ b/storybook/stories/bar/58_data_values.story.tsx @@ -53,6 +53,7 @@ export const Example = () => { { { { { xAccessor="x" yAccessors={['y']} stackAccessors={['x']} - splitSeriesAccessors={['g']} data={[ { x: 0, y: 3 }, { x: 1, y: 2 }, diff --git a/storybook/stories/grids/3_lines.story.tsx b/storybook/stories/grids/3_lines.story.tsx index 71f1e93609..9fbe06a9c4 100644 --- a/storybook/stories/grids/3_lines.story.tsx +++ b/storybook/stories/grids/3_lines.story.tsx @@ -83,7 +83,14 @@ export const Example = () => { /> - + ); }; diff --git a/storybook/stories/legend/14_single_series.story.tsx b/storybook/stories/legend/14_single_series.story.tsx index a4e872f3ee..cb2250244c 100644 --- a/storybook/stories/legend/14_single_series.story.tsx +++ b/storybook/stories/legend/14_single_series.story.tsx @@ -32,6 +32,8 @@ export const Example = () => { series.push( { /> { - const yAccessors = ['y1', 'y2']; - const splitSeriesAccessors = ['g1', 'g2']; - return ( { xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} xAccessor="x" - yAccessors={yAccessors} - splitSeriesAccessors={splitSeriesAccessors} + yAccessors={['y1', 'y2']} + splitSeriesAccessors={['g1', 'g2']} data={TestDatasets.BARCHART_2Y2G} hideInLegend={false} /> diff --git a/storybook/stories/legend/7_display_values.story.tsx b/storybook/stories/legend/7_display_values.story.tsx index 4b4f9e93a4..d3d423d30b 100644 --- a/storybook/stories/legend/7_display_values.story.tsx +++ b/storybook/stories/legend/7_display_values.story.tsx @@ -32,7 +32,7 @@ export const Example = () => { const namesArray = arrayKnobs('series names (in sort order)', ['jpg', 'php', 'png', 'css', 'gif']); - const seriesComponents = tsvbSeries.map((series: any) => { + const seriesComponents = tsvbSeries.map((series) => { const nameIndex = namesArray.findIndex((name) => name === series.label); const sortIndex = nameIndex > -1 ? nameIndex : undefined; diff --git a/storybook/stories/line/15_test_negative_points.story.tsx b/storybook/stories/line/15_test_negative_points.story.tsx index eeb2d0958f..72bf5f81b8 100644 --- a/storybook/stories/line/15_test_negative_points.story.tsx +++ b/storybook/stories/line/15_test_negative_points.story.tsx @@ -38,7 +38,15 @@ export const Example = () => { - + ); }; diff --git a/storybook/stories/mixed/6_fitting.story.tsx b/storybook/stories/mixed/6_fitting.story.tsx index 234e10c99e..1e16e4ef13 100644 --- a/storybook/stories/mixed/6_fitting.story.tsx +++ b/storybook/stories/mixed/6_fitting.story.tsx @@ -27,8 +27,13 @@ import { ColorVariant } from '../../../packages/charts/src/utils/common'; import { AreaFitStyle, LineFitStyle, TextureShape } from '../../../packages/charts/src/utils/themes/theme'; import { useBaseTheme } from '../../use_base_theme'; +interface MixedDatum { + x: number | string; + y: number | string | null; +} + export const Example = () => { - const dataTypes = { + const dataTypes: Record = { isolated: [ { x: 0, y: 3 }, { x: 1, y: 5 }, diff --git a/storybook/stories/scales/7_log_scale_options.story.tsx b/storybook/stories/scales/7_log_scale_options.story.tsx index 52d92e4ce4..3d7eb5a0e4 100644 --- a/storybook/stories/scales/7_log_scale_options.story.tsx +++ b/storybook/stories/scales/7_log_scale_options.story.tsx @@ -140,6 +140,8 @@ export const Example = () => { { yScaleType={yScaleType} data={data} yNice={yNice} + xAccessor="x" yAccessors={[yAccessor]} /> diff --git a/storybook/stories/small_multiples/5_histogram_bars.story.tsx b/storybook/stories/small_multiples/5_histogram_bars.story.tsx index 7d8b4cd141..4bad47a7c8 100644 --- a/storybook/stories/small_multiples/5_histogram_bars.story.tsx +++ b/storybook/stories/small_multiples/5_histogram_bars.story.tsx @@ -78,6 +78,8 @@ export const Example = () => { xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} data={data} + xAccessor="x" + yAccessors={['y']} splitSeriesAccessors={['split']} color={(seriesIdentifier) => { return colorMap[seriesIdentifier.splitAccessors.get('split') ?? 'Default']; diff --git a/storybook/stories/small_multiples/7_sunbursts.story.tsx b/storybook/stories/small_multiples/7_sunbursts.story.tsx index da0bddc831..8c35a7ea49 100644 --- a/storybook/stories/small_multiples/7_sunbursts.story.tsx +++ b/storybook/stories/small_multiples/7_sunbursts.story.tsx @@ -111,7 +111,6 @@ export const Example = () => { sort={select('Panel order', { alphaAsc: 'alphaAsc', alphaDesc: 'alphaDesc' }, 'alphaAsc')} /> { data={data} layout={PartitionLayout.sunburst} valueAccessor={(d: Datum) => d.exportVal as number} - valueFormatter={(d: number) => `$${defaultPartitionValueFormatter(Math.round(d / 1000000000))}\u00A0Bn`} - smallMultiples="sm" + valueFormatter={(d) => `$${defaultPartitionValueFormatter(Math.round(d / 1000000000))}\u00A0Bn`} layers={[ { groupByRollup: (d: Datum) => d.sitc1, diff --git a/storybook/stories/stylings/23_with_texture.story.tsx b/storybook/stories/stylings/23_with_texture.story.tsx index 6efc8991c0..5005ded5e5 100644 --- a/storybook/stories/stylings/23_with_texture.story.tsx +++ b/storybook/stories/stylings/23_with_texture.story.tsx @@ -112,6 +112,8 @@ export const Example = () => { color={seriesColor} xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} + xAccessor="x" + yAccessors={['y']} data={seriesType === 'bar' ? barData : areaData} curve={CurveType.CURVE_MONOTONE_X} /> diff --git a/storybook/stories/stylings/24_texture_multiple_series.story.tsx b/storybook/stories/stylings/24_texture_multiple_series.story.tsx index d5b828d7b0..9e6f6188f2 100644 --- a/storybook/stories/stylings/24_texture_multiple_series.story.tsx +++ b/storybook/stories/stylings/24_texture_multiple_series.story.tsx @@ -144,6 +144,8 @@ export const Example = () => { texture: getTexture(random), }, }} + xAccessor="x" + yAccessors={['y']} color={chartColor} stackAccessors={['yes']} data={data[i]} diff --git a/storybook/stories/stylings/25_mixed_point_shapes.story.tsx b/storybook/stories/stylings/25_mixed_point_shapes.story.tsx index 8a31699ffd..b4742c52f7 100644 --- a/storybook/stories/stylings/25_mixed_point_shapes.story.tsx +++ b/storybook/stories/stylings/25_mixed_point_shapes.story.tsx @@ -60,6 +60,8 @@ export const Example = () => { fill: fillKnobArea, }, }} + xAccessor="x" + yAccessors={['y']} xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} data={[ @@ -79,6 +81,8 @@ export const Example = () => { fill: fillKnobLine, }, }} + xAccessor="x" + yAccessors={['y']} xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} data={[ @@ -98,6 +102,8 @@ export const Example = () => { fill: fillKnobBubble, }, }} + xAccessor="x" + yAccessors={['y']} xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} data={[ 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 40ff724fbc..57ec0f894a 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 @@ -76,6 +76,8 @@ export const Example = () => { xScaleType="time" yScaleType={ScaleType.Linear} stackAccessors={['yes']} + xAccessor="x" + yAccessors={['y']} splitSeriesAccessors={['g']} data={data} /> diff --git a/storybook/stories/test_cases/4_filter_zero_values_log.story.tsx b/storybook/stories/test_cases/4_filter_zero_values_log.story.tsx index bcd728bc07..a522cf4177 100644 --- a/storybook/stories/test_cases/4_filter_zero_values_log.story.tsx +++ b/storybook/stories/test_cases/4_filter_zero_values_log.story.tsx @@ -33,6 +33,8 @@ export const Example = () => { {