Use functions in options rather than preset data attributes
Closed this issue · 4 comments
The layout depends on specific data attributes, like type: 'snp'
. It would be better if instead you had functions in options
so that the dev can specify the data more flexibly.
In 0d30d32 I added options for the selectors that define the genes and snps, but what is the canonical way for attaching specific pieces of data for using in placement? At a minimum I need the chromosome (for the snp) , snp and local degree (for the gene), and the start and end base pair (for both). Any recommendations would be greatly appreciated!
For those cases you listed, you could have something like:
isSnp: function( ele ){
return ele.is('[type = "snp"]');
}
The dev can specify a selector like I have, or they can have their own logic in the function. Using similar functions to get chrom
, start
, end
, etc would also be great.
If you want options like isSnp
to also directly allow selectors for brevity (i.e. isSnp: '[type = "snp"]'
), you can use something like:
var typeofStr = typeof '';
var is = function( ele, condition ){
if( typeof condition === typeofStr ){
return ele.is( condition );
} else {
return condition( ele );
}
};
var isEleSnp = is( ele, options.isSnp );
Oops, forgot to add Polywas to the extension list before. Added now: cytoscape/cytoscape.js@e6f406c