Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API type experiment #1960

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/charts/src/chart_types/goal_chart/specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SpecType } from '../../../specs/constants';
import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory';
import { LabelAccessor, round, stripUndefined, ValueFormatter } from '../../../utils/common';
import { Logger } from '../../../utils/logger';
import { Prettify } from '../../../utils/types';
import { defaultGoalSpec } from '../layout/types/viewmodel_types';

/** @alpha */
Expand Down Expand Up @@ -130,4 +131,4 @@ To prevent overlapping, the value of \`angleEnd\` will be replaced.
};

/** @public */
export type GoalProps = ComponentProps<typeof Goal>;
export type GoalProps = Prettify<ComponentProps<typeof Goal>>;
22 changes: 14 additions & 8 deletions packages/charts/src/chart_types/heatmap/specs/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_facto
import { Accessor, AccessorFn } from '../../../utils/accessor';
import { ESCalendarInterval, ESFixedInterval } from '../../../utils/chrono/elasticsearch';
import { Datum, LabelAccessor, stripUndefined, ValueFormatter } from '../../../utils/common';
import { Prettify } from '../../../utils/types';
import { Cell } from '../layout/types/viewmodel_types';

/** @public */
Expand Down Expand Up @@ -55,11 +56,13 @@ export interface TimeScale {
type: typeof ScaleType.Time;
}

/** @public */
export interface RasterTimeScale extends TimeScale {
interface RasterTimeScaleInt extends TimeScale {
interval: ESCalendarInterval | ESFixedInterval;
}

/** @public */
export type RasterTimeScale = Prettify<RasterTimeScaleInt>;

/** @public */
export interface LinearScale {
type: typeof ScaleType.Linear;
Expand All @@ -70,8 +73,8 @@ export interface OrdinalScale {
type: typeof ScaleType.Ordinal;
}

/** @alpha */
export interface HeatmapSpec<D extends BaseDatum = Datum> extends Spec {
/** @internal */
interface HeatmapSpecInternal<D extends BaseDatum = Datum> extends Spec {
specType: typeof SpecType.Series;
chartType: typeof ChartType.Heatmap;
data: D[];
Expand All @@ -94,8 +97,11 @@ export interface HeatmapSpec<D extends BaseDatum = Datum> extends Spec {
yAxisLabelName: string;
yAxisLabelFormatter: LabelAccessor<string | number>;
}
/** @public */
export type HeatmapSpec<D extends BaseDatum = Datum> = Prettify<HeatmapSpecInternal<D>>;

const buildProps = buildSFProps<HeatmapSpec>()(
/** @internal */
export const buildProps = buildSFProps<HeatmapSpecInternal>()(
{
chartType: ChartType.Heatmap,
specType: SpecType.Series,
Expand Down Expand Up @@ -126,17 +132,17 @@ const buildProps = buildSFProps<HeatmapSpec>()(
*/
export const Heatmap = function <D extends BaseDatum = Datum>(
props: SFProps<
HeatmapSpec<D>,
HeatmapSpecInternal<D>,
keyof (typeof buildProps)['overrides'],
keyof (typeof buildProps)['defaults'],
keyof (typeof buildProps)['optionals'],
keyof (typeof buildProps)['requires']
>,
) {
const { defaults, overrides } = buildProps;
useSpecFactory<HeatmapSpec<D>>({ ...defaults, ...stripUndefined(props), ...overrides });
useSpecFactory<HeatmapSpecInternal<D>>({ ...defaults, ...stripUndefined(props), ...overrides });
return null;
};

/** @public */
export type HeatmapProps = ComponentProps<typeof Heatmap>;
export type HeatmapProps = Prettify<ComponentProps<typeof Heatmap>>;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { LegendPath } from '../../../../state/actions/legend';
import { Size } from '../../../../utils/dimensions';
import { LIGHT_THEME } from '../../../../utils/themes/light_theme';
import { Theme } from '../../../../utils/themes/theme';
import { Prettify } from '../../../../utils/types';
import { ContinuousDomainFocus } from '../../renderer/canvas/partition';
import { Layer } from '../../specs';
import { MODEL_KEY, ValueGetterName } from '../config';
Expand Down Expand Up @@ -235,17 +236,19 @@ export interface LayerFromTo {
y1: TreeLevel;
}

/**
* @public
*/
export interface TreeNode extends AngleFromTo {
interface TreeNodeInternal extends AngleFromTo {
x0: Radian;
x1: Radian;
y0: TreeLevel;
y1: TreeLevel;
fill?: Color;
}

/**
* @public
*/
export type TreeNode = Prettify<TreeNodeInternal>;

/**
* @public
*/
Expand All @@ -257,8 +260,7 @@ export interface SectorGeomSpecY {
/** @public */
export type DataName = CategoryKey; // todo consider narrowing it to eg. primitives

/** @public */
export interface ShapeTreeNode extends TreeNode, SectorGeomSpecY {
interface ShapeTreeNodeInternal extends TreeNode, SectorGeomSpecY {
yMidPx: Distance;
depth: number;
sortIndex: number;
Expand All @@ -268,6 +270,9 @@ export interface ShapeTreeNode extends TreeNode, SectorGeomSpecY {
[MODEL_KEY]: ArrayNode;
}

/** @public */
export type ShapeTreeNode = Prettify<ShapeTreeNodeInternal>;

/** @public */
export type RawTextGetter = (node: ShapeTreeNode) => string;
/** @public */
Expand Down
12 changes: 12 additions & 0 deletions packages/charts/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

/**
* @internal
*/
export type Prettify<T> = T extends Function ? T : T extends object ? { [K in keyof T]: Prettify<T[K]> } & {} : T;