Last active
August 29, 2015 14:16
-
-
Save cmizony/5b47a4d557350d3a84e9 to your computer and use it in GitHub Desktop.
D3 chart skeleton using closures and getter-setters config methods
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
// ____ __ __ ___ ________ _ ___ __ ____ _____ _ | |
// / ___| \/ |_ _|__ / _ \| \ | \ \ / / | _ \___ / (_)___ | |
// | | | |\/| || | / / | | | \| |\ V / _____ | | | ||_ \ | / __| | |
// | |___| | | || | / /| |_| | |\ | | | |_____| | |_| |__) | | \__ \ | |
// \____|_| |_|___/____\___/|_| \_| |_| |____/____(_)/ |___/ | |
// |__/ | |
/** | |
* @method getSkeletonChart | |
* | |
* @description Skeleton or reusable chat implemented as closures with | |
* getter-setter methods | |
* | |
* @params {Array} Data to render | |
* @return {Function} Callable function to render the chart | |
*/ | |
function getSkeletonChart () { | |
var data = []; | |
var width = 800; | |
var height = 500; | |
function my (container) { | |
// Remove existing SVG | |
container.select("svg").remove(); | |
// Create new SVG | |
var svg = container.append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
// TODO Code Chart | |
return my; | |
}; | |
my.data = function (value) { | |
if (!arguments.length) { | |
return data; | |
} | |
data = value; | |
return my; | |
}; | |
my.width = function(value) { | |
if (!arguments.length) { | |
return width; | |
} | |
width = value; | |
return my; | |
}; | |
my.height = function(value) { | |
if (!arguments.length) { | |
return height; | |
} | |
height = value; | |
return my; | |
}; | |
return my; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment