Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treemap new trace type #4185

Merged
merged 63 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ec6a9de
bar textpad const
archmoj Aug 28, 2019
52ded31
refactor base_plot files
archmoj Aug 29, 2019
320f81a
changes to sunburst attributes - add percentages - add colorscale and…
archmoj Aug 29, 2019
06d93ae
prep to add treemap to the lib
archmoj Aug 29, 2019
6cc8590
treemap mocks
archmoj Aug 28, 2019
6a595b6
treemap jasmine tests
archmoj Aug 28, 2019
671e864
treemap code
archmoj Sep 11, 2019
648167d
correct current path when there is no parent
archmoj Sep 11, 2019
6dad958
various attribute revisions
archmoj Sep 13, 2019
cceee49
drop stroke-linejoin
archmoj Sep 13, 2019
f3d38b8
revisit pathbar draw as well as transition
archmoj Sep 13, 2019
088b0e0
revert sunburst hoverinfo defaults
archmoj Sep 13, 2019
e23a577
move attachFxHandlers to fx.js
archmoj Sep 13, 2019
eb54f24
pass hover and transition options to fx
archmoj Sep 13, 2019
0e3185f
expand setSliceCursor logic to handle treemap and pathbar cases
archmoj Sep 13, 2019
fdd69e7
drop stroke-linejoin again
archmoj Sep 13, 2019
a7b6074
use constant _hoverd.marker.line.width - improve a treemap mock and u…
archmoj Sep 14, 2019
4c85360
correct transition of text inside pathbar namely when side is bottom
archmoj Sep 14, 2019
65c0e02
display percent of root on leaf when it is an entry
archmoj Sep 14, 2019
ca4b385
some refRect clean up and rename interpolator functions in sunburst a…
archmoj Sep 14, 2019
0012fa1
make the opacity logic slightly more user-friendly by applying leaf.o…
archmoj Sep 14, 2019
544977e
thanks to a typo leading to apply a better easing option suitable for…
archmoj Sep 14, 2019
13e0449
dont use sunburst naming in treemap
archmoj Sep 14, 2019
57dec38
move getTransform function to Lib and use it in bar and treemap
archmoj Sep 14, 2019
65f0213
correct exit case of zoom out when maxdepth is set - avoid overlaps a…
archmoj Sep 15, 2019
ad24987
when exiting with maxdepth try to use parent if that is visible on th…
archmoj Sep 16, 2019
36fb510
early exit out of maxdepth elements for better transitions and avoid …
archmoj Sep 16, 2019
284bf6d
add constant zero fillet - could expose that in next version
archmoj Sep 16, 2019
4e2c328
add default tests of treemap and sunburst
archmoj Sep 16, 2019
0cf5bf6
remove the case that never happens now
archmoj Sep 16, 2019
2405ba4
revisit pathbar divider default
archmoj Sep 16, 2019
19c7a61
[wip] add test for sunburst tween edge cases
etpinard Sep 17, 2019
4e3b7f3
address various treemap transition case e.g. maxdepth, tweening and p…
archmoj Sep 19, 2019
e5181ac
texttemplate and other fixes for treemap and sunburst
archmoj Sep 19, 2019
e9c0202
add calc test for count branches and leaves
archmoj Sep 19, 2019
e4bc91e
treemap drop leaf.opacity
archmoj Sep 19, 2019
a54ca9c
better description regarding the position of pathbar also move the ga…
archmoj Sep 19, 2019
d7b06a1
change divider to edgeshape
archmoj Sep 19, 2019
c91f9db
revisit ancestors draw - avoid overlaps - end pathbar with edgeshape
archmoj Sep 19, 2019
ceb13f7
tween and animate text for new points on pathbar from their parent
archmoj Sep 19, 2019
1270d67
draw new points of pathbar below parents (to avoid text overlay) - im…
archmoj Sep 20, 2019
35ea4b3
correct current path function - reuse listPath in helpers i.e. to hav…
archmoj Sep 20, 2019
1de80d9
add mock to test with and without values - and pathbar fade with depth
archmoj Sep 20, 2019
e7e22c6
texttemplate and hovertemplate fixes
archmoj Sep 20, 2019
6130f96
rename key to
archmoj Sep 20, 2019
e3a8e91
check for falsy 0 numbers when searching for level and ids
archmoj Sep 20, 2019
14674d6
handle hover edge cases
archmoj Sep 20, 2019
01c5f68
use onPathbar everywhere referring to points on pathbar - this make l…
archmoj Sep 20, 2019
4c7a092
revisit marker opacities: no opacity with colorscale, now having
archmoj Sep 21, 2019
1860826
improve sunburst texttemplate tests - drop the comment for a fixed tr…
archmoj Sep 22, 2019
d2b07b5
improve mocks to show various percentage values and colorscale using …
archmoj Sep 22, 2019
1fdf574
correct displaying percentages
archmoj Sep 23, 2019
3004a9a
fix more percentage edge cases - handle branchvalues remainder
archmoj Sep 23, 2019
4d790a1
correct texttemplate and hover
archmoj Sep 23, 2019
1c6e47b
dont touch pt.parent
archmoj Sep 23, 2019
e339bf5
Avoid using random ids in recording position of empty root
archmoj Sep 23, 2019
1309bfd
improve treemap jasmine tests
archmoj Sep 23, 2019
217c0f4
revisit sunburst and treemap percentages
archmoj Sep 24, 2019
8416883
rework working with parent references in hover and plot
archmoj Sep 24, 2019
c918da9
Reference fixups
archmoj Sep 25, 2019
7d67c7a
try to make parent getter more consistent by using pt.data.data.pid i…
archmoj Sep 25, 2019
f8cef49
add tolerance to tween tests
etpinard Sep 25, 2019
3c12bf6
remove unnecessary check for NaNs
archmoj Sep 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Plotly.register([

require('./pie'),
require('./sunburst'),
require('./treemap'),
require('./funnelarea'),

require('./scatter3d'),
Expand Down
11 changes: 11 additions & 0 deletions lib/treemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/treemap');
33 changes: 33 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,10 @@ lib.isValidTextValue = function(v) {
return v || v === 0;
};

/**
* @param {number} ratio
* @param {number} n (number of decimal places)
*/
lib.formatPercent = function(ratio, n) {
n = n || 0;
var str = (Math.round(100 * ratio * Math.pow(10, n)) * Math.pow(0.1, n)).toFixed(n) + '%';
Expand All @@ -1175,3 +1179,32 @@ lib.isHidden = function(gd) {
var display = window.getComputedStyle(gd).display;
return !display || display === 'none';
};

lib.getTextTransform = function(opts) {
var textX = opts.textX;
var textY = opts.textY;
var targetX = opts.targetX;
var targetY = opts.targetY;
var scale = opts.scale;
var rotate = opts.rotate;

var transformScale;
var transformRotate;
var transformTranslate;

if(scale < 1) transformScale = 'scale(' + scale + ') ';
else {
scale = 1;
transformScale = '';
}

transformRotate = (rotate) ?
'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : '';

// Note that scaling also affects the center of the text box
var translateX = (targetX - scale * textX);
var translateY = (targetY - scale * textY);
transformTranslate = 'translate(' + translateX + ' ' + translateY + ')';

return transformTranslate + transformScale + transformRotate;
};
5 changes: 4 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ var traceUIControlPatterns = [
{pattern: /(^|value\.)visible$/, attr: 'legend.uirevision'},
{pattern: /^dimensions\[\d+\]\.constraintrange/},
{pattern: /^node\.(x|y|groups)/}, // for Sankey nodes
{pattern: /^level$/}, // for Sunburst traces
{pattern: /^level$/}, // for Sunburst & Treemap traces

// below this you must be in editable: true mode
// TODO: I still put name and title with `trace.uirevision`
Expand Down Expand Up @@ -3780,6 +3780,9 @@ function makePlotFramework(gd) {
// single pie layer for the whole plot
fullLayout._pielayer = fullLayout._paper.append('g').classed('pielayer', true);

// single treemap layer for the whole plot
fullLayout._treemaplayer = fullLayout._paper.append('g').classed('treemaplayer', true);

// single sunburst layer for the whole plot
fullLayout._sunburstlayer = fullLayout._paper.append('g').classed('sunburstlayer', true);

Expand Down
20 changes: 19 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var axisIDs = require('./cartesian/axis_ids');
var animationAttrs = require('./animation_attributes');
var frameAttrs = require('./frame_attributes');

var getModuleCalcData = require('../plots/get_data').getModuleCalcData;

var relinkPrivateKeys = Lib.relinkPrivateKeys;
var _ = Lib._;

Expand Down Expand Up @@ -2771,9 +2773,10 @@ plots.doCalcdata = function(gd, traces) {
gd._hmpixcount = 0;
gd._hmlumcount = 0;

// for sharing colors across pies / sunbursts / funnelarea (and for legend)
// for sharing colors across pies / sunbursts / treemap / funnelarea (and for legend)
fullLayout._piecolormap = {};
fullLayout._sunburstcolormap = {};
fullLayout._treemapcolormap = {};
fullLayout._funnelareacolormap = {};

// If traces were specified and this trace was not included,
Expand Down Expand Up @@ -3203,3 +3206,18 @@ plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subpl
// update moduleName -> calcData hash
subplot.traceHash = traceHash;
};

plots.plotBasePlot = function(desiredType, gd, traces, transitionOpts, makeOnCompleteCallback) {
var _module = Registry.getModule(desiredType);
var cdmodule = getModuleCalcData(gd.calcdata, _module)[0];
_module.plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback);
};

plots.cleanBasePlot = function(desiredType, newFullData, newFullLayout, oldFullData, oldFullLayout) {
var had = (oldFullLayout._has && oldFullLayout._has(desiredType));
var has = (newFullLayout._has && newFullLayout._has(desiredType));

if(had && !has) {
oldFullLayout['_' + desiredType + 'layer'].selectAll('g.trace').remove();
}
};
2 changes: 1 addition & 1 deletion src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplat
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
var colorScaleAttrs = require('../../components/colorscale/attributes');
var fontAttrs = require('../../plots/font_attributes');
var constants = require('./constants.js');
var constants = require('./constants');

var extendFlat = require('../../lib/extend').extendFlat;

Expand Down
1 change: 1 addition & 0 deletions src/traces/bar/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
'use strict';

module.exports = {
TEXTPAD: 3, // padding in pixels around text
eventDataKeys: []
};
38 changes: 4 additions & 34 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ var tickText = require('../../plots/cartesian/axes').tickText;

var style = require('./style');
var helpers = require('./helpers');
var constants = require('./constants');
var attributes = require('./attributes');

var attributeText = attributes.text;
var attributeTextPosition = attributes.textposition;

var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;

// padding in pixels around text
var TEXTPAD = 3;
var TEXTPAD = constants.TEXTPAD;

function dirSign(a, b) {
return (a < b) ? 1 : -1;
Expand Down Expand Up @@ -342,7 +342,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
trace.constraintext === 'both' ||
trace.constraintext === 'outside';

transform = getTransform(toMoveOutsideBar(x0, x1, y0, y1, textBB, {
transform = Lib.getTextTransform(toMoveOutsideBar(x0, x1, y0, y1, textBB, {
isHorizontal: isHorizontal,
constrained: constrained,
angle: trace.textangle
Expand All @@ -352,7 +352,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
trace.constraintext === 'both' ||
trace.constraintext === 'inside';

transform = getTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
transform = Lib.getTextTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
isHorizontal: isHorizontal,
constrained: constrained,
angle: trace.textangle,
Expand Down Expand Up @@ -510,35 +510,6 @@ function toMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
};
}

function getTransform(opts) {
var textX = opts.textX;
var textY = opts.textY;
var targetX = opts.targetX;
var targetY = opts.targetY;
var scale = opts.scale;
var rotate = opts.rotate;

var transformScale;
var transformRotate;
var transformTranslate;

if(scale < 1) transformScale = 'scale(' + scale + ') ';
else {
scale = 1;
transformScale = '';
}

transformRotate = (rotate) ?
'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : '';

// Note that scaling also affects the center of the text box
var translateX = (targetX - scale * textX);
var translateY = (targetY - scale * textY);
transformTranslate = 'translate(' + translateX + ' ' + translateY + ')';

return transformTranslate + transformScale + transformRotate;
}

function getText(fullLayout, calcTrace, index, xa, ya) {
var trace = calcTrace[0].trace;
var texttemplate = trace.texttemplate;
Expand Down Expand Up @@ -695,7 +666,6 @@ function calcTextinfo(calcTrace, index, xa, ya) {

module.exports = {
plot: plot,
getTransform: getTransform,
toMoveInsideBar: toMoveInsideBar,
toMoveOutsideBar: toMoveOutsideBar
};
16 changes: 4 additions & 12 deletions src/traces/funnelarea/base_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@

'use strict';

var Registry = require('../../registry');
var getModuleCalcData = require('../../plots/get_data').getModuleCalcData;
var plots = require('../../plots/plots');

exports.name = 'funnelarea';

exports.plot = function(gd) {
var Funnelarea = Registry.getModule('funnelarea');
var cdFunnelarea = getModuleCalcData(gd.calcdata, Funnelarea)[0];
Funnelarea.plot(gd, cdFunnelarea);
exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
plots.plotBasePlot(exports.name, gd, traces, transitionOpts, makeOnCompleteCallback);
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var hadFunnelarea = (oldFullLayout._has && oldFullLayout._has('funnelarea'));
var hasFunnelarea = (newFullLayout._has && newFullLayout._has('funnelarea'));

if(hadFunnelarea && !hasFunnelarea) {
oldFullLayout._funnelarealayer.selectAll('g.trace').remove();
}
plots.cleanBasePlot(exports.name, newFullData, newFullLayout, oldFullData, oldFullLayout);
};
3 changes: 1 addition & 2 deletions src/traces/funnelarea/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var Lib = require('../../lib');
var svgTextUtils = require('../../lib/svg_text_utils');

var barPlot = require('../bar/plot');
var getTransform = barPlot.getTransform;
var toMoveInsideBar = barPlot.toMoveInsideBar;

var pieHelpers = require('../pie/helpers');
Expand Down Expand Up @@ -115,7 +114,7 @@ module.exports = function plot(gd, cdModule) {
x0 = Math.max(pt.TL[0], pt.BL[0]);
x1 = Math.min(pt.TR[0], pt.BR[0]);

transform = getTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
transform = Lib.getTextTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
isHorizontal: true,
constrained: true,
angle: 0,
Expand Down
16 changes: 4 additions & 12 deletions src/traces/indicator/base_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@

'use strict';

var Registry = require('../../registry');
var getModuleCalcData = require('../../plots/get_data').getModuleCalcData;
var plots = require('../../plots/plots');

var name = exports.name = 'indicator';
exports.name = 'indicator';

exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
var _module = Registry.getModule(name);
var cdmodule = getModuleCalcData(gd.calcdata, _module)[0];
_module.plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback);
plots.plotBasePlot(exports.name, gd, traces, transitionOpts, makeOnCompleteCallback);
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var had = (oldFullLayout._has && oldFullLayout._has(name));
var has = (newFullLayout._has && newFullLayout._has(name));

if(had && !has) {
oldFullLayout._indicatorlayer.selectAll('g.trace').remove();
}
plots.cleanBasePlot(exports.name, newFullData, newFullLayout, oldFullData, oldFullLayout);
};
16 changes: 4 additions & 12 deletions src/traces/pie/base_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@

'use strict';

var Registry = require('../../registry');
var getModuleCalcData = require('../../plots/get_data').getModuleCalcData;
var plots = require('../../plots/plots');

exports.name = 'pie';

exports.plot = function(gd) {
var Pie = Registry.getModule('pie');
var cdPie = getModuleCalcData(gd.calcdata, Pie)[0];
Pie.plot(gd, cdPie);
exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
plots.plotBasePlot(exports.name, gd, traces, transitionOpts, makeOnCompleteCallback);
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var hadPie = (oldFullLayout._has && oldFullLayout._has('pie'));
var hasPie = (newFullLayout._has && newFullLayout._has('pie'));

if(hadPie && !hasPie) {
oldFullLayout._pielayer.selectAll('g.trace').remove();
}
plots.cleanBasePlot(exports.name, newFullData, newFullLayout, oldFullData, oldFullLayout);
};
Loading