Skip to content

Colorbar refactor #3786

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

Merged
merged 20 commits into from
Apr 29, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
rename outerCont -> parentCont + add jsDoc
  • Loading branch information
etpinard committed Apr 29, 2019
commit 29a92a60ad17c2dfcae1021a924f3e2f433058b2
39 changes: 25 additions & 14 deletions src/components/colorscale/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,38 @@ var colorbarDefaults = require('../colorbar/defaults');
var isValidScale = require('./scales').isValid;
var traceIs = require('../../registry').traceIs;

function npMaybe(outerCont, prefix) {
function npMaybe(parentCont, prefix) {
var containerStr = prefix.slice(0, prefix.length - 1);
return prefix ?
Lib.nestedProperty(outerCont, containerStr).get() || {} :
outerCont;
Lib.nestedProperty(parentCont, containerStr).get() || {} :
parentCont;
}

module.exports = function colorScaleDefaults(outerContIn, outerContOut, layout, coerce, opts) {
/**
* Colorscale / colorbar default handler
*
* @param {object} parentContIn : user (input) parent container (e.g. trace or layout coloraxis object)
* @param {object} parentContOut : full parent container
* @param {object} layout : (full) layout object
* @param {fn} coerce : Lib.coerce wrapper
* @param {object} opts :
* - prefix {string} : attr string prefix to colorscale container from parent root
* - cLetter {string} : 'c or 'z' color letter
*/
module.exports = function colorScaleDefaults(parentContIn, parentContOut, layout, coerce, opts) {
var prefix = opts.prefix;
var cLetter = opts.cLetter;
var inTrace = '_module' in outerContOut;
var containerIn = npMaybe(outerContIn, prefix);
var containerOut = npMaybe(outerContOut, prefix);
var template = npMaybe(outerContOut._template || {}, prefix) || {};
var inTrace = '_module' in parentContOut;
var containerIn = npMaybe(parentContIn, prefix);
var containerOut = npMaybe(parentContOut, prefix);
var template = npMaybe(parentContOut._template || {}, prefix) || {};

// colorScaleDefaults wrapper called if-ever we need to reset the colorscale
// attributes for containers that were linked to invalid color axes
var thisFn = function() {
delete outerContIn.coloraxis;
delete outerContOut.coloraxis;
return colorScaleDefaults(outerContIn, outerContOut, layout, coerce, opts);
delete parentContIn.coloraxis;
delete parentContOut.coloraxis;
return colorScaleDefaults(parentContIn, parentContOut, layout, coerce, opts);
};

if(inTrace) {
Expand All @@ -46,8 +57,8 @@ module.exports = function colorScaleDefaults(outerContIn, outerContOut, layout,

if(colorAx) {
var colorbarVisuals = (
traceIs(outerContOut, 'contour') &&
Lib.nestedProperty(outerContOut, 'contours.coloring').get()
traceIs(parentContOut, 'contour') &&
Lib.nestedProperty(parentContOut, 'contours.coloring').get()
) || 'heatmap';

var stash = colorAxes[colorAx];
Expand All @@ -67,7 +78,7 @@ module.exports = function colorScaleDefaults(outerContIn, outerContOut, layout,
// - colorbar visual 'type'
// - colorbar options to help in Colorbar.draw
// - list of colorScaleDefaults wrapper functions
colorAxes[colorAx] = [colorbarVisuals, outerContOut, [thisFn]];
colorAxes[colorAx] = [colorbarVisuals, parentContOut, [thisFn]];
}
return;
}
Expand Down