How to split one html file which uses dc library into several html codes.
I have used this amazing library which helps me a lot.
But Source gets stressful as I add more charts and elements because the html file has too many lines of codes.
My question is How to split the html file into several files for ease of maintenance.
Based on my current knowledge with dc library, I have to put all the codes for drawing charts in the following area.
d3.csv("ndx.csv", function (data) { /* all the codes for drawing charts should be positioned here.. */ }
Let me know a way to split them into several files.
If I understand this question correctly, it seems more like a plain javascript architecture solution than a dc.js library solution (but I may have misunderstood it).
Here's how I originally structured one of my apps, breaking out the different pieces:
// On DOM ready, load the data
$(function(){
var dsv = d3.dsv("|", "text/plain");
queue()
.defer(dsv, "data/jobs.txt")
.await(prepData);
});
// prepare data
function prepData(error, jobs) {
// Using underscore library with custom mixins to verify data quality
data.forEach(function(d) {
d.jobId = +d.job_id
d.jobAppointmentDatetime = _.cleanDate(d.job_service_datetime);
d.jobCreatedHour = _.isLegitDate(d.jobDateCreated) ? d.jobDateCreated.getHours() : undefinedNumber;
// and so on....
}
// only pass on properly formatted data, remove the originals.
var keepers = ['jobId', 'jobAppointmentDatetime', 'jobCreatedHour']
data = _.map(data, function(d){
return _.pick(d, keepers);
})
renderCharts(data)
}
function renderCharts(data) {
// Crossfilter and Render Charts
}
I've got a lot more data and charts, but that gives you the idea. I've since moved to using Backbone + Browserify modules, which is much cleaner and modular. If you have a really large app, you may want to consider that approach.
You understood exactly what I ask.
Thanks for your quick answer. I am now reviewing the codes you just uploaded above.
Right, in general such questions are better asked on the mailing list or on stackoverflow, as there isn't a bug or enhancement on the library here. Thanks @jefffriesen for answering.
@elsdy, I'm closing this, but please reopen if you think you need library support for this.