Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); extend zhoverformat to 2d histogram types by alexcjohnson · Pull Request #2127 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/traces/contour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,4 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
13 changes: 10 additions & 3 deletions src/traces/contour/style_defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,16 +13,17 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var Lib = require('../../lib');


module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, defaultColor, defaultWidth) {
module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
if(!opts) opts = {};
var coloring = coerce('contours.coloring');

var showLines;
var lineColor = '';
if(coloring === 'fill') showLines = coerce('contours.showlines');

if(showLines !== false) {
if(coloring !== 'lines') lineColor = coerce('line.color', defaultColor || '#000');
coerce('line.width', defaultWidth === undefined ? 0.5 : defaultWidth);
if(coloring !== 'lines') lineColor = coerce('line.color', opts.defaultColor || '#000');
coerce('line.width', opts.defaultWidth === undefined ? 0.5 : opts.defaultWidth);
coerce('line.dash');
}

Expand All@@ -44,4 +45,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout,
});
coerce('contours.labelformat');
}

if(opts.hasHover !== false) {
coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
}
};
12 changes: 8 additions & 4 deletions src/traces/contourcarpet/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,7 +80,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// If there's a fill color, use it at full opacity for the line color
var lineDfltColor = traceOut.fillcolor ? addOpacity(traceOut.fillcolor, 1) : defaultColor;

handleStyleDefaults(traceIn, traceOut, coerce, layout, lineDfltColor, 2);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {
hasHover: false,
defaultColor: lineDfltColor,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈 Shoutout to @rreusser 's numerous carpet image mocks !

defaultWidth: 2
});

if(contours.operation === '=') {
coerce('line.color', defaultColor);
Expand DownExpand Up@@ -108,8 +112,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
delete traceOut.line.maxcolor;
}

// TODO: These shouldb e deleted in accordance with toolpanel convention, but
// we can't becuase we require them so that it magically makes the contour
// TODO: These should be deleted in accordance with toolpanel convention, but
// we can't because we require them so that it magically makes the contour
// parts of the code happy:
// delete traceOut.contours.start;
// delete traceOut.contours.end;
Expand DownExpand Up@@ -141,7 +145,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('ncontours');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});

delete traceOut.value;
delete traceOut.operation;
Expand Down
11 changes: 2 additions & 9 deletions src/traces/heatmap/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ var Lib = require('../../lib');

var hasColumns = require('./has_columns');
var handleXYZDefaults = require('./xyz_defaults');
var handleStyleDefaults = require('./style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -30,17 +31,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}
handleStyleDefaults(traceIn, traceOut, coerce, layout);

coerce('connectgaps', hasColumns(traceOut) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});

coerce('zhoverformat');
traceOut._separators = layout.separators; // Needed for formatting of hoverlabel if format is not explicitly specified
};
23 changes: 23 additions & 0 deletions src/traces/heatmap/style_defaults.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2012-2017, 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 = function handleStyleDefaults(traceIn, traceOut, coerce, layout) {
var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

coerce('zhoverformat');
// Needed for formatting of hoverlabel if format is not explicitly specified
traceOut._separators = layout.separators;
};
3 changes: 2 additions & 1 deletion src/traces/histogram2d/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,8 @@ module.exports = extendFlat({},

xgap: heatmapAttrs.xgap,
ygap: heatmapAttrs.ygap,
zsmooth: heatmapAttrs.zsmooth
zsmooth: heatmapAttrs.zsmooth,
zhoverformat: heatmapAttrs.zhoverformat
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
10 changes: 3 additions & 7 deletions src/traces/histogram2d/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('./sample_defaults');
var handleStyleDefaults = require('../heatmap/style_defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');

Expand All@@ -22,14 +23,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
// ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
coerce('xgap');
coerce('ygap');
}

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
);
Expand Down
3 changes: 2 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,8 @@ module.exports = extendFlat({
autocontour: contourAttrs.autocontour,
ncontours: contourAttrs.ncontours,
contours: contourAttrs.contours,
line: contourAttrs.line
line: contourAttrs.line,
zhoverformat: histogram2dAttrs.zhoverformat
},
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'calc'}),
Expand Down
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

handleSampleDefaults(traceIn, traceOut, coerce, layout);
if(traceOut.visible === false) return;

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
20 changes: 18 additions & 2 deletions test/jasmine/tests/histogram2d_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,29 +20,43 @@ describe('Test histogram2d', function() {
traceOut = {};
});

it('should set zsmooth to false when zsmooth is empty', function() {
it('should quit early if there is no data', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).toBe(false);
['zsmooth', 'xgap', 'ygap', 'calendar'].forEach(function(v) {
expect(traceOut[v]).toBeUndefined(v);
});
});

it('should set zsmooth to false when zsmooth is empty', function() {
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.visible).not.toBe(false);
expect(traceOut.zsmooth).toBe(false);
});

it('doesnt step on zsmooth when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
zsmooth: 'fast'
};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.zsmooth).toBe('fast');
});

it('should set xgap and ygap to 0 when xgap and ygap are empty', function() {
traceIn = {};
traceIn = {x: [1, 2], y: [1, 2]};
supplyDefaults(traceIn, traceOut, '', {});
expect(traceOut.xgap).toBe(0);
expect(traceOut.ygap).toBe(0);
});

it('shouldnt step on xgap and ygap when xgap and ygap are set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5
};
Expand All@@ -53,6 +67,8 @@ describe('Test histogram2d', function() {

it('shouldnt coerce gap when zsmooth is set', function() {
traceIn = {
x: [1, 2],
y: [1, 2],
xgap: 10,
ygap: 5,
zsmooth: 'best'
Expand Down
132 changes: 125 additions & 7 deletions test/jasmine/tests/hover_label_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -474,9 +474,12 @@ describe('hover info', function() {
}

describe('\'hover info for x/y/z traces', function() {
it('should display correct label content', function(done) {
var gd = createGraphDiv();
var gd;
beforeEach(function() {
gd = createGraphDiv();
});

it('should display correct label content', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
Expand DownExpand Up@@ -510,20 +513,20 @@ describe('hover info', function() {
.then(done);
});

it('should display correct label content with specified format', function(done) {
var gd = createGraphDiv();

it('should display correct label content with specified format - heatmap', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f'
zhoverformat: '.2f',
showscale: false
}, {
type: 'heatmap',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two'
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
Expand All@@ -546,6 +549,121 @@ describe('hover info', function() {
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - contour', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. Lovely tests!

Plotly.plot(gd, [{
type: 'contour',
y: [0, 1],
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]],
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'contour',
y: [2, 3],
z: [[1, 2, 3], [2, 2, 1]],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2d', function(done) {
Plotly.plot(gd, [{
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2d',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 100);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 300);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});

it('should display correct label content with specified format - histogram2dcontour', function(done) {
Plotly.plot(gd, [{
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1],
y: [0, 0, 0, 1, 1, 1, 1],
z: [1.11111, 2.2222, 3.3333, 4.4444, 4.4444, 6.6666, 1.1111],
histfunc: 'sum',
name: 'one',
zhoverformat: '.2f',
showscale: false
}, {
type: 'histogram2dcontour',
x: [0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2],
y: [2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2],
name: 'two',
showscale: false
}], {
width: 500,
height: 400,
margin: {l: 0, t: 0, r: 0, b: 0}
})
.then(function() {
_hover(gd, 250, 50);
assertHoverLabelContent({
nums: 'x: 1\ny: 3\nz: 2',
name: 'two'
});
})
.then(function() {
_hover(gd, 250, 270);
assertHoverLabelContent({
nums: 'x: 1\ny: 1\nz: 5.56',
name: 'one'
});
})
.catch(fail)
.then(done);
});
});

describe('hover info for negative data on a log axis', function() {
Expand Down