Skip to content

Commit a8cca6c

Browse files
committed
copy treemap
1 parent f0fef6f commit a8cca6c

16 files changed

+1751
-0
lines changed

src/traces/voronoi/attributes.js

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
'use strict';
2+
3+
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
4+
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
5+
6+
var colorScaleAttrs = require('../../components/colorscale/attributes');
7+
var domainAttrs = require('../../plots/domain').attributes;
8+
var pieAttrs = require('../pie/attributes');
9+
var sunburstAttrs = require('../sunburst/attributes');
10+
var constants = require('./constants');
11+
var extendFlat = require('../../lib/extend').extendFlat;
12+
var pattern = require('../../components/drawing/attributes').pattern;
13+
14+
module.exports = {
15+
labels: sunburstAttrs.labels,
16+
parents: sunburstAttrs.parents,
17+
18+
values: sunburstAttrs.values,
19+
branchvalues: sunburstAttrs.branchvalues,
20+
count: sunburstAttrs.count,
21+
22+
level: sunburstAttrs.level,
23+
maxdepth: sunburstAttrs.maxdepth,
24+
25+
tiling: {
26+
packing: {
27+
valType: 'enumerated',
28+
values: [
29+
'squarify',
30+
'binary',
31+
'dice',
32+
'slice',
33+
'slice-dice',
34+
'dice-slice'
35+
],
36+
dflt: 'squarify',
37+
editType: 'plot',
38+
description: [
39+
'Determines d3 treemap solver.',
40+
'For more info please refer to https://github.com/d3/d3-hierarchy#treemap-tiling'
41+
].join(' ')
42+
},
43+
44+
squarifyratio: {
45+
valType: 'number',
46+
min: 1,
47+
dflt: 1,
48+
editType: 'plot',
49+
description: [
50+
'When using *squarify* `packing` algorithm, according to https://github.com/d3/d3-hierarchy/blob/v3.1.1/README.md#squarify_ratio',
51+
'this option specifies the desired aspect ratio of the generated rectangles.',
52+
'The ratio must be specified as a number greater than or equal to one.',
53+
'Note that the orientation of the generated rectangles (tall or wide)',
54+
'is not implied by the ratio; for example, a ratio of two will attempt',
55+
'to produce a mixture of rectangles whose width:height ratio is either 2:1 or 1:2.',
56+
'When using *squarify*, unlike d3 which uses the Golden Ratio i.e. 1.618034,',
57+
'Plotly applies 1 to increase squares in treemap layouts.'
58+
].join(' ')
59+
},
60+
61+
flip: {
62+
valType: 'flaglist',
63+
flags: [
64+
'x',
65+
'y'
66+
],
67+
dflt: '',
68+
editType: 'plot',
69+
description: [
70+
'Determines if the positions obtained from solver are flipped on each axis.'
71+
].join(' ')
72+
},
73+
74+
pad: {
75+
valType: 'number',
76+
min: 0,
77+
dflt: 3,
78+
editType: 'plot',
79+
description: [
80+
'Sets the inner padding (in px).'
81+
].join(' ')
82+
},
83+
84+
editType: 'calc',
85+
},
86+
87+
marker: extendFlat({
88+
pad: {
89+
t: {
90+
valType: 'number',
91+
min: 0,
92+
editType: 'plot',
93+
description: [
94+
'Sets the padding form the top (in px).'
95+
].join(' ')
96+
},
97+
l: {
98+
valType: 'number',
99+
min: 0,
100+
editType: 'plot',
101+
description: [
102+
'Sets the padding form the left (in px).'
103+
].join(' ')
104+
},
105+
r: {
106+
valType: 'number',
107+
min: 0,
108+
editType: 'plot',
109+
description: [
110+
'Sets the padding form the right (in px).'
111+
].join(' ')
112+
},
113+
b: {
114+
valType: 'number',
115+
min: 0,
116+
editType: 'plot',
117+
description: [
118+
'Sets the padding form the bottom (in px).'
119+
].join(' ')
120+
},
121+
122+
editType: 'calc'
123+
},
124+
125+
colors: sunburstAttrs.marker.colors,
126+
127+
pattern: pattern,
128+
129+
depthfade: {
130+
valType: 'enumerated',
131+
values: [true, false, 'reversed'],
132+
editType: 'style',
133+
description: [
134+
'Determines if the sector colors are faded towards',
135+
'the background from the leaves up to the headers.',
136+
'This option is unavailable when a `colorscale` is present,',
137+
'defaults to false when `marker.colors` is set,',
138+
'but otherwise defaults to true.',
139+
'When set to *reversed*, the fading direction is inverted,',
140+
'that is the top elements within hierarchy are drawn with fully saturated colors',
141+
'while the leaves are faded towards the background color.'
142+
].join(' ')
143+
},
144+
145+
line: sunburstAttrs.marker.line,
146+
147+
cornerradius: {
148+
valType: 'number',
149+
min: 0,
150+
dflt: 0,
151+
editType: 'plot',
152+
description: [
153+
'Sets the maximum rounding of corners (in px).'
154+
].join(' ')
155+
},
156+
157+
editType: 'calc',
158+
},
159+
colorScaleAttrs('marker', {
160+
colorAttr: 'colors',
161+
anim: false // TODO: set to anim: true?
162+
})
163+
),
164+
165+
pathbar: {
166+
visible: {
167+
valType: 'boolean',
168+
dflt: true,
169+
editType: 'plot',
170+
description: [
171+
'Determines if the path bar is drawn',
172+
'i.e. outside the trace `domain` and',
173+
'with one pixel gap.'
174+
].join(' ')
175+
},
176+
177+
side: {
178+
valType: 'enumerated',
179+
values: [
180+
'top',
181+
'bottom'
182+
],
183+
dflt: 'top',
184+
editType: 'plot',
185+
description: [
186+
'Determines on which side of the the treemap the',
187+
'`pathbar` should be presented.'
188+
].join(' ')
189+
},
190+
191+
edgeshape: {
192+
valType: 'enumerated',
193+
values: [
194+
'>',
195+
'<',
196+
'|',
197+
'/',
198+
'\\'
199+
],
200+
dflt: '>',
201+
editType: 'plot',
202+
description: [
203+
'Determines which shape is used for edges between `barpath` labels.'
204+
].join(' ')
205+
},
206+
207+
thickness: {
208+
valType: 'number',
209+
min: 12,
210+
editType: 'plot',
211+
description: [
212+
'Sets the thickness of `pathbar` (in px). If not specified the `pathbar.textfont.size` is used',
213+
'with 3 pixles extra padding on each side.'
214+
].join(' ')
215+
},
216+
217+
textfont: extendFlat({}, pieAttrs.textfont, {
218+
description: 'Sets the font used inside `pathbar`.'
219+
}),
220+
221+
editType: 'calc'
222+
},
223+
224+
text: pieAttrs.text,
225+
textinfo: sunburstAttrs.textinfo,
226+
// TODO: incorporate `label` and `value` in the eventData
227+
texttemplate: texttemplateAttrs({editType: 'plot'}, {
228+
keys: constants.eventDataKeys.concat(['label', 'value'])
229+
}),
230+
231+
hovertext: pieAttrs.hovertext,
232+
hoverinfo: sunburstAttrs.hoverinfo,
233+
hovertemplate: hovertemplateAttrs({}, {
234+
keys: constants.eventDataKeys
235+
}),
236+
237+
textfont: pieAttrs.textfont,
238+
insidetextfont: pieAttrs.insidetextfont,
239+
outsidetextfont: extendFlat({}, pieAttrs.outsidetextfont, {
240+
description: [
241+
'Sets the font used for `textinfo` lying outside the sector.',
242+
'This option refers to the root of the hierarchy',
243+
'presented on top left corner of a treemap graph.',
244+
'Please note that if a hierarchy has multiple root nodes,',
245+
'this option won\'t have any effect and `insidetextfont` would be used.'
246+
].join(' ')
247+
}),
248+
249+
textposition: {
250+
valType: 'enumerated',
251+
values: [
252+
'top left', 'top center', 'top right',
253+
'middle left', 'middle center', 'middle right',
254+
'bottom left', 'bottom center', 'bottom right'
255+
],
256+
dflt: 'top left',
257+
editType: 'plot',
258+
description: [
259+
'Sets the positions of the `text` elements.'
260+
].join(' ')
261+
},
262+
sort: pieAttrs.sort,
263+
root: sunburstAttrs.root,
264+
265+
domain: domainAttrs({name: 'treemap', trace: true, editType: 'calc'}),
266+
};

