Skip to content

Commit 278ed7c

Browse files
committed
first cut "Trace module design" section
1 parent 636b44e commit 278ed7c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

CONTRIBUTING.md

+49
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,55 @@ This will produce the following plot, and say you want to simulate a selection p
227227
- Test dashboard and image viewer code is in `devtools/`
228228
- Built files are in `build/` (the files in here are git-ignored, except for `plotcss.js`)
229229

230+
## Trace module design
231+
232+
The trace modules (found in [`src/traces`](https://github.com/plotly/plotly.js/tree/master/src/traces))
233+
are defined as plain objects with functions and constants attached to them in an index file
234+
(e.g. `src/traces/scatter/index.js`). The trace modules are "registered" undo the `Registry` object
235+
(found in [`src/registry.js`](https://github.com/plotly/plotly.js/blob/master/src/registry.js)) using
236+
`Plotly.register` (as done in the index files in `dist/`).
237+
238+
The trace module methods are meant to be called as part of loops during subplot-specific
239+
(e.g. in `plots/cartesian/index.js`) and figure-wide (e.g. in `plots/plots.js`) subroutines.
240+
That way, the subroutines work no matter which trace modules got registered.
241+
242+
All traces modules defined:
243+
244+
- `_module.name`: name of the trace module as used by the trace `type` attribute.
245+
- `_module.basePlotModule`: base plot (or subplot) module corresponding to the
246+
trace type (e.g. `scatter` links up the `Cartesian` base plot module, `scatter3d` links up `gl3d`).
247+
- `_module.attributes`: JSON-serializable object of attribute declarations.
248+
This object is used to generate the plot-schema JSON.
249+
- `_module.supplyDefaults`: Takes in input trace settings and coerces them into "full" settings
250+
under `gd._fullData`. This one is called during the figure-wide `Plots.supplyDefaults` routine.
251+
Note that the `suppyDefaults` method performance should scale with the number of attribute **not** the
252+
number of data points.
253+
- `_module.calc`: Converts inputs data into "calculated" (or sanitized) data. This one is called during
254+
the figure-wide `Plots.doCalcdata` routine. The `calc` method is allowed to
255+
scale with the number of data points and is in general more costly than `supplyDefaults`.
256+
Please note that some edit pathways skip `Plots.doCalcdata`.
257+
- `_module.plot`: Draws the trace on screen. This one is called by the defined `basePlotModule`.
258+
259+
Other methods used by some trace modules:
260+
261+
- `_module.categories`: list of string identifies used to grouped traces by behavior
262+
- `_module.layoutAttributes`: JSON-serializable object of attribute declarations
263+
in the layout (e.g. `barmode` for `bar` traces)
264+
- `_module.supplyLayoutDefaults`: Default logic for layout attributes.
265+
- `_module.crossTraceDefaults`: Default logic that depends on input setting of multiple traces.
266+
- `_module.crossTraceCalc`: Computations that depend on the data of multiple traces.
267+
- `_module.colorbar`: Defines the colorbar appearance when the trace supports it.
268+
- `_module.hoverPoints`: Point-picking logic called during hover.
269+
- `_module.selectPoints`: Polygon-containing logic called during selections.
270+
- `_module.style`: Sometimes split from `_module.plot` where `_module.plot` only
271+
draws the elements and `_module.style` styles them.
272+
- `_module.styleOnSelect`: Optimization of `_module.style` called during
273+
selections.
274+
- `_module.convert`: Sometimes separated from `_module.plot` or `_module.calc` to convert the
275+
plotly.js settings to another framework e.g. to `gl-plot3d` for `gl3d` traces, to
276+
`mapbox-gl` from `mapbox` traces. This split can also make the logic easier to
277+
test.
278+
230279
## Coding style
231280

232281
Check if ok, with `npm run lint`

0 commit comments

Comments
 (0)