Skip to content

Commit 1238236

Browse files
committed
transforms: add 'calcTransform' handler in doCalcdata
- to allow calcTransform methods where fullTrace / or calcdata items can be modified during the calc step. - this allows writing transforms that are applied after much of the 'computed' fields are filled e.g. axis (auto) 'type' - calcTransforms can only manipulate trace object 1-to-1 e.g. grouping operation should be done at the defaults step as previously.
1 parent 64dc72a commit 1238236

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/plots/plots.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ plots.doCalcdata = function(gd, traces) {
15811581
var axList = Plotly.Axes.list(gd),
15821582
fullData = gd._fullData,
15831583
fullLayout = gd._fullLayout,
1584-
i;
1584+
i, j;
15851585

15861586
// XXX: Is this correct? Needs a closer look so that *some* traces can be recomputed without
15871587
// *all* needing doCalcdata:
@@ -1619,7 +1619,6 @@ plots.doCalcdata = function(gd, traces) {
16191619
}
16201620

16211621
var trace = fullData[i],
1622-
_module = trace._module,
16231622
cd = [];
16241623

16251624
// If traces were specified and this trace was not included, then transfer it over from
@@ -1629,8 +1628,30 @@ plots.doCalcdata = function(gd, traces) {
16291628
continue;
16301629
}
16311630

1632-
if(_module && trace.visible === true) {
1633-
if(_module.calc) cd = _module.calc(gd, trace);
1631+
var _module;
1632+
if(trace.visible === true) {
1633+
1634+
// call calcTransform method if any
1635+
if(trace.transforms) {
1636+
1637+
// we need one round of of trace module calc before
1638+
// the calc transform to 'fill in' the categories list
1639+
// used for example in the data-to-coordinate method
1640+
_module = trace._module;
1641+
if(_module && _module.calc) _module.calc(gd, trace);
1642+
1643+
for(j = 0; j < trace.transforms.length; j++) {
1644+
var transform = trace.transforms[j];
1645+
1646+
_module = transformsRegistry[transform.type];
1647+
if(_module && _module.calcTransform) {
1648+
_module.calcTransform(gd, trace, transform);
1649+
}
1650+
}
1651+
}
1652+
1653+
_module = trace._module;
1654+
if(_module && _module.calc) cd = _module.calc(gd, trace);
16341655
}
16351656

16361657
// make sure there is a first point

0 commit comments

Comments
 (0)