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

Sunburst traces #3594

Merged
merged 26 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4549692
move pie hover logic into own scope
etpinard Mar 1, 2019
450ceda
export of few things in Pie.plot that sunburst will reuse
etpinard Mar 1, 2019
6695e76
export a few things in Pie.calc that sunburst will reuse
etpinard Mar 1, 2019
a7e7e65
add Sunburst trace module
etpinard Mar 1, 2019
50922a6
add 4 preliminary sunburst mocks
etpinard Mar 1, 2019
a1d9b2b
adapt test syntax to not fail on `.children`
etpinard Mar 1, 2019
c1ccad6
make marker.line.width dflt 1
etpinard Mar 4, 2019
66b45ab
style up sunburst values mock a bit more
etpinard Mar 4, 2019
d5fd040
fix a couple text-rendering bug
etpinard Mar 6, 2019
a3f1cf8
fix root-level multiple-roots view when maxdepth is set
etpinard Mar 7, 2019
aa3adf3
sunburstclick transitions:
etpinard Mar 6, 2019
92e5fe7
add some TODOs about tweaning for leaf.textposition:'outside'
etpinard Mar 8, 2019
f1aa7d3
lower "full" circle tolerance, to :hocho: transition glitches
etpinard Mar 8, 2019
05a0209
adapt sunburst-specific block in assertSrcContents
etpinard Mar 8, 2019
79545db
Merge branch 'master' into sunburst
etpinard Mar 8, 2019
1584434
add a sunburst mock to mock list
etpinard Mar 19, 2019
0da13db
hook in uirevision for sunburst click handler
etpinard Mar 19, 2019
27d0bda
smooth out start/end from entry,
etpinard Mar 19, 2019
bb37e51
add sunburst jasmine suite + misc bug fixups
etpinard Mar 22, 2019
160bf4b
:hocho: leaf.textposition (for now)
etpinard Mar 22, 2019
1b21aae
use same 'stroke-linejoin' as pie traces
etpinard Mar 22, 2019
285b115
rm 'sort', 'direction' and 'rotation' attrs (for now)
etpinard Mar 22, 2019
5d981c2
Merge branch 'master' into sunburst
etpinard Mar 22, 2019
1258f2d
rename 'extra' -> 'remainder' + attrs description fixes
etpinard Mar 28, 2019
b59be1d
pull transition constants into own file, lower duration to 750ms
etpinard Mar 28, 2019
4a2f7a5
do not render hierarchy when partial sums > sector value
etpinard Mar 28, 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
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ Plotly.register([
require('./histogram'),
require('./histogram2d'),
require('./histogram2dcontour'),
require('./pie'),
require('./contour'),
require('./scatterternary'),
require('./violin'),

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

require('./scatter3d'),
require('./surface'),
require('./isosurface'),
Expand Down
11 changes: 11 additions & 0 deletions lib/sunburst.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/sunburst');
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"country-regex": "^1.1.0",
"d3": "^3.5.12",
"d3-force": "^1.0.6",
"d3-hierarchy": "^1.1.8",
"d3-interpolate": "1",
"d3-sankey-circular": "0.33.0",
"delaunay-triangulate": "^1.1.6",
Expand Down
3 changes: 2 additions & 1 deletion src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ var pointKeyMap = {
locations: 'location',
labels: 'label',
values: 'value',
'marker.colors': 'color'
'marker.colors': 'color',
parents: 'parent'
};

function getPointKey(astr) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/angles.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function rad2deg(rad) { return rad / PI * 180; }
* @return {boolean}
*/
function isFullCircle(aBnds) {
return Math.abs(aBnds[1] - aBnds[0]) > twoPI - 1e-15;
return Math.abs(aBnds[1] - aBnds[0]) > twoPI - 1e-14;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,7 @@ var traceUIControlPatterns = [
{pattern: /(^|value\.)visible$/, attr: 'legend.uirevision'},
{pattern: /^dimensions\[\d+\]\.constraintrange/},
{pattern: /^node\.(x|y)/}, // for Sankey nodes
{pattern: /^level$/}, // for Sunburst traces

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

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

// fill in image server scrape-svg
fullLayout._glimages = fullLayout._paper.append('g').classed('glimages', true);

Expand Down
3 changes: 2 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2723,8 +2723,9 @@ plots.doCalcdata = function(gd, traces) {
gd._hmpixcount = 0;
gd._hmlumcount = 0;

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

// If traces were specified and this trace was not included,
// then transfer it over from the old calcdata:
Expand Down
64 changes: 36 additions & 28 deletions src/traces/pie/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ var tinycolor = require('tinycolor2');
var Color = require('../../components/color');
var helpers = require('./helpers');

exports.calc = function calc(gd, trace) {
var pieExtendedColorWays = {};

function calc(gd, trace) {
var vals = trace.values;
var hasVals = isArrayOrTypedArray(vals) && vals.length;
var labels = trace.labels;
var colors = trace.marker.colors || [];
var cd = [];
var fullLayout = gd._fullLayout;
var colorMap = fullLayout._piecolormap;
var allThisTraceLabels = {};
var vTotal = 0;
var hiddenLabels = fullLayout.hiddenlabels || [];
Expand All @@ -36,18 +37,7 @@ exports.calc = function calc(gd, trace) {
}
}

function pullColor(color, label) {
if(!color) return false;

color = tinycolor(color);
if(!color.isValid()) return false;

color = Color.addOpacity(color, color.getAlpha());
if(!colorMap[label]) colorMap[label] = color;

return color;
}

var pullColor = makePullColorFn(fullLayout._piecolormap);
var seriesLen = (hasVals ? vals : labels).length;

for(i = 0; i < seriesLen; i++) {
Expand Down Expand Up @@ -121,7 +111,21 @@ exports.calc = function calc(gd, trace) {
}

return cd;
};
}

function makePullColorFn(colorMap) {
return function pullColor(color, id) {
if(!color) return false;

color = tinycolor(color);
if(!color.isValid()) return false;

color = Color.addOpacity(color, color.getAlpha());
if(!colorMap[id]) colorMap[id] = color;

return color;
};
}

/*
* `calc` filled in (and collated) explicit colors.
Expand All @@ -130,45 +134,41 @@ exports.calc = function calc(gd, trace) {
* This is done after sorting, so we pick defaults
* in the order slices will be displayed
*/
exports.crossTraceCalc = function(gd) {
function crossTraceCalc(gd) {
var fullLayout = gd._fullLayout;
var calcdata = gd.calcdata;
var pieColorWay = fullLayout.piecolorway;
var colorMap = fullLayout._piecolormap;

if(fullLayout.extendpiecolors) {
pieColorWay = generateExtendedColors(pieColorWay);
pieColorWay = generateExtendedColors(pieColorWay, pieExtendedColorWays);
}
var dfltColorCount = 0;

var i, j, cd, pt;
for(i = 0; i < calcdata.length; i++) {
cd = calcdata[i];
for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
if(cd[0].trace.type !== 'pie') continue;

for(j = 0; j < cd.length; j++) {
pt = cd[j];
for(var j = 0; j < cd.length; j++) {
var pt = cd[j];
if(pt.color === false) {
// have we seen this label and assigned a color to it in a previous trace?
if(colorMap[pt.label]) {
pt.color = colorMap[pt.label];
}
else {
} else {
colorMap[pt.label] = pt.color = pieColorWay[dfltColorCount % pieColorWay.length];
dfltColorCount++;
}
}
}
}
};
}

/**
* pick a default color from the main default set, augmented by
* itself lighter then darker before repeating
*/
var extendedColorWays = {};

function generateExtendedColors(colorList) {
function generateExtendedColors(colorList, extendedColorWays) {
var i;
var colorString = JSON.stringify(colorList);
var pieColors = extendedColorWays[colorString];
Expand All @@ -187,3 +187,11 @@ function generateExtendedColors(colorList) {

return pieColors;
}

module.exports = {
calc: calc,
crossTraceCalc: crossTraceCalc,

makePullColorFn: makePullColorFn,
generateExtendedColors: generateExtendedColors
};
2 changes: 1 addition & 1 deletion src/traces/pie/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var calcModule = require('./calc');
Pie.calc = calcModule.calc;
Pie.crossTraceCalc = calcModule.crossTraceCalc;

Pie.plot = require('./plot');
Pie.plot = require('./plot').plot;
Pie.style = require('./style');
Pie.styleOne = require('./style_one');

Expand Down
Loading