aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scalam/plotting/DataSet.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/scalam/plotting/DataSet.scala')
-rw-r--r--src/main/scala/scalam/plotting/DataSet.scala17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/scala/scalam/plotting/DataSet.scala b/src/main/scala/scalam/plotting/DataSet.scala
index 31e65c7..052ad8c 100644
--- a/src/main/scala/scalam/plotting/DataSet.scala
+++ b/src/main/scala/scalam/plotting/DataSet.scala
@@ -3,11 +3,12 @@ package scalam.plotting
import scalam.m.ast.Identifier
import scalax.file.Path
import breeze.linalg.{ Vector, DenseVector }
+import scalam.io._
case class DataSet(points: Seq[(Double, Double)], label: String, name: String) {
-
+
lazy val (xs, ys) = points.unzip
-
+
def save(path: Path) = {
path.createFile(createParents = true, failIfExists = false)
for (processor <- path.outputProcessor; out = processor.asOutput)
@@ -17,8 +18,16 @@ case class DataSet(points: Seq[(Double, Double)], label: String, name: String) {
}
object DataSet {
-
+
def apply(points: Seq[(Double, Double)], label: String) = new DataSet(points, label, Identifier.makeValid(label))
-
+
+ implicit val dataSetIsSaveable = (ds: DataSet) => new Saveable {
+ def save(out: scalax.io.Output) = for ((x, y) <- ds.points) yield out.write(x + " " + y + "\n")
+ }
+
+ implicit def dataSetIsLoadable = new Loadable[DataSet] {
+ def load(in: scalax.io.Input) = new DataSet(Seq(), "", "")
+ }
+
}