-
Notifications
You must be signed in to change notification settings - Fork 31
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
Show all values in a series on mouse hover #2245
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,8 +380,202 @@ function renderCompareMultibarChart(chartEl, name, label, colors, stacked, yMax, | |
} | ||
|
||
d3.select(svg) | ||
.datum(data) | ||
.call(chart); | ||
.datum(data) | ||
.call(chart); | ||
|
||
// filter definition for drop shadows | ||
var filter = | ||
d3.select(svg) | ||
.selectAll("defs") | ||
.append("filter") | ||
.attr("id","drop-shadow") | ||
.attr("height", "120%"); | ||
|
||
filter.append("feGaussianBlur") | ||
.attr("in", "SourceAlpha") | ||
.attr("stdDeviation", 2) | ||
.attr("result", "blur"); | ||
|
||
filter.append("feOffset") | ||
.attr("in", "blur") | ||
.attr("dx", 2) | ||
.attr("dy", 2) | ||
.attr("result", "offsetBlur"); | ||
|
||
var feMerge = filter.append("feMerge"); | ||
feMerge.append("feMergeNode") | ||
.attr("in", "offsetBlur"); | ||
feMerge.append("feMergeNode") | ||
.attr("in", "SourceGraphic"); | ||
|
||
var chartContainerId = chartEl.id + "-chart-container"; | ||
|
||
// iterate over the series names to add the svg elements to the chart | ||
_.forEach(["nv-series-0", "nv-series-1", "nv-series-2"], | ||
function(el) { | ||
d3.select("#" + chartEl.id).select("svg").selectAll("g." + el).each(function() { | ||
var g = d3.select(this); | ||
var parentG = d3.select(this.parentNode); | ||
parentG.attr("id", chartContainerId); | ||
|
||
g.selectAll(".nv-bar").each(function(bar) { | ||
var b = d3.select(this); | ||
var barWidth = b.attr("width"); | ||
var bgWidth = 40.0; | ||
var bgHeight = 20.0; | ||
var bgVertOffset = -20.0; | ||
|
||
var dialogTickSize = 5.0; | ||
|
||
// add drop-shadow | ||
parentG.append("rect") | ||
.each(function () { | ||
d3.select(this).attr({ | ||
"transform": b.attr("transform"), | ||
"y": (parseFloat(b.attr("y")) + bgVertOffset - 1), | ||
"x": (parseFloat(b.attr("x")) + (parseFloat(barWidth) / 2) - (bgWidth / 2) - 1), | ||
"width": bgWidth + 2, | ||
"height": bgHeight + 2, | ||
"stroke": 1, | ||
"class": ("bar-value-text-bg-shadow_" + el) | ||
}); | ||
|
||
d3.select(this).style({ | ||
"fill": "#aaaaaa", | ||
"opacity": 0, | ||
"fill-opacity": 0, | ||
"filter": "url(#drop-shadow)" | ||
}); | ||
}); | ||
|
||
// add background shape | ||
parentG.append("rect") | ||
.each(function() { | ||
d3.select(this).attr({ | ||
"transform": b.attr("transform"), | ||
"y": (parseFloat(b.attr("y")) + bgVertOffset), | ||
"x": (parseFloat(b.attr("x")) + (parseFloat(barWidth) / 2) - (bgWidth / 2)), | ||
"width": bgWidth, | ||
"height": bgHeight, | ||
"stroke": "#aaaaaa", | ||
"stroke-width": 0.5, | ||
"class": ("bar-value-text-bg_" + el) | ||
}); | ||
|
||
d3.select(this).style({ | ||
"fill": "white", | ||
"opacity": "0", | ||
"fill-opacity": "0", | ||
"stroke-opacity": 0.75 | ||
}); | ||
}); | ||
|
||
// add tick mark under shape | ||
parentG.append("rect") | ||
.each(function() { | ||
var rotatedX = parseFloat(b.attr("x")) + parseFloat(barWidth) / 2; | ||
var rotatedY = parseFloat(b.attr("y")) + bgHeight + bgVertOffset - (dialogTickSize / 2); | ||
d3.select(this).attr({ | ||
"transform": (b.attr("transform") + " rotate(45," + rotatedX +"," + rotatedY + ")"), | ||
"y": (parseFloat(b.attr("y")) + bgHeight + bgVertOffset - dialogTickSize), | ||
"x": (parseFloat(b.attr("x")) + (parseFloat(barWidth) / 2)), | ||
"width": dialogTickSize, | ||
"height": dialogTickSize, | ||
"class": ("bar-value-text-bg-tick_" + el) | ||
}); | ||
|
||
d3.select(this).style({ | ||
"fill": "white", | ||
"fill-opacity": "0", | ||
"opacity": "0" | ||
}); | ||
}); | ||
|
||
// add the text value | ||
parentG.append("text") | ||
.each(function() { | ||
d3.select(this).text(function() { | ||
if (bar.y === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, here's where the zero values seem to get filtered out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return; | ||
} | ||
return parseFloat(bar.y).toFixed(2); | ||
}); | ||
|
||
var width = this.getBBox().width; | ||
|
||
d3.select(this).attr({ | ||
"transform": b.attr("transform"), | ||
"y": (parseFloat(b.attr("y")) + 15 + bgVertOffset), | ||
"x": (parseFloat(b.attr("x")) + (parseFloat(barWidth) / 2) - (width / 2)), | ||
"font-size": "0.8rem", | ||
"font-weight": "normal", | ||
"font-family": "helvetica", | ||
"class": ("bar-value-text_" + el) | ||
}); | ||
|
||
d3.select(this).style({ | ||
"stroke": "black", | ||
"stroke-width": 0.2, | ||
"opacity": 0, | ||
"font-weight": "normal", | ||
"font-family": "arial" | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
d3.select(svg) | ||
.select("#" + chartContainerId) | ||
.selectAll("g." + el) | ||
.selectAll("rect.nv-bar") | ||
.on("mouseover", function () { | ||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text_" + el) | ||
.style("opacity", "1"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg-shadow_" + el) | ||
.style("opacity", "0.5") | ||
.style("fill-opacity", "0.5"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg_" + el) | ||
.style("opacity", "1") | ||
.style("fill-opacity", "1"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg-tick_" + el) | ||
.style("opacity", "1") | ||
.style("fill-opacity", "1"); | ||
}); | ||
|
||
d3.select(svg) | ||
.select("#" + chartContainerId) | ||
.selectAll("g." + el) | ||
.selectAll("rect.nv-bar") | ||
.on("mouseout", function () { | ||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text_" + el) | ||
.style("opacity", "0"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg-shadow_" + el) | ||
.style("opacity", "0") | ||
.style("fill-opacity", "0"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg_" + el) | ||
.style("opacity", "0") | ||
.style("fill-opacity", "0"); | ||
|
||
d3.select("#" + chartContainerId) | ||
.selectAll(".bar-value-text-bg-tick_" + el) | ||
.style("opacity", "0") | ||
.style("fill-opacity", "0"); | ||
}); | ||
}); | ||
|
||
|
||
return chart; | ||
}, onRenderComplete); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of appending with an underscore, prefer appending with a space so these elements can be targeted via CSS like
.bar-value-test-bg-shadow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can then do something like this:
Which allows hovering on the stacked chart in areas obscured by hidden tooltips to function correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's so specific is that those elements have to be manipulated via D3 later on. Could D3 selection be performed (easily) with a lower degree of specificity in the elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that CSS get tested on the D3 charts? I observed that CSS and D3/SVG elements didn't seem to play very nice together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As shown in the diff, a CSS class of
abcd_wxyz
can be accessed only via.abcd_wxyz
, but one ofabcd wxyz
can be accessed specifically with.abcd.wxyz
, but also in other groupings with.abcd
and.wxyz
. So the existing selection behavior is preserved by switching to spaces and dots instead of the underscore, and enables this CSS targeting after the fact.