From aa444a8b509213a4817c9ec001ae0bb2824d1b23 Mon Sep 17 00:00:00 2001 From: Tre' Seymour Date: Mon, 29 Mar 2021 12:37:38 -0600 Subject: [PATCH] refactor: rename enum types to singular Fixup AnnotationTypes. Signed-off-by: Tre' Seymour --- api/charts.api.md | 16 ++++++++-------- .../xy_chart/annotations/line/tooltip.test.tsx | 6 +++--- .../xy_chart/annotations/rect/tooltip.test.ts | 4 ++-- .../xy_chart/annotations/rect/tooltip.ts | 4 ++-- .../renderer/dom/annotations/tooltip_content.tsx | 6 +++--- .../xy_chart/specs/line_annotation.tsx | 4 ++-- .../xy_chart/specs/rect_annotation.tsx | 4 ++-- .../selectors/get_annotation_tooltip_state.ts | 6 +++--- src/chart_types/xy_chart/utils/specs.ts | 14 +++++++------- src/mocks/specs/specs.ts | 6 +++--- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/api/charts.api.md b/api/charts.api.md index 79517048fd..e7a1918bca 100644 --- a/api/charts.api.md +++ b/api/charts.api.md @@ -67,18 +67,18 @@ export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; // @public (undocumented) export type AnnotationTooltipFormatter = (details?: string) => JSX.Element | null; -// @public (undocumented) -export type AnnotationType = $Values; - -// Warning: (ae-missing-release-tag) "AnnotationTypes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "AnnotationType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const AnnotationTypes: Readonly<{ +export const AnnotationType: Readonly<{ Line: "line"; Rectangle: "rectangle"; Text: "text"; }>; +// @public (undocumented) +export type AnnotationType = $Values; + // Warning: (ae-missing-release-tag) "ArcSeriesStyle" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -295,7 +295,7 @@ export type BarStyleOverride = RecursivePartial | Color | null; // Warning: (ae-missing-release-tag) "BaseAnnotationSpec" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface BaseAnnotationSpec extends Spec, AnnotationPortalSettings { +export interface BaseAnnotationSpec extends Spec, AnnotationPortalSettings { annotationType: T; // (undocumented) chartType: typeof ChartType.XYAxis; @@ -1346,7 +1346,7 @@ export interface LineAnnotationDatum { } // @public (undocumented) -export type LineAnnotationSpec = BaseAnnotationSpec & { +export type LineAnnotationSpec = BaseAnnotationSpec & { domainType: AnnotationDomainType; marker?: JSX.Element; markerDimensions?: { @@ -1764,7 +1764,7 @@ export interface RectAnnotationDatum { } // @public (undocumented) -export type RectAnnotationSpec = BaseAnnotationSpec & { +export type RectAnnotationSpec = BaseAnnotationSpec & { renderTooltip?: AnnotationTooltipFormatter; zIndex?: number; }; diff --git a/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx b/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx index 95e44fd4bc..3fd97648f7 100644 --- a/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx +++ b/src/chart_types/xy_chart/annotations/line/tooltip.test.tsx @@ -30,7 +30,7 @@ import { Dimensions } from '../../../../utils/dimensions'; import { AnnotationId } from '../../../../utils/ids'; import { LineAnnotation } from '../../specs/line_annotation'; import { LineSeries } from '../../specs/line_series'; -import { AnnotationDomainTypes, AnnotationTypes, AxisSpec, RectAnnotationSpec } from '../../utils/specs'; +import { AnnotationDomainTypes, AnnotationType, AxisSpec, RectAnnotationSpec } from '../../utils/specs'; import { computeRectAnnotationTooltipState } from '../tooltip'; import { AnnotationDimensions } from '../types'; import { AnnotationLineProps } from './types'; @@ -148,7 +148,7 @@ describe('Annotation tooltips', () => { specType: SpecType.Annotation, id: 'rect', groupId, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, dataValues: [{ coordinates: { x0: 1, x1: 2, y0: 3, y1: 5 } }], }; @@ -170,7 +170,7 @@ describe('Annotation tooltips', () => { expect(rectTooltipState).toMatchObject({ isVisible: true, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, anchor: { left: 18, top: 9, diff --git a/src/chart_types/xy_chart/annotations/rect/tooltip.test.ts b/src/chart_types/xy_chart/annotations/rect/tooltip.test.ts index 38b805e3b4..5365f00335 100644 --- a/src/chart_types/xy_chart/annotations/rect/tooltip.test.ts +++ b/src/chart_types/xy_chart/annotations/rect/tooltip.test.ts @@ -18,7 +18,7 @@ */ import { MockAnnotationRectProps } from '../../../../mocks/annotations/annotations'; import { Dimensions } from '../../../../utils/dimensions'; -import { AnnotationTypes } from '../../utils/specs'; +import { AnnotationType } from '../../utils/specs'; import { AnnotationTooltipState } from '../types'; import { getRectAnnotationTooltipState } from './tooltip'; import { AnnotationRectProps } from './types'; @@ -43,7 +43,7 @@ describe('Rect annotation tooltip', () => { const visibleTooltip = getRectAnnotationTooltipState(cursorPosition, annotationRects, 0, chartDimensions); const expectedVisibleTooltipState: AnnotationTooltipState = { isVisible: true, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, anchor: { top: cursorPosition.y, left: cursorPosition.x, diff --git a/src/chart_types/xy_chart/annotations/rect/tooltip.ts b/src/chart_types/xy_chart/annotations/rect/tooltip.ts index 094fe4e16e..d7bbce8370 100644 --- a/src/chart_types/xy_chart/annotations/rect/tooltip.ts +++ b/src/chart_types/xy_chart/annotations/rect/tooltip.ts @@ -22,7 +22,7 @@ import { Rotation } from '../../../../utils/common'; import { Dimensions } from '../../../../utils/dimensions'; import { Point } from '../../../../utils/point'; import { isHorizontalRotation } from '../../state/utils/common'; -import { AnnotationTypes } from '../../utils/specs'; +import { AnnotationType } from '../../utils/specs'; import { AnnotationTooltipState, Bounds } from '../types'; import { isWithinRectBounds } from './dimensions'; import { AnnotationRectProps } from './types'; @@ -51,7 +51,7 @@ export function getRectAnnotationTooltipState( if (isWithinBounds) { return { isVisible: true, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, anchor: { left: cursorPosition.x, top: cursorPosition.y, diff --git a/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx b/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx index 23139c7668..cdd05223a3 100644 --- a/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx +++ b/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx @@ -19,7 +19,7 @@ import React, { useCallback } from 'react'; -import { AnnotationTypes, LineAnnotationDatum, RectAnnotationDatum } from '../../../../specs'; +import { AnnotationType, LineAnnotationDatum, RectAnnotationDatum } from '../../../../specs'; import { AnnotationTooltipState } from '../../../annotations/types'; /** @internal */ @@ -64,10 +64,10 @@ export const TooltipContent = ({ } switch (annotationType) { - case AnnotationTypes.Line: { + case AnnotationType.Line: { return renderLine(); } - case AnnotationTypes.Rectangle: { + case AnnotationType.Rectangle: { return renderRect(); } default: diff --git a/src/chart_types/xy_chart/specs/line_annotation.tsx b/src/chart_types/xy_chart/specs/line_annotation.tsx index 1faf89d425..bb4d62a174 100644 --- a/src/chart_types/xy_chart/specs/line_annotation.tsx +++ b/src/chart_types/xy_chart/specs/line_annotation.tsx @@ -23,13 +23,13 @@ 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, AnnotationTypes } from '../utils/specs'; +import { LineAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } from '../utils/specs'; const defaultProps = { chartType: ChartType.XYAxis, specType: SpecType.Annotation, groupId: DEFAULT_GLOBAL_ID, - annotationType: AnnotationTypes.Line, + annotationType: AnnotationType.Line, style: DEFAULT_ANNOTATION_LINE_STYLE, hideLines: false, hideTooltips: false, diff --git a/src/chart_types/xy_chart/specs/rect_annotation.tsx b/src/chart_types/xy_chart/specs/rect_annotation.tsx index 6aa78cab7b..dee32bdcf5 100644 --- a/src/chart_types/xy_chart/specs/rect_annotation.tsx +++ b/src/chart_types/xy_chart/specs/rect_annotation.tsx @@ -23,13 +23,13 @@ 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, AnnotationTypes } from '../utils/specs'; +import { RectAnnotationSpec, DEFAULT_GLOBAL_ID, AnnotationType } from '../utils/specs'; const defaultProps = { chartType: ChartType.XYAxis, specType: SpecType.Annotation, groupId: DEFAULT_GLOBAL_ID, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, zIndex: -1, style: DEFAULT_ANNOTATION_RECT_STYLE, }; diff --git a/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts b/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts index 7d3d48491e..22a74e779e 100644 --- a/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts +++ b/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts @@ -33,7 +33,7 @@ import { AnnotationLineProps } from '../../annotations/line/types'; import { AnnotationRectProps } from '../../annotations/rect/types'; import { computeRectAnnotationTooltipState } from '../../annotations/tooltip'; import { AnnotationTooltipState, AnnotationDimensions } from '../../annotations/types'; -import { AxisSpec, AnnotationSpec, AnnotationTypes } from '../../utils/specs'; +import { AxisSpec, AnnotationSpec, AnnotationType } from '../../utils/specs'; import { ComputedGeometries } from '../utils/types'; import { computeAnnotationDimensionsSelector } from './compute_annotations'; import { computeChartDimensionsSelector } from './compute_chart_dimensions'; @@ -107,7 +107,7 @@ function getAnnotationTooltipState( if ( tooltipState && tooltipState.isVisible && - tooltipState.annotationType === AnnotationTypes.Rectangle && + tooltipState.annotationType === AnnotationType.Rectangle && isChartTooltipDisplayed ) { return null; @@ -143,7 +143,7 @@ function getTooltipStateForDOMElements( return { isVisible: true, - annotationType: AnnotationTypes.Line, + annotationType: AnnotationType.Line, datum: dimension.datum, anchor: { top: (dimension.markers[0]?.position.top ?? 0) + dimension.panel.top + chartDimensions.top, diff --git a/src/chart_types/xy_chart/utils/specs.ts b/src/chart_types/xy_chart/utils/specs.ts index 26a5ba2087..d367d18911 100644 --- a/src/chart_types/xy_chart/utils/specs.ts +++ b/src/chart_types/xy_chart/utils/specs.ts @@ -694,13 +694,13 @@ export type TickFormatterOptions = { /** @public */ export type TickFormatter = (value: V, options?: TickFormatterOptions) => string; -export const AnnotationTypes = Object.freeze({ +export const AnnotationType = Object.freeze({ Line: 'line' as const, Rectangle: 'rectangle' as const, Text: 'text' as const, }); /** @public */ -export type AnnotationType = $Values; +export type AnnotationType = $Values; /** * The domain type enum that can be associated with an annotation @@ -738,7 +738,7 @@ export interface LineAnnotationDatum { /** @public */ export type LineAnnotationSpec = BaseAnnotationSpec< - typeof AnnotationTypes.Line, + typeof AnnotationType.Line, LineAnnotationDatum, LineAnnotationStyle > & { @@ -810,7 +810,7 @@ export interface RectAnnotationDatum { /** @public */ export type RectAnnotationSpec = BaseAnnotationSpec< - typeof AnnotationTypes.Rectangle, + typeof AnnotationType.Rectangle, RectAnnotationDatum, RectAnnotationStyle > & { @@ -844,7 +844,7 @@ export type AnnotationPortalSettings = TooltipPortalSettings<'chart'> & { }; export interface BaseAnnotationSpec< - T extends typeof AnnotationTypes.Rectangle | typeof AnnotationTypes.Line, + T extends typeof AnnotationType.Rectangle | typeof AnnotationType.Line, D extends RectAnnotationDatum | LineAnnotationDatum, S extends RectAnnotationStyle | LineAnnotationStyle > extends Spec, @@ -884,12 +884,12 @@ export type AnnotationSpec = LineAnnotationSpec | RectAnnotationSpec; /** @internal */ export function isLineAnnotation(spec: AnnotationSpec): spec is LineAnnotationSpec { - return spec.annotationType === AnnotationTypes.Line; + return spec.annotationType === AnnotationType.Line; } /** @internal */ export function isRectAnnotation(spec: AnnotationSpec): spec is RectAnnotationSpec { - return spec.annotationType === AnnotationTypes.Rectangle; + return spec.annotationType === AnnotationType.Rectangle; } /** @internal */ diff --git a/src/mocks/specs/specs.ts b/src/mocks/specs/specs.ts index 72174498fc..ea85d58fbf 100644 --- a/src/mocks/specs/specs.ts +++ b/src/mocks/specs/specs.ts @@ -36,7 +36,7 @@ import { BubbleSeriesSpec, LineAnnotationSpec, RectAnnotationSpec, - AnnotationTypes, + AnnotationType, AnnotationDomainTypes, AxisSpec, } from '../../chart_types/xy_chart/utils/specs'; @@ -348,7 +348,7 @@ export class MockAnnotationSpec { groupId: DEFAULT_GLOBAL_ID, chartType: ChartType.XYAxis, specType: SpecType.Annotation, - annotationType: AnnotationTypes.Line, + annotationType: AnnotationType.Line, dataValues: [], domainType: AnnotationDomainTypes.XDomain, }; @@ -358,7 +358,7 @@ export class MockAnnotationSpec { groupId: DEFAULT_GLOBAL_ID, chartType: ChartType.XYAxis, specType: SpecType.Annotation, - annotationType: AnnotationTypes.Rectangle, + annotationType: AnnotationType.Rectangle, dataValues: [], };