Skip to content

Commit cd76ef7

Browse files
ryan-williamsclaude
andcommitted
convert plots/plots.js to named exports
Convert 54 methods from aggregation pattern to named exports. Update 9 consumer files in the factory bundle to use named imports. Remove `extendFlat(plots, Registry)` — consumers that accessed Registry methods via Plots now use Registry directly. Keep `export default plots` for backward compat with non-factory files. Modest savings (~0.5 KB) since the default export keeps all methods reachable. Full tree-shaking requires converting all consumers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 732af18 commit cd76ef7

File tree

12 files changed

+266
-217
lines changed

12 files changed

+266
-217
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"upstream_full__min_": 4831947,
33
"upstream_basic__min_": 1114816,
4-
"fork_full__min_": 4797107,
5-
"fork_basic__min_": 1083866,
6-
"fork_minimal__min_": 976177,
7-
"fork_lite__min_": 836151,
4+
"fork_full__min_": 4795415,
5+
"fork_basic__min_": 1082008,
6+
"fork_minimal__min_": 974321,
7+
"fork_lite__min_": 834293,
88
"app___upstream_basic": 1115573,
9-
"app___fork_basic": 1084014,
10-
"app___fork_lite": 836243,
11-
"fork_factory__min_": 710590,
12-
"app___fork_factory": 710590
9+
"app___fork_basic": 1082156,
10+
"app___fork_lite": 834385,
11+
"fork_factory__min_": 706417,
12+
"app___fork_factory": 706417
1313
}

