-
Notifications
You must be signed in to change notification settings - Fork 41
Weird FFx/Safari bars bug #1631
Changes from 2 commits
12fe2af
eb3fb3c
b4e9f80
7f94aef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,8 @@ | |
.key(function(d) { return d.x; }) | ||
.rollup(function(d) { return d[0]; }) | ||
.entries(data); | ||
|
||
|
||
} else { | ||
values = Object.keys(data).reduce(function(map, key) { | ||
map[key] = {x: +key, y: data[key]}; | ||
|
@@ -81,9 +83,9 @@ | |
}); | ||
} | ||
|
||
// console.log('data:', data, 'values:', values); | ||
|
||
var xrange = this.xrange; | ||
|
||
if (!xrange) { | ||
xrange = d3.extent(data, function(d) { | ||
return +d.x; | ||
|
@@ -102,6 +104,12 @@ | |
} | ||
}); | ||
|
||
// filter the data so that only values within the domain | ||
// are included in calculations and rendering | ||
data = data.filter(function(d){ | ||
return xdomain.indexOf(d.x) > -1; | ||
}); | ||
|
||
var extent = d3.extent(data, function(d) { return d.y; }); | ||
var ymax = extent[1]; | ||
var ymin = Math.min(0, extent[0]); | ||
|
@@ -136,7 +144,11 @@ | |
bars.exit().remove(); | ||
|
||
bars.attr('transform', function(d) { | ||
return 'translate(' + [x(d.x), 0] + ')'; | ||
if (x(d.x)) { | ||
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. Is this this right test? Presumably 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. maybe ?
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. Let me play around with this. 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. Actually, it looks like this was fixed by the filter function above 😄 |
||
return 'translate(' + [x(d.x), 0] + ')'; | ||
} else { | ||
console.warn(d.x, 'not in bar chart domain') | ||
} | ||
}); | ||
|
||
bars.select('.bar-value') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,46 +87,52 @@ | |
var svgLegend = d3.select(this) | ||
.select('.legend-svg'); | ||
|
||
svgLegend.append('g') | ||
.attr('class', 'legendScale'); | ||
|
||
var legend = d3.legend.color() | ||
.labelFormat(format.si) | ||
.useClass(false) | ||
.ascending(true) | ||
.labelDelimiter('-') | ||
.shapePadding(6) | ||
.scale(scale); | ||
|
||
svgLegend.select('.legendScale') | ||
.call(legend); | ||
|
||
// reverse because the scale is in ascending order | ||
var _steps = d3.range(0, 9).reverse(); | ||
|
||
// find which steps are represented in the map | ||
var uniqueSteps = getUnique(marks.data(), _steps, domain); | ||
|
||
// start consolidate (translate) visible cells | ||
var cells = svgLegend.selectAll('.cell'); | ||
var cellHeight = legend.shapeHeight() + legend.shapePadding(); | ||
var count = 0; | ||
cells.each(function(cell, i) { | ||
var present = uniqueSteps.indexOf(i) > -1; | ||
|
||
if (!present) { | ||
// hide cells swatches that aren't in the map | ||
cells[0][i].setAttribute('aria-hidden', true); | ||
count++; | ||
} else { | ||
// trim spacing between swatches that are visible | ||
var translateHeight = (i * cellHeight) - (count * cellHeight); | ||
cells[0][i].setAttribute('transform', | ||
'translate(0,' + translateHeight + ')'); | ||
} | ||
}); | ||
// end consolidation | ||
// end map legend | ||
if (svgLegend[0][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. More succinctly: |
||
svgLegend.append('g') | ||
.attr('class', 'legendScale'); | ||
|
||
var legend = d3.legend.color() | ||
.labelFormat(format.si) | ||
.useClass(false) | ||
.ascending(true) | ||
.labelDelimiter('-') | ||
.shapePadding(6) | ||
.scale(scale); | ||
|
||
svgLegend.select('.legendScale') | ||
.call(legend); | ||
|
||
// reverse because the scale is in ascending order | ||
var _steps = d3.range(0, 9).reverse(); | ||
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. Not a blocker, but why 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. I think I did this to not overwrite |
||
|
||
// find which steps are represented in the map | ||
var uniqueSteps = getUnique(marks.data(), _steps, domain); | ||
|
||
// start consolidate (translate) visible cells | ||
var cells = svgLegend.selectAll('.cell'); | ||
var cellHeight = legend.shapeHeight() + legend.shapePadding(); | ||
var count = 0; | ||
cells.each(function(cell, i) { | ||
var present = uniqueSteps.indexOf(i) > -1; | ||
|
||
if (!present) { | ||
// hide cells swatches that aren't in the map | ||
cells[0][i].setAttribute('aria-hidden', true); | ||
count++; | ||
} else { | ||
// trim spacing between swatches that are visible | ||
var translateHeight = (i * cellHeight) - (count * cellHeight); | ||
cells[0][i].setAttribute('transform', | ||
'translate(0,' + translateHeight + ')'); | ||
} | ||
}); | ||
// end consolidation | ||
// end map legend | ||
} else { | ||
console.warn('<eiti-data-map> does not exist on this page.') | ||
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. This should say that the legend doesn't exist, right? 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. how about |
||
} | ||
|
||
|
||
|
||
// start trim height on map container | ||
var svgContainer = d3.select(this) | ||
|
@@ -145,14 +151,6 @@ | |
svgContainer.style('padding-bottom', pixelize); | ||
// end trim | ||
|
||
|
||
// var swatches = d3.select(this).selectAll('.swatch[data-value-swatch]') | ||
// .datum(function() { | ||
// return +this.getAttribute('data-value-swatch') || 0; | ||
// }); | ||
|
||
// swatches.style('background-color', scale); | ||
// console.log(swatches) | ||
}} | ||
} | ||
) | ||
|
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.
Missing a space between the
)
and{
. I'm wondering why Hound didn't spot this...