App-Netdisco
view release on metacpan or search on metacpan
share/public/javascripts/d3-force-network-chart.js view on Meta::CPAN
/**
* This is the global function which encapsulates all variables and methods. All
* parameters are optional.
*
* The shortest possible way to get up and running a graph with the shipped sample data:
*
* example = netGobrechtsD3Force().start();
*
* You can then interact with the graph API like so:
*
* example.width(800).height(600).resume();
* @see {@link module:API.start}
* @see {@link module:API.render}
* @see {@link module:API.resume}
* @param {string} [domContainerId] - The DOM container, where the graph should be rendered
* @param {Object} [options] - The configuration object to configure the graph
* @param {string} [apexPluginId] - APEX plugin only: The plugin identifier for the AJAX calls
* @param {string} [apexPageItemsToSubmit] - APEX plugin only: Page items to submit before an AJAX call
* @returns {Object} The public graph API function to allow method chaining
*/
function netGobrechtsD3Force(domContainerId, options, apexPluginId, apexPageItemsToSubmit) { // jshint ignore:line
/* exported netGobrechtsD3Force */
/* globals apex, $v, navigator, d3, document, console, window, clearInterval, ActiveXObject, DOMParser, setTimeout */
/* jshint -W101 */
"use strict";
// setup graph variable
var v = {
"conf": {},
"confDefaults": {},
"data": {},
"dom": {},
"events": {},
"lib": {},
"main": {},
"status": {},
"tools": {},
"version": "x.x.x"
};
/**
* A module representing the public graph API.
* @exports API
*/
var graph = {};
/**
* A helper function to initialize the graph
*/
v.main.init = function() {
// save parameter for later use
v.dom.containerId = domContainerId || "D3Force" + Math.floor(Math.random() * 1000000);
v.confUser = options || {};
v.status.apexPluginId = apexPluginId;
v.status.apexPageItemsToSubmit = (!apexPageItemsToSubmit || apexPageItemsToSubmit === "" ? false :
apexPageItemsToSubmit.replace(/\s/g, "").split(","));
// initialize the graph function
v.main.setupConfiguration();
v.main.setupDom();
v.main.setupFunctionReferences();
};
/*******************************************************************************************************************
* MAIN: SETUP CONFIGURATION
*/
v.main.setupConfiguration = function() {
/* jshint -W074, -W071 */
// configure debug mode for APEX, can be overwritten by users configuration object
// or later on with the API debug method
v.conf.debug = (v.status.apexPluginId && apex.jQuery("#pdebug").length === 1);
v.status.debugPrefix = "D3 Force in DOM container #" + v.dom.containerId + ": ";
// status variables
v.status.customize = false;
v.status.customizeCurrentMenu = "nodes";
v.status.customizeCurrentTabPosition = null;
v.status.forceTickCounter = 0;
v.status.forceStartTime = 0;
v.status.forceRunning = false;
share/public/javascripts/d3-force-network-chart.js view on Meta::CPAN
}
v.conf.debug = value;
if (v.status.graphStarted) {
if (v.conf.debug) {
v.tools.createCustomizeLink();
} else {
v.tools.removeCustomizeLink();
}
}
return graph;
};
/**
* Returns the detected user agent. Expects no parameter and terminates the method chain:
*
* example.userAgent();
* @see {@link module:API.inspect}
* @returns {string} The detected user agent.
*/
graph.userAgent = function() {
return v.status.userAgent;
};
/**
* Shows the current closure object, which holds all functions and data. This method expects no parameter and terminates the method chain:
*
* example.inspect();
* @see {@link module:API.userAgent}
* @returns {Object} The graph's internal object with all functions and data.
*/
graph.inspect = function() {
return v;
};
/**
* Shows the current plugin version. This method expects no parameter and terminates the method chain:
*
* example.version();
* @see {@link module:API.userAgent}
* @returns {string} The plugin version.
*/
graph.version = function() {
return v.version;
};
/*******************************************************************************************************************
* Startup code - runs one time after the initialization of a new chart - example:
* var myChart = net_gobrechts_d3_force( domContainerId, pConf, apexPluginId ).start();
*/
if (v.status.apexPluginId) {
// bind to the apexrefresh event, so that this region can be refreshed by a dynamic action
apex.jQuery("#" + v.dom.containerId).bind("apexrefresh", function() {
graph.start();
});
//rerender on window resize
apex.jQuery(window).on("apexwindowresized", function() {
graph.render();
});
apex.jQuery("#t_Button_navControl").click(function() {
setTimeout(function() {
graph.render();
}, 500);
});
}
// final return
return graph;
}
( run in 0.809 second using v1.01-cache-2.11-cpan-39bf76dae61 )