Skip to content

Commit ce39cf5

Browse files
committed
put plot components into src/components/
1 parent db76f02 commit ce39cf5

19 files changed

+1469
-4590
lines changed

src/axes.js

Lines changed: 0 additions & 3154 deletions
This file was deleted.

src/annotations.js renamed to src/components/annotations/annotations.js

Lines changed: 5 additions & 286 deletions
Original file line numberDiff line numberDiff line change
@@ -1,293 +1,14 @@
11
'use strict';
22

3-
var Plotly = require('./plotly');
3+
var Plotly = require('../../plotly');
44
var d3 = require('d3');
55
var isNumeric = require('fast-isnumeric');
66

77
var annotations = module.exports = {};
88

9-
// centerx is a center of scaling tuned for maximum scalability of
10-
// the arrowhead ie throughout mag=0.3..3 the head is joined smoothly
11-
// to the line, but the endpoint moves.
12-
// backoff is the distance to move the arrowhead, and the end of the
13-
// line, in order to end at the right place
14-
// TODO: option to have the pointed-to point a little in front of the
15-
// end of the line, as people tend to want a bit of a gap there...
16-
annotations.ARROWPATHS = [
17-
// no arrow
18-
'',
19-
// wide with flat back
20-
{
21-
path: 'M-2.4,-3V3L0.6,0Z',
22-
backoff: 0.6
23-
},
24-
// narrower with flat back
25-
{
26-
path: 'M-3.7,-2.5V2.5L1.3,0Z',
27-
backoff: 1.3
28-
},
29-
// barbed
30-
{
31-
path: 'M-4.45,-3L-1.65,-0.2V0.2L-4.45,3L1.55,0Z',
32-
backoff: 1.55
33-
},
34-
// wide line-drawn
35-
{
36-
path: 'M-2.2,-2.2L-0.2,-0.2V0.2L-2.2,2.2L-1.4,3L1.6,0L-1.4,-3Z',
37-
backoff: 1.6
38-
},
39-
// narrower line-drawn
40-
{
41-
path: 'M-4.4,-2.1L-0.6,-0.2V0.2L-4.4,2.1L-4,3L2,0L-4,-3Z',
42-
backoff: 2
43-
},
44-
// circle
45-
{
46-
path: 'M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z',
47-
backoff: 0
48-
},
49-
// square
50-
{
51-
path: 'M2,2V-2H-2V2Z',
52-
backoff: 0
53-
}
54-
];
55-
56-
annotations.layoutAttributes = {
57-
_isLinkedToArray: true,
58-
59-
text: {
60-
valType: 'string',
61-
role: 'info',
62-
description: [
63-
'Sets the text associated with this annotation.',
64-
'Plotly uses a subset of HTML tags to do things like',
65-
'newline (<br>), bold (<b></b>), italics (<i></i>),',
66-
'hyperlinks (<a href=\'...\'></a>). Tags <em>, <sup>, <sub>',
67-
'<span> are also supported.'
68-
].join(' ')
69-
},
70-
textangle: {
71-
valType: 'angle',
72-
dflt: 0,
73-
role: 'style',
74-
description: [
75-
'Sets the angle at which the `text` is drawn',
76-
'with respect to the horizontal.'
77-
].join(' ')
78-
},
79-
font: Plotly.Lib.extendFlat({}, Plotly.Plots.fontAttrs, {
80-
description: 'Sets the annotation text font.'
81-
}),
82-
opacity: {
83-
valType: 'number',
84-
min: 0,
85-
max: 1,
86-
dflt: 1,
87-
role: 'style',
88-
description: 'Sets the opacity of the annotation (text + arrow).'
89-
},
90-
align: {
91-
valType: 'enumerated',
92-
values: ['left', 'center', 'right'],
93-
dflt: 'center',
94-
role: 'style',
95-
description: [
96-
'Sets the vertical alignment of the `text` with',
97-
'respect to the set `x` and `y` position.',
98-
'Has only an effect if `text` spans more two or more lines',
99-
'(i.e. `text` contains one or more <br> HTML tags).'
100-
].join(' ')
101-
},
102-
bgcolor: {
103-
valType: 'color',
104-
dflt: 'rgba(0,0,0,0)',
105-
role: 'style',
106-
description: 'Sets the background color of the annotation.'
107-
},
108-
bordercolor: {
109-
valType: 'color',
110-
dflt: 'rgba(0,0,0,0)',
111-
role: 'style',
112-
description: [
113-
'Sets the color of the border enclosing the annotation `text`.'
114-
].join(' ')
115-
},
116-
borderpad: {
117-
valType: 'number',
118-
min: 0,
119-
dflt: 1,
120-
role: 'style',
121-
description: [
122-
'Sets the padding (in px) between the `text`',
123-
'and the enclosing border.'
124-
].join(' ')
125-
},
126-
borderwidth: {
127-
valType: 'number',
128-
min: 0,
129-
dflt: 1,
130-
role: 'style',
131-
description: [
132-
'Sets the width (in px) of the border enclosing',
133-
'the annotation `text`.'
134-
].join(' ')
135-
},
136-
// arrow
137-
showarrow: {
138-
valType: 'boolean',
139-
dflt: true,
140-
role: 'style',
141-
description: [
142-
'Determines whether or not the annotation is drawn with an arrow.',
143-
'If *true*, `text` is placed near the arrow\'s tail.',
144-
'If *false*, `text` lines up with the `x` and `y` provided.'
145-
].join(' ')
146-
},
147-
arrowcolor: {
148-
valType: 'color',
149-
role: 'style',
150-
description: 'Sets the color of the annotation arrow.'
151-
},
152-
arrowhead: {
153-
valType: 'integer',
154-
min: 0,
155-
max: annotations.ARROWPATHS.length,
156-
dflt: 1,
157-
role: 'style',
158-
description: 'Sets the annotation arrow head style.'
159-
},
160-
arrowsize: {
161-
valType: 'number',
162-
min: 0.3,
163-
dflt: 1,
164-
role: 'style',
165-
description: 'Sets the size (in px) of annotation arrow head.'
166-
},
167-
arrowwidth: {
168-
valType: 'number',
169-
min: 0.1,
170-
role: 'style',
171-
description: 'Sets the width (in px) of annotation arrow.'
172-
},
173-
ax: {
174-
valType: 'number',
175-
dflt: -10,
176-
role: 'info',
177-
description: [
178-
'Sets the x component of the arrow tail about the arrow head.',
179-
'A positive (negative) component corresponds to an arrow pointing',
180-
'from right to left (left to right)'
181-
].join(' ')
182-
},
183-
ay: {
184-
valType: 'number',
185-
dflt: -30,
186-
role: 'info',
187-
description: [
188-
'Sets the y component of the arrow tail about the arrow head.',
189-
'A positive (negative) component corresponds to an arrow pointing',
190-
'from bottom to top (top to bottom)'
191-
].join(' ')
192-
},
193-
// positioning
194-
xref: {
195-
valType: 'enumerated',
196-
values: [
197-
'paper',
198-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString()
199-
],
200-
role: 'info',
201-
description: [
202-
'Sets the annotation\'s x coordinate axis.',
203-
'If set to an x axis id (e.g. *x* or *x2*), the `x` position',
204-
'refers to an x coordinate',
205-
'If set to *paper*, the `x` position refers to the distance from',
206-
'the left side of the plotting area in normalized coordinates',
207-
'where 0 (1) corresponds to the left (right) side.'
208-
].join(' ')
209-
},
210-
x: {
211-
valType: 'number',
212-
role: 'info',
213-
description: [
214-
'Sets the annotation\'s x position.',
215-
'Note that dates and categories are converted to numbers.'
216-
].join(' ')
217-
},
218-
xanchor: {
219-
valType: 'enumerated',
220-
values: ['auto', 'left', 'center', 'right'],
221-
dflt: 'auto',
222-
role: 'info',
223-
description: [
224-
'Sets the annotation\'s horizontal position anchor',
225-
'This anchor binds the `x` position to the *left*, *center*',
226-
'or *right* of the annotation.',
227-
'For example, if `x` is set to 1, `xref` to *paper* and',
228-
'`xanchor` to *right* then the right-most portion of the',
229-
'annotation lines up with the right-most edge of the',
230-
'plotting area.',
231-
'If *auto*, the anchor is equivalent to *center* for',
232-
'data-referenced annotations',
233-
'whereas for paper-referenced, the anchor picked corresponds',
234-
'to the closest side.'
235-
].join(' ')
236-
},
237-
yref: {
238-
valType: 'enumerated',
239-
values: [
240-
'paper',
241-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
242-
],
243-
role: 'info',
244-
description: [
245-
'Sets the annotation\'s y coordinate axis.',
246-
'If set to an y axis id (e.g. *y* or *y2*), the `y` position',
247-
'refers to an y coordinate',
248-
'If set to *paper*, the `y` position refers to the distance from',
249-
'the bottom of the plotting area in normalized coordinates',
250-
'where 0 (1) corresponds to the bottom (top).'
251-
].join(' ')
252-
},
253-
y: {
254-
valType: 'number',
255-
role: 'info',
256-
description: [
257-
'Sets the annotation\'s y position.',
258-
'Note that dates and categories are converted to numbers.'
259-
].join(' ')
260-
},
261-
yanchor: {
262-
valType: 'enumerated',
263-
values: ['auto', 'top', 'middle', 'bottom'],
264-
dflt: 'auto',
265-
role: 'info',
266-
description: [
267-
'Sets the annotation\'s vertical position anchor',
268-
'This anchor binds the `y` position to the *top*, *middle*',
269-
'or *bottom* of the annotation.',
270-
'For example, if `y` is set to 1, `yref` to *paper* and',
271-
'`yanchor` to *top* then the top-most portion of the',
272-
'annotation lines up with the top-most edge of the',
273-
'plotting area.',
274-
'If *auto*, the anchor is equivalent to *middle* for',
275-
'data-referenced annotations',
276-
'whereas for paper-referenced, the anchor picked corresponds',
277-
'to the closest side.'
278-
].join(' ')
279-
},
280-
281-
_deprecated: {
282-
ref: {
283-
valType: 'string',
284-
role: 'info',
285-
description: [
286-
'Obsolete. Set `xref` and `yref` separately instead.'
287-
].join(' ')
288-
}
289-
}
290-
};
9+
annotations.ARROWPATHS = require('./arrow_paths');
10+
11+
annotations.layoutAttributes = require('./attributes');
29112

29213
annotations.supplyLayoutDefaults = function(layoutIn, layoutOut) {
29314
var containerIn = layoutIn.annotations || [],
@@ -302,9 +23,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
30223
var annOut = {};
30324

30425
function coerce(attr, dflt) {
305-
return Plotly.Lib.coerce(annIn, annOut,
306-
annotations.layoutAttributes,
307-
attr, dflt);
26+
return Plotly.Lib.coerce(annIn, annOut, annotations.layoutAttributes, attr, dflt);
30827
}
30928

31029
coerce('opacity');
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* centerx is a center of scaling tuned for maximum scalability of
3+
* the arrowhead ie throughout mag=0.3..3 the head is joined smoothly
4+
* to the line, but the endpoint moves.
5+
* backoff is the distance to move the arrowhead, and the end of the
6+
* line, in order to end at the right place
7+
*
8+
* TODO: option to have the pointed-to point a little in front of the
9+
* end of the line, as people tend to want a bit of a gap there...
10+
*/
11+
module.exports = [
12+
// no arrow
13+
'',
14+
// wide with flat back
15+
{
16+
path: 'M-2.4,-3V3L0.6,0Z',
17+
backoff: 0.6
18+
},
19+
// narrower with flat back
20+
{
21+
path: 'M-3.7,-2.5V2.5L1.3,0Z',
22+
backoff: 1.3
23+
},
24+
// barbed
25+
{
26+
path: 'M-4.45,-3L-1.65,-0.2V0.2L-4.45,3L1.55,0Z',
27+
backoff: 1.55
28+
},
29+
// wide line-drawn
30+
{
31+
path: 'M-2.2,-2.2L-0.2,-0.2V0.2L-2.2,2.2L-1.4,3L1.6,0L-1.4,-3Z',
32+
backoff: 1.6
33+
},
34+
// narrower line-drawn
35+
{
36+
path: 'M-4.4,-2.1L-0.6,-0.2V0.2L-4.4,2.1L-4,3L2,0L-4,-3Z',
37+
backoff: 2
38+
},
39+
// circle
40+
{
41+
path: 'M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z',
42+
backoff: 0
43+
},
44+
// square
45+
{
46+
path: 'M2,2V-2H-2V2Z',
47+
backoff: 0
48+
}
49+
];

0 commit comments

Comments
 (0)