Difference between revisions of "Widget:GraphInteractivity"
m (first attempt at space state update) |
m (fixed various (jslint) issues) |
||
Line 22: | Line 22: | ||
var g_coloredNodes; | var g_coloredNodes; | ||
− | window.addEventListener( "load", function() | + | window.addEventListener( "load", function(){g_graphs = document.querySelectorAll( "svg > g.graph" ); |
g_coloredNodes = [];//[ [ g_graphs[0].querySelector( "g#h4" ), "green" ] ]; | g_coloredNodes = [];//[ [ g_graphs[0].querySelector( "g#h4" ), "green" ] ]; | ||
Line 57: | Line 57: | ||
_graph.querySelectorAll( "g[id] > *" ).forEach( function( _gNode ) | _graph.querySelectorAll( "g[id] > *" ).forEach( function( _gNode ) | ||
{ | { | ||
− | if ( !_arrNodeColors.some( function( _nodeColor )
| + | if ( !_arrNodeColors.some( function( _nodeColor )
|
+ | { | ||
if ( _nodeColor[0] && _nodeColor[0].getAttribute( "class" ) !== "graph" && _gNode.parentNode.id === _nodeColor[0].id ) | if ( _nodeColor[0] && _nodeColor[0].getAttribute( "class" ) !== "graph" && _gNode.parentNode.id === _nodeColor[0].id ) | ||
− | return _gNode.style.stroke = _nodeColor[1]; | + | return ( _gNode.style.stroke = _nodeColor[1] ); |
return false; | return false; | ||
} ) ) | } ) ) | ||
Line 84: | Line 85: | ||
return; | return; | ||
if ( _event.target.status === 200 ) | if ( _event.target.status === 200 ) | ||
− | _xhr_onload | + | _xhr_onload( _event ); |
//else | //else | ||
− | //_xhr_onerror | + | //_xhr_onerror( _event ); |
− | } | + | }; |
} | } | ||
else | else | ||
{ | { | ||
// Modern xhr | // Modern xhr | ||
− | xhr.onload = _xhr_onload | + | xhr.onload = _xhr_onload( ); |
− | //xhr.onerror = _xhr_onerror | + | //xhr.onerror = _xhr_onerror( ); |
} | } | ||
xhr.open( "GET", "//ackspace.nl/spaceAPI/", true ); | xhr.open( "GET", "//ackspace.nl/spaceAPI/", true ); | ||
Line 103: | Line 104: | ||
// No data needs to be sent along with the request. | // No data needs to be sent along with the request. | ||
xhr.send( null ); | xhr.send( null ); | ||
− | } | + | } |
function _xhr_onload( _event ) | function _xhr_onload( _event ) | ||
Line 127: | Line 128: | ||
var color = "green"; | var color = "green"; | ||
− | g_coloredNodes.push( document.querySelector( "g#" + _powerConsumption.name ), color ] ); | + | g_coloredNodes.push( [ document.querySelector( "g#" + _powerConsumption.name ), color ] ); |
} ); | } ); | ||
Revision as of 13:39, 29 May 2018
This widget allows you to display the Space API data (provided as JSON)
Created by Xopr
Using this widget
To insert this widget, use the following code:
{{#widget:GraphInteractivity}}
This will add javascript logic that enables 'interactivity' to graphs.
Copy to your site
To use this widget on your site, just install MediaWiki Widgets extension and copy full source code of this page to your wiki as Widget:GraphInteractivity article.