Last active
August 29, 2015 14:24
-
-
Save joshjordan/9645b43357df13528ec3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nv.chartScripts = [] | |
for(var model in nv.models) | |
{ | |
if(model.match(/[cC]hart$/)) { | |
(function() { | |
var currentModel = model; | |
var chartFunction = nv.models[currentModel]; | |
nv.models[currentModel] = function() { | |
var chart = chartFunction(); | |
chart.apply = function() { | |
var d3Selection = arguments[0]; | |
var data = d3Selection[0][0].__data__; | |
var chartId = "chart-" + new Date().getTime(); | |
var script = "<svg id='" + chartId + "'></svg><script type='text/javascript'>"; | |
script += "nv.addGraph({generate: function() {"; | |
script += "var data = " + JSON.stringify(data) + ";"; | |
script += "var chart = nv.models." + currentModel + "();"; | |
script += "chart"; | |
var optionNames = Object.getOwnPropertyNames(this._options || {}).concat(this._inherited || []) | |
for(var i = 0; i < optionNames.length && (property = optionNames[i]); i++) | |
{ | |
ignoredProperties = ['labelFormat', 'valueFormat'] | |
if(ignoredProperties.indexOf(property) == -1) | |
{ | |
var value = this[property](); | |
if(property == 'color') | |
{ | |
if(typeof(value) == 'function') | |
{ | |
value = []; | |
for(var i = 0; i < data.length; i++) | |
{ | |
value.push(this.color()({}, i)) | |
} | |
} | |
} | |
if(value && typeof(value) === 'object') | |
{ | |
value = JSON.stringify(value) | |
} | |
else if(typeof(value) === 'string') | |
{ | |
value = '"' + value + '"'; | |
} | |
script += "." + property + "(" + value + ")"; | |
} | |
} | |
script += ";"; | |
script += "d3.select('#" + chartId + "').datum(data).call(chart);}});"; | |
script += "<\/script>"; | |
nv.chartScripts.push(script); | |
return this(d3Selection); | |
} | |
return chart; | |
} | |
})(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment