Skip to content

Commit 606ae93

Browse files
committed
Rename PlotType to TraceType, add alias
1 parent b4dea80 commit 606ae93

7 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/types/ARCHITECTURE.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ The split:
4545
types**.
4646
- **`src/types/generated/schema.d.ts`** contains:
4747
- **Common enum aliases** discovered from the schema (Calendar, Dash,
48-
AxisType, PatternShape, XRef, YRef, TransitionEasing, PlotType).
48+
AxisType, PatternShape, XRef, YRef, TransitionEasing, TraceType — plus
49+
a deprecated `PlotType` alias for back-compat).
4950
- **Shared sub-interfaces** extracted from repeated subtrees (Font,
5051
FontArray, ColorBar, HoverLabel, Domain, Pattern, TickFormatStops,
5152
LegendGroupTitle).
@@ -138,7 +139,8 @@ test/plot-schema.json (runtime schema: traces + layout + animation + config)
138139
139140
│ 0. Discover common enum aliases via COMMON_TYPE_ANCHORS
140141
│ (Calendar/Dash/AxisType/PatternShape/XRef/YRef/TransitionEasing,
141-
│ plus PlotType derived from the trace-names list)
142+
│ plus TraceType derived from the trace-names list, plus a deprecated
143+
│ `PlotType` alias)
142144
│ 1. Fingerprint every container subtree across traces and layout
143145
│ 2. Extract shared interfaces (Font, ColorBar, HoverLabel, etc.).
144146
│ Inject Transition and AnimationFrameOpts as shared types
@@ -156,7 +158,9 @@ test/plot-schema.json (runtime schema: traces + layout + animation + config)
156158
src/types/generated/schema.d.ts
157159
│ // Common enum aliases
158160
│ export type Calendar = 'chinese' | 'coptic' | ...;
159-
│ export type PlotType = 'bar' | 'scatter' | ...;
161+
│ export type TraceType = 'bar' | 'scatter' | ...;
162+
│ /** @deprecated Renamed to TraceType. */
163+
│ export type PlotType = TraceType;
160164
│ // Shared interfaces (public)
161165
│ export interface Font { ... }
162166
│ export interface ColorBar { ... }

src/types/GENERATOR.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ reads `plot-schema.json` and emits all the schema-derived TypeScript
55
types into `src/types/generated/schema.d.ts`:
66

77
- Common enum aliases (Calendar, Dash, AxisType, PatternShape, XRef, YRef,
8-
TransitionEasing, PlotType)
8+
TransitionEasing, TraceType — plus a deprecated `PlotType` alias)
99
- Shared sub-interfaces (Font, ColorBar, HoverLabel, etc.)
1010
- Data interfaces for each trace type (BarData, ScatterData, IndicatorData, etc.)
1111
- Layout component interfaces (LayoutAxis, Legend, Scene, Annotation, etc.)
@@ -43,8 +43,9 @@ const COMMON_TYPE_ANCHORS = [
4343
When multiple sites match an anchor (e.g. 3D scene axes vs cartesian axes
4444
both have `xaxis.type` enumerations), the generator picks the largest
4545
value set — the superset — so the alias is always permissive enough.
46-
`PlotType` is special-cased: derived from `Object.keys(schema.traces)`
47-
rather than from an attribute.
46+
`TraceType` is special-cased: derived from `Object.keys(schema.traces)`
47+
rather than from an attribute. A deprecated `PlotType = TraceType` alias
48+
is also emitted for back-compat with prior versions of the type surface.
4849

4950
Each discovered alias is emitted as `export type Name = 'a' | 'b' | ...`
5051
and registered in `VALUES_TO_COMMON_TYPE` so subsequent emission of any
@@ -184,7 +185,7 @@ descriptions are escaped to prevent prematurely closing the comment.
184185
src/types/generated/schema.d.ts
185186
├── import { Color, ColorScale, Datum, MarkerSymbol, TypedArray } from '../lib/common'
186187
├── Common enum types (Calendar, Dash, AxisType, PatternShape, XRef, YRef,
187-
│ TransitionEasing, PlotType)
188+
│ TransitionEasing, TraceType + deprecated PlotType alias)
188189
├── Shared interfaces — public (Font, FontArray, ColorBar, HoverLabel, Domain,
189190
│ Pattern, TickFormatStops, LegendGroupTitle, ...)
190191
├── Internal shared interfaces in `namespace _internal` (Marker, Line,
@@ -242,9 +243,10 @@ you want a named alias for it:
242243
and rewrites matching enumerated attributes to reference the alias.
243244
3. Run `npm run typecheck` to verify.
244245

245-
`PlotType` is a special case derived from `Object.keys(schema.traces)`
246+
`TraceType` is a special case derived from `Object.keys(schema.traces)`
246247
rather than from an enumerated attribute; it doesn't follow the anchor
247-
mechanism.
248+
mechanism. A deprecated `PlotType = TraceType` alias is emitted alongside it
249+
to keep older imports working.
248250

249251
### Adding a new layout container
250252

src/types/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The following are **auto-generated from `plot-schema.json`** by
4646
`tasks/generate_schema_types.mjs`:
4747

4848
- Common enum aliases (Calendar, Dash, AxisType, PatternShape, XRef, YRef,
49-
TransitionEasing, PlotType)
49+
TransitionEasing, TraceType — and a deprecated `PlotType` alias)
5050
- Data interfaces for each trace type (BarData, ScatterData, IndicatorData, etc.)
5151
- Layout component interfaces (LayoutAxis, Legend, Scene, Annotation,
5252
Shape, Slider, UpdateMenu, etc.) and the Layout interface itself

src/types/core/data.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ import type {
5858
SunburstData,
5959
SurfaceData,
6060
TableData,
61+
TraceType,
6162
TreemapData,
6263
ViolinData,
6364
VolumeData,
6465
WaterfallData
6566
} from '../generated/schema';
6667

67-
export type { PlotType };
68+
export type { PlotType, TraceType };
6869

6970
/**
7071
* Union of every trace shape. All fields are optional via `Partial<…>` —

src/types/core/layout.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import type { Layout } from '../generated/schema';
12-
import type { Data, PlotType } from './data';
12+
import type { Data, TraceType } from './data';
1313
import type { PlotlyHTMLElement } from './events';
1414

1515
// ---------------------------------------------------------------------------
@@ -142,7 +142,7 @@ export type ModeBarButtonAny = ModeBarDefaultButtons | ModeBarButton;
142142
*/
143143
export interface Template {
144144
/** Template trace defaults, keyed by trace type. */
145-
data?: { [type in PlotType]?: Data[] } | undefined;
145+
data?: { [type in TraceType]?: Data[] } | undefined;
146146
/** Template layout defaults. */
147147
layout?: Partial<Layout> | undefined;
148148
}

src/types/generated/schema.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export type PatternShape = '' | '/' | '\\' | 'x' | '-' | '|' | '+' | '.';
2323

2424
export type TransitionEasing = 'linear' | 'quad' | 'cubic' | 'sin' | 'exp' | 'circle' | 'elastic' | 'back' | 'bounce' | 'linear-in' | 'quad-in' | 'cubic-in' | 'sin-in' | 'exp-in' | 'circle-in' | 'elastic-in' | 'back-in' | 'bounce-in' | 'linear-out' | 'quad-out' | 'cubic-out' | 'sin-out' | 'exp-out' | 'circle-out' | 'elastic-out' | 'back-out' | 'bounce-out' | 'linear-in-out' | 'quad-in-out' | 'cubic-in-out' | 'sin-in-out' | 'exp-in-out' | 'circle-in-out' | 'elastic-in-out' | 'back-in-out' | 'bounce-in-out';
2525

26-
export type PlotType = 'bar' | 'barpolar' | 'box' | 'candlestick' | 'carpet' | 'choropleth' | 'choroplethmap' | 'choroplethmapbox' | 'cone' | 'contour' | 'contourcarpet' | 'densitymap' | 'densitymapbox' | 'funnel' | 'funnelarea' | 'heatmap' | 'histogram' | 'histogram2d' | 'histogram2dcontour' | 'icicle' | 'image' | 'indicator' | 'isosurface' | 'mesh3d' | 'ohlc' | 'parcats' | 'parcoords' | 'pie' | 'sankey' | 'scatter' | 'scatter3d' | 'scattercarpet' | 'scattergeo' | 'scattergl' | 'scattermap' | 'scattermapbox' | 'scatterpolar' | 'scatterpolargl' | 'scattersmith' | 'scatterternary' | 'splom' | 'streamtube' | 'sunburst' | 'surface' | 'table' | 'treemap' | 'violin' | 'volume' | 'waterfall';
26+
export type TraceType = 'bar' | 'barpolar' | 'box' | 'candlestick' | 'carpet' | 'choropleth' | 'choroplethmap' | 'choroplethmapbox' | 'cone' | 'contour' | 'contourcarpet' | 'densitymap' | 'densitymapbox' | 'funnel' | 'funnelarea' | 'heatmap' | 'histogram' | 'histogram2d' | 'histogram2dcontour' | 'icicle' | 'image' | 'indicator' | 'isosurface' | 'mesh3d' | 'ohlc' | 'parcats' | 'parcoords' | 'pie' | 'sankey' | 'scatter' | 'scatter3d' | 'scattercarpet' | 'scattergeo' | 'scattergl' | 'scattermap' | 'scattermapbox' | 'scatterpolar' | 'scatterpolargl' | 'scattersmith' | 'scatterternary' | 'splom' | 'streamtube' | 'sunburst' | 'surface' | 'table' | 'treemap' | 'violin' | 'volume' | 'waterfall';
27+
28+
/** @deprecated Renamed to TraceType. */
29+
export type PlotType = TraceType;
2730

2831
// ---------------------------------------------------------------------------
2932
// Shared interfaces — extracted from repeated attribute subtrees

tasks/generate_schema_types.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function refName(name, inInternalNamespace) {
8181
/**
8282
* Walk the schema to find the canonical `values` array for each anchor in
8383
* `COMMON_TYPE_ANCHORS`. The first matching enumerated attribute wins.
84-
* Also emits a `PlotType` alias derived from the trace-names list.
84+
* Also emits a `TraceType` alias derived from the trace-names list,
85+
* plus a deprecated `PlotType` alias for back-compat.
8586
*
8687
* Populates `VALUES_TO_COMMON_TYPE` and returns `Map<name, {values}>` for
8788
* emitting type aliases.
@@ -131,8 +132,9 @@ function discoverCommonTypes(schema) {
131132
VALUES_TO_COMMON_TYPE.set(JSON.stringify(best.slice().sort()), anchor.name);
132133
}
133134

134-
// PlotType — derived from the list of trace names, not from an attribute.
135-
found.set('PlotType', { values: Object.keys(schema.traces).sort() });
135+
// TraceType — derived from the list of trace names, not from an attribute.
136+
// (A deprecated `PlotType` alias is also emitted; see the emit loop.)
137+
found.set('TraceType', { values: Object.keys(schema.traces).sort() });
136138

137139
return found;
138140
}
@@ -1107,6 +1109,12 @@ export function generateSchemaTypes(schema, outputPath) {
11071109
chunks.push('');
11081110
}
11091111

1112+
// Deprecated back-compat alias — kept so existing consumers importing
1113+
// `PlotType` continue to work. New code should use `TraceType`.
1114+
chunks.push('/** @deprecated Renamed to TraceType. */');
1115+
chunks.push('export type PlotType = TraceType;');
1116+
chunks.push('');
1117+
11101118
// Emit shared interfaces — public ones at the top level, "internal" ones
11111119
// wrapped in `export namespace _internal { ... }` so consumers reach them
11121120
// via the namespace prefix rather than directly.
@@ -1268,6 +1276,7 @@ export function generateSchemaTypes(schema, outputPath) {
12681276
// falsely flag them as missing.
12691277
const exportedNames = new Set();
12701278
for (const name of commonTypes.keys()) exportedNames.add(name);
1279+
exportedNames.add('PlotType');
12711280
for (const [name] of sharedList) {
12721281
if (!INTERNAL_INTERFACES.has(name)) exportedNames.add(name);
12731282
}

0 commit comments

Comments
 (0)