on master help sign in
switch to advanced interface for Gnuplot graphing in anticipation of more style changes
6247771AgentM
ProjectM36/Relation/Show/Gnuplot.hs+15−16
@@ -5,9 +5,13 @@ import ProjectM36.Relation
5import ProjectM36.Tuple
5import ProjectM36.Tuple
6import qualified ProjectM36.Attribute as A
6import qualified ProjectM36.Attribute as A
7import qualified Data.Vector as V
7import qualified Data.Vector as V
8−import qualified Graphics.Gnuplot.Simple as GP
8+
9import qualified Graphics.Gnuplot.Plot.ThreeDimensional as Plot3D
9import qualified Graphics.Gnuplot.Plot.ThreeDimensional as Plot3D
10import qualified Graphics.Gnuplot.Graph.ThreeDimensional as Graph3D
10import 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+
11import qualified Graphics.Gnuplot.Advanced as GPA
15import qualified Graphics.Gnuplot.Advanced as GPA
12
16
13--this module support plotting relations containing integer attributes with arity 1,2, or 3 only
17--this module support plotting relations containing integer attributes with arity 1,2, or 3 only
@@ -22,30 +26,25 @@ data PlotError = InvalidAttributeCountError |
22intFromAtomIndex :: Int -> RelationTuple -> Int
26intFromAtomIndex :: Int -> RelationTuple -> Int
23intFromAtomIndex index tup = (\(IntAtom i) -> i) $ (tupleAtoms tup) V.! index
27intFromAtomIndex index tup = (\(IntAtom i) -> i) $ (tupleAtoms tup) V.! index
24
28
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 ()
29+graph1DRelation :: Relation -> Plot2D.T Int Int
30−graph1DRelation rel = GP.plotPathStyle [] pointStyle $ map (\i -> (i, 0)) (points1DRelation rel)
30+graph1DRelation rel = Plot2D.list Graph2D.listPoints $ points1DRelation rel
31
31
32points1DRelation :: Relation -> [Int]
32points1DRelation :: Relation -> [Int]
33points1DRelation rel = relFold folder [] rel
33points1DRelation rel = relFold folder [] rel
34 where
34 where
35 folder tup acc = intFromAtomIndex 0 tup : acc
35 folder tup acc = intFromAtomIndex 0 tup : acc
36
36
37−graph2DRelation :: Relation -> IO ()
37+graph2DRelation :: Relation -> Plot2D.T Int Int
38−graph2DRelation rel = GP.plotPathStyle [] pointStyle $ points2DRelation rel
38+graph2DRelation rel = Plot2D.list Graph2D.points (points2DRelation rel)
39
39
40points2DRelation :: Relation -> [(Int, Int)]
40points2DRelation :: Relation -> [(Int, Int)]
41points2DRelation rel = relFold folder [] rel
41points2DRelation rel = relFold folder [] rel
42 where
42 where
43 folder tup acc = (intFromAtomIndex 0 tup, intFromAtomIndex 1 tup) : acc
43 folder tup acc = (intFromAtomIndex 0 tup, intFromAtomIndex 1 tup) : acc
44
44
45−graph3DRelation :: Relation -> IO ()
45+graph3DRelation :: Relation -> Plot3D.T Int Int Int
46graph3DRelation rel = do
46graph3DRelation rel = do
47− _ <- GPA.plotDefault $ Plot3D.cloud Graph3D.points $ points3DRelation rel
47+ Plot3D.cloud Graph3D.points $ points3DRelation rel
48− return ()
49
48
50points3DRelation :: Relation -> [(Int, Int, Int)]
49points3DRelation :: Relation -> [(Int, Int, Int)]
51points3DRelation rel = relFold folder [] rel
50points3DRelation rel = relFold folder [] rel
@@ -73,11 +72,11 @@ plotRelation :: Relation -> IO (Maybe PlotError)
73plotRelation rel = let attrTypes = V.replicate (arity rel) IntAtomType in
72plotRelation rel = let attrTypes = V.replicate (arity rel) IntAtomType in
74 if attrTypes /= A.atomTypes (attributes rel) then
73 if attrTypes /= A.atomTypes (attributes rel) then
75 return $ Just InvalidAttributeTypeError
74 return $ Just InvalidAttributeTypeError
76− else
75+ else do
77 case arity rel of
76 case arity rel of
78− 1 -> graph1DRelation rel >> return Nothing
77+ 1 -> (GPA.plotDefault $ graph1DRelation rel) >> return Nothing
79− 2 -> graph2DRelation rel >> return Nothing
78+ 2 -> (GPA.plotDefault $ graph2DRelation rel) >> return Nothing
80− 3 -> graph3DRelation rel >> return Nothing
79+ 3 -> (GPA.plotDefault $ graph3DRelation rel) >> return Nothing
81 _ -> return $ Just InvalidAttributeCountError
80 _ -> return $ Just InvalidAttributeCountError
82
81
83
82