Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add option for visibility of x-value hover detail. #472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions src/js/Rickshaw.Graph.HoverDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
return y === null ? y : y.toFixed(2);
};

// Whether the x-value hover detail is visible; true by default.
this.xHoverVisible = (args.xHoverVisible === undefined) || args.xHoverVisible;

var element = this.element = document.createElement('div');
element.className = 'detail';

Expand Down Expand Up @@ -164,11 +167,13 @@ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
this.element.innerHTML = '';
this.element.style.left = graph.x(point.value.x) + 'px';

var xLabel = document.createElement('div');

xLabel.className = 'x_label';
xLabel.innerHTML = formattedXValue;
this.element.appendChild(xLabel);
// Add x-value hover detail.
if (this.xHoverVisible) {
var xLabel = document.createElement('div');
xLabel.className = 'x_label';
xLabel.innerHTML = formattedXValue;
this.element.appendChild(xLabel);
}

var item = document.createElement('div');

Expand Down Expand Up @@ -198,7 +203,8 @@ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({

// Assume left alignment until the element has been displayed and
// bounding box calculations are possible.
var alignables = [xLabel, item];
var alignables = [item];
if (this.xHoverVisible) alignables.push(xLabel);
alignables.forEach(function(el) {
el.classList.add('left');
});
Expand Down