// set up showformats constructor ShowFormats = function(formatList, number) { // list of format specifiers to show this.formatList = formatList; this.formatObject = constructFormatObject(formatList); this.dataset = Array.apply(0, Array(this.formatObject.length)).map(function(x, y) { return y; });; // number to format this.number = number; this.colorScale = setColorScale(this.dataset.length) this.updateFormats() } ShowFormats.prototype.changeNumber = function(number) { var format = d3.time.format("%Y,%m,%d,%H,%M,%S"); this.number = format.parse(number); this.updateFormats(); } ShowFormats.prototype.addToList = function(specifier) { this.formatList.unshift(specifier) this.formatObject = constructFormatObject(this.formatList); // update dataset array w/ new length this.dataset = Array.apply(0, Array(this.formatObject.length)).map(function(x, y) { return y; });; this.updateFormats(); } ShowFormats.prototype.tdtextStyling = function(selection) { selection.text(function(d) { return self.formatObject[d].text; }) .style("color", function(d) { return self.colorScale(d) }) .attr("class", "formattext"); } ShowFormats.prototype.tdcodeStyling = function(selection) { selection.text(function(d) { return self.formatObject[d].code(self.number); }) .style("color", function(d) { return self.colorScale(d) }) .attr("class", "formatresult"); } ShowFormats.prototype.updateFormats = function() { self = this; document.getElementById('dateEntered').innerHTML = this.number; document.getElementById('rawDate').innerHTML = this.number.getFullYear() + ',' + this.number.getMonth() + ',' + this.number.getDay() + ',' + this.number.getHours() + ',' + this.number.getMinutes() + ',' + this.number.getSeconds(); // bind with current dataset this.selection = d3.selectAll("tbody").selectAll("tr") .data(self.dataset); // enter elements var k = this.selection.enter().append("tr") k.append("td") .call(self.tdtextStyling); k.append("td") .call(self.tdcodeStyling); // update elements this.selection .selectAll("td") .text(function(d, i) { if (i == 0) { return self.formatObject[d].text; } if (i == 1) { return self.formatObject[d].code(self.number); } }) .style("color", function(d) { return self.colorScale(d) }) .attr("class", function(d, i) { if (i == 0) { return "formattext" } else { return "formatresult" } }) }