Ricardo
unread,May 29, 2011, 2:42:07 PM5/29/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to d3-js
I've been trying to get this to work for the past 3 days,
unsuccessfully. I have create a simple chart that resizes when the
window containing it resizes. The problem comes when I try to print
the same chart. The chart is printed smaller or cropped depending on
the size of the window at the moment of the print command. In google
chrome the resize event is being called but not with the size of the
printed page but with the size of the window browser. Maybe this is
trying to push it in terms of printing from the browser, but I really
need the liquid flow charts that print nicely. Any ideas?
I'm using jQuery to attach a handler for the window.resize event that
later gets sent to all elements with the class "resizable" as such:
$(document).ready(function() {
$(window).resize(function() { $('.resizable').resize(); })
});
The chart is very simple and I have encapsulated it into an anonymous
function so that I don't pollute the global namespace:
<div id="chart" class="resizable"></div>
<script type="text/javascript">
(function(ce) {
var data = [ 10, 20, 30, 40 ];
function draw() {
var w = $(ce).width(),
h = $(ce).height();
// console.log('size', w, h);
d3.select(ce).selectAll('svg').remove();
var chart = d3.select(ce)
.append('svg:svg')
.attr('width', w)
.attr('height', h)
.append('svg:g');
var x =
d3.scale.ordinal().domain(d3.range(data.length)).rangeBands([0, w],
0.2),
y = d3.scale.linear().domain([0, d3.max(data)]).range([0, h]);
chart.selectAll('rect')
.data(data)
.enter().append('svg:rect')
.attr('x', function(d, i) { return x(i); })
.attr('y', function(d) { return h - y(d); })
.attr('width', x.rangeBand())
.attr('height', function(d) { return y(d); });
}
$(ce).resize(function() {
draw();
});
draw();
})('#chart');
</script>