<commit_before><SimpleVisTool xmlns="weave.visualization.tools.*" 
	     xmlns:mx="http://www.adobe.com/2006/mxml"
	     xmlns:ui="weave.ui.*" 
		 xmlns:userControls="weave.ui.userControls.*"
		 layout="absolute">
	<mx:Script>
		<![CDATA[
			import weave.Weave;
			import weave.api.WeaveAPI;
			import weave.api.data.IKeySet;
			import weave.api.data.IQualifiedKey;
			import weave.api.data.IAttributeColumn;
			import weave.api.getCallbackCollection;
			import weave.api.graphs.IGraphAlgorithm;
			import weave.api.linkBindableProperty;
			import weave.api.linkSessionState;
			import weave.api.primitives.IBounds2D;
			import weave.api.registerLinkableChild;
			import weave.api.registerDisposableChild;
			import weave.api.data.ColumnMetadata;
			import weave.api.ui.IVisTool;
			import weave.core.LinkableBoolean;
			import weave.data.AttributeColumns.AlwaysDefinedColumn;
			import weave.data.AttributeColumns.DynamicColumn;
			import weave.data.KeySets.KeySet;
			import weave.primitives.Bounds2D;
			import flash.external.ExternalInterface;

			public const colorColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleNodeColumnChange);
			public const nodesColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleNodeColumnChange);
			public const edgeSourceColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleEdgeColumnChange);
			public const edgeTargetColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleEdgeColumnChange);
			public const labelColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(), handleNodeColumnChange);
			public const nodeRadiusColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn());
			public const edgeThicknessColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn());

			//private var _subset:KeyFilter = Weave.defaultSubsetKeyFilter;
			private var _selection:KeySet = Weave.defaultSelectionKeySet;
			private var _probe:KeySet = Weave.defaultProbeKeySet;				

			//WeaveAPI.registerImplementation(IVisTool, CytoscapeWebTool, lang("Cytoscape-Web Tool"));
			private var _toolName:String;
			private var _primitive_edges:Object;
			private var _primitive_nodes:Object;
			private var _primitive_network:Object;
			private function launchCytoscape():void
			{
				ExternalInterface.call(
				"function (weaveID, toolname, url, name) {\
				 var weave = weaveID ? document.getElementById(weaveID) : document;\
				 if (weave.cytoscape == undefined) weave.cytoscape = {};\
				 weave.cytoscape[toolname] = window.open(url, toolname);\
				  }", 
					ExternalInterface.objectID, _toolName, "cytoscapeweb/popout.html", _toolName);
			}
			private function sendNetworkToCytoscape():void
			{
				ExternalInterface.call(
					"function (weaveID, toolname, network) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].weave = weave;\
						weave.cytoscape[toolname].WeaveArray = Array;\
						weave.cytoscape[toolname].network = network;\
						weave.cytoscape[toolname].draw(network);\
						}",
						ExternalInterface.objectID, _toolName, _primitive_network);
			}

			private function keySetToNodesAndEdges(keys:IKeySet):Object
			{
				var set_edges:Array = [];
				var set_nodes:Array = [];
				var key_idx:int;
				var key_len:int;
				var node_keytype:String = nodesColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				var edge_keytype:String = edgeSourceColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				if (node_keytype == null || edge_keytype == null || keys == null)
					return {nodes: [], edges: []};
				key_len = keys.keys.length;
				for (key_idx = 0; key_idx < key_len; key_idx++)
				{
					var key:IQualifiedKey = keys.keys[key_idx];
					if (key.keyType == node_keytype)
						set_nodes.push(key.localName);
					else if (key.keyType == edge_keytype)
						set_edges.push(key.localName);
					else
						continue;
				}
				return {nodes: set_nodes, edges: set_edges};
			}
			private function updateProbeChange():void
			{
				var idx:int;
				var len:int;
				var result:Object = keySetToNodesAndEdges(_probe);
				var bypass:Object = {nodes: {}, edges: {}};

				var nodes:Array = result.nodes;
				len = nodes.length;
				for (idx = 0; idx < len; idx++)
				{
					bypass.nodes[nodes[idx]] = {color: "#d9dafe"}; // TODO, set appropriately from Weave style
				}

				var edges:Array = result.edges;
				len = edges.length;
				for (idx = 0; idx < len; idx++)
				{
					bypass.edges[edges[idx]] = {color: "#d9dafe"};
				}
				ExternalInterface.call(
					"function (weaveID, toolname, bypass) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].vis.visualStyleBypass(bypass);\
						}",
						ExternalInterface.objectID, _toolName, bypass);
			}
			private function updateSelectionChange():void
			{
				var result:Object = keySetToNodesAndEdges(_selection);
				ExternalInterface.call(
					"function (weaveID, toolname, elements) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].select(elements);\
						}",
						ExternalInterface.objectID, _toolName, result);
			}

			private function buildPrimitiveNodes():void
			{
				var nodesKeys:Array = nodesColumn.keys;
				var numNodes:int = nodesKeys.length;
				var key_idx:int;
				var key:IQualifiedKey;
				var id:String;
				var label:String;
				var node:Object;
				var nodes:Array = [];
				for (key_idx = 0; key_idx < numNodes; key_idx++)
				{
					node = {};
					key = nodesKeys[key_idx];
					node.id = nodesColumn.getValueFromKey(key, String);
					node.label = labelColumn.getValueFromKey(key, String);
					node.keyType = key.keyType;
					node.localName = key.localName;
					nodes.push(node);
				}
				
				_primitive_nodes = nodes;
			}

			private function buildPrimitiveEdges():void
			{
				var edgeKeys:Array = edgeSourceColumn.keys;
				var numEdges:int = edgeKeys.length;
				var key_idx:int;
				var key:IQualifiedKey;
				var id:String;
				var label:String;
				var edge:Object;
				var edges:Array = [];
				for (key_idx = 0; key_idx < numEdges; key_idx++)
				{
					edge = {};
					key = edgeKeys[key_idx];
					edge.id = key.localName;
					edge.source = edgeSourceColumn.getValueFromKey(key, String);
					edge.target = edgeTargetColumn.getValueFromKey(key, String);
					edge.keyType = key.keyType;
					edge.localName = key.localName;
					edges.push(edge);
				}
				
				_primitive_edges = edges;
			}

			public function buildPrimitiveNetwork():void
			{
				var network:Object = {data: {nodes: [], edges: []}};
				network.dataSchema = {
					nodes: [{name: "label", type: "string"}, {name: "keyType", type: "string"}, {name: "localName", type: "string"}],
					edges: [{name: "label", type: "string"}, {name: "keyType", type: "string"}, {name: "localName", type: "string"}]
				};
				network.data.nodes = _primitive_nodes;
				network.data.edges = _primitive_edges;
				_primitive_network = network;
			}
			private function handleNodeColumnChange():void
			{
				/* We have no real way of validating that a given nodelist corresponds to a given edgelist, so we just assume this is right. */
				buildPrimitiveNodes();
				buildPrimitiveNetwork();
				sendNetworkToCytoscape();
			}
			private function handleEdgeColumnChange():void
			{
				/* If edgesource and edgetarget don't share a common keytype, don't bother rebuilding the edges; the result will be garbage. */
				var srcKeyType:String = edgeSourceColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				var targetKeyType:String = edgeTargetColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				if (srcKeyType != targetKeyType) return;
				buildPrimitiveEdges();
				buildPrimitiveNetwork();
				sendNetworkToCytoscape();
			}

			override protected function childrenCreated():void
			{
				super.childrenCreated();

				colorComponent.dynamicObject = colorColumn;
				nodeComponent.dynamicObject = nodesColumn;
				labelComponent.dynamicObject = labelColumn;<commit_msg>Added session state property for layout choices in CytoscapeWebTool tool.<commit_after><SimpleVisTool xmlns="weave.visualization.tools.*" 
	     xmlns:mx="http://www.adobe.com/2006/mxml"
	     xmlns:ui="weave.ui.*" 
		 xmlns:userControls="weave.ui.userControls.*"
		 layout="absolute">
	<mx:Script>
		<![CDATA[
			import weave.Weave;
			import weave.api.WeaveAPI;
			import weave.api.data.IKeySet;
			import weave.api.data.IQualifiedKey;
			import weave.api.data.IAttributeColumn;
			import weave.api.getCallbackCollection;
			import weave.api.graphs.IGraphAlgorithm;
			import weave.api.linkBindableProperty;
			import weave.api.linkSessionState;
			import weave.api.primitives.IBounds2D;
			import weave.api.registerLinkableChild;
			import weave.api.registerDisposableChild;
			import weave.api.data.ColumnMetadata;
			import weave.api.ui.IVisTool;
			import weave.core.LinkableBoolean;
			import weave.core.LinkableString;
			import weave.core.LinkableNumber;
			import weave.data.AttributeColumns.AlwaysDefinedColumn;
			import weave.data.AttributeColumns.DynamicColumn;
			import weave.data.KeySets.KeySet;
			import weave.primitives.Bounds2D;
			import flash.external.ExternalInterface;

			public const colorColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleNodeColumnChange);
			public const nodesColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleNodeColumnChange);
			public const edgeSourceColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleEdgeColumnChange);
			public const edgeTargetColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(IAttributeColumn), handleEdgeColumnChange);
			public const labelColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn(), handleNodeColumnChange);
			public const nodeRadiusColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn());
			public const edgeThicknessColumn:DynamicColumn = registerLinkableChild(this, new DynamicColumn());
			public const layoutSeed:LinkableNumber = registerLinkableChild(this, new LinkableNumber(0), handleGraphLayoutChange);
			public const layoutType:LinkableString = registerLinkableChild(this, new LinkableString("ForceDirected"), handleGraphLayoutChange);

			//private var _subset:KeyFilter = Weave.defaultSubsetKeyFilter;
			private var _selection:KeySet = Weave.defaultSelectionKeySet;
			private var _probe:KeySet = Weave.defaultProbeKeySet;				

			//WeaveAPI.registerImplementation(IVisTool, CytoscapeWebTool, lang("Cytoscape-Web Tool"));
			private var _toolName:String;
			private var _primitive_edges:Object;
			private var _primitive_nodes:Object;
			private var _primitive_network:Object;
			private function launchCytoscape():void
			{
				ExternalInterface.call(
				"function (weaveID, toolname, url, name) {\
				 var weave = weaveID ? document.getElementById(weaveID) : document;\
				 if (weave.cytoscape == undefined) weave.cytoscape = {};\
				 weave.cytoscape[toolname] = window.open(url, toolname);\
				  }", 
					ExternalInterface.objectID, _toolName, "cytoscapeweb/popout.html", _toolName);
			}
			private function sendNetworkToCytoscape():void
			{
				ExternalInterface.call(
					"function (weaveID, toolname, network) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].weave = weave;\
						weave.cytoscape[toolname].WeaveArray = Array;\
						weave.cytoscape[toolname].network = network;\
						weave.cytoscape[toolname].draw(network);\
						}",
						ExternalInterface.objectID, _toolName, _primitive_network);
			}
			private function keySetToNodesAndEdges(keys:IKeySet):Object
			{
				var set_edges:Array = [];
				var set_nodes:Array = [];
				var key_idx:int;
				var key_len:int;
				var node_keytype:String = nodesColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				var edge_keytype:String = edgeSourceColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				if (node_keytype == null || edge_keytype == null || keys == null)
					return {nodes: [], edges: []};
				key_len = keys.keys.length;
				for (key_idx = 0; key_idx < key_len; key_idx++)
				{
					var key:IQualifiedKey = keys.keys[key_idx];
					if (key.keyType == node_keytype)
						set_nodes.push(key.localName);
					else if (key.keyType == edge_keytype)
						set_edges.push(key.localName);
					else
						continue;
				}
				return {nodes: set_nodes, edges: set_edges};
			}
			private function updateProbeChange():void
			{
				var idx:int;
				var len:int;
				var result:Object = keySetToNodesAndEdges(_probe);
				var bypass:Object = {nodes: {}, edges: {}};

				var nodes:Array = result.nodes;
				len = nodes.length;
				for (idx = 0; idx < len; idx++)
				{
					bypass.nodes[nodes[idx]] = {color: "#d9dafe"}; // TODO, set appropriately from Weave style
				}

				var edges:Array = result.edges;
				len = edges.length;
				for (idx = 0; idx < len; idx++)
				{
					bypass.edges[edges[idx]] = {color: "#d9dafe"};
				}
				ExternalInterface.call(
					"function (weaveID, toolname, bypass) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].vis.visualStyleBypass(bypass);\
						}",
						ExternalInterface.objectID, _toolName, bypass);
			}
			private function updateSelectionChange():void
			{
				var result:Object = keySetToNodesAndEdges(_selection);
				ExternalInterface.call(
					"function (weaveID, toolname, elements) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].select(elements);\
                        console.log(elements);\
						}",
						ExternalInterface.objectID, _toolName, result);
			}

			private function buildPrimitiveNodes():void
			{
				var nodesKeys:Array = nodesColumn.keys;
				var numNodes:int = nodesKeys.length;
				var key_idx:int;
				var key:IQualifiedKey;
				var id:String;
				var label:String;
				var node:Object;
				var nodes:Array = [];
				for (key_idx = 0; key_idx < numNodes; key_idx++)
				{
					node = {};
					key = nodesKeys[key_idx];
					node.id = nodesColumn.getValueFromKey(key, String);
					node.label = labelColumn.getValueFromKey(key, String);
					node.keyType = key.keyType;
					node.localName = key.localName;
					nodes.push(node);
				}
				
				_primitive_nodes = nodes;
			}

			private function buildPrimitiveEdges():void
			{
				var edgeKeys:Array = edgeSourceColumn.keys;
				var numEdges:int = edgeKeys.length;
				var key_idx:int;
				var key:IQualifiedKey;
				var id:String;
				var label:String;
				var edge:Object;
				var edges:Array = [];
				for (key_idx = 0; key_idx < numEdges; key_idx++)
				{
					edge = {};
					key = edgeKeys[key_idx];
					edge.id = key.localName;
					edge.source = edgeSourceColumn.getValueFromKey(key, String);
					edge.target = edgeTargetColumn.getValueFromKey(key, String);
					edge.keyType = key.keyType;
					edge.localName = key.localName;
					edges.push(edge);
				}
				
				_primitive_edges = edges;
			}

			public function buildPrimitiveNetwork():void
			{
				var network:Object = {data: {nodes: [], edges: []}};
				network.dataSchema = {
					nodes: [{name: "label", type: "string"}, {name: "keyType", type: "string"}, {name: "localName", type: "string"}],
					edges: [{name: "label", type: "string"}, {name: "keyType", type: "string"}, {name: "localName", type: "string"}]
				};
				network.data.nodes = _primitive_nodes;
				network.data.edges = _primitive_edges;
				_primitive_network = network;
			}
			private function handleGraphLayoutChange():void
			{
				ExternalInterface.call(
					"function (weaveID, toolname, layout_name, seed) {\
						var weave = weaveID ? document.getElementById(weaveID) : document;\
						weave.cytoscape[toolname].vis.layout({name: layout_name, options: {seed: seed}});\
						}",
						ExternalInterface.objectID, _toolName, layoutType.value, layoutSeed.value);

			}
			private function handleNodeColumnChange():void
			{
				/* We have no real way of validating that a given nodelist corresponds to a given edgelist, so we just assume this is right. */
				buildPrimitiveNodes();
				buildPrimitiveNetwork();
				sendNetworkToCytoscape();
			}
			private function handleEdgeColumnChange():void
			{
				/* If edgesource and edgetarget don't share a common keytype, don't bother rebuilding the edges; the result will be garbage. */
				var srcKeyType:String = edgeSourceColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				var targetKeyType:String = edgeTargetColumn.getMetadata(ColumnMetadata.KEY_TYPE);
				if (srcKeyType != targetKeyType) return;
				buildPrimitiveEdges();
				buildPrimitiveNetwork();
				sendNetworkToCytoscape();
			}

			override protected function childrenCreated():void
			{
				super.childrenCreated();

				colorComponent.dynamicObject = colorColumn;
				nodeComponent.dynamicObject = nodesColumn;
				labelComponent.dynamicObject = labelColumn;
{'fraction_non_alphanumeric': 0.11332983009283587, 'fraction_numerical': 0.0015764582238570678, 'mean_word_length': 3.8951128893969704, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4624950', 'n_tokens_mistral': 6564, 'n_tokens_neox': 5210, 'n_words': 1072}