<commit_before><?xml version="1.0" encoding="utf-8"?>
<!--
/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/
-->
<SliderTool
	xmlns="weave.visualization.tools.*" 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	xmlns:ui="weave.ui.*"
	xmlns:settings="weave.ui.settings.*"
	xmlns:LinkableObjectList="weave.ui.LinkableObjectList.*"
	verticalScrollPolicy="off"
	width="400" 
	title="Time Slider Tool"
	height="40">

<mx:Script>
		<![CDATA[
			import weave.Weave;
			import weave.api.WeaveAPI;
			import weave.api.data.IDataSource;
			import weave.api.getSessionState;
			import weave.core.SessionManager;
			import weave.core.weave_internal;
			import weave.data.ColumnReferences.HierarchyColumnReference;
			import weave.primitives.AttributeHierarchy;
			import weave.utils.HierarchyUtils;
            use namespace weave_internal;

	//constructor
	
	override protected function constructor():void
	{
		super.constructor();
	}
	
	//overrides of abstract SliderTool functions
	
	/**
	 * This function finds a list of attribute tags in the same attribute hierarchy
	 * that have the same @dataTable and @name attributes, then returns a list of
	 * their @year values.
	 * @param ref A reference to an attribute tag in an AttributeHierarchy.
	 * @return An Array of @year values that the referenced column is defined for.
	 */
	override protected function getValuesFromColHier(ref:HierarchyColumnReference):Array
	{
		var times:Array = getTimesFromDimension(ref);
		if (times.length > 0)
			addToListOfDims(ref);
		return times;
	}
	
	/**
	 * handleLabelChange
	 * This method is called every time there is a change in labels,
	 * so be sure to change labels only as often as is necesary.  
	 * We fill in the hslider labels from this.labelsLinkableString
	 * Since this.labelsLinkableString is a LinkableString it can be changed by
	 * the user by editing the sessionHistory.  
	 * */
	override public function handleLabelChange():void
	{
		//@TODO have values associated with the labels so that the labels can be
		//   changed and the values are still passed into the column request
		if (parent == null)
			return callLater(handleLabelChange);
		var labelsString:String = labelsLinkableString.value || ''; // avoid null pointer error
		dimensionSlider.labels = labelsString.split(',');
		dimensionSlider.minimum = 0;
		dimensionSlider.maximum = dimensionSlider.labels.length - 1;		
		labelsInput.text = labelsString;
	}	
	
	/** 
	 * change - this method is automatically called when the hslider
	 *  is changed.  Here we update all the visualization tools to 
	 *  the new time.  
	 * **/
	override public function handleSliderChange():void
	{
		var newTime:String = dimensionSlider.labels[dimensionSlider.value];
		var descendants:Array = (WeaveAPI.SessionManager as SessionManager).getDescendants(Weave.root, HierarchyColumnReference);
		var len:int = descendants.length;
		for (var i:int = 0; i < len; i++)
		{
			var ref:HierarchyColumnReference = descendants[i] as HierarchyColumnReference;
			var path:XML = ref.hierarchyPath.value;
			var attr:XML = path..attribute[0];
			if (String(attr.@year) != '')
			{
				attr.@year = newTime;
				if (attr.@csvColumn)
				{
					// this hack adds support for CSVDataSource
					try
					{
						var search:XML = attr.copy();
						delete search.@csvColumn;
						var hierarchy:AttributeHierarchy = ref.getDataSource().attributeHierarchy as AttributeHierarchy;
						var list:XMLList = hierarchy.value.descendants('attribute');
						for (var j:int = 0; j < list.length(); j++)
						{
							if (HierarchyUtils.nodeContainsAttributes(list[j], search))
							{
								ref.hierarchyPath.value = hierarchy.getPathFromNode(list[j]);
								break;
							}
						}
					}
					catch (e:Error) { }
				}
			}
			ref.hierarchyPath.detectChanges();
		}
	}
	
	
	/**
	 * This is specified in the HSlider above - called to get the tooltip that appears when 
	 * the user probes over the slider.  Item is the index of the value that the user is hovering 
	 * over.  
	 **/
	override protected function formatDataTip(item:Number):String 
	{
		var value:String = dimensionSlider.labels[item];
		return value;
	}
	
	//other class methods
	
	/**
	 * For a given datasource/dataTable/columnName, get the year values from the hierarchy
	 * */
	protected static function getTimesFromDimension(ref:HierarchyColumnReference):Array
	{
		var path:XML = ref.hierarchyPath.value;
		var dataSource:IDataSource = ref.getDataSource();
		var node:XML = (dataSource.attributeHierarchy as AttributeHierarchy).getNodeFromPath(path);
		
		var times:Array = [];
		if (dataSource == null)
			return times;

		var hierarchy:XML = getSessionState(dataSource.attributeHierarchy) as XML;
		if (!hierarchy)
			return times;<commit_msg>Fixed null reference error in TimeSliderTool.<commit_after><?xml version="1.0" encoding="utf-8"?>
<!--
/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/
-->
<SliderTool
	xmlns="weave.visualization.tools.*" 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	xmlns:ui="weave.ui.*"
	xmlns:settings="weave.ui.settings.*"
	xmlns:LinkableObjectList="weave.ui.LinkableObjectList.*"
	verticalScrollPolicy="off"
	width="400" 
	title="Time Slider Tool"
	height="40">

<mx:Script>
		<![CDATA[
			import weave.Weave;
			import weave.api.WeaveAPI;
			import weave.api.data.IDataSource;
			import weave.api.getSessionState;
			import weave.core.SessionManager;
			import weave.core.weave_internal;
			import weave.data.ColumnReferences.HierarchyColumnReference;
			import weave.primitives.AttributeHierarchy;
			import weave.utils.HierarchyUtils;
            use namespace weave_internal;

	//constructor
	
	override protected function constructor():void
	{
		super.constructor();
	}
	
	//overrides of abstract SliderTool functions
	
	/**
	 * This function finds a list of attribute tags in the same attribute hierarchy
	 * that have the same @dataTable and @name attributes, then returns a list of
	 * their @year values.
	 * @param ref A reference to an attribute tag in an AttributeHierarchy.
	 * @return An Array of @year values that the referenced column is defined for.
	 */
	override protected function getValuesFromColHier(ref:HierarchyColumnReference):Array
	{
		var times:Array = getTimesFromDimension(ref);
		if (times.length > 0)
			addToListOfDims(ref);
		return times;
	}
	
	/**
	 * handleLabelChange
	 * This method is called every time there is a change in labels,
	 * so be sure to change labels only as often as is necesary.  
	 * We fill in the hslider labels from this.labelsLinkableString
	 * Since this.labelsLinkableString is a LinkableString it can be changed by
	 * the user by editing the sessionHistory.  
	 * */
	override public function handleLabelChange():void
	{
		//@TODO have values associated with the labels so that the labels can be
		//   changed and the values are still passed into the column request
		if (parent == null)
			return callLater(handleLabelChange);
		var labelsString:String = labelsLinkableString.value || ''; // avoid null pointer error
		dimensionSlider.labels = labelsString.split(',');
		dimensionSlider.minimum = 0;
		dimensionSlider.maximum = dimensionSlider.labels.length - 1;		
		labelsInput.text = labelsString;
	}	
	
	/** 
	 * change - this method is automatically called when the hslider
	 *  is changed.  Here we update all the visualization tools to 
	 *  the new time.  
	 * **/
	override public function handleSliderChange():void
	{
		var newTime:String = dimensionSlider.labels[dimensionSlider.value];
		var descendants:Array = (WeaveAPI.SessionManager as SessionManager).getDescendants(Weave.root, HierarchyColumnReference);
		var len:int = descendants.length;
		for (var i:int = 0; i < len; i++)
		{
			var ref:HierarchyColumnReference = descendants[i] as HierarchyColumnReference;
			var path:XML = ref.hierarchyPath.value;
			var attr:XML = path..attribute[0];
			if (String(attr.@year) != '')
			{
				attr.@year = newTime;
				if (attr.@csvColumn)
				{
					// this hack adds support for CSVDataSource
					try
					{
						var search:XML = attr.copy();
						delete search.@csvColumn;
						var hierarchy:AttributeHierarchy = ref.getDataSource().attributeHierarchy as AttributeHierarchy;
						var list:XMLList = hierarchy.value.descendants('attribute');
						for (var j:int = 0; j < list.length(); j++)
						{
							if (HierarchyUtils.nodeContainsAttributes(list[j], search))
							{
								ref.hierarchyPath.value = hierarchy.getPathFromNode(list[j]);
								break;
							}
						}
					}
					catch (e:Error) { }
				}
			}
			ref.hierarchyPath.detectChanges();
		}
	}
	
	
	/**
	 * This is specified in the HSlider above - called to get the tooltip that appears when 
	 * the user probes over the slider.  Item is the index of the value that the user is hovering 
	 * over.  
	 **/
	override protected function formatDataTip(item:Number):String 
	{
		var value:String = dimensionSlider.labels[item];
		return value;
	}
	
	//other class methods
	
	/**
	 * For a given datasource/dataTable/columnName, get the year values from the hierarchy
	 * */
	protected static function getTimesFromDimension(ref:HierarchyColumnReference):Array
	{
		var times:Array = [];
		
		var path:XML = ref.hierarchyPath.value;
		var dataSource:IDataSource = ref.getDataSource();
		if (dataSource == null)
			return times;

		var node:XML = (dataSource.attributeHierarchy as AttributeHierarchy).getNodeFromPath(path);
		var hierarchy:XML = getSessionState(dataSource.attributeHierarchy) as XML;
		if (!hierarchy)
			return times;
{'fraction_non_alphanumeric': 0.09329044117647059, 'fraction_numerical': 0.004963235294117647, 'mean_word_length': 3.60864040660737, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 14}, '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': '3868763', 'n_tokens_mistral': 3634, 'n_tokens_neox': 3129, 'n_words': 1012}