Skip to content

Commit 280a0a1

Browse files
committed
treemap remaining items - rework key functions - jasmine tests - descriptions
1 parent 7df59a5 commit 280a0a1

File tree

6 files changed

+29
-69
lines changed

6 files changed

+29
-69
lines changed

src/traces/sunburst/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function plotOne(gd, cd, element, transitionOpts) {
151151
var transTextX = function(d) { return cx + d.pxmid[0] * d.transform.rCenter + (d.transform.x || 0); };
152152
var transTextY = function(d) { return cy + d.pxmid[1] * d.transform.rCenter + (d.transform.y || 0); };
153153

154-
slices = slices.data(sliceData, function(pt) { return helpers.getPtId(pt); });
154+
slices = slices.data(sliceData, helpers.getPtId);
155155

156156
slices.enter().append('g')
157157
.classed('slice', true);

src/traces/treemap/attributes.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ module.exports = {
147147
'Fades headers towards the background.',
148148
'When `marker.colors` are not set within the trace it is defaulted to *false*;',
149149
'otherwise it is defaulted to *true*.',
150-
'This options is not available when having a `colorscale` or',
151-
'when .'
150+
'This option is not available when having a `colorscale`.'
152151
].join(' ')
153152
},
154153

@@ -225,8 +224,8 @@ module.exports = {
225224
min: 0,
226225
dflt: 0.5,
227226
description: [
228-
'Sets the opacity of the pathbar',
229-
'This options is not available when having a `colorscale`.'
227+
'Sets the opacity of the pathbar.',
228+
'This option is not available when having a `colorscale`.'
230229
].join(' ')
231230
},
232231

src/traces/treemap/draw_ancestors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
7373

7474
sliceData.reverse();
7575

76-
slices = slices.data(sliceData, function(pt) { return helpers.getPtId(pt); });
76+
slices = slices.data(sliceData, helpers.getPtId);
7777

7878
slices.enter().append('g')
7979
.classed('pathbar', true);

src/traces/treemap/draw_descendants.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
6767

