css - D3 Elements are invisible despite existing in DOM -
i have bootstrap tab panel , want display different d3 chart each tab.
when document loads, first d3 chart present in dom elements invisible. here's example: http://i.imgur.com/7attyhi.png
here setup tab pane in bootstrap:
<div role="tabpanel"> <!-- nav tabs --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#ghg-co2" aria-controls="ghg-co2" role="tab" data-toggle="tab"> <h4>change in co<sub>2</sub></h4></a> </li> <li role="presentation"><a href="#ghg-ch4" aria-controls="ghg-ch4" role="tab" data-toggle="tab"> <h4>change in ch4 (methane)</h4></a> </li> <li role="presentation"><a href="#ghg-nos" aria-controls="ghg-nos" role="tab" data-toggle="tab"> <h4>change in nitrous oxide</h4></a> </li> </ul> <!-- tab panes --> <div class="tab-content"> <script src="js/ghg.js"></script> <div role="tabpanel" class="tab-pane active fade fade-in" id="ghg-co2"> <div id="chart-ghg-co2" class="d3-chart"></div> </div> <div role="tabpanel" class="tab-pane fade fade-in" id="ghg-ch4"> <div id="chart-ghg-ch4" class="d3-chart"></div> </div> <div role="tabpanel" class="tab-pane fade fade-in" id="ghg-nos"> <div id="chart-ghg-nos" class="d3-chart"></div> </div> </div> </div>
i have had issues bootstrap displaying content in tab pane correctly. using hack in style.css override bootstrap properties:
/* bootstrap hack: fix content width inside hidden tabs */ .tab-content > .tab-pane, .pill-content > .pill-pane { display: block; /* undo display:none */ height: 0; /* height:0 invisible */ overflow-y: hidden; /* no-overflow */ } .tab-content > .active, .pill-content > .active { height: auto; /* let content decide */ } /* bootstrap hack end */
i got this thread
my d3 function identical example: d3 scatterplot
but different data.
at bottom of html, have:
<script> // check if dom ready d3 $( document ).ready(ghgco2()); // names of 3 d3 chart functions $( document ).ready(ghgch4()); $( document ).ready(ghgnos()); </script>
i suspect problem d3 function, ghgco2() attempting render before div in resides, .chart-ghg-co2 ready. reason, svg has correct dimensions, , elements present, it's blank. resolved when switch between tabs on bootstrap pane.
any , appreciated.
Comments
Post a Comment