{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FunctionalDependencies #-}
module Plots.Types.Line
(
trailPlot
, trailPlot'
, pathPlot
, pathPlot'
, linePlot
, linePlot'
, smoothLinePlot
, smoothLinePlot'
, mkTrail
, mkTrailOf
, mkPath
, mkPathOf
) where
import Control.Monad.State.Lazy
import qualified Data.Foldable as F
import Diagrams.Coordinates.Isomorphic
import Diagrams.Prelude
import Plots.Axis
import Plots.Types
trailPlot
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Trail v n
-> State (Plot (Path v n) b) ()
-> m ()
trailPlot = pathPlot . toPath
trailPlot'
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Trail v n
-> m ()
trailPlot' = pathPlot' . toPath
pathPlot
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Path v n
-> State (Plot (Path v n) b) ()
-> m ()
pathPlot = addPlotable
pathPlot'
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Path v n
-> m ()
pathPlot' = addPlotable'
linePlot
:: (BaseSpace c ~ v,
Metric v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> f p
-> State (Plot (Path v n) b) ()
-> m ()
linePlot = addPlotable . toPath . mkTrail
linePlot'
:: (BaseSpace c ~ v,
Metric v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> f p
-> m ()
linePlot' = addPlotable' . toPath . mkTrail
smoothLinePlot
:: (BaseSpace c ~ v,
F.Foldable f,
Metric v,
PointLike v n p,
Plotable (Path v n) b,
Fractional (v n),
MonadState (Axis b c n) m)
=> f p
-> State (Plot (Path v n) b) ()
-> m ()
smoothLinePlot = addPlotable . cubicSpline False . toListOf (folded . unpointLike)
smoothLinePlot'
:: (BaseSpace c ~ v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
Fractional (v n),
MonadState (Axis b c n) m)
=> f p
-> m ()
smoothLinePlot' xs = smoothLinePlot xs (return ())
mkTrail :: (PointLike v n p, OrderedField n, F.Foldable f) => f p -> Located (Trail v n)
mkTrail = mkTrailOf folded
mkTrailOf :: (PointLike v n p, OrderedField n) => Fold s p -> s -> Located (Trail v n)
mkTrailOf f ps = fromVertices $ toListOf (f . unpointLike) ps
mkPath :: (PointLike v n p, OrderedField n, F.Foldable f, F.Foldable g) => g (f p) -> Path v n
mkPath pss = toPath $ map mkTrail (F.toList pss)
mkPathOf :: (PointLike v n p, OrderedField n) => Fold s t -> Fold t p -> s -> Path v n
mkPathOf f1 f2 as = Path $ map (mkTrailOf f2) (toListOf f1 as)