6868
var minVisibleDepth = Infinity;
6969
var maxVisibleDepth = -Infinity;
70-
71-
slices = slices.data(sliceData, function(pt) {
70+
sliceData.forEach(function(pt) {
7271
var depth = pt.depth;
7372
if(depth >= trace._maxDepth) {
7473
// hide slices that won't show up on graph
@@ -78,10 +77,10 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
7877
minVisibleDepth = Math.min(minVisibleDepth, depth);
7978
maxVisibleDepth = Math.max(maxVisibleDepth, depth);
8079
}
81-
82-
return helpers.getPtId(pt);
8380
});
8481

82+
slices = slices.data(sliceData, helpers.getPtId);
83+
8584
trace._maxVisibleLayers = isFinite(maxVisibleDepth) ? maxVisibleDepth - minVisibleDepth + 1 : 0;
8685

8786
slices.enter().append('g')

test/jasmine/tests/sunburst_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('Test sunburst defaults:', function() {
115115
expect(fullData[1].marker.line.color).toBe('#fff', 'dflt');
116116
});
117117

118-
it('should default *leaf.opacity* depending on having or not having *colorscale*', function() {
118+
it('should default *leaf.opacity* depending on a *colorscale* being present or not', function() {
119119
_supply([
120120
{labels: [1], parents: ['']},
121121
{labels: [1], parents: [''], marker: {colorscale: 'Blues'}}
@@ -154,15 +154,15 @@ describe('Test sunburst defaults:', function() {
154154
.toEqual(['cyan', 'yellow', 'black'], 'user-defined value');
155155
});
156156

157-
it('should not default *marker.colorscale* when not having *marker.colors*', function() {
157+
it('should not default *marker.colorscale* when *marker.colors* is not present', function() {
158158
_supply([
159159
{labels: [1], parents: ['']}
160160
]);
161161

162162
expect(fullData[0].marker.colorscale).toBe(undefined);
163163
});
164164

165-
it('should default *marker.colorscale* to *Reds* when having *marker.colors*', function() {
165+
it('should default *marker.colorscale* to *Reds* when *marker.colors* is present', function() {
166166
_supply([
167167
{labels: [1], parents: [''], marker: {
168168
colors: [0]

test/jasmine/tests/treemap_test.js

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,22 @@ describe('Test treemap defaults:', function() {
116116
expect(fullData[1].marker.line.color).toBe('#fff', 'dflt');
117117
});
118118

119-
it('should not coerce *marker.opacitybase* and *pathbar.opacity* when having *colorscale*', function() {
119+
it('should default *marker.depthfade* depending on *marker.colors* is present or not', function() {
120+
_supply([
121+
{labels: ['A', 'B', 'a'], parents: ['', '', 'A']},
122+
{labels: ['A', 'B', 'a'], parents: ['', '', 'A'], marker: {colors: ['red', 'green', 'blue']}}
123+
]);
124+
125+
expect(fullData[0].marker.depthfade).toBe(true);
126+
expect(fullData[1].marker.depthfade).toBe(false);
127+
});
128+
129+
it('should not coerce *marker.depthfade* when a *colorscale* is present', function() {
120130
_supply([
121-
{labels: [1], parents: ['']},
122131
{labels: [1], parents: [''], marker: {colorscale: 'Blues'}}
123132
]);
124133

125-
expect(fullData[0].marker.opacitybase).toBe(0.5);
126-
expect(fullData[0].pathbar.opacity).toBe(0.5);
127-
expect(fullData[1].marker.opacitybase).toBe(undefined, 'not coerced');
128-
expect(fullData[1].pathbar.opacity).toBe(undefined, 'not coerced');
134+
expect(fullData[0].marker.depthfade).toBe(undefined);
129135
});
130136

131137
it('should use *textfont.size* to adjust top, bottom , left and right *marker.pad* defaults', function() {
@@ -263,15 +269,15 @@ describe('Test treemap defaults:', function() {
263269
expect(fullData[0].pathbar.thickness).toBe(30);
264270
});
265271

266-
it('should not default *marker.colorscale* when not having *marker.colors*', function() {
272+
it('should not default *marker.colorscale* when *marker.colors* is not present', function() {
267273
_supply([
268274
{labels: [1], parents: ['']}
269275
]);
270276

271277
expect(fullData[0].marker.colorscale).toBe(undefined);
272278
});
273279

274-
it('should default *marker.colorscale* to *Reds* when having *marker.colors*', function() {
280+
it('should default *marker.colorscale* to *Reds* when *marker.colors* is present', function() {
275281
_supply([
276282
{labels: [1], parents: [''], marker: {
277283
colors: [0]
@@ -1190,50 +1196,6 @@ describe('Test treemap restyle:', function() {
11901196
.then(done);
11911197
});
11921198

1193-
it('should be able to restyle *marker.opacitybase*', function(done) {
1194-
var mock = {
1195-
data: [{
1196-
type: 'treemap', pathbar: { visible: false },
1197-
labels: ['Root', 'A', 'B', 'b', 'b2', 'b3'],
1198-
parents: ['', 'Root', 'Root', 'B', 'b', 'b2']
1199-
}]
1200-
};
1201-
1202-
function _assert(msg, exp) {
1203-
return function() {
1204-
var layer = d3.select(gd).select('.treemaplayer');
1205-
1206-
var opacities = [];
1207-
layer.selectAll('path.surface').each(function() {
1208-
opacities.push(this.style.opacity);
1209-
});
1210-
1211-
expect(opacities).toEqual(exp, msg);
1212-
1213-
// editType:style
1214-
if(msg !== 'base') {
1215-
expect(Plots.doCalcdata).toHaveBeenCalledTimes(0);
1216-
expect(gd._fullData[0]._module.plot).toHaveBeenCalledTimes(0);
1217-
}
1218-
};
1219-
}
1220-
1221-
Plotly.plot(gd, mock)
1222-
.then(_assert('base', ['1', '1', '0.5', '0.5', '1', '1']))
1223-
.then(function() {
1224-
spyOn(Plots, 'doCalcdata').and.callThrough();
1225-
spyOn(gd._fullData[0]._module, 'plot').and.callThrough();
1226-
})
1227-
.then(_restyle({'marker.opacitybase': 0.2}))
1228-
.then(_assert('lower marker.opacitybase', ['1', '1', '0.2', '0.5', '1', '1']))
1229-
.then(_restyle({'marker.opacitybase': 0.8}))
1230-
.then(_assert('raise marker.opacitybase', ['1', '1', '0.8', '0.1', '0.2', '1']))
1231-
.then(_restyle({'marker.opacitybase': null}))
1232-
.then(_assert('back to dflt', ['1', '1', '0.5', '0.1', '0.2', '1']))
1233-
.catch(failTest)
1234-
.then(done);
1235-
});
1236-
12371199
it('should be able to restyle *pathbar.opacity*', function(done) {
12381200
var mock = {
12391201
data: [{
@@ -1264,17 +1226,17 @@ describe('Test treemap restyle:', function() {
12641226
}
12651227

12661228
Plotly.plot(gd, mock)
1267-
.then(_assert('base', ['0.5', '0.5', '1', '0.5', '0.5']))
1229+
.then(_assert('base', ['', '', '', '0.5', '0.5']))
12681230
.then(function() {
12691231
spyOn(Plots, 'doCalcdata').and.callThrough();
12701232
spyOn(gd._fullData[0]._module, 'plot').and.callThrough();
12711233
})
12721234
.then(_restyle({'pathbar.opacity': 0.2}))
1273-
.then(_assert('lower pathbar.opacity', ['0.5', '0.5', '1', '0.2', '0.2']))
1235+
.then(_assert('lower pathbar.opacity', ['', '', '', '0.2', '0.2']))
12741236
.then(_restyle({'pathbar.opacity': 0.8}))
1275-
.then(_assert('raise pathbar.opacity', ['0.5', '0.5', '1', '0.8', '0.8']))
1237+
.then(_assert('raise pathbar.opacity', ['', '', '', '0.8', '0.8']))
12761238
.then(_restyle({'pathbar.opacity': null}))
1277-
.then(_assert('back to dflt', ['0.5', '0.5', '1', '0.5', '0.5']))
1239+
.then(_assert('back to dflt', ['', '', '', '0.5', '0.5']))
12781240
.catch(failTest)
12791241
.then(done);
12801242
});

0 commit comments

Comments
 (0)