3426a07096
WIP #488 Added logs for graph plotting WIP #488 Added graph creation from cmdline logs WIP #488 Fixed JobEditor bugs exposed by metadata WIP #488 Removed old metadata on ExecuteJob WIP #488 Moved graph points to graph attribute WIP #488 Removed extra whitespace in points WIP #488 Fixed graph id collisions between jobs WIP #488 Created OutputViewer WIP #488 Added filtering for the metadata nodes WIP #488 Fixed visibility WIP #488 Adding auto hide when not relevant WIP #488 remove entries from pagination on delete WIP #488 Added initialization to the LineGraph WIP #488 Added LineGraph viz boilerplate WIP #488 Added basic linegraph WIP #488 Set LineGraph to use the 'Graph' node WIP #488 Fixed double-playing commands WIP #488 Fixed graph sizing and showing in the outputviewer WIP #488 Adding metadata updating support WIP #488 Updating graph w/ new data WIP #488 Added some multi-line support WIP #488 Added mult-line support for LineGraph WIP #488 Added Graph metadata type WIP #488 Fixed 'No Data Available' on quick graph open WIP #488 revert to console if active graph deleted WIP #488 Fixed graph update error WIP #488 Fixed JobEditor nodeId checking WIP #488 Removed 'points' from Graph WIP #488 Filtered out deepforge commands from stdout WIP #488 Fixed filtering deepforge cmds WIP #488 Fixed ExecutePipeline WIP #488 Added nvd3 to codeclimate ignore WIP #488. better error handling for incorrect node types WIP #488 Removed extra files and fixed code climate issues
185 linhas
5.8 KiB
JavaScript
185 linhas
5.8 KiB
JavaScript
/*globals define, WebGMEGlobal*/
|
|
/*jshint browser: true*/
|
|
|
|
define([
|
|
'js/Constants',
|
|
'js/Utils/GMEConcepts',
|
|
'js/NodePropertyNames'
|
|
], function (
|
|
CONSTANTS,
|
|
GMEConcepts,
|
|
nodePropertyNames
|
|
) {
|
|
|
|
'use strict';
|
|
|
|
var LineGraphControl;
|
|
|
|
LineGraphControl = function (options) {
|
|
|
|
this._logger = options.logger.fork('Control');
|
|
|
|
this._client = options.client;
|
|
this._embedded = options.embedded;
|
|
|
|
// Initialize core collections and variables
|
|
this._widget = options.widget;
|
|
|
|
this._currentNodeId = null;
|
|
this._currentNodeParentId = undefined;
|
|
|
|
this._logger.debug('ctor finished');
|
|
};
|
|
|
|
/* * * * * * * * Visualizer content update callbacks * * * * * * * */
|
|
// One major concept here is with managing the territory. The territory
|
|
// defines the parts of the project that the visualizer is interested in
|
|
// (this allows the browser to then only load those relevant parts).
|
|
LineGraphControl.prototype.selectedObjectChanged = function (nodeId) {
|
|
var desc = this._getObjectDescriptor(nodeId),
|
|
self = this;
|
|
|
|
self._logger.debug('activeObject nodeId \'' + nodeId + '\'');
|
|
|
|
// Remove current territory patterns
|
|
if (self._currentNodeId) {
|
|
self._client.removeUI(self._territoryId);
|
|
}
|
|
|
|
self._currentNodeId = nodeId;
|
|
self._currentNodeParentId = undefined;
|
|
|
|
if (typeof self._currentNodeId === 'string') {
|
|
// Put new node's info into territory rules
|
|
self._selfPatterns = {};
|
|
self._selfPatterns[nodeId] = {children: 0}; // Territory "rule"
|
|
|
|
self._widget.setTitle(desc.name.toUpperCase());
|
|
|
|
self._currentNodeParentId = desc.parentId;
|
|
|
|
self._territoryId = self._client.addUI(self, function (events) {
|
|
self._eventCallback(events);
|
|
});
|
|
|
|
// Update the territory
|
|
self._client.updateTerritory(self._territoryId, self._selfPatterns);
|
|
|
|
self._selfPatterns[nodeId] = {children: 1};
|
|
self._client.updateTerritory(self._territoryId, self._selfPatterns);
|
|
}
|
|
};
|
|
|
|
// This next function retrieves the relevant node information for the widget
|
|
LineGraphControl.prototype._getObjectDescriptor = function (nodeId) {
|
|
var node = this._client.getNode(nodeId),
|
|
desc;
|
|
|
|
if (node) {
|
|
desc = {
|
|
id: node.getId(),
|
|
name: node.getAttribute(nodePropertyNames.Attributes.name)
|
|
};
|
|
|
|
// Check if it is a line
|
|
if (desc.id !== this._currentNodeId) {
|
|
var points = (node.getAttribute('points') || '').split(';')
|
|
.map(pair => {
|
|
var nums = pair.split(','),
|
|
x = +nums[0],
|
|
y = +nums[1];
|
|
|
|
return {
|
|
x: x,
|
|
y:y
|
|
};
|
|
});
|
|
desc.type = 'line';
|
|
desc.points = points;
|
|
}
|
|
}
|
|
|
|
return desc;
|
|
};
|
|
|
|
/* * * * * * * * Node Event Handling * * * * * * * */
|
|
LineGraphControl.prototype._eventCallback = function (events) {
|
|
var i = events ? events.length : 0,
|
|
event;
|
|
|
|
this._logger.debug('_eventCallback \'' + i + '\' items');
|
|
|
|
while (i--) {
|
|
event = events[i];
|
|
switch (event.etype) {
|
|
|
|
case CONSTANTS.TERRITORY_EVENT_LOAD:
|
|
this._onLoad(event.eid);
|
|
break;
|
|
case CONSTANTS.TERRITORY_EVENT_UPDATE:
|
|
this._onUpdate(event.eid);
|
|
break;
|
|
case CONSTANTS.TERRITORY_EVENT_UNLOAD:
|
|
this._onUnload(event.eid);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
this._logger.debug('_eventCallback \'' + events.length + '\' items - DONE');
|
|
};
|
|
|
|
LineGraphControl.prototype._onLoad = function (gmeId) {
|
|
var description = this._getObjectDescriptor(gmeId);
|
|
this._widget.addNode(description);
|
|
};
|
|
|
|
LineGraphControl.prototype._onUpdate = function (gmeId) {
|
|
var description = this._getObjectDescriptor(gmeId);
|
|
this._widget.updateNode(description);
|
|
};
|
|
|
|
LineGraphControl.prototype._onUnload = function (gmeId) {
|
|
this._widget.removeNode(gmeId);
|
|
};
|
|
|
|
LineGraphControl.prototype._stateActiveObjectChanged = function (model, activeObjectId) {
|
|
if (this._currentNodeId === activeObjectId) {
|
|
// The same node selected as before - do not trigger
|
|
} else {
|
|
this.selectedObjectChanged(activeObjectId);
|
|
}
|
|
};
|
|
|
|
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
|
|
LineGraphControl.prototype.destroy = function () {
|
|
this._detachClientEventListeners();
|
|
};
|
|
|
|
LineGraphControl.prototype._attachClientEventListeners = function () {
|
|
this._detachClientEventListeners();
|
|
WebGMEGlobal.State.on('change:' + CONSTANTS.STATE_ACTIVE_OBJECT, this._stateActiveObjectChanged, this);
|
|
};
|
|
|
|
LineGraphControl.prototype._detachClientEventListeners = function () {
|
|
WebGMEGlobal.State.off('change:' + CONSTANTS.STATE_ACTIVE_OBJECT, this._stateActiveObjectChanged);
|
|
};
|
|
|
|
LineGraphControl.prototype.onActivate = function () {
|
|
this._attachClientEventListeners();
|
|
|
|
if (typeof this._currentNodeId === 'string') {
|
|
WebGMEGlobal.State.registerSuppressVisualizerFromNode(true);
|
|
WebGMEGlobal.State.registerActiveObject(this._currentNodeId);
|
|
WebGMEGlobal.State.registerSuppressVisualizerFromNode(false);
|
|
}
|
|
};
|
|
|
|
LineGraphControl.prototype.onDeactivate = function () {
|
|
this._detachClientEventListeners();
|
|
};
|
|
|
|
return LineGraphControl;
|
|
});
|