/** * D3 for basic PCA plot * * @class * @extends Biojs * @author Rowland Mosbergen * @version 0.0.1 * @category 3 * * @requires d3 v3.4.8 * @dependency * @requires Biojs * @dependency * @requires jQuery 1.8.2 * @dependency * @requires D3 queue * @dependency * * @param {Object} options An object with the options for PCA component * @option {string} target * Identifier of the DIV tag where the component should be displayed. * * * * * @option {int} [height=800] * Full height of svg * * @option {int} [width=1024] * Full width of svg * * @option {string} [shape="circle"] * To be passed into d3.svg.symbol eg. circle, square * * @option {string} [unique_id="sample_id"] * Unique id column of the data file. * * * @option {string} [x_column="component1"] * column of the data file that will be used as the x axis. * * @option {string} [y_column="component2"] * column of the data file that will be used as the y axis. * * @option {string} [x_axis_title="Component 1"] * title of the x axis. * * * @option {string} [y_axis_title="Component 2"] * title of the y axis. * * @option {string} [title_class="title"] * class to add to the title. * * @option {string} [tooltip_class="tooltip"] * class to add to the tooltip. * * @option {string} [point_class="dot"] * class to add to the points. * * @option {string} [legend_class="legend"] * class to add to the legend. * * @option {function} [tooltip_name="function"] * function to use for the tooltip. defaults to: *
* function (d,this_object){
* name = d[this_object.unique_id] +':' + d[this_object.x_column] + ' ' + d[this_object.y_column];
* return name;
* },
*
* @option {object} [margin="{top:80,right:20,bottom:30,left:40}"]
* margin around the svg graph.
*
* @option {array} [domain="array"]
* specific types of values to be used for colours. eg. ['Apple','Orange','Pear','Grape']
*
* @option {array} [domain_colours="array"];
* colours that match the domain array eg. ['blue','green','orange','red'] where blue is Apple
*
*
* @example
* //data columns are state,type,component1,component2 tab separated
* d3.tsv('../biojs/data/usarrests.tsv',function (error,data){
*
* data.forEach(function(d){
* d.component1 = +d.component1;
* d.component2 = +d.component2;
* });
*
* target = "#YourOwnDivId";
* var options = {
* target: target,
* title: "US Arrests",
* unique_id: "state",
* domain : ['Republican','Democrat'],
* domain_colours:['blue','green'],
* margin:{top: 80, right: 20, bottom: 30, left: 40},
* height: 600,
* width:960,
* x_axis_title: "Principal Component #1",
* y_axis_title: "Principal Component #2",
* shape:'square',
* point_class: 'states',
* tooltip_name: function (d,this_object){
* name = d[this_object.unique_id] + '| |' + d[this_object.x_column] + ' ' + d[this_object.y_column];
* return name;
* },
*
* data: data
* }
* var new_instance = new Biojs.PCAD3(options);
* new_instance.pointClick(
* function( objEvent ) {
* alert('You just clicked ' + objEvent.data_object.state);
* }
* );
*
* });
*
* @css-example
* #CSS for tool tip with default class tooltip
* div.tooltip{
* @include default_large_text;
* padding: 8px;
* display: inline-block;
* max-width: 300px;
* z-index: 11000;
* position: absolute;
* color: #5a5a5a;
* background-color: #FFF;
* border: 1px solid #000;
* display:block;
* word-wrap: break-word;
* }
*
*
*
*
*
*
*
*/
// later on want to download the svg
// http://stackoverflow.com/questions/18492617/button-to-download-inpage-svg-code-as-an-svg-file
Biojs.PCAD3 = Biojs.extend ({
/** @lends Biojs.PCAD3# */
constructor: function (options) {
/* Your constructor code here
Note: options provided on instantiation time overrides the
default values in this.opt, automatically; i.e. ‘options’
argument refers to the provided values and ‘this.opt’
refers to the the overridden options. For more details,
go to section 6.3.2 in the spec. doc. */
var self = this;
this._container = jQuery(self.opt.target);
this._container.addClass('PCA');
this._init();
this._setup_graph();
this._set_points();
this._setup_legend();
},
opt: {
/* Target DIV
This mandatory parameter is the identifier of the DIV tag where the
component should be displayed. Use this value to draw your
component into. */
target: "YourOwnDivId",
title: "Title",
/* Component Options
These options defines the input data for your component.
Must have a default value for each one. Note that, either some or
all of values might be replaced by the constructor using the values
provided in instantiation time.
*/
height: 800,
width: 1024,
shape: "circle",
unique_id: "sample_id",
x_column: "component1",
y_column: "component2",
x_axis_title: "Component 1",
y_axis_title: "Component 2",
title_class: "title",
tooltip_class: "tooltip",
point_class: "dot",
legend_class: "legend",
tooltip_name: function (d,this_object){
name = d[this_object.unique_id] +':' + d[this_object.x_column] + ' ' + d[this_object.y_column];
return name;
},
margin: {top: 80, right: 20, bottom: 30, left: 40}
},
eventTypes: [
/* Event Names
The parent class Biojs build the event handlers automatically
with the names defined here. Use this.raiseEvent(