@@ -5,9 +5,13 @@ import ProjectM36.Relation
55import ProjectM36.Tuple
66import qualified ProjectM36.Attribute as A
77import qualified Data.Vector as V
8−import qualified Graphics.Gnuplot.Simple as GP
8+
99import qualified Graphics.Gnuplot.Plot.ThreeDimensional as Plot3D
1010import qualified Graphics.Gnuplot.Graph.ThreeDimensional as Graph3D
11+
12+import qualified Graphics.Gnuplot.Plot.TwoDimensional as Plot2D
13+import qualified Graphics.Gnuplot.Graph.TwoDimensional as Graph2D
14+
1115import qualified Graphics.Gnuplot.Advanced as GPA
1216
1317--this module support plotting relations containing integer attributes with arity 1,2, or 3 only
@@ -22,30 +26,25 @@ data PlotError = InvalidAttributeCountError |
2226intFromAtomIndex :: Int -> RelationTuple -> Int
2327intFromAtomIndex index tup = (\(IntAtom i) -> i) $ (tupleAtoms tup) V.! index
2428
25−pointStyle :: GP.PlotStyle
26−pointStyle = GP.PlotStyle { GP.plotType = GP.Points,
27− GP.lineSpec = GP.CustomStyle [GP.PointSize 2.0]}
28−
29−graph1DRelation :: Relation -> IO ()
30−graph1DRelation rel = GP.plotPathStyle [] pointStyle $ map (\i -> (i, 0)) (points1DRelation rel)
29+graph1DRelation :: Relation -> Plot2D.T Int Int
30+graph1DRelation rel = Plot2D.list Graph2D.listPoints $ points1DRelation rel
3131
3232points1DRelation :: Relation -> [Int]
3333points1DRelation rel = relFold folder [] rel
3434 where
3535 folder tup acc = intFromAtomIndex 0 tup : acc
3636
37−graph2DRelation :: Relation -> IO ()
38−graph2DRelation rel = GP.plotPathStyle [] pointStyle $ points2DRelation rel
37+graph2DRelation :: Relation -> Plot2D.T Int Int
38+graph2DRelation rel = Plot2D.list Graph2D.points (points2DRelation rel)
3939
4040points2DRelation :: Relation -> [(Int, Int)]
4141points2DRelation rel = relFold folder [] rel
4242 where
4343 folder tup acc = (intFromAtomIndex 0 tup, intFromAtomIndex 1 tup) : acc
4444
45−graph3DRelation :: Relation -> IO ()
45+graph3DRelation :: Relation -> Plot3D.T Int Int Int
4646graph3DRelation rel = do
47− _ <- GPA.plotDefault $ Plot3D.cloud Graph3D.points $ points3DRelation rel
48− return ()
47+ Plot3D.cloud Graph3D.points $ points3DRelation rel
4948
5049points3DRelation :: Relation -> [(Int, Int, Int)]
5150points3DRelation rel = relFold folder [] rel
@@ -73,11 +72,11 @@ plotRelation :: Relation -> IO (Maybe PlotError)
7372plotRelation rel = let attrTypes = V.replicate (arity rel) IntAtomType in
7473 if attrTypes /= A.atomTypes (attributes rel) then
7574 return $ Just InvalidAttributeTypeError
76− else
75+ else do
7776 case arity rel of
78− 1 -> graph1DRelation rel >> return Nothing
79− 2 -> graph2DRelation rel >> return Nothing
80− 3 -> graph3DRelation rel >> return Nothing
77+ 1 -> (GPA.plotDefault $ graph1DRelation rel) >> return Nothing
78+ 2 -> (GPA.plotDefault $ graph2DRelation rel) >> return Nothing
79+ 3 -> (GPA.plotDefault $ graph3DRelation rel) >> return Nothing
8180 _ -> return $ Just InvalidAttributeCountError
8281
8382