perf/thresholds.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"bundleSize": {
33
"lite": {
4-
"expected_bytes": 1791466
4+
"expected_bytes": 1790948
55
},
66
"lite-min": {
77
"expected_bytes": 916326
88
},
99
"minimal": {
10-
"expected_bytes": 2114209
10+
"expected_bytes": 2113705
1111
},
1212
"minimal-min": {
1313
"expected_bytes": 1076875
1414
},
1515
"basic": {
16-
"expected_bytes": 2419312
16+
"expected_bytes": 2418808
1717
},
1818
"basic-min": {
1919
"expected_bytes": 1185641

src/components/legend/draw.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { select } from 'd3-selection';
22
import { zoom as d3Zoom } from 'd3-zoom';
33
import { drag as d3Drag } from 'd3-drag';
44
import { constrain, ensureSingle, ensureSingleById, identity, isBottomAnchor, isCenterAnchor, isMiddleAnchor, isRightAnchor, log, syncOrAsync, templateString } from '../../lib/index.js';
5-
import Plots from '../../plots/plots.js';
5+
import { autoMargin, previousPromises } from '../../plots/plots.js';
66
import Registry from '../../registry.js';
77
import Events from '../../lib/events.js';
88
import dragElement from '../dragelement/index.js';
@@ -145,7 +145,7 @@ function drawOne(gd, opts) {
145145
if(!inHover && (!fullLayout.showlegend || !legendData.length)) {
146146
layer.selectAll('.' + legendId).remove();
147147
fullLayout._topdefs.select('#' + clipId).remove();
148-
return Plots.autoMargin(gd, legendId);
148+
return autoMargin(gd, legendId);
149149
}
150150

151151
var legend = ensureSingle(layer, 'g', legendId, function(s) {
@@ -206,7 +206,7 @@ function drawOne(gd, opts) {
206206
.each(function() { if(!inHover) select(this).call(setupTraceToggle, gd, legendId); });
207207

208208
syncOrAsync([
209-
Plots.previousPromises,
209+
previousPromises,
210210
function() { return computeLegendDimensions(gd, groups, traces, legendObj); },
211211
function() {
212212
var gs = fullLayout._size;
@@ -973,7 +973,7 @@ function expandMargin(gd, legendId, lx, ly) {
973973
};
974974

975975
if(isPaperX && isPaperY) {
976-
return Plots.autoMargin(gd, legendId, {
976+
return autoMargin(gd, legendId, {
977977
x: legendObj.x,
978978
y: legendObj.y,
979979
l: legendObj._width * (FROM_TL[xanchor]),

src/components/titles/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { select } from 'd3-selection';
22
function d3Round(x, n) { return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x); }
33
import isNumeric from 'fast-isnumeric';
4-
import Plots from '../../plots/plots.js';
4+
import { previousPromises } from '../../plots/plots.js';
55
import Registry from '../../registry.js';
66
import { bBoxIntersect, ensureSingle, extendFlat, strTranslate, syncOrAsync, templateString } from '../../lib/index.js';
77
import { bBox, font } from '../drawing/index.js';
@@ -257,7 +257,7 @@ function draw(gd, titleClass, options) {
257257
.call(svgTextUtils.convertToTspans, gd);
258258
}
259259

260-
return Plots.previousPromises(gd);
260+
return previousPromises(gd);
261261
}
262262

263263
function scootTitle(titleAndSubtitleEls) {

src/core-factory.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Registry from './registry.js';
2424
// to_image, validate, template_api, snapshot/download
2525
import main from './plot_api/plot_api.js';
2626
import FxModule from './components/fx/index.js';
27-
import PlotsModule from './plots/plots.js';
27+
import { resize, graphJson, sendDataToCloud } from './plots/plots.js';
2828
import { version } from './version.js';
2929
import './plotcss.js';
3030

@@ -72,11 +72,7 @@ export function createPlotly({ traces = [], components = [], Icons, Snapshot, Pl
7272
delete window.PlotlyLocales;
7373
}
7474

75-
Plotly.Plots = {
76-
resize: PlotsModule.resize,
77-
graphJson: PlotsModule.graphJson,
78-
sendDataToCloud: PlotsModule.sendDataToCloud,
79-
};
75+
Plotly.Plots = { resize, graphJson, sendDataToCloud };
8076
Plotly.Fx = {
8177
hover: FxModule.hover,
8278
unhover: FxModule.unhover,

src/plot_api/helpers.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import isNumeric from 'fast-isnumeric';
22
import Registry from '../registry.js';
33
import { isIndex, isPlainObject, log, nestedProperty, swapAttrs, warn } from '../lib/index.js';
4-
import Plots from '../plots/plots.js';
4+
// Note: subplotsRegistry access goes through Registry directly
5+
// (no longer mixed into Plots via extendFlat)
56
import AxisIds from '../plots/cartesian/axis_ids.js';
67
import Color from '../components/color/index.js';
78

@@ -38,10 +39,10 @@ export var cleanLayout = function (layout) {
3839
delete layout.scene1;
3940
}
4041

41-
var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex;
42-
var polarAttrRegex = (Plots.subplotsRegistry.polar || {}).attrRegex;
43-
var ternaryAttrRegex = (Plots.subplotsRegistry.ternary || {}).attrRegex;
44-
var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex;
42+
var axisAttrRegex = (Registry.subplotsRegistry.cartesian || {}).attrRegex;
43+
var polarAttrRegex = (Registry.subplotsRegistry.polar || {}).attrRegex;
44+
var ternaryAttrRegex = (Registry.subplotsRegistry.ternary || {}).attrRegex;
45+
var sceneAttrRegex = (Registry.subplotsRegistry.gl3d || {}).attrRegex;
4546

4647
var keys = Object.keys(layout);
4748
for (i = 0; i < keys.length; i++) {
@@ -187,7 +188,7 @@ export var cleanData = function (data) {
187188

188189
// scene ids scene1 -> scene
189190
if (traceIs(trace, 'gl3d') && trace.scene) {
190-
trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene);
191+
trace.scene = Registry.subplotsRegistry.gl3d.cleanId(trace.scene);
191192
}
192193

193194
if (!traceIs(trace, 'pie-like') && !traceIs(trace, 'bar-like')) {

0 commit comments

Comments
 (0)