DataRange

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 Add a new subrange to the DataRange. Examples
AddInput Add data to a DataRange object from named columns in a workbook. Examples
BreakUp Remove all ranges in the DataRange object. Examples
Clone Get a copy of the datarange. Examples
Create Create a valid DataRange object. Examples
DataRange Default constructor for the DataRange class. Examples
Destroy Destroy this Origin object. Examples
FindNext Threshold or matching string replacement for a DataRange. Examples
GetBookSheet Get book and sheet name of the index-th x range. Examples
GetData Get the data from indexed subrange get data from all subrange if nIndex is negative. Examples
GetDescription Get a text string to describe a data range. Examples
GetFactorsValues Get all the factors as a string array. Examples
GetIndices Find data points inside polygon enclosed by vX, vY, only supported by single XYRange. Examples
GetMaskedData Get all masked data into a vector. Examples
GetMissingData Get all missing data into a vector. Examples
GetName Get the name of the datarange as a string. Examples
GetNamesOfDatasets Gets the names of all the datasets that appear in the DataRange. Examples
GetNumData Get the number of data ranges according to the rules dwRules. Examples
GetNumRanges Get the numer of subranges in this datarange. Examples
GetPlots Get dataplot's uids as to access them, dataplots are generated by this datarange. Examples
GetRange Get one single range's data. Examples
GetRuntimeDescription Get the description string of the datarange. Examples
GetSubRange Get one subrange. Examples
GetTree Get the datarange as a tree. Examples
HasNamedRange Get the datarange's named range if exist. Examples
Intersects Find if a DataRange intersects another DataRange. Examples
IsEmpty Check DataRange is valid or whether it includes any empty subrange. Examples
IsReal Check DataRange is real or not. Examples
Merge Merge another DataRange into this DataRange. Examples
Replace Threshold or matching string replacement for a DataRange. Examples
Reset Clear all the subranges. Examples
SetColumnData Set data by column offset index. Examples
SetData It sets a matrix data into the data referred to by the DataRange object. Examples
SetMask Set data in the range maksed/unmasked. Examples
SetName Update the Name property of the datarange. Examples
SetPlotUID Set dataplot's uid by index. Examples
SetRange Set the subrange at the given index. Examples
SetToVirtualDataset It sets a DataRange object into a virtual dataset. Examples
SetTree Specify a datarange from a tree. Examples