{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
module Text.Pandoc.Filter.Plot.Renderers.GNUPlot (
gnuplotSupportedSaveFormats
, gnuplotCommand
, gnuplotCapture
, gnuplotAvailable
) where
import Text.Pandoc.Filter.Plot.Renderers.Prelude
gnuplotSupportedSaveFormats :: [SaveFormat]
gnuplotSupportedSaveFormats = [PNG, SVG, EPS, GIF, JPG, PDF]
gnuplotCommand :: OutputSpec -> IO Text
gnuplotCommand OutputSpec{..} = do
exe <- executable GNUPlot oConfiguration
return [st|#{exe} -c "#{oScriptPath}"|]
gnuplotAvailable :: Configuration -> IO Bool
gnuplotAvailable conf = do
exe <- executable GNUPlot conf
commandSuccess [st|#{exe} -h|]
gnuplotCapture :: FigureSpec -> FilePath -> Script
gnuplotCapture FigureSpec{..} fname = [st|
set terminal #{terminalString saveFormat}
set output '#{fname}'
|]
terminalString :: SaveFormat -> Text
terminalString PNG = "pngcairo"
terminalString SVG = "svg"
terminalString EPS = "postscript eps"
terminalString GIF = "gif"
terminalString JPG = "jpeg"
terminalString PDF = "pdfcairo"
terminalString fmt = error $ "gnuplot: unsupported save format" <> show fmt