src/traces/voronoi/base_plot.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
var plots = require('../../plots/plots');
4+
5+
exports.name = 'treemap';
6+
7+
exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
8+
plots.plotBasePlot(exports.name, gd, traces, transitionOpts, makeOnCompleteCallback);
9+
};
10+
11+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
12+
plots.cleanBasePlot(exports.name, newFullData, newFullLayout, oldFullData, oldFullLayout);
13+
};

src/traces/voronoi/calc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var calc = require('../sunburst/calc');
4+
5+
exports.calc = function(gd, trace) {
6+
return calc.calc(gd, trace);
7+
};
8+
9+
exports.crossTraceCalc = function(gd) {
10+
return calc._runCrossTraceCalc('treemap', gd);
11+
};

src/traces/voronoi/constants.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
module.exports = {
4+
CLICK_TRANSITION_TIME: 750,
5+
CLICK_TRANSITION_EASING: 'poly',
6+
eventDataKeys: [
7+
// string
8+
'currentPath',
9+
'root',
10+
'entry',
11+
// no need to add 'parent' here
12+
13+
// percentages i.e. ratios
14+
'percentRoot',
15+
'percentEntry',
16+
'percentParent'
17+
],
18+
gapWithPathbar: 1 // i.e. one pixel
19+
};

0 commit comments

Comments
 (0)