2.2.4.9 DataRange

Contents

Name

DataRange

Remark

The DataRange class provides methods and properties to construct data ranges for getting and putting data from and to a Worksheet, Matrix and Graph window. This class itself does not contain data; it just keeps the data range with the page name, sheet name (layer index for graph) and row/column indices (data plot index for graph). One DataRange object can contain multiple data ranges. The sub data range can be a whole data sheet, one column or row, or multiple continuous columns or rows.

Hierarchy

Examples

EX1

// plotting multiple columns in a group plot with X column from the end
void DataRange_ex1()
{
    Worksheet wks;
    wks.Create("Origin");
    int nCols = 5;
    int nRows = 100;
    wks.SetSize(nRows, nCols);
    // for a demo, lets use the last col as X
    int nX = nCols-1;
    Dataset dx(wks, nX);
    dx.Data(1, nRows);
    // fill the Y cols (even though 1st col is really X in the wks, we will plot it as Y anyway)
    for(int nC = 0; nC < nCols-1; nC++)
    {
        Dataset dy(wks, nC);
        dy.Normal(nRows);
        dy += nC * 2;
    }
    //now we will construct our data range with all the Y columns to plot againt the X column at the end of the worksheet
    DataRange dr;
    dr.Add(wks, nX, "X");
    for(int ii = 0; ii < nCols-1; ii++)
        dr.Add(wks, ii, "Y");
    GraphPage gp;
    gp.Create("Origin", CREATE_HIDDEN);
    GraphLayer gl = gp.Layers();
    gl.AddPlot(dr, IDM_PLOT_LINE);
    gl.Rescale();
    gp.SetShow();
    // you can verify that all the plots are plotting againt the last col as X even though the worksheet is having 1st col as X
}

EX2

// This example prints out the minimum and maximum X and Y values in all existing
// XY selections of the active worksheet or graph
// you can make the plot from example code above, or from any existing plot
// if you do not make a selection, then the whole active plot is considered selected,
// otherwise you can use the Regional Selection tool to select multiple regions
void DataRange_ex2()
{
    Tree trXYSelection;
    DWORD dwRules = DRR_GET_DEPENDENT | DRR_NO_FACTORS;
    init_input_data_branch_from_selection(trXYSelection, dwRules);
    //    out_tree(trXYSelection);

    DataRange dr;
    dr.Create(trXYSelection, false);

    DWORD dwPlotID; // This is to retrieve DataPlot UID if present
    vector vX, vY;
    double xmin, xmax, ymin, ymax;
    string strRange;
    int nNumRanges = dr.GetNumData(dwRules);
    for( int nIndex = 0; nIndex < nNumRanges; nIndex++ )
    {
        // Copy data associated with nIndex of dr into vectors using DataRange::GetData
        dr.GetData( dwRules, nIndex, &dwPlotID, NULL, &vY, &vX);

        // Now we have made a copy of XY data into vectors vX and vY
        // so we can do analysis on the data...for example:
        vX.GetMinMax(xmin, xmax);
        vY.GetMinMax(ymin, ymax);
        DataRange drSub;
        dr.GetSubRange(drSub, dwRules, nIndex);
        strRange = drSub.GetDescription();
        printf("%s\nxmin = %g\nxmax = %g\nymin = %g\nymax = %g\n", strRange, xmin, xmax, ymin, ymax);
    }
}

EX3

//strX,Y are col names
//call XF to integrate an area using data from active book, given sheet name

#include <XFbase.h>
void DataRange_ex3(string strX, string strY, string strSheet)
{
	Worksheet wks = Project.ActiveLayer();
	wks.AddCol();
	wks.AddCol();
	//Create input datarange.
    DataRange dr1;
    string strRange;
    strRange.Format("%s!(%s,%s)", strSheet, strX, strY);
    dr1.Create(strRange, XVT_XYDATARANGE);
    //Created output datarange.
    DataRange dr2;
    dr2.Add(wks, 2, "X");
    dr2.Add(wks, 3, "Y");
    
    XYRange yi(dr1);
    //integ1 -h to see usage of this XF
    XFBase xf("integ1");    
    XYRange yo(dr2);
    
    xf.SetArg("iy", yi);
    xf.SetArg("oy", yo);// to make it <optional>
    double dArea;
    xf.SetArg("area", dArea);
    if ( !xf.Evaluate() )
        out_str("failed to execute XF");
    else
        printf("for XY Data %s\narea = %g\n", yi.GetDescription(), dArea);
}

Header to Include

origin.h

Reference

Members

Name Brief Example
Add a new subrange to the DataRange.
Add data to a DataRange object from named columns in a workbook.
Remove all ranges in the DataRange object.
Get a copy of the datarange.
Create a valid DataRange object.
Default constructor for the DataRange class.
Destroy this Origin object.
Threshold or matching string replacement for a DataRange.
Get book and sheet name of the index-th x range.
Get the data from indexed subrange get data from all subrange if nIndex is negative.
Get a text string to describe a data range.
Get all the factors as a string array.
Find data points inside polygon enclosed by vX, vY, only supported by single XYRange.
Get all masked data into a vector.
Get all missing data into a vector.
Get the name of the datarange as a string.
Gets the names of all the datasets that appear in the DataRange.
Get the number of data ranges according to the rules dwRules.
Get the numer of subranges in this datarange.
Get dataplot's uids as to access them, dataplots are generated by this datarange.
Get one single range's data.
Get the description string of the datarange.
Get one subrange.
Get the datarange as a tree.
Get the datarange's named range if exist.
Find if a DataRange intersects another DataRange.
Check DataRange is valid or whether it includes any empty subrange.
Check DataRange is real or not.
Merge another DataRange into this DataRange.
Threshold or matching string replacement for a DataRange.
Clear all the subranges.
Set data by column offset index.
It sets a matrix data into the data referred to by the DataRange object.
Set data in the range maksed/unmasked.
Update the Name property of the datarange.
Set dataplot's uid by index.
Set the subrange at the given index.
It sets a DataRange object into a virtual dataset.
Specify a datarange from a tree.