2010-04-14 07:14:33 +02:00
function ScatterplotDialog ( column ) {
this . _column = column ;
2010-04-13 02:25:43 +02:00
this . _plot _method = "lin" ;
2010-04-13 06:48:20 +02:00
this . _createDialog ( ) ;
2010-04-30 21:14:45 +02:00
this . _active = true ;
2010-04-10 10:28:06 +02:00
}
ScatterplotDialog . prototype . _createDialog = function ( ) {
var self = this ;
var frame = DialogSystem . createDialog ( ) ;
2010-04-13 02:25:43 +02:00
frame . width ( "1100px" ) ;
2010-04-10 10:28:06 +02:00
2010-04-14 07:14:33 +02:00
var header = $ ( '<div></div>' ) . addClass ( "dialog-header" ) . text ( 'Scatterplot Matrix' + ( ( typeof this . _column == "undefined" ) ? "" : " (focusing on '" + this . _column + "')" ) ) . appendTo ( frame ) ;
2010-04-10 10:28:06 +02:00
var body = $ ( '<div></div>' ) . addClass ( "dialog-body" ) . appendTo ( frame ) ;
var footer = $ (
2010-05-07 02:02:32 +02:00
'<div>' +
2010-04-10 10:28:06 +02:00
'<table width="100%"><tr>' +
'<td class="left" style="text-align: left"></td>' +
'<td class="right" style="text-align: right"></td>' +
'</tr></table>' +
'</div>'
) . appendTo ( frame ) ;
2010-05-07 02:02:32 +02:00
$ ( '<div class="grid-layout layout-normal">' +
'<div bind="tableContainer" class="scatterplot-dialog-table-container"></div>' +
'</div>' ) . appendTo ( body ) ;
var left _footer = footer . find ( ".left" ) ;
var right _footer = footer . find ( ".right" ) ;
2010-04-10 10:28:06 +02:00
2010-05-07 02:14:46 +02:00
$ ( '<button></button>' ) . text ( "Close" ) . click ( function ( ) { self . _dismiss ( ) ; } ) . appendTo ( right _footer ) ;
2010-04-13 02:25:43 +02:00
2010-05-07 02:02:32 +02:00
$ ( '<div class="scatterplot-dialog-selectors-container">' +
'<table class="scatterplot-selectors"><tr>' +
'<td nowrap>' +
'<div class="buttonset scatterplot-dim-selector" bind="plotSelector">' +
'<input type="radio" id="clustering-dialog-dim-lin" name="clustering-dialog-dim" value="lin" checked="checked"/><label class="dim-lin-label" for="clustering-dialog-dim-lin" title="Linear Plot">lin</label>' +
'<input type="radio" id="clustering-dialog-dim-log" name="clustering-dialog-dim" value="log"/><label class="dim-log-label" for="clustering-dialog-dim-log" title="Logarithmic Plot">log</label>' +
'</div>' +
'</td>' +
'<td nowrap>' +
'<div class="buttonset scatterplot-rot-selector" bind="rotationSelector">' +
'<input type="radio" id="clustering-dialog-rot-ccw" name="clustering-dialog-rot" value="ccw"/><label class="rot-ccw-label" for="clustering-dialog-rot-ccw" title="Rotated 45° Counter-Clockwise"> </label>' +
'<input type="radio" id="clustering-dialog-rot-none" name="clustering-dialog-rot" value="none" checked="checked"/><label class="rot-none-label" for="clustering-dialog-rot-none" title="No rotation"> </label>' +
'<input type="radio" id="clustering-dialog-rot-cw" name="clustering-dialog-rot" value="cw"/><label class="rot-cw-label" for="clustering-dialog-rot-cw" title="Rotated 45° Clockwise"> </label>' +
'</div>' +
'</td>' +
'<td nowrap>' +
'<div class="buttonset scatterplot-dot-selector" bind="dotSelector">' +
'<input type="radio" id="clustering-dialog-dot-small" name="clustering-dialog-dot" value="small"/><label class="dot-small-label" for="clustering-dialog-dot-small" title="Small Dot Size"> </label>' +
'<input type="radio" id="clustering-dialog-dot-regular" name="clustering-dialog-dot" value="regular" checked="checked"/><label class="dot-regular-label" for="clustering-dialog-dot-regular" title="Regular Dot Size"> </label>' +
'<input type="radio" id="clustering-dialog-dot-big" name="clustering-dialog-dot" value="big"/><label class="dot-big-label" for="clustering-dialog-dot-big" title="Big Dot Size"> </label>' +
'</div>' +
'</td>' +
'</tr></table>' +
'</div>' ) . appendTo ( left _footer ) ;
this . _elmts = DOM . bind ( frame ) ;
2010-05-07 01:20:51 +02:00
this . _elmts . plotSelector . buttonset ( ) . change ( function ( ) {
self . _plot _method = $ ( this ) . find ( "input:checked" ) . val ( ) ;
2010-04-13 02:25:43 +02:00
self . _renderMatrix ( ) ;
} ) ;
2010-05-07 01:20:51 +02:00
this . _elmts . rotationSelector . buttonset ( ) . change ( function ( ) {
self . _rotation = $ ( this ) . find ( "input:checked" ) . val ( ) ;
2010-04-17 05:00:38 +02:00
self . _renderMatrix ( ) ;
} ) ;
2010-05-07 01:20:51 +02:00
this . _elmts . dotSelector . buttonset ( ) . change ( function ( ) {
var dot _size = $ ( this ) . find ( "input:checked" ) . val ( ) ;
if ( dot _size == "small" ) {
self . _dot _size = 0.4 ;
} else if ( dot _size == "big" ) {
self . _dot _size = 1.4 ;
} else {
self . _dot _size = 0.8 ;
2010-04-13 02:25:43 +02:00
}
2010-05-07 01:20:51 +02:00
self . _renderMatrix ( ) ;
2010-04-13 02:25:43 +02:00
} ) ;
2010-04-10 10:28:06 +02:00
this . _level = DialogSystem . showDialog ( frame ) ;
2010-04-13 02:25:43 +02:00
this . _renderMatrix ( ) ;
2010-04-10 10:28:06 +02:00
} ;
2010-04-13 02:25:43 +02:00
ScatterplotDialog . prototype . _renderMatrix = function ( ) {
2010-04-10 10:28:06 +02:00
var self = this ;
2010-04-13 02:25:43 +02:00
var container = this . _elmts . tableContainer . html (
2010-04-15 08:20:56 +02:00
'<div style="margin: 1em; font-size: 130%; color: #888; background-color: white;">Processing... <img src="/images/small-spinner.gif"></div>'
2010-04-13 02:25:43 +02:00
) ;
2010-04-15 08:20:56 +02:00
if ( theProject . columnModel . columns . length > 0 ) {
var params = {
project : theProject . id
2010-04-13 05:44:42 +02:00
} ;
2010-04-15 08:20:56 +02:00
$ . getJSON ( "/command/get-columns-info?" + $ . param ( params ) , function ( data ) {
2010-05-05 02:26:26 +02:00
if ( data === null || typeof data . length == 'undefined' ) {
2010-04-15 08:20:56 +02:00
container . html ( "Error calling 'get-columns-info'" ) ;
return ;
}
2010-04-14 07:14:33 +02:00
2010-04-15 08:20:56 +02:00
var columns = [ ] ;
for ( var i = 0 ; i < data . length ; i ++ ) {
if ( data [ i ] . is _numeric ) {
columns . push ( data [ i ] ) ;
}
2010-04-13 08:40:33 +02:00
}
2010-04-15 08:20:56 +02:00
if ( typeof self . _plot _size == 'undefined' ) {
self . _plot _size = Math . max ( Math . floor ( 500 / columns . length / 5 ) * 5 , 20 ) ;
2010-05-06 21:34:51 +02:00
self . _dot _size = 0.8 ;
2010-04-15 08:20:56 +02:00
}
var table = '<table class="scatterplot-matrix-table"><tbody>' ;
2010-04-30 21:14:45 +02:00
var createScatterplot = function ( cx , cy ) {
2010-04-15 08:20:56 +02:00
var title = cx + ' (x) vs. ' + cy + ' (y)' ;
var link = '<a href="javascript:{}" title="' + title + '" cx="' + cx + '" cy="' + cy + '">' ;
var plotter _params = {
'cx' : cx ,
'cy' : cy ,
2010-04-17 05:00:38 +02:00
'l' : self . _plot _size ,
2010-04-15 08:20:56 +02:00
'dot' : self . _dot _size ,
2010-04-17 05:00:38 +02:00
'dim_x' : self . _plot _method ,
'dim_y' : self . _plot _method ,
'r' : self . _rotation
2010-04-15 08:20:56 +02:00
} ;
var params = {
project : theProject . id ,
engine : JSON . stringify ( ui . browsingEngine . getJSON ( ) ) ,
plotter : JSON . stringify ( plotter _params )
} ;
2010-04-30 21:14:45 +02:00
var url = "/command/get-scatterplot?" + $ . param ( params ) ;
2010-04-30 06:09:04 +02:00
var attrs = [
'width="' + self . _plot _size + '"' ,
2010-04-30 21:14:45 +02:00
'height="' + self . _plot _size + '"' ,
'src2="' + url + '"'
2010-04-30 06:09:04 +02:00
] ;
return link + '<img ' + attrs . join ( ' ' ) + ' /></a>' ;
2010-04-14 07:14:33 +02:00
} ;
2010-04-15 08:20:56 +02:00
for ( var i = 0 ; i < columns . length ; i ++ ) {
table += '<tr>' ;
var div _class = "column_header" ;
if ( columns [ i ] . name == self . _column ) div _class += " current_column" ;
2010-05-05 02:26:26 +02:00
table += '<td class="' + div _class + '" colspan="' + ( i + 1 ) + '">' + columns [ i ] . name + '</td>' ;
2010-04-15 08:20:56 +02:00
for ( var j = i + 1 ; j < columns . length ; j ++ ) {
var cx = columns [ i ] . name ;
var cy = columns [ j ] . name ;
var div _class = "scatterplot" ;
2010-04-30 06:09:04 +02:00
var current = cx == self . _column || cy == self . _column ;
if ( current ) div _class += " current_column" ;
2010-04-30 21:14:45 +02:00
table += '<td><div class="' + div _class + '">' + createScatterplot ( cx , cy ) + '</div></td>' ;
2010-04-15 08:20:56 +02:00
}
table += '</tr>' ;
2010-04-14 07:14:33 +02:00
}
2010-04-15 08:20:56 +02:00
table += "</tbody></table>" ;
var width = container . width ( ) ;
2010-04-30 06:09:04 +02:00
container . empty ( ) . css ( "width" , width + "px" ) . html ( table ) ;
2010-04-15 08:20:56 +02:00
container . find ( "a" ) . click ( function ( ) {
var options = {
"name" : $ ( this ) . attr ( "title" ) ,
2010-04-17 05:00:38 +02:00
"cx" : $ ( this ) . attr ( "cx" ) ,
"cy" : $ ( this ) . attr ( "cy" ) ,
2010-04-30 08:12:42 +02:00
"l" : 150 ,
2010-04-17 05:00:38 +02:00
"ex" : "value" ,
"ey" : "value" ,
2010-04-15 08:20:56 +02:00
"dot" : self . _dot _size ,
2010-04-17 05:00:38 +02:00
"dim_x" : self . _plot _method ,
"dim_y" : self . _plot _method ,
'r' : self . _rotation
2010-04-15 08:20:56 +02:00
} ;
ui . browsingEngine . addFacet ( "scatterplot" , options ) ;
2010-05-07 01:20:51 +02:00
self . _dismiss ( ) ;
2010-04-15 08:20:56 +02:00
} ) ;
2010-04-30 23:19:13 +02:00
2010-04-30 21:14:45 +02:00
var load _images = function ( data ) {
2010-04-30 23:19:13 +02:00
if ( self . _active ) {
data . batch = 0 ;
var end = Math . min ( data . index + data . batch _size , data . images . length ) ;
for ( ; data . index < end ; data . index ++ ) {
load _image ( data ) ;
2010-04-30 06:09:04 +02:00
}
2010-04-15 08:20:56 +02:00
}
2010-04-30 21:14:45 +02:00
} ;
2010-04-30 23:19:13 +02:00
var load _image = function ( data ) {
var img = $ ( data . images [ data . index ] ) ;
var src2 = img . attr ( "src2" ) ;
if ( src2 ) {
img . attr ( "src" , src2 ) ;
img . removeAttr ( "src2" ) ;
img . load ( function ( ) {
data . batch ++ ;
if ( data . batch == data . batch _size ) {
load _images ( data ) ;
}
} ) ;
}
} ;
2010-04-30 21:14:45 +02:00
load _images ( {
index : 0 ,
2010-04-30 23:19:13 +02:00
batch _size : 4 ,
2010-04-30 21:14:45 +02:00
images : container . find ( ".scatterplot img" )
2010-05-05 02:26:26 +02:00
} ) ;
2010-04-15 08:20:56 +02:00
} ) ;
2010-04-10 10:28:06 +02:00
} else {
container . html (
'<div style="margin: 2em;"><div style="font-size: 130%; color: #333;">There are no columns in this dataset</div></div>'
) ;
}
} ;
ScatterplotDialog . prototype . _dismiss = function ( ) {
2010-04-30 21:14:45 +02:00
this . _active = false ;
2010-04-10 10:28:06 +02:00
DialogSystem . dismissUntil ( this . _level - 1 ) ;
} ;