Skip to content

Commit

Permalink
refactor: rename enum types to singular
Browse files Browse the repository at this point in the history
Fixup AnnotationTypes.

Signed-off-by: Tre' Seymour <[email protected]>
  • Loading branch information
wayneseymour committed Mar 29, 2021
1 parent ff37e2b commit aa444a8
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
16 changes: 8 additions & 8 deletions api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof AnnotationTypes>;

// 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<typeof AnnotationType>;

// 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)
Expand Down Expand Up @@ -295,7 +295,7 @@ export type BarStyleOverride = RecursivePartial<BarSeriesStyle> | 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<T extends typeof AnnotationTypes.Rectangle | typeof AnnotationTypes.Line, D extends RectAnnotationDatum | LineAnnotationDatum, S extends RectAnnotationStyle | LineAnnotationStyle> extends Spec, AnnotationPortalSettings {
export interface BaseAnnotationSpec<T extends typeof AnnotationType.Rectangle | typeof AnnotationType.Line, D extends RectAnnotationDatum | LineAnnotationDatum, S extends RectAnnotationStyle | LineAnnotationStyle> extends Spec, AnnotationPortalSettings {
annotationType: T;
// (undocumented)
chartType: typeof ChartType.XYAxis;
Expand Down Expand Up @@ -1346,7 +1346,7 @@ export interface LineAnnotationDatum {
}

// @public (undocumented)
export type LineAnnotationSpec = BaseAnnotationSpec<typeof AnnotationTypes.Line, LineAnnotationDatum, LineAnnotationStyle> & {
export type LineAnnotationSpec = BaseAnnotationSpec<typeof AnnotationType.Line, LineAnnotationDatum, LineAnnotationStyle> & {
domainType: AnnotationDomainType;
marker?: JSX.Element;
markerDimensions?: {
Expand Down Expand Up @@ -1764,7 +1764,7 @@ export interface RectAnnotationDatum {
}

// @public (undocumented)
export type RectAnnotationSpec = BaseAnnotationSpec<typeof AnnotationTypes.Rectangle, RectAnnotationDatum, RectAnnotationStyle> & {
export type RectAnnotationSpec = BaseAnnotationSpec<typeof AnnotationType.Rectangle, RectAnnotationDatum, RectAnnotationStyle> & {
renderTooltip?: AnnotationTooltipFormatter;
zIndex?: number;
};
Expand Down
6 changes: 3 additions & 3 deletions src/chart_types/xy_chart/annotations/line/tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 } }],
};

Expand All @@ -170,7 +170,7 @@ describe('Annotation tooltips', () => {

expect(rectTooltipState).toMatchObject({
isVisible: true,
annotationType: AnnotationTypes.Rectangle,
annotationType: AnnotationType.Rectangle,
anchor: {
left: 18,
top: 9,
Expand Down
4 changes: 2 additions & 2 deletions src/chart_types/xy_chart/annotations/rect/tooltip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/chart_types/xy_chart/annotations/rect/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/chart_types/xy_chart/specs/line_annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/chart_types/xy_chart/specs/rect_annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -107,7 +107,7 @@ function getAnnotationTooltipState(
if (
tooltipState &&
tooltipState.isVisible &&
tooltipState.annotationType === AnnotationTypes.Rectangle &&
tooltipState.annotationType === AnnotationType.Rectangle &&
isChartTooltipDisplayed
) {
return null;
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions src/chart_types/xy_chart/utils/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,13 @@ export type TickFormatterOptions = {
/** @public */
export type TickFormatter<V = any> = (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<typeof AnnotationTypes>;
export type AnnotationType = $Values<typeof AnnotationType>;

/**
* The domain type enum that can be associated with an annotation
Expand Down Expand Up @@ -738,7 +738,7 @@ export interface LineAnnotationDatum {

/** @public */
export type LineAnnotationSpec = BaseAnnotationSpec<
typeof AnnotationTypes.Line,
typeof AnnotationType.Line,
LineAnnotationDatum,
LineAnnotationStyle
> & {
Expand Down Expand Up @@ -810,7 +810,7 @@ export interface RectAnnotationDatum {

/** @public */
export type RectAnnotationSpec = BaseAnnotationSpec<
typeof AnnotationTypes.Rectangle,
typeof AnnotationType.Rectangle,
RectAnnotationDatum,
RectAnnotationStyle
> & {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/mocks/specs/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
BubbleSeriesSpec,
LineAnnotationSpec,
RectAnnotationSpec,
AnnotationTypes,
AnnotationType,
AnnotationDomainTypes,
AxisSpec,
} from '../../chart_types/xy_chart/utils/specs';
Expand Down Expand Up @@ -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,
};
Expand All @@ -358,7 +358,7 @@ export class MockAnnotationSpec {
groupId: DEFAULT_GLOBAL_ID,
chartType: ChartType.XYAxis,
specType: SpecType.Annotation,
annotationType: AnnotationTypes.Rectangle,
annotationType: AnnotationType.Rectangle,
dataValues: [],
};

Expand Down

0 comments on commit aa444a8

Please sign in to comment.