GraphLayer::AddPlots
AddPlots
Description
Add multiple dataplots onto graphlayer
Syntax
int AddPlots( TreeNode & tr, DWORD dwOptions = 0 )
Parameters
- tr
- [input] a TreeNode that contains the proper layer contents
- dwOptions
- [input] bits to control how the tree is used, supported bits include
- ADDPLOTSFROMTREE_EDIT to indicate an update process, tree was originally obtained via GetLayerContents and may have been modified
- ADDPLOTSFROMTREE_NEW to make new plots using the given tree
- ADDPLOTSFROMTREE_RESCALE to force rescale of the entire layer if this bit is on, otherwise rescale only if tr has Rescale turned on individual data plot
- ADDPLOTSFROMTREE_IMPLICIT_STYLEHOLDERS to prevent style holders from being removed when tree does not contain the style holder info
Return
total number of data plots in the layer
Examples
EX1
// Keep a graph window is active with at least two plots and run "GraphLayer_AddPlots_ex1 1 1"
void GraphLayer_AddPlots_ex1(int nPlot, bool bRegroup = false)
{
GraphLayer gl = Project.ActiveLayer();
if(!gl)
return;
Tree tr;
bool bWasGroup = gl.UngroupPlots();
gl.GetLayerContents(tr, GETLC_DATAPLOTS | GETLC_NO_LIMITS);
if(dataplots_move_row_to_bottom_top(tr.FirstNode, nPlot))
{
gl.AddPlots(tr.FirstNode, ADDPLOTSFROMTREE_EDIT | ADDPLOTSFROMTREE_IMPLICIT_STYLEHOLDERS);
if(bWasGroup && bRegroup)
gl.GroupPlots(0);
gl.LT_execute("legend -s");// this will force the legend to update
gl.GetPage().Refresh();
}
}
static bool dataplots_move_row_to_bottom_top(TreeNode& tr, int nRow, bool bMoveToTopOfTree = true)
{
Tree trTemp;
TreeNode tr1stPlot;// for the case of bMoveToTopOfTree
int nCount = 0;
string strName;
string strPrefix;
foreach(TreeNode trNode in tr.Children)
{
strName = trNode.tagName;
int nIndex = string_to_prefix_end_number(strPrefix.GetBuffer(MAXLINE), strName);
strPrefix.ReleaseBuffer();
if(strPrefix.CompareNoCase("DataPlot") != 0)
continue;
if(!tr1stPlot)
tr1stPlot = trNode;// remember 1st DataPlot node for insert later
// top level
if(nRow == nCount)
{
trTemp = trNode; // make copy
tr.RemoveChild(trNode);
break;
}
nCount++;
}
if(trTemp)
{
if(!bMoveToTopOfTree) // bottom of tree, then top of plot list
tr.AddNode(trTemp.Clone());
else // move to bottom of plot list, which means top of the tree
{
if(!tr1stPlot)
{
out_str("No data plot in layer, nothing to move");
return false;
}
TreeNode tr1 = tr.InsertNode(tr1stPlot, "Junk");// tagName does not matter, will be replaced later
tr1.Replace(trTemp.Clone());
}
return true;
}
return false;
}
Remark
Update the layer contents with a tree which has been properly constructed, maybe from GetLayerContents
A graph layer has both DataPlots and StyleHolders. When ADDPLOTSFROMTREE_EDIT is used to update the contents of a layer, the supplied tree is
interpreted to contain complete info on the layer, so that removal of a data plot can be achieved by deleting the corresponding tree node in the
layer contents tree obtained from a call to GetLayerContents. If GetLayerContents was called without the GETLC_STYLE_HOLDERS bit, the resulting
tree will not have any style holder, and thus the AddPlots call with ADDPLOTSFROMTREE_EDIT would naturally remove all the style holders in the layer
as they are not present in the tree. To prevent this from happening, you need to add the ADDPLOTSFROMTREE_IMPLICIT_STYLEHOLDERS to the AddPlots call.
See Also
GraphLayer::GetLayerContents
header to Include
origin.h
|