Skip to content

Commit a5fa3aa

Browse files
Add CONTRIBUTING.md
1 parent 2bdd3d1 commit a5fa3aa

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Contributing
2+
3+
Thanks for helping out! This converter runs in both MATLAB and GNU Octave, so
4+
changes should work in both. Below is how to run the tests and how to add
5+
support for a new plot type or gallery example.
6+
7+
## Running the tests
8+
9+
The test runner is `plotly/testing/runplotlytests.m`; it discovers every
10+
`Test_*.m` under `plotly/`.
11+
12+
```matlab
13+
addpath(fullfile(pwd, 'plotly', 'testing'));
14+
runplotlytests % everything
15+
runplotlytests('Test_m2json') % one suite
16+
runplotlytests('Test_plotlyfig_lines/testLinePlotData') % one test
17+
```
18+
19+
In Octave, install the optional packages once if you haven't:
20+
`pkg install -forge datatypes statistics`.
21+
22+
## Adding a plot handler
23+
24+
Every supported graphics type has an `updateX` function in
25+
`plotly/plotlyfig_aux/handlegraphics/`. To add one:
26+
27+
1. Inspect the object first. Octave and MATLAB expose different graphics
28+
objects. Use `get`/`set` rather than dot indexing.
29+
2. Add `plotly/plotlyfig_aux/handlegraphics/updateX.m`:
30+
31+
```matlab
32+
function obj = updateX(obj, dataIndex)
33+
h = obj.State.Plot(dataIndex).Handle;
34+
obj.data{dataIndex}.type = 'scatter';
35+
obj.data{dataIndex}.x = get(h, 'XData');
36+
obj.data{dataIndex}.y = get(h, 'YData');
37+
end
38+
```
39+
3. Register it in the switch in `plotly/plotlyfig_aux/core/updateData.m`.
40+
4. Add a test to the matching suite (`Test_plotlyfig_lines`, `_bars`, `_3d`
41+
or `_special`).
42+
43+
Reusable code belongs in `plotly/plotlyfig_aux/helpers/`; local functions in
44+
one file are not visible from another.
45+
46+
## Adding a gallery entry
47+
48+
The gallery compares native and converted figures for each entry in
49+
`galleryEntries()` at the bottom of `plotly/makegallery.m`. Add a `{name, code}`
50+
row:
51+
52+
```matlab
53+
'myplot', 'myplot(1:10, [3 5 2 8 4 6 9 1 7 5]);'; ...
54+
```
55+
56+
The gallery creates the figure for you, so the code just has to draw into it.
57+
Use fixed data (or seed the RNG) so the picture is reproducible, and keep the
58+
entry working in both engines when possible. Iterate on a single entry with:
59+
60+
```matlab
61+
makegallery('Functions', {'myplot'}, 'Open', false)
62+
```
63+
64+
Keep commits to one logical change with a short imperative message.

0 commit comments

Comments
 (0)