Skip to content

Instantly share code, notes, and snippets.

@vicapow
Created April 10, 2014 16:41
Show Gist options
  • Save vicapow/10400706 to your computer and use it in GitHub Desktop.
Save vicapow/10400706 to your computer and use it in GitHub Desktop.
custom symbol generator
function mySymbols(){
var symbol = d3.svg.symbol();
var my_types = []; // our other types
my_types.NewSymbolName = function(size){
return 'Custom Symbol 1 Path'
}
var me = function(datum, index){
var type = symbol.type(), size = symbol.size();
if(type instanceof Function){
type = type(datum, index);
}
if(size instanceof Function){
size = size(datum, index);
}
// generating a built in type.
if(d3.svg.symbolTypes.indexOf(type) !== -1) {
return symbol(datum, index);
}
return my_types[type](size);
};
var my_size = symbol.size();
me.size = function(size){
if(arguments.length){
symbol.size(size);
return me;
}
return symbol.size();
};
var my_type = symbol.type();
me.type = function(type){
if(arguments.length){
symbol.type(type);
return me;
}
return symbol.type();
};
return me;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment