Skip to content
Merged
Changes from 1 commit
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
9 changes: 3 additions & 6 deletions src/traces/choropleth/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var attributes = require('./attributes');

Expand Down Expand Up @@ -80,12 +81,8 @@ function makeHoverInfo(pointData, trace, pt, axis) {

if(hasZ) text.push(formatter(pt.z));
if(hasText) {
var tx;

if(pt.tx) tx = pt.tx;
else if(trace.text) tx = trace.text;

if(!Array.isArray(tx)) text.push(tx);
var tx = Lib.extractOption(pt, trace, 'tx', 'text');
if(tx && tx !== '') text.push(tx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

'' is already falsey, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Strictly speaking, I think this should be:

if(tx !== undefined && tx !== '') {
  text.push(tx);
}

as Lib.extractOption returns undefined for all falsy values except 0 in calcdata. But, trace.text is allowed to be '' (which is the default by the way).


To make this easier to maintain (and remember 🙂 ), I'm thinking either

  • (1) we could remove the dflt: '' line in the text (and hovertext) attribute declarations. This leads to a slight change in behavior (but might more consistent) as now:
{
   text: 'on-chart text',
   hovertext: ''
}

would use '' for the hover label text field (i.e. not show anything). On master, hovertext: '' is ignored and 'on-chart text' shows in the hover labels.

  • (2) we could make Lib.extractOption return undefined when trace.text: '', making it a little more opinionated (I think this only makes sense for string attributes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's what I came up with 3931273

I made Lib.extractOption less opinionated, and made scatter/fill_hover_text handle falsy but valid text values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I like it. There are some edge cases this makes a little weird - eg trying to make one point have text but no hovertext, while all the others have both - but there are ways to get what you want (in that example using hoverinfo as an array) and I don't see any way to make everything more intuitive. So lets keep this, it's nice clean logic, will make sense to people, and will do what people expect 99.9% of the time.

}

pointData.extraText = text.join('<br>');
Expand Down