2011-06-24 21:41:32 +05:30
// var R;
2011-06-28 00:48:53 +05:30
function supportsSvg ( ) {
2011-06-28 01:20:39 +05:30
return ! ! document . createElementNS && ! ! document . createElementNS ( "http://www.w3.org/2000/svg" , "svg" ) . createSVGRect ;
2011-06-28 00:48:53 +05:30
}
2011-06-24 21:15:19 +05:30
2011-06-27 19:23:03 +05:30
function getNode ( nodeKey ) {
var ret = false ;
$ ( 'text' ) . each ( function ( ) {
var $this = $ ( this ) ;
if ( typeof ( $ ( this ) . data ( "key" ) ) != 'undefined' ) {
if ( $this . data ( "key" ) == nodeKey ) {
ret = $this ;
}
}
} ) ;
return ret ;
}
2011-06-24 21:38:29 +05:30
2011-06-24 21:15:19 +05:30
$ ( function ( ) {
2011-06-28 00:48:53 +05:30
if ( ! supportsSvg ) {
$ ( 'body' ) . text ( "Sorry, your browser does not support Scalable Vector Graphics (SVG), which were used to make this page. Please use Firefox 4.0+ or Google Chrome if you wish to see this page. Thanks! Sorry for the trouble..." ) ;
return ;
}
2011-06-25 01:47:05 +05:30
$ ( window ) . resize ( function ( ) {
var svgAspect = 1220 / 560 ;
var windowWidth = $ ( window ) . width ( ) ;
var svgWidth = windowWidth - 20 ;
var svgHeight = parseInt ( svgWidth / svgAspect ) ;
$ ( 'svg' ) . attr ( "width" , svgWidth ) ;
$ ( 'svg' ) . attr ( "height" , svgHeight ) ;
} ) ;
$ ( window ) . resize ( ) ;
2011-06-24 21:15:19 +05:30
$ . getJSON ( "radia.json" , { } , function ( data ) {
2011-06-27 19:23:03 +05:30
var highlightCSS = {
2011-06-27 20:23:56 +05:30
'opacity' : "1.0"
// 'fontWeight': 'bold',
// 'backgroundColor': '#ffff00'
2011-06-27 19:23:03 +05:30
}
var unhighlightCSS = {
2011-06-27 22:47:39 +05:30
'opacity' : "0.7"
2011-06-27 20:23:56 +05:30
// 'fontWeight': 'normal',
// 'backgroundColor': '#ffffff'
2011-06-27 19:23:03 +05:30
}
2011-06-24 21:41:32 +05:30
var R = data ;
2011-06-24 21:38:29 +05:30
var $texts = [ ] ;
2011-06-26 02:49:04 +05:30
$ ( 'g' ) . each ( function ( ) {
// console.log("hi");
if ( typeof ( $ ( this ) . attr ( "id" ) ) === 'undefined' ) {
return ;
}
2011-06-27 19:23:03 +05:30
2011-06-26 02:49:04 +05:30
$ ( this ) . click ( function ( ) {
2011-06-27 03:55:16 +05:30
// console.log($(this).attr("id"));
2011-06-26 02:49:04 +05:30
} ) ;
2011-06-27 19:23:03 +05:30
$ ( this ) . hover ( function ( ) {
// console.log("hovered " + $(this).attr("id"));
var $this = $ ( this ) ;
var id = $this . attr ( "id" ) ;
if ( id . indexOf ( "box" ) != - 1 ) {
return ; //FIXME: handle box hovers
}
if ( RIDS . hasOwnProperty ( id ) ) {
$this . highlightLine ( ) ;
// console.log(id);
if ( LINES . hasOwnProperty ( id ) ) {
var nodes = LINES [ id ] ;
// console.log(nodes);
for ( var i = 0 ; i < nodes . length ; i ++ ) {
2011-06-28 00:48:53 +05:30
// console.log(nodes[i]);
2011-06-27 19:23:03 +05:30
var $node = getNode ( nodes [ i ] ) ;
2011-06-27 22:47:39 +05:30
$node . highlightNode ( ) ;
2011-06-27 19:23:03 +05:30
}
}
}
2011-06-27 03:55:16 +05:30
// console.log($(this).attr("id"));
2011-06-27 19:23:03 +05:30
} , function ( ) {
var $this = $ ( this ) ;
var id = $this . attr ( "id" ) ;
if ( id . indexOf ( "box" ) != - 1 ) {
return ; //FIXME: handle box hovers
}
if ( RIDS . hasOwnProperty ( id ) ) {
$this . unhighlightLine ( ) ;
// console.log(id);
if ( LINES . hasOwnProperty ( id ) ) {
var nodes = LINES [ id ] ;
// console.log(nodes);
for ( var i = 0 ; i < nodes . length ; i ++ ) {
2011-06-28 00:48:53 +05:30
// console.log(nodes[i]);
2011-06-27 19:23:03 +05:30
var $node = getNode ( nodes [ i ] ) ;
2011-06-27 22:47:39 +05:30
$node . unhighlightNode ( ) ;
2011-06-27 19:23:03 +05:30
}
}
}
2011-06-26 02:49:04 +05:30
} ) ;
} ) ;
2011-06-26 07:56:54 +05:30
$ ( '#heartpng' ) . hover ( function ( ) {
// console.log("HEART damnit");
// $('#rajakani').find('line').css({'stroke': '#ff00ff'});
$ ( '#loveline' ) . css ( { 'stroke' : '#ff00ff' } ) ;
2011-06-26 04:44:43 +05:30
} , function ( ) {
2011-06-27 19:23:03 +05:30
$ ( '#loveline' ) . css ( { 'stroke' : '#666666' } ) ;
2011-06-26 04:44:43 +05:30
} ) ;
2011-06-26 07:56:54 +05:30
// $('#heartpng').click(function() { alert("foo") });
2011-06-26 04:44:43 +05:30
2011-06-24 21:15:19 +05:30
$ ( 'text' ) . each ( function ( ) {
2011-06-26 01:43:33 +05:30
$ ( this ) . css ( { 'cursor' : 'pointer' } ) ;
2011-06-24 21:15:19 +05:30
var $tspan = $ ( this ) . children ( 'tspan' ) . eq ( 0 ) ;
var key = $ . trim ( $tspan . text ( ) ) ;
if ( R . hasOwnProperty ( key ) ) {
thisData = R [ key ] ;
var $this = $ ( this ) ;
2011-06-27 03:55:16 +05:30
if ( key == 'Journalists' ) {
J = $this ;
}
2011-06-24 21:15:19 +05:30
// $this.data("r", thisData);
2011-06-26 08:50:09 +05:30
$this . data ( "key" , key ) ;
2011-06-24 21:15:19 +05:30
$this . data ( "name" , thisData . name ) ;
$this . data ( "type" , thisData . type ) ;
$this . data ( "link" , thisData . link ) ;
2011-06-27 19:41:30 +05:30
if ( thisData . hasOwnProperty ( "lines" ) ) {
$this . data ( "lines" , thisData . lines . split ( ", " ) ) ;
} else {
$this . data ( "lines" , [ ] ) ;
}
2011-06-26 07:56:54 +05:30
// $this.addClass(thisData.type);
2011-06-27 03:55:16 +05:30
// console.log($this.data("key"));
// console.log($this.hasTooltip());
2011-06-27 04:02:07 +05:30
if ( ! $this . isLegend ( ) ) {
2011-06-27 03:55:16 +05:30
$this . tooltip ( {
'delay' : 0 ,
'showURL' : false ,
'bodyHandler' : function ( ) {
var html = "<div class='ttWrapper'>" ;
html += "<div class='tooltipName'>" + $ ( this ) . data ( "name" ) + "</div>" ;
html += "<div class='padmaPosters'>" + getPostersHTML ( PADMA [ $ ( this ) . data ( "key" ) ] ) + "</div>" ;
html += "</div>" ;
return html ;
}
} ) ;
} else {
// console.log(key);
}
2011-06-24 21:38:29 +05:30
$texts . push ( $this ) ;
2011-06-27 19:23:03 +05:30
// var highlightShadow = '2px 2px 1px #666';
2011-06-24 21:15:19 +05:30
$this . mouseover ( function ( e ) {
2011-06-24 21:38:29 +05:30
var typ = $ ( this ) . data ( "type" ) ;
2011-06-27 03:55:16 +05:30
if ( typ === "" ) { return }
2011-06-24 21:38:29 +05:30
for ( var i = 0 ; i < $texts . length ; i ++ ) {
var $t = $texts [ i ] ;
if ( $t . data ( "type" ) == typ ) {
2011-06-27 22:47:39 +05:30
$t . highlightNode ( ) ;
2011-06-24 21:38:29 +05:30
}
}
2011-06-27 19:23:03 +05:30
var lines = $ ( this ) . data ( "lines" ) ;
if ( lines . length > 0 ) {
for ( var i = 0 ; i < lines . length ; i ++ ) {
var thisLine = lines [ i ] ;
var $line = $ ( '#' + thisLine ) ;
$line . highlightLine ( ) ;
}
}
2011-06-24 21:38:29 +05:30
// $('.' + cls).addClass("highlighted");
// console.log($('.' + cls).length);
2011-06-24 21:15:19 +05:30
} ) ;
$this . mouseout ( function ( e ) {
2011-06-24 21:38:29 +05:30
var typ = $ ( this ) . data ( "type" ) ;
2011-06-27 03:55:16 +05:30
if ( typ === '' ) { return ; }
2011-06-24 21:38:29 +05:30
for ( var i = 0 ; i < $texts . length ; i ++ ) {
var $t = $texts [ i ] ;
if ( $t . data ( "type" ) == typ ) {
2011-06-27 22:47:39 +05:30
$t . unhighlightNode ( ) ;
2011-06-24 21:38:29 +05:30
}
}
2011-06-27 19:23:03 +05:30
var lines = $ ( this ) . data ( "lines" ) ;
if ( lines . length > 0 ) {
for ( var i = 0 ; i < lines . length ; i ++ ) {
var thisLine = lines [ i ] ;
var $line = $ ( '#' + thisLine ) ;
$line . unhighlightLine ( ) ;
}
}
2011-06-24 21:38:29 +05:30
// $('.' + cls).removeClass("highlighted");
2011-06-24 21:15:19 +05:30
} ) ;
2011-06-24 21:38:29 +05:30
2011-06-24 21:15:19 +05:30
$this . click ( function ( ) {
2011-06-27 04:02:07 +05:30
if ( $this . isLegend ( ) ) {
2011-06-27 03:59:43 +05:30
return ;
}
2011-06-26 01:37:37 +05:30
window . open ( $ ( this ) . data ( "link" ) ) ;
// console.log($(this).data("link"));
2011-06-24 21:15:19 +05:30
} ) ;
}
} ) ;
} ) ;
} ) ;
2011-06-24 21:38:29 +05:30
2011-06-26 08:50:09 +05:30
function getPostersHTML ( padma _ids ) {
2011-06-27 01:23:44 +05:30
if ( typeof ( padma _ids ) === 'undefined' ) {
return '' ;
}
2011-06-26 22:22:47 +05:30
var limit = 0 ; //limit is the no of posters to show minus one
2011-06-26 08:50:09 +05:30
var html = '' ;
for ( var i = 0 ; i < padma _ids . length ; i ++ ) {
if ( i > limit ) { break ; }
2012-02-14 15:01:11 +05:30
var posterLink = "http://next.pad.ma/" + padma _ids [ i ] + "/icon320.jpg" ;
2011-06-26 08:50:09 +05:30
html += "<img src='" + posterLink + "' />" ;
}
return html ;
}
2011-06-27 03:55:16 +05:30
2011-06-27 04:02:07 +05:30
jQuery . fn . isLegend = function ( ) {
2011-06-27 03:55:16 +05:30
if ( typeof ( this . data ( "key" ) ) == 'undefined' ) {
2011-06-27 04:02:07 +05:30
return true ;
2011-06-27 03:55:16 +05:30
}
// console.log(parseInt(this.attr("x")));
if ( parseInt ( this . attr ( "x" ) ) > 1200 ) {
if ( $ . inArray ( this . data ( "key" ) , [ "Journalists" , "Corporates" , "Vaishnavi" , "Politicians" , "Issues" , "Mention of," ] ) != - 1 ) {
return true ;
2011-06-27 04:02:07 +05:30
} else {
return false ;
2011-06-27 03:55:16 +05:30
}
}
2011-06-27 04:02:07 +05:30
return false ;
2011-06-27 03:55:16 +05:30
}
2011-06-27 19:23:03 +05:30
jQuery . fn . highlightLine = function ( ) {
this . find ( 'line, polyline, path' ) . css ( { 'stroke' : '#000000' } ) ;
2011-06-27 20:09:02 +05:30
this . find ( 'path' ) . css ( { 'strokeDasharray' : '0' } ) ;
2011-06-27 19:23:03 +05:30
}
jQuery . fn . unhighlightLine = function ( ) {
this . find ( 'line, polyline, path' ) . css ( { 'stroke' : '#666666' } ) ;
2011-06-27 20:09:02 +05:30
this . find ( "path" ) . css ( { 'strokeDasharray' : '4' } ) ;
2011-06-27 19:23:03 +05:30
}
2011-06-27 22:47:39 +05:30
jQuery . fn . highlightNode = function ( ) {
this . css ( { 'opacity' : '1.0' } ) ;
if ( this . data ( "type" ) == 'rivalgroup' ) {
this . css ( { 'fontWeight' : 'bold' } ) ;
} else {
var prev = this . prev ( ) ;
if ( prev . is ( 'rect' ) ) {
this . prev ( ) . css ( { 'fill' : '#FAFF3E' } ) ;
}
}
}
jQuery . fn . unhighlightNode = function ( ) {
this . css ( { 'opacity' : '0.7' } ) ;
if ( this . data ( "type" ) == 'rivalgroup' ) {
this . css ( { 'fontWeight' : 'normal' } ) ;
} else {
var prev = this . prev ( ) ;
if ( prev . is ( 'rect' ) ) {
this . prev ( ) . css ( { 'fill' : '#ffffff' } ) ;
}
}
}