Workbook.StatCorrTabSheetSource

Syntax

StatCorrTabSheetSource: PP.TS.StatTabSheetSource;

Description

The StatCorrTabSheetSource property sets data source for a sheet in the Correlation Matrix tab in the statistics panel.

Example

To execute the example, the page must contain the WorkbookBox component named workbookBox (see Example of Creating the WorkbookBox Component), and also add the following code in the handler, that processes document opening event:

	//Add a handler to the metabase connection end event that 
	//sets whether the Add Series button is available depending on the selected series
	metabase.EndRequest.add(PP.Delegate(function(){		
		var selectedSeries = wbk.getActiveSheet().getSelectedSeries();		
		//Check whether there are group series in the selected series
		var groupSerieSelected = False;	
		for (var i = 0; i < selectedSeries.length; i++)
		{
			if (PP.TS.isGroupSerie(selectedSeries[i]))
			{
				groupSerieSelected = True;
				break;
			}
		}
		//Check if there are child series in the selected series
		var derivedSerieSelected = False;
		for (var i = 0; i < selectedSeries.length; i++)
		{
			if (PP.TS.isDerivedSerie(selectedSeries[i]))
			{
				derivedSerieSelected = True;
				break;
			}
		}
		//Set button availability
		if(selectedSeries.length>1 && !groupSerieSelected && !derivedSerieSelected)
		{
			addLRRowButton.setEnabled(True);
		}
		else
		{
			addLRRowButton.setEnabled(False);
		}					
	}));
			
	var addLRRowButton = new PP.Ui.Button({
		ParentNode: document.body, //DOM parent node
		Content: "Add Series", //Text
		Click: PP.Delegate(onClickAddLRRow)					
	});
	function onClickAddLRRow(){
		//Create an object that will contain information about the added series
		var metaData  = {};	
		//Assign the Linear Regression added series formula type
		metaData.formulaType = PP.TS.Ui.FormulaTypeEnum.LinearRegression;
		//Get selected workbook series
		var selectedSeries = wbk.getActiveSheet().getSelectedSeries();
		var series = [];
		for (var i = 0; i < selectedSeries.length; i++)
		{
			if (!PP.TS.isGroupSerie(selectedSeries[i]))
				//Create an array of non-group series from the array of selected ones
				series.push(selectedSeries[i]);
		}
		if (series.length > 0)
		{
			//Get index of the last selected non-group series
			var lastSerieIndex = series[series.length - 1].index;
		}
		metaData.serieFlags = 0;					
		metaData.selectedRows = series;
		metaData.index = lastSerieIndex;
		//Set level
		metaData.formulaLevel = series[0].level;	
		//Create a body of server request for adding a calculated series
		var requestBody = tsService._getSetWbkMdSettings(wbk, metaData, PP.Mb.ListOperation.Add);
		requestBody.SetWbkMd.tArg.metaGet.getTabSheet = {
			pattern: {
				DHTML: True,
				structure: True
			}
		};
		//Set whether workbook is changed
		wbk.setIsChanged(True);
		//Send request to server
		tsService._invokeRemoteProc(wbk, requestBody, PP.Delegate(onResponse));
	}
				
	function onResponse(sender, args)
	{					
		//Get information 
		var res = JSON.parse(args.ResponseText);
		var report = args.Args.Workbook || args.Args.Report;
		var doc = args.Args.Document;
		if (res.SetWbkMdResult.meta)
		{
			var md = res.SetWbkMdResult.meta;
			report.setWbkMetadata(md);
			//Determine a set of time series for workbook
			if (md.series && md.series && md.series.its && md.series.its.it && md.series.its.it.length == md.series["@count"])
			{
				report.setSeries(md.series.its.it);
				report.setNeedUpdateSelection(True);
			}
			else
			{
				if (md.series && md.series && md.series.its && md.series.its.it)
				{
					//refreshes the list of workbook time series
					report.updateSeriesList(md.series.its.it);
					//Set whether selection must be refreshed
					report.setNeedUpdateSelection(True);
				}
			}
			//Calculate and create a mew selection
			var headerSz = tsService._getHeaderSizes(report); //width and height of sidehead and header
			//Get selected cells in workbook table
			var oldsel = report.getSelection();
			//Get range of selected cells
			var oldparts = PP.getProperty(oldsel, "range.parts.it") ? PP.getProperty(oldsel, "range.parts.it") : [PP.getProperty(oldsel, "range")];
			var minleft = null;
			var mintop = null;
			var maxright = null;
			var maxbottom = null;
			//Get coordinates of selection angles
			for (i = 0; i < oldparts.length; i++)
			{
				if (minleft == null || oldparts[i].left < minleft)
					minleft = oldparts[i].left;
				if (mintop == null || oldparts[i].top < mintop)
					mintop = oldparts[i].top;
				var right = oldparts[i].left + oldparts[i].width - 1;
				if (maxright == null || right > maxright)
					maxright = right;
				var bottom = oldparts[i].top + oldparts[i].height - 1;
				if (maxbottom == null || bottom > maxbottom)
					maxbottom = bottom;
			}
			//Get whether table is rotated
			var trans = report.getMetadata().grid.transposed;
			//Create an object that will contain information about selected areas
			var part = { type: "Cells" };
			//Initialize an object that will contain information about selected areas
			if (trans)
			{
				part.left = headerSz.Width + report.getRealIndex(md.series.its.it[0].index);
				part.width = md.series.its.it.length;
				part.top = mintop;
				part.height = maxbottom - mintop + 1;
			}
			else
			{
				part.left = minleft;
				part.width = maxright - minleft + 1;
				part.top = headerSz.Height + report.getRealIndex(md.series.its.it[0].index);
				part.height = md.series.its.it.length;
			}
			//Initialize an object that will contain information about table selection
						var sel = {
							type: "Normal",
							range: {
								left: 0,
								top: 0,
								height: 0,
								width: 0,
								parts: {
									it: [part]
								},
								type: "MultiPart"
							}
						};
						
						var selSeriesIdxes = [];
						for (i = 0; i < md.series.its.it.length; i++)
							selSeriesIdxes.push(md.series.its.it[i].index);
						//Send request for changing table selection
						setTableSelection(report, selSeriesIdxes, undefined, undefined, True, sel, part.left, part.top, part.width, part.height);	
					}	
				}					
		function setTableSelection(wbk, selectedIndexSeries, selectedIndexCols, callback, _setSelectedSerieses, selection, left, top, width, height)
		{					
			if (selectedIndexSeries && selectedIndexSeries.length > 0)
				//Set array of indexes of selected table series
				wbk.setSelectedIndexSeries(selectedIndexSeries);
			else selectedIndexSeries = wbk.getSelectedIndexSeries();
					if (!selectedIndexSeries)
						selectedIndexSeries = [];
					if (selectedIndexCols && selectedIndexCols.length > 0)
						//Set indexes of selected columns
						wbk.setSelectedIndexCols(selectedIndexCols);
					else selectedIndexCols = wbk.getSelectedIndexCols();
					if (!selectedIndexCols)
						selectedIndexCols = [];
					//Get the least index from indexes of the selected series
					var start = tsService._minIndexVal(selectedIndexSeries);
					//Get the greatest index from indexes of the selected series
					var count = tsService._maxIndexVal(selectedIndexSeries) - start + 1;
					if (isNaN(start))
						start = undefined;
					if (isNaN(count))
						count = undefined;
					//Get the least index from indexes of the selected columns	
					var colStart = tsService._minIndexVal(selectedIndexCols);
					//Get the greatest index from indexes of the selected columns
					var colCount = tsService._maxIndexVal(selectedIndexCols) - colStart + 1;
					if (isNaN(colStart))
						start = undefined;
					if (isNaN(colCount))
						count = undefined;
					
					//create a body of server request for selecting the added series
					var body =
					{
						SetWbkMd:
						{
							tWbk: wbk.getOdId(),
							tArg:
							{
								meta:
								{
								},
								pattern:
								{
									setTabSheet: {
										setPattern: {
											metaData: True,
											selection: True
										},
										metaData: {
											selection: selection
										}
									}
								},
								metaGet:
								{
									seriesFilter: {
										range: {
											start: start,
											count: count
										}
									},
									columnsFilter:
									{
										range: {
											start: selectedIndexCols[0],
											count: selectedIndexCols.length
										}
									},
									statistics: {
										includeAll: True
									},
									lanerFilter: True,
									period: True,
									seriesDependencies: True,
									seriesDependents: True,
									seriesAtts: True,
									seriesDiscrepancies: True,
									seriesDisplayParams: True,
									sorting: True,
									series: PP.Mb.ListOperation.Get,
									columns: PP.Mb.ListOperation.Get															
								}
							}
						}
					};
			//Enter information about data sources for statistics panel to the body of server request
			if (selectedIndexSeries.length == 1 || wbk.getPinned())
					{
						var res = { it: [] };
						if (wbk.getPinned())
							res.it.push({ k: wbk.getSelectedOrPinnedSeries()[0].k });
						else
						{
							var ser = wbk.getSeries()[selectedIndexSeries[0]];
							if (ser)
								res.it.push({ k: ser.k });
						}
						if (res)
						{
							body.SetWbkMd.tArg.metaGet.results = {
								correlation: True,
								coefficients: True,
								tabSheet: True,
								series: res
							};
						}
					}				
					tsService._send(body, PP.Delegate(onGetMd, undefined, { Workbook: wbk, SetSelectedSerieses: _setSelectedSerieses, Indexes: selectedIndexSeries }));							
				}
				
				function onGetMd(sender, args)
				{	
					//Get JSON object from server response
					var res = JSON.parse(args.ResponseText);	
					//Get workbook metadata
					var wbkMd = wbk.getActiveSheet().getWbkMetadata();
					//Create an object that will contain information about statistics data
					var meta = undefined;
					if (wbkMd)
					{
						//Initialize an object that will contain information about statistics data from the body of server response
						if (res.GetWbkMdResult)
							meta = res.GetWbkMdResult.meta;
						else meta = res.SetWbkMdResult.meta;
					}
					//Refresh data sources for statistics panel
					refreshStatSources(wbkMd, meta);	
					//Get statistics panel
					var tsPanel = workbookBox.getDataView()._TabStatPanel;	
					tsPanel.refresh();
				}
				
				function refreshStatSources(wbkMd, meta)
				{	
					//Assign statistics data to workbook metadata
					wbkMd.statistics = meta.statistics;
					if (meta.statistics)
						//Set statistics data for workbook
						wbk.getActiveSheet().setStatData(meta.statistics);
					if (meta.results && meta.results.its && meta.results.its.it.length == 1)
					{
						if (meta.series.its.it)
						{
							//Set data sources of statistics panel for workbook
							var result = meta.results.its.it[0];
							if (result.correlation)
							{
								
								wbk.getActiveSheet().setStatCorrTabSheetSource(new PP.TS.StatTabSheetSource({ 	
								WbkOdId: wbk.getActiveSheet().getOdId().id, //workbook moniker
								Metabase: wbk.getMetabase() //Metabase connection object
								}));
							}
							else wbk.getActiveSheet().setStatCorrTabSheetSource(undefined);
							if (result.coefficients)
							{
								//Set data source for the Equation statistics panel tab
								wbk.getActiveSheet().setStatCoeffTabSheetSource(new PP.TS.StatTabSheetSource({ 	
								WbkOdId: wbk.getActiveSheet().getOdId().id, //workbook moniker
								Metabase: wbk.getMetabase() //Metabase connection object
								}));
							}
							else wbk.getActiveSheet().setStatCoeffTabSheetSource(undefined);
							if (result.weights)
							{
								//Set data source for the Weight Matrix statistics panel tab
								wbk.getActiveSheet().setStatWeightsTabSheetSource(new PP.TS.StatTabSheetSource({
								WbkOdId: wbk.getActiveSheet().getOdId().id, //workbook moniker
								Type: PP.TS.Ui.StatTabSheetType.Weights,  //Type
								Metabase: wbk.getMetabase() //Metabase connection object
								}));
							}
							else
								wbk.getActiveSheet().setStatWeightsTabSheetSource(undefined);
						}
					}
					else
					{
						wbk.getActiveSheet().setStatCorrTabSheetSource(undefined);
						wbk.getActiveSheet().setStatCoeffTabSheetSource(undefined);
						wbk.getActiveSheet().setStatWeightsTabSheetSource(undefined);
					}
				}				

After executing the example a button named Add Series is placed on the HTML page. Open the statistics panel by clicking the Statistics button.  To make the Add Series button available, select several series in the workbook. None of the selected series should be a group series or a child one. On clicking the Add Series button a series with the Linear Regression formula type is added to the workbook. After a series is added to the workbook, data sources are set for the Equation and Correlation Matrix tabs in the statistics panel. TO seethe series added to the workbook, click the Refresh button in the Home tab of the tool ribbon.

See also:

Workbook