Skip to content

Commit

Permalink
implement condstructor that adds the values of two columns as xvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
spengler authored and spengler committed Apr 3, 2016
1 parent b68d506 commit adc113b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/de/linearbits/subframe/graph/Series2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ public Series2D(CSVFile file,
}
}

/**
* Creates a series by selecting rows and combining some values (x = x1 - x2)
*
* @param file
* @param selector
* @param x1Field
* @param x2Field
* @param yField
*/
public Series2D(CSVFile file,
Selector<String[]> selector,
Field x1Field,
Field x2Field,
Field yField){

Iterator<CSVLine> iter = file.iterator();
while (iter.hasNext()) {
CSVLine csvline = iter.next();
String[] line = csvline.getData();
if (selector.isSelected(line)) {
String x1 = csvline.get(x1Field.category, x1Field.measure);
String x2 = csvline.get(x2Field.category, x2Field.measure);
Double x = Double.parseDouble(x1)- Double.parseDouble(x2);
String y = csvline.get(yField.category, yField.measure);
if (!Double.isInfinite(Double.parseDouble(y)))
data.add(new Point2D(x.toString(), y));
}
}
}

/**
* Creates a series by selecting rows,
* grouping by x and applying the analyzer to y
Expand Down

0 comments on commit adc113b

Please sign in to comment.