Hi airflow,
We will add to Origin 7.5 SR2 a couple of utility functions (add_plots_to_layer(), make_plots_tree(), get_plot_type_info() from the code below) to facilitate adding plots to graph layers. For now you can use the code below.
"Your" function (the one that uses those utility functions to create plots) is make_XYXY(). You can call it directly from LabTalk window by passing arguments. As an example I provide (at the bottom of the code below), a little function test_XYXY() that calls make_XYXY().
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
#define EXIST_FUNC_PLOT EXIST_PLOT
static int get_plot_type_info(int nPlotID, int nPageType, DWORD dwTargetLayer, DWORD& dwAuxTypeInfo, DWORD& dwAuxPlotInfo, string& strColPattern)
{
int nPlotType = 0;
if(nPlotID)
nPlotType = Project.GetPlotTypeInfo(nPlotID, dwAuxTypeInfo, dwAuxPlotInfo, strColPattern);
if(nPageType)
{
if(EXIST_DATA == nPageType || EXIST_FUNC_PLOT == nPageType)
dwAuxTypeInfo &= ~PCD_CAN_ADD_E_H_L;
if(EXIST_FUNC_PLOT == nPageType)
dwAuxTypeInfo |= PCD_NO_X;
}
if (PCD_LAYER_TRI == dwTargetLayer)
{
DWORD dwSaveModifiers = dwAuxTypeInfo & ( PCD_MODIFIER_SIZE | PCD_MODIFIER_COLOR );
dwAuxTypeInfo = PCD_LAYER_TRI | PCD_EXACT_YCOLS | PCD_Z_PREFER_Y | PCD_GROUP_MULTI_YS | PCD_PREFER_X | PCD_CAN_ADD_E_H_L | PCD_HIDE_ERR_BARS;
dwAuxTypeInfo |= dwSaveModifiers;
}
else if (PCD_LAYER_SMITH == dwTargetLayer)
dwAuxTypeInfo |= PCD_HIDE_ERR_BARS;
return nPlotType;
}
int make_plots_tree(TreeNode &tr, int nPlotType, vector<string> &vsWksPages, vector<string> &vsLayers, vector<string> &vsCols, vector<uint> &vpdesig)
{
DWORD dwAuxTypeInfo, dwLTPlotInfo;
string strColPattern;
uint nExVal = 0;
int nn = get_plot_type_info(nPlotType, EXIST_WKS, 0, dwAuxTypeInfo, dwLTPlotInfo, strColPattern);
int nRet = Project.MakeDataplotsTree(tr, nn, dwAuxTypeInfo, dwLTPlotInfo, strColPattern, nExVal, vpdesig, vsWksPages, vsLayers, vsCols, TRUE);
return nRet;
}
// ---------------------------------------------------------------------------------- //
// It adds one or more plots to a graph layer.
// Parameters:
// lay=graph layer to add the plot(s) to.
// nPlotType=plot type id
// lpcszWksName=the name of the worksheet to take the data from
// vsCols=vector of strings with the column names to use when creating the plot.
// vpdesig=a vector of integers holding the column designations for each column
// from the vector vsCols. The size of the vector vpdesig must match
// the size of the vector vsCols. The column designations must have the
// values from the following enumeration:
// typedef enum tagPlotDesignationEx {
// COLDESIG_NONE = 0,
// COLDESIG_X = 1,
// COLDESIG_Y,
// COLDESIG_Z,
// COLDESIG_ERROR_OR_LABEL_BEGIN,
// COLDESIG_LABEL = COLDESIG_ERROR_OR_LABEL_BEGIN,
// COLDESIG_XERROR,
// COLDESIG_YERROR,
// COLDESIG_YPLUSERROR,
// COLDESIG_ERROR_OR_LABEL_END,
// COLDESIG_YMINUSERROR = COLDESIG_ERROR_OR_LABEL_END,
// COLDESIG_SIZE, // for symbol size in bubble plots
// COLDESIG_COLOR, // for symbol color in scatter color plots
// COLDESIG_VECTOR_ANGLE, // for vector XYAM plots
// COLDESIG_VECTOR_MAGNITUDE, // for vector XYAM plots
// COLDESIG_VECTOR_XEND, // for vector XYXY plots
// COLDESIG_VECTOR_YEND // for vector XYXY plots
// } PlotDesignationEx;
//
// Returns:
// the total number of plots added.
// ---------------------------------------------------------------------------------- //
int add_plots_to_layer(GraphLayer &lay, int nPlotType, LPCSTR lpcszWksName, vector<string> &vsCols, vector<uint> &vpdesig)
{
Tree tr;
vector<string> vsWksPages;
vector<string> vsLayers;
vsWksPages.Add(lpcszWksName);
vsLayers.SetSize(1);
int nRet = make_plots_tree(tr, nPlotType, vsWksPages, vsLayers, vsCols, vpdesig);
if (!nRet)
{
out_str("Cannot create plot tree.");
return FALSE;
}
TreeNode trLayer = tr.FirstNode;
int nNumPlotsAdded = lay.AddPlots(trLayer, ADDPLOTSFROMTREE_NEW);
if (nNumPlotsAdded <= 0)
{
out_str("Failed to add dataplots");
}
return nNumPlotsAdded;
}
// ---------------------------------------------------------------------------------- //
// It creates a graph with a vector XYXY plot.
// Parameters:
// strWksName=the name of the worksheet to take the data from.
// strX1ColName=the name of the column for X1
// strY1ColName=the name of the column for Y1
// strX2ColName=the name of the column for X2
// strY2ColName=the name of the column for Y2
// ---------------------------------------------------------------------------------- //
void make_XYXY(string strWksName, string strX1ColName, string strY1ColName, string strX2ColName, string strY2ColName)
{
GraphPage pg;
// Create a new graph from the template appropriate for vector XYXY graphs:
if ( !pg.Create("VectXYXY"))
{
out_str("Cannot create page");
return;
}
// Get the first layer from the graph:
GraphLayer lay = pg.Layers(0);
if ( !lay )
{
out_str("Cannot get graph layer");
return;
}
// Build the arrays of the column names and designations.
vector<string> vsCols;
vector<uint> vpdesig;
vpdesig.SetSize(4);
vsCols.SetSize(4);
vsCols[0] = strX1ColName;
vpdesig[0] = COLDESIG_X;
vsCols[1] = strY1ColName;
vpdesig[1] = COLDESIG_Y;
vsCols[2] = strX2ColName;
vpdesig[2] = COLDESIG_VECTOR_XEND;
vsCols[3] = strY2ColName;
vpdesig[3] = COLDESIG_VECTOR_YEND;
int nNum = add_plots_to_layer(lay, IDM_PLOT_FLOWVECTOR, strWksName, vsCols, vpdesig);
if (0 < nNum)
lay.Rescale(); // rescale the layer to show all the data points
return;
}
void test_XYXY()
{
// This call assumes, that there exists worksheet "Data1"
// with four columns with names "A", "B", "D", "C".
make_XYXY("Data1", "A", "B", "D", "C");
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
Edited by - ML on 12/04/2003 3:26:32 PM