module Graphics.Rendering.Plot.Light.PlotTypes.Scatter where
import Graphics.Rendering.Plot.Light.Internal
import Graphics.Rendering.Plot.Light.Internal.Utils
import Data.Fixed
import Data.Maybe (fromMaybe)
import Control.Monad (forM_)
import Text.Blaze.Svg
import Text.Blaze.Svg.Renderer.String (renderSvg)
import qualified Data.Colour as C
import qualified Data.Colour.Names as C
import qualified Data.Text as T
import qualified Data.Text.IO as T
scatter :: (Foldable t, Show a, RealFrac a) =>
ScatterPointData a
-> t (Point a)
-> Svg
scatter (ScatterPointData glshape w sw fcol alpha) ps =
forM_ ps $ glyph w sw glshape fcol alpha
scatterLP :: (Foldable t, RealFrac a, Show a) =>
(l -> b -> a)
-> (l -> b -> a)
-> (l -> C.Colour Double -> C.Colour Double)
-> (l -> b -> a)
-> ScatterPointData b
-> t (LabeledPoint l a)
-> Svg
scatterLP f g h i spdat lps = forM_ lps (scatterLP1 f g h i spdat)
scatterLP1 :: (Show a, RealFrac a) =>
(l -> b -> a)
-> (l -> b -> a)
-> (l -> C.Colour Double -> C.Colour Double)
-> (l -> b -> a)
-> ScatterPointData b
-> LabeledPoint l a
-> Svg
scatterLP1 f g h i spdat lp = glyph w' sw' sh col' a' (_lp lp)
where
ScatterPointData sh w' sw' col' a' = modifyScatterPoint f g h i spdat lp
scatterLPBar :: (RealFrac t, Enum t, RealFrac b, Show b) =>
FigureData b
-> b
-> t
-> t
-> Int
-> LegendPosition_
-> b
-> (t -> b -> b)
-> (t -> b -> b)
-> (t -> C.Colour Double -> C.Colour Double)
-> (t -> b -> b)
-> ScatterPointData b
-> Svg
scatterLPBar fdat w vmin vmax n legpos legh f g h i spdat = legendBar fdat w vmin vmax n legpos legh fun where
wglyph = spSize spdat
fun _ _ _ _ _ lp@(LabeledPoint p val) = do
scatterLP1 f g h i spdat lp
text 0 (figLabelFontSize fdat) C.black TAStart (T.pack $ show (rr val :: Fixed E3)) (V2 (2 * wglyph) (0.5 * wglyph)) p
data ScatterPointData a = ScatterPointData
{
spGlyphShape :: GlyphShape_
, spSize :: a
, spStrokeWidth :: a
, spColour :: C.Colour Double
, spAlpha :: a
} deriving (Eq, Show)
modifyScatterPoint ::
(l -> b -> c)
-> (l -> b -> c)
-> (l -> C.Colour Double -> C.Colour Double)
-> (l -> b -> c)
-> ScatterPointData b
-> LabeledPoint l d
-> ScatterPointData c
modifyScatterPoint f g h i (ScatterPointData glsh sz w col alpha) lp =
ScatterPointData glsh (f lab sz) (g lab w) (h lab col) (i lab alpha)
where
lab = _lplabel lp
data GlyphShape_ = Square | Circle | Cross | Plus deriving (Eq, Show, Enum)
glyph :: (Show a, RealFrac a) =>
a
-> a
-> GlyphShape_
-> C.Colour Double
-> a
-> Point a
-> Svg
glyph w sw sh col alpha p =
let cf = shapeColNoBorder col alpha
in
case sh of
Square -> squareCentered w cf p
Circle -> circle w cf p
Cross -> crossGlyph w sw col p
Plus -> plusGlyph w sw col p