{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Text.Pandoc.Filter.Plot.Renderers (
scriptExtension
, comment
, preambleSelector
, supportedSaveFormats
, scriptChecks
, parseExtraAttrs
, command
, capture
, toolkitAvailable
, availableToolkits
, unavailableToolkits
) where
import Control.Concurrent.ParallelIO.Local
import Data.List ((\\))
import Data.Map.Strict (Map)
import Data.Maybe (catMaybes)
import Data.Text (Text)
import Text.Pandoc.Filter.Plot.Renderers.Mathematica
import Text.Pandoc.Filter.Plot.Renderers.Matlab
import Text.Pandoc.Filter.Plot.Renderers.Matplotlib
import Text.Pandoc.Filter.Plot.Renderers.Octave
import Text.Pandoc.Filter.Plot.Renderers.Plotly
import Text.Pandoc.Filter.Plot.Renderers.GGPlot2
import Text.Pandoc.Filter.Plot.Renderers.GNUPlot
import Text.Pandoc.Filter.Plot.Types
scriptExtension :: Toolkit -> String
scriptExtension Matplotlib = ".py"
scriptExtension PlotlyPython = ".py"
scriptExtension Matlab = ".m"
scriptExtension Mathematica = ".m"
scriptExtension Octave = ".m"
scriptExtension GGPlot2 = ".r"
scriptExtension GNUPlot = ".gp"
comment :: Toolkit -> (Text -> Text)
comment Matplotlib = mappend "# "
comment PlotlyPython = mappend "# "
comment Matlab = mappend "% "
comment Mathematica = \t -> mconcat ["(*", t, "*)"]
comment Octave = mappend "% "
comment GGPlot2 = mappend "# "
comment GNUPlot = mappend "# "
preambleSelector :: Toolkit -> (Configuration -> Script)
preambleSelector Matplotlib = matplotlibPreamble
preambleSelector PlotlyPython = plotlyPythonPreamble
preambleSelector Matlab = matlabPreamble
preambleSelector Mathematica = mathematicaPreamble
preambleSelector Octave = octavePreamble
preambleSelector GGPlot2 = ggplot2Preamble
preambleSelector GNUPlot = gnuplotPreamble
supportedSaveFormats :: Toolkit -> [SaveFormat]
supportedSaveFormats Matplotlib = matplotlibSupportedSaveFormats
supportedSaveFormats PlotlyPython = plotlyPythonSupportedSaveFormats
supportedSaveFormats Matlab = matlabSupportedSaveFormats
supportedSaveFormats Mathematica = mathematicaSupportedSaveFormats
supportedSaveFormats Octave = octaveSupportedSaveFormats
supportedSaveFormats GGPlot2 = ggplot2SupportedSaveFormats
supportedSaveFormats GNUPlot = gnuplotSupportedSaveFormats
scriptChecks :: Toolkit -> [Script -> CheckResult]
scriptChecks = const mempty
parseExtraAttrs :: Toolkit -> Map Text Text -> Map Text Text
parseExtraAttrs Matplotlib = matplotlibExtraAttrs
parseExtraAttrs _ = return mempty
command :: Toolkit -> (Configuration -> FigureSpec -> FilePath -> Text)
command Matplotlib = matplotlibCommand
command PlotlyPython = plotlyPythonCommand
command Matlab = matlabCommand
command Mathematica = mathematicaCommand
command Octave = octaveCommand
command GGPlot2 = ggplot2Command
command GNUPlot = gnuplotCommand
capture :: Toolkit -> (FigureSpec -> FilePath -> Script)
capture Matplotlib = matplotlibCapture
capture PlotlyPython = plotlyPythonCapture
capture Matlab = matlabCapture
capture Mathematica = mathematicaCapture
capture Octave = octaveCapture
capture GGPlot2 = ggplot2Capture
capture GNUPlot = gnuplotCapture
toolkitAvailable :: Toolkit -> Configuration -> IO Bool
toolkitAvailable Matplotlib = matplotlibAvailable
toolkitAvailable PlotlyPython = plotlyPythonAvailable
toolkitAvailable Matlab = matlabAvailable
toolkitAvailable Mathematica = mathematicaAvailable
toolkitAvailable Octave = octaveAvailable
toolkitAvailable GGPlot2 = ggplot2Available
toolkitAvailable GNUPlot = gnuplotAvailable
availableToolkits :: Configuration -> IO [Toolkit]
availableToolkits conf = do
maybeToolkits <- withPool (length toolkits) $
\pool -> parallel pool (maybeToolkit <$> toolkits)
return $ catMaybes maybeToolkits
where
maybeToolkit tk = do
available <- toolkitAvailable tk conf
if available
then return $ Just tk
else return Nothing
unavailableToolkits :: Configuration -> IO [Toolkit]
unavailableToolkits conf = ((\\) toolkits) <$> availableToolkits conf