packages feed

HPlot 0.2 → 0.3

raw patch · 3 files changed

+62/−32 lines, 3 files

Files

Example.hs view
@@ -1,43 +1,75 @@ -- | ----- Demonstrates the basic usage of the PlplotCanvas to embed a plot in a Gnome application. +-- Demonstrates the basic usage of the PlplotCanvas+-- to embed a plot in a Gnome application. --+-- (C) Yakov ZAYTSEV, Roman Salmin, 2009+-- module Main where  import Graphics.UI.Gtk import Graphics.UI.Gtk.Glade+import Graphics.UI.Gtk.Gdk.Events  import Graphics.PLplot -main :: IO ()-main = do-  initGUI-  Just xml <- xmlNew "example.glade"-  window1 <- xmlGetWidget xml castToWindow "window1"-  -- button <- xmlGetWidget xml castToButton "button1"-  onDestroy window1 mainQuit  -- ???-  canvas <- plplotCanvasNew-  plplotCanvasSetSize canvas 1000 600-  containerAdd window1 canvas-  widgetShowAll window1-  runPLplot canvas example-  mainGUI+type PlotData = [(Double, Double)] -example :: PLplot p => PLplotM p ()--- example :: PLplotM' ()-example = do-  adv 0 -- Advance to first page+data1 = [(i, i*i / 10) | i <- [1..10]] :: PlotData+data2 = [(i, 5 - abs (i - 5)) | i <- [0..10]] :: PlotData++main = drawWithHPlot example2++example2 :: (PLplot p) => PLplotM p ()+example2 = do+  ssub 2 1+  adv 0+  plotList [(line, data1, ["x", "y", "y = x*x / 10"])+          , (bin [BinCentred], data2, ["some", "some value", "something"])]++plotList :: (PLplot p) => [(PlotData -> PLplotM p (), PlotData, [String])]-> PLplotM p ()+plotList [] = adv 0+plotList (x:xs) = plotOneHlp x >> adv 0 >> plotList xs++plotOneHlp :: (PLplot p) => (PlotData -> PLplotM p (), PlotData, [String])-> PLplotM p ()+plotOneHlp (f, content, titles) = do   col0 15 -- Set color to black   wid 2 -- Set the pen width   vsta -- Set the viewport-  wind 0.0 10.0 0.0 10.0 -- Set the window++  let minx = minimum $ map fst content+  let maxx = maximum $ map fst content+  let miny =  minimum $ map snd content+  let maxy = maximum $ map snd content++  wind (minx - 0.5)  (maxx + 0.5)  miny (maxy + 1) -- Set the window+   box "bcnst" 0.0 0 "bcnstv" 0.0 0 -- Set the box-  -- bin [] [BinNoExpand]-  lab "#<0x10>Мир" "y-axis" "A Simple Plot" -- Draw some labels+  lab (titles !! 0) (titles !! 1)  (titles !! 2) -- Draw some labels    -- Draw the line   col0 1 -- Set the pen color-  line $ zip [0,1,2,3,4,5,6,7,8,9,10] [0,0.1,0.4,0.9,1.6,2.6,3.6,4.9,6.4,8.1,10]+  f content -  -- Advancing the page finalizes this plot-  adv 0++drawWithHPlot :: PLplotM PlplotCanvas () -> IO ()+drawWithHPlot plotf = do+  initGUI+  Just xml <- xmlNew "example.glade"+  window1 <- xmlGetWidget xml castToWindow "window1"+  onDestroy window1 mainQuit+  onKeyPress window1 keyHandler+  canvas <- plplotCanvasNew+  plplotCanvasSetSize canvas 1000 700+  containerAdd window1 canvas+  widgetShowAll window1+  runPLplot canvas $ plotf+  mainGUI+++keyHandler :: Event -> IO Bool+keyHandler ekey = do+  let key = eventKeyName ekey+  if (key == "q" || key == "Q")+    then mainQuit >> return True+    else return True
Graphics/PLplot.chs view
@@ -138,7 +138,7 @@     box :: String -> Flt -> Int -> String -> Flt -> Int -> PLplotM p ()     lab :: String -> String -> String -> PLplotM p ()     line :: [(Flt, Flt)] -> PLplotM p ()-    bin :: [(Flt, Flt)] -> [BinOpt] -> PLplotM p ()+    bin :: [BinOpt] -> [(Flt, Flt)] -> PLplotM p ()     ssub :: Int -> Int -> PLplotM p ()  instance PLplot PlplotCanvas where@@ -161,8 +161,8 @@ gtk_ssub nx ny = MkP (\(PlplotCanvas o) -> {# call plplot_canvas_ssub #} (unsafeForeignPtrToPtr o) 						(fromIntegral nx) (fromIntegral ny)) -gtk_bin :: [(Flt, Flt)] -> [BinOpt] -> PLplotM PlplotCanvas ()-gtk_bin ps bops = MkP $ \(PlplotCanvas o) -> withArray xs $ \x -> withArray ys $ \y -> {# call plplot_canvas_bin #} (unsafeForeignPtrToPtr o) (fromIntegral (length ps)) x y (fromIntegral bops')+gtk_bin :: [BinOpt] -> [(Flt, Flt)] -> PLplotM PlplotCanvas ()+gtk_bin bops ps = MkP $ \(PlplotCanvas o) -> withArray xs $ \x -> withArray ys $ \y -> {# call plplot_canvas_bin #} (unsafeForeignPtrToPtr o) (fromIntegral (length ps)) x y (fromIntegral bops')                                where                                    (xs', ys') = unzip ps                                    xs = map (fromRational . toRational) xs'
HPlot.cabal view
@@ -1,5 +1,5 @@ Name:		HPlot-Version:	0.2+Version:	0.3 -- Cabal-Version:  >= 1.2 License:	BSD3 License-file:   license@@ -24,11 +24,9 @@   .   It will be great if you will do 'git format-patch' to prepare email with changes against particular version   .-  Changes since 0.1:-  .-  * Roman Salmin contributed 'ssub' and 'bin' functions+  Changes since 0.2:   .-  * 'Flt' type has been added which mirrors PLFLT+  * Roman Salmin contributed new elaborated Example.hs   . build-type:     Simple extra-source-files: example.glade, license