Data Visualization tool for GH

Data Visualization tool is set of simple GH component to provide easy multi dimension data visualization interface.

This tool set consists of 2 parts.

CSV parcer is a simple text based data parcer to convert each array into data tree branch.

Data Filter can cull multi dimensional coincidental value, similar to Grasshopper Cross reference component cull option.
It can also number code string value, which can become useful when trying to interpret string value into geometric terms.

Following is a sample application of this tool used in commuting traffic data visualization. (string)Departure location, (string)Destination location, (double)Traffic Amount

Data Filter

View Code (C#) Data Filter

//Cull coincidental values
static void CullCoincident(string x, string y, int z, ref object A, ref object B, ref object C)
{

//initializing list data for output
List<string> xCulled = new List<string>();
List<string> yCulled = new List<string>();
List<int> zCulled = new List<int>();

//cull if x and y are same
if(x != y)
{

xCulled.Add(x);
yCulled.Add(y);
zCulled.Add(z);

}
else{}

//return
A = xCulled;
B = yCulled;
C = zCulled;

}

//Group same names as Branch
static void GroupByName (List<string> nameSet, string departureCity, string arrivalCity, int count, ref object A, ref object B, ref object C)
{

//internalize nameSet
List<string> names = nameSet;

//initialize DataTree data for output
DataTree<string> depCities = new DataTree<string>();
DataTree<string> arrCities = new DataTree<string>();
DataTree<int> counts = new DataTree<int>();

//group datas into branch in nameSet order
for(int i = 0;i < names.Count;i++){

//if departureCity has same name as name at i,
if(departureCity == names[i]){

//initialize grouping path
GH_Path path = new GH_Path(i);
//add data into each branch at i
depCities.Add(departureCity, path);
arrCities.Add(arrivalCity, path);
counts.Add(count, path);

}
else{}

}
//return
A = depCities;
B = arrCities;
C = counts;

}

//Number code strings
static void NumberCode (List<string> nameSet, string departureCity, string arrivalCity, int count, ref object A, ref object B, ref object C)
{

List<string> names = nameSet;
List<int> DepCodes = new List<int>();
List<int> ArrCodes = new List<int>();
List<int> counts = new List<int>();

for(int i = 0;i < names.Count;i++){

if(departureCity == names[i]){

DepCodes.Add(i);
counts.Add(count);

}
else if(arrivalCity == names[i]){

ArrCodes.Add(i);

}
else{}

}

A = DepCodes;
B = ArrCodes;
C = counts;

}

 

CSV Parcer

View Code (C#) CSV Parcer

private void RunScript(bool open, string separator, ref object DataAsTree, ref object Path)
{

if(open){

//open file dialog
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Title = “Open CSV or TXT”;
openDialog.Filter = “TXT file|*.txt|CSV file|*.csv”;
openDialog.FilterIndex = 2;
//get file path
if (openDialog.ShowDialog() == DialogResult.OK){

filePath = openDialog.FileName.ToString();

}
else{}

}
else{

if(filePath != null){

//delimit char
char sep = Convert.ToChar(separator);
treeArray = new DataTree<string>();
string[] rows = System.IO.File.ReadAllLines(filePath);
int arrayCount = rows[0].Split(sep).Length;
//separation
foreach(string row in rows){

for(int i = 0;i < arrayCount;i++){

GH_Path ghpath = new GH_Path(i);
string[] cells = row.Split(sep);
treeArray.Add(cells[i], ghpath);

}

}

DataAsTree = treeArray;

}
else{}

}
Path = filePath;

}

public string filePath = null;
public DataTree<string> treeArray = new DataTree<string>();

Leave a Reply