Skip to content

Commit fe6422f

Browse files
authored
Merge pull request #8020 from plotly/cam/8018/include-trace-layout-attributes
fix: Include trace-contributed layout attributes in generated types
2 parents 9ad81fe + 038ce20 commit fe6422f

4 files changed

Lines changed: 276 additions & 6 deletions

File tree

draftlogs/8020_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Include trace-contributed layout attributes in generated types [[#8020](https://github.com/plotly/plotly.js/pull/8020)]

src/types/GENERATOR.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,29 @@ schema flows through automatically.
9999

100100
### Phase 4: Layout types
101101

102-
Layout generation handles three categories:
102+
Before generation, `mergeTraceLayoutAttributes` folds every
103+
`schema.traces[<type>].layoutAttributes` map into the layout attribute tree.
104+
Trace modules contribute layout keys such as `barmode`, `boxmode` and
105+
`piecolorway`, and the schema files them under the trace that contributes
106+
them. At runtime they are ordinary layout keys, so the generated types must
107+
carry them.
108+
109+
Most modules contribute to the top level of layout. barpolar is the
110+
exception: its `supplyLayoutDefaults` coerces from `layoutIn[trace.subplot]`,
111+
so `layout.polar.barmode` is the real key and `layout.barmode` does nothing
112+
for a barpolar trace. `SUBPLOT_SCOPED_TRACE_LAYOUT` maps barpolar to `polar`,
113+
which is why `Layout.barmode` allows all four bar values while
114+
`PolarLayout.barmode` allows only `'stack'` and `'overlay'`. Add an entry
115+
there if another module ever reads its layout attributes from a subplot.
116+
117+
Two modules that contribute the same key to the same target must agree on
118+
the definition. If they disagree, generation throws rather than guessing,
119+
because one property cannot describe both. The repo shares such keys by
120+
reference instead of copying them, so a disagreement means either the shared
121+
require was broken, or the two modules mean genuinely different things and
122+
one of them belongs in its own container.
123+
124+
Layout generation then handles three categories:
103125

104126
- **Subplot containers** (`_isSubplotObj` flag) — grouped by target name
105127
and merged into supersets. E.g., `xaxis` and `yaxis` both map to

src/types/generated/schema.d.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13186,6 +13186,17 @@ export interface PolarLayout {
1318613186
*/
1318713187
visible?: boolean;
1318813188
};
13189+
/**
13190+
* Sets the gap between bars of adjacent location coordinates. Values are unitless, they represent fractions of the minimum difference in bar positions in the data.
13191+
* @default 0.1
13192+
* Range: [0, 1]
13193+
*/
13194+
bargap?: number;
13195+
/**
13196+
* Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *overlay*, the bars are plotted over one another, you might need to reduce *opacity* to see multiple bars.
13197+
* @default 'stack'
13198+
*/
13199+
barmode?: 'stack' | 'overlay';
1318913200
/**
1319013201
* Set the background color of the subplot
1319113202
* @default '#fff'
@@ -15948,6 +15959,43 @@ export interface Layout {
1594815959
* @default 'convert types'
1594915960
*/
1595015961
autotypenumbers?: 'convert types' | 'strict';
15962+
/** Sets the rounding of bar corners. May be an integer number of pixels, or a percentage of bar width (as a string ending in %). */
15963+
barcornerradius?: any;
15964+
/**
15965+
* Sets the gap (in plot fraction) between bars of adjacent location coordinates.
15966+
* Range: [0, 1]
15967+
*/
15968+
bargap?: number;
15969+
/**
15970+
* Sets the gap (in plot fraction) between bars of the same location coordinate.
15971+
* @default 0
15972+
* Range: [0, 1]
15973+
*/
15974+
bargroupgap?: number;
15975+
/**
15976+
* Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *relative*, the bars are stacked on top of one another, with negative values below the axis, positive values above With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to reduce *opacity* to see multiple bars.
15977+
* @default 'group'
15978+
*/
15979+
barmode?: 'stack' | 'group' | 'overlay' | 'relative';
15980+
/** Sets the normalization for bar traces on the graph. With *fraction*, the value of each bar is divided by the sum of all values at that location coordinate. *percent* is the same but multiplied by 100 to show percentages. */
15981+
barnorm?: '' | 'fraction' | 'percent';
15982+
/**
15983+
* Sets the gap (in plot fraction) between boxes of adjacent location coordinates. Has no effect on traces that have *width* set.
15984+
* @default 0.3
15985+
* Range: [0, 1]
15986+
*/
15987+
boxgap?: number;
15988+
/**
15989+
* Sets the gap (in plot fraction) between boxes of the same location coordinate. Has no effect on traces that have *width* set.
15990+
* @default 0.3
15991+
* Range: [0, 1]
15992+
*/
15993+
boxgroupgap?: number;
15994+
/**
15995+
* Determines how boxes at the same location coordinate are displayed on the graph. If *group*, the boxes are plotted next to one another centered around the shared location. If *overlay*, the boxes are plotted over one another, you might need to set *opacity* to see them multiple boxes. Has no effect on traces that have *width* set.
15996+
* @default 'overlay'
15997+
*/
15998+
boxmode?: 'group' | 'overlay';
1595115999
/**
1595216000
* Sets the default calendar system to use for interpreting and displaying dates throughout the plot.
1595316001
* @default 'gregorian'
@@ -15997,8 +16045,51 @@ export interface Layout {
1599716045
dragmode?: 'zoom' | 'pan' | 'select' | 'lasso' | 'drawclosedpath' | 'drawopenpath' | 'drawline' | 'drawrect' | 'drawcircle' | 'orbit' | 'turntable' | false;
1599816046
/** Controls persistence of user-driven changes in `editable: true` configuration, other than trace names and axis titles. Defaults to `layout.uirevision`. */
1599916047
editrevision?: any;
16048+
/**
16049+
* If `true`, the funnelarea slice colors (whether given by `funnelareacolorway` or inherited from `colorway`) will be extended to three times its original length by first repeating every color 20% lighter then each color 20% darker. This is intended to reduce the likelihood of reusing the same color when you have many slices, but you can set `false` to disable. Colors provided in the trace, using `marker.colors`, are never extended.
16050+
* @default true
16051+
*/
16052+
extendfunnelareacolors?: boolean;
16053+
/**
16054+
* If `true`, the icicle slice colors (whether given by `iciclecolorway` or inherited from `colorway`) will be extended to three times its original length by first repeating every color 20% lighter then each color 20% darker. This is intended to reduce the likelihood of reusing the same color when you have many slices, but you can set `false` to disable. Colors provided in the trace, using `marker.colors`, are never extended.
16055+
* @default true
16056+
*/
16057+
extendiciclecolors?: boolean;
16058+
/**
16059+
* If `true`, the pie slice colors (whether given by `piecolorway` or inherited from `colorway`) will be extended to three times its original length by first repeating every color 20% lighter then each color 20% darker. This is intended to reduce the likelihood of reusing the same color when you have many slices, but you can set `false` to disable. Colors provided in the trace, using `marker.colors`, are never extended.
16060+
* @default true
16061+
*/
16062+
extendpiecolors?: boolean;
16063+
/**
16064+
* If `true`, the sunburst slice colors (whether given by `sunburstcolorway` or inherited from `colorway`) will be extended to three times its original length by first repeating every color 20% lighter then each color 20% darker. This is intended to reduce the likelihood of reusing the same color when you have many slices, but you can set `false` to disable. Colors provided in the trace, using `marker.colors`, are never extended.
16065+
* @default true
16066+
*/
16067+
extendsunburstcolors?: boolean;
16068+
/**
16069+
* If `true`, the treemap slice colors (whether given by `treemapcolorway` or inherited from `colorway`) will be extended to three times its original length by first repeating every color 20% lighter then each color 20% darker. This is intended to reduce the likelihood of reusing the same color when you have many slices, but you can set `false` to disable. Colors provided in the trace, using `marker.colors`, are never extended.
16070+
* @default true
16071+
*/
16072+
extendtreemapcolors?: boolean;
1600016073
/** Sets the global font. Note that fonts used in traces and other layout components inherit from the global font. */
1600116074
font?: Font;
16075+
/** Sets the default funnelarea slice colors. Defaults to the main `colorway` used for trace colors. If you specify a new list here it can still be extended with lighter and darker colors, see `extendfunnelareacolors`. */
16076+
funnelareacolorway?: Color[];
16077+
/**
16078+
* Sets the gap (in plot fraction) between bars of adjacent location coordinates.
16079+
* Range: [0, 1]
16080+
*/
16081+
funnelgap?: number;
16082+
/**
16083+
* Sets the gap (in plot fraction) between bars of the same location coordinate.
16084+
* @default 0
16085+
* Range: [0, 1]
16086+
*/
16087+
funnelgroupgap?: number;
16088+
/**
16089+
* Determines how bars at the same location coordinate are displayed on the graph. With *stack*, the bars are stacked on top of one another With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to reduce *opacity* to see multiple bars.
16090+
* @default 'stack'
16091+
*/
16092+
funnelmode?: 'stack' | 'group' | 'overlay';
1600216093
geo?: GeoLayout;
1600316094
grid?: {
1600416095
/**
@@ -16066,6 +16157,8 @@ export interface Layout {
1606616157
* Minimum: 10
1606716158
*/
1606816159
height?: number;
16160+
/** hiddenlabels is the funnelarea & pie chart analog of visible:'legendonly' but it can contain many labels, and can simultaneously hide slices from several pies/funnelarea charts */
16161+
hiddenlabels?: Datum[] | Datum[][] | TypedArray;
1606916162
/**
1607016163
* If true, `plotly_hover` events will fire for any cursor position within the plot area, not just over traces. When the cursor is not over a trace, the event will have an empty `points` array but will include `xvals` and `yvals` with cursor coordinates in data space, and `xPixel` and `yPixel` with cursor coordinates in pixels, relative to the top-left corner of the graph div. A `plotly_unhover` event fires when the cursor leaves the plot area.
1607116164
* @default false
@@ -16118,6 +16211,8 @@ export interface Layout {
1611816211
* @default 'overlaying'
1611916212
*/
1612016213
hoversubplots?: 'single' | 'overlaying' | 'axis';
16214+
/** Sets the default icicle slice colors. Defaults to the main `colorway` used for trace colors. If you specify a new list here it can still be extended with lighter and darker colors, see `extendiciclecolors`. */
16215+
iciclecolorway?: Color[];
1612116216
images?: LayoutImage[];
1612216217
legend?: Legend;
1612316218
map?: MapLayout;
@@ -16324,12 +16419,24 @@ export interface Layout {
1632416419
* @default '#fff'
1632516420
*/
1632616421
paper_bgcolor?: Color;
16422+
/** Sets the default pie slice colors. Defaults to the main `colorway` used for trace colors. If you specify a new list here it can still be extended with lighter and darker colors, see `extendpiecolors`. */
16423+
piecolorway?: Color[];
1632716424
/**
1632816425
* Sets the background color of the plotting area in-between x and y axes.
1632916426
* @default '#fff'
1633016427
*/
1633116428
plot_bgcolor?: Color;
1633216429
polar?: PolarLayout;
16430+
/**
16431+
* Sets the gap (in plot fraction) between scatter points of adjacent location coordinates. Defaults to `bargap`.
16432+
* Range: [0, 1]
16433+
*/
16434+
scattergap?: number;
16435+
/**
16436+
* Determines how scatter points at the same location coordinate are displayed on the graph. With *group*, the scatter points are plotted next to one another centered around the shared location. With *overlay*, the scatter points are plotted over one another, you might need to reduce *opacity* to see multiple scatter points.
16437+
* @default 'overlay'
16438+
*/
16439+
scattermode?: 'group' | 'overlay';
1633316440
scene?: Scene;
1633416441
/**
1633516442
* When `dragmode` is set to *select*, this limits the selection of the drag to horizontal, vertical or diagonal. *h* only allows horizontal selection, *v* only vertical, *d* only diagonal and *any* sets no limit.
@@ -16352,6 +16459,8 @@ export interface Layout {
1635216459
* Minimum: -1
1635316460
*/
1635416461
spikedistance?: number;
16462+
/** Sets the default sunburst slice colors. Defaults to the main `colorway` used for trace colors. If you specify a new list here it can still be extended with lighter and darker colors, see `extendsunburstcolors`. */
16463+
sunburstcolorway?: Color[];
1635516464
/** Default attributes to be applied to the plot. Templates can be created from existing plots using `Plotly.makeTemplate`, or created manually. They should be objects with format: `{layout: layoutTemplate, data: {[type]: [traceTemplate, ...]}, ...}` `layoutTemplate` and `traceTemplate` are objects matching the attribute structure of `layout` and a data trace. Trace templates are applied cyclically to traces of each type. Container arrays (eg `annotations`) have special handling: An object ending in `defaults` (eg `annotationdefaults`) is applied to each array item. But if an item has a `templateitemname` key we look in the template array for an item with matching `name` and apply that instead. If no matching `name` is found we mark the item invisible. Any named template item not referenced is appended to the end of the array, so you can use this for a watermark annotation or a logo image, for example. To omit one of these items on the plot, make an item with matching `templateitemname` and `visible: false`. */
1635616465
template?: any;
1635716466
ternary?: TernaryLayout;
@@ -16424,6 +16533,8 @@ export interface Layout {
1642416533
};
1642516534
/** Sets transition options used during Plotly.react updates. */
1642616535
transition?: Transition;
16536+
/** Sets the default treemap slice colors. Defaults to the main `colorway` used for trace colors. If you specify a new list here it can still be extended with lighter and darker colors, see `extendtreemapcolors`. */
16537+
treemapcolorway?: Color[];
1642716538
/** Used to allow user interactions with the plot to persist after `Plotly.react` calls that are unaware of these interactions. If `uirevision` is omitted, or if it is given and it changed from the previous `Plotly.react` call, the exact new figure is used. If `uirevision` is truthy and did NOT change, any attribute that has been affected by user interactions and did not receive a different value in the new figure will keep the interaction value. `layout.uirevision` attribute serves as the default for `uirevision` attributes in various sub-containers. For finer control you can set these sub-attributes directly. For example, if your app separately controls the data on the x and y axes you might set `xaxis.uirevision=*time*` and `yaxis.uirevision=*cost*`. Then if only the y data is changed, you can update `yaxis.uirevision=*quantity*` and the y axis range will reset but the x axis range will retain any user-driven zoom. */
1642816539
uirevision?: any;
1642916540
uniformtext?: {
@@ -16440,6 +16551,39 @@ export interface Layout {
1644016551
mode?: false | 'hide' | 'show';
1644116552
};
1644216553
updatemenus?: UpdateMenu[];
16554+
/**
16555+
* Sets the gap (in plot fraction) between violins of adjacent location coordinates. Has no effect on traces that have *width* set.
16556+
* @default 0.3
16557+
* Range: [0, 1]
16558+
*/
16559+
violingap?: number;
16560+
/**
16561+
* Sets the gap (in plot fraction) between violins of the same location coordinate. Has no effect on traces that have *width* set.
16562+
* @default 0.3
16563+
* Range: [0, 1]
16564+
*/
16565+
violingroupgap?: number;
16566+
/**
16567+
* Determines how violins at the same location coordinate are displayed on the graph. If *group*, the violins are plotted next to one another centered around the shared location. If *overlay*, the violins are plotted over one another, you might need to set *opacity* to see them multiple violins. Has no effect on traces that have *width* set.
16568+
* @default 'overlay'
16569+
*/
16570+
violinmode?: 'group' | 'overlay';
16571+
/**
16572+
* Sets the gap (in plot fraction) between bars of adjacent location coordinates.
16573+
* Range: [0, 1]
16574+
*/
16575+
waterfallgap?: number;
16576+
/**
16577+
* Sets the gap (in plot fraction) between bars of the same location coordinate.
16578+
* @default 0
16579+
* Range: [0, 1]
16580+
*/
16581+
waterfallgroupgap?: number;
16582+
/**
16583+
* Determines how bars at the same location coordinate are displayed on the graph. With *group*, the bars are plotted next to one another centered around the shared location. With *overlay*, the bars are plotted over one another, you might need to reduce *opacity* to see multiple bars.
16584+
* @default 'group'
16585+
*/
16586+
waterfallmode?: 'group' | 'overlay';
1644316587
/**
1644416588
* Sets the plot's width (in px).
1644516589
* @default 700

0 commit comments

Comments
 (0)