{-# LANGUAGE TypeSynonymInstances, NoMonomorphismRestriction #-}
module Graphics.GChart (
module Graphics.GChart.Types,
solid ,
legend ,
legendWithPosition ,
makeAxis ,
makeGrid ,
simple ,
text ,
extended ,
automatic ,
automaticWithSpacing ,
barwidth ,
barwidthspacing ,
relative ,
makeShapeMarker ,
makeRangeMarker ,
makeFinancialMarker ,
makeLineMarker ,
makeLineStyle ,
setChartSize ,
setChartHeight ,
setChartType ,
setChartTitle ,
setChartTitleWithColor ,
setChartTitleWithColorAndFontSize,
setDataEncoding ,
addChartData ,
addDataScale ,
addChartDataXY ,
setColors ,
addColor ,
addFill ,
setLegend ,
addAxis ,
setGrid ,
addShapeMarker ,
addRangeMarker ,
addFinancialMarker ,
addLineMarker ,
addLineFill ,
setLabels ,
setLabel ,
setBarWidthSpacing ,
setPieChartOrientation ,
addLineStyle ,
setFormula ,
setQREncoding ,
setQRWidth ,
setQRErrorCorrection ,
getChartData,
getChartUrl,
convertToUrl
) where
import Graphics.GChart.Types
import Graphics.GChart.ChartItems
import Graphics.GChart.DataEncoding
import Data.List
solid :: Color -> FillType -> Fill
solid color filltype = Fill (Solid color) filltype
legend :: [String] -> ChartLegend
legend labels = Legend labels Nothing
legendWithPosition :: [String] -> LegendPosition -> ChartLegend
legendWithPosition labels position = Legend labels (Just position)
makeAxis :: Axis
makeAxis = defaultAxis
makeGrid :: ChartGrid
makeGrid = defaultGrid
simple :: ChartData
simple = Simple []
text :: ChartData
text = Text []
extended :: ChartData
extended = Extended []
automatic :: BarChartWidthSpacing
automatic = (Just Automatic,Nothing)
automaticWithSpacing :: Int -> Int -> BarChartWidthSpacing
automaticWithSpacing b g= (Just Automatic, Just (Fixed (b,g)))
barwidth :: Int -> BarChartWidthSpacing
barwidth n = (Just (BarWidth n), Nothing)
barwidthspacing :: Int -> Int -> Int -> BarChartWidthSpacing
barwidthspacing bw b g = (Just (BarWidth bw), Just (Fixed (b,g)))
relative :: Float -> Float -> BarChartWidthSpacing
relative b g = (Nothing, Just (Relative (b,g)))
makeShapeMarker :: ShapeMarker
makeShapeMarker = defaultShapeMarker
makeRangeMarker :: RangeMarker
makeRangeMarker = defaultRangeMarker
makeLineMarker :: LineMarker
makeLineMarker = defaultLineMarker
makeFinancialMarker :: FinancialMarker
makeFinancialMarker = defaultFinancialMarker
makeLineStyle :: LineStyle
makeLineStyle = defaultLineStyle
setChartSize :: Int -> Int -> ChartM ()
setChartSize w h = set (Size w h)
setChartHeight :: Int -> ChartM ()
setChartHeight h = set (Size 0 h)
setChartType :: ChartType -> ChartM ()
setChartType = set
setChartTitle :: String -> ChartM ()
setChartTitle title = set $ ChartTitle title Nothing Nothing
setChartTitleWithColor :: String -> Color -> ChartM()
setChartTitleWithColor title color = set $ ChartTitle title (Just color) Nothing
setChartTitleWithColorAndFontSize :: String -> Color -> FontSize -> ChartM ()
setChartTitleWithColorAndFontSize title color fontsize =
set $ ChartTitle title (Just color) (Just fontsize)
setDataEncoding :: ChartData -> ChartM ()
setDataEncoding = set
addChartData :: ChartDataEncodable a => [a] -> ChartM ()
addChartData = addDataToChart
addDataScale :: DataScale -> ChartM ()
addDataScale = addScaleToChart
addChartDataXY :: ChartDataEncodable a => [(a,a)] -> ChartM ()
addChartDataXY series = do addDataToChart xseries
addDataToChart yseries
where xseries = map fst series
yseries = map snd series
setColors :: [Color] -> ChartM ()
setColors = set . ChartColors
addColor :: Color -> ChartM()
addColor = addColorToChart
addFill :: Fill -> ChartM ()
addFill = addFillToChart
setLegend :: ChartLegend -> ChartM ()
setLegend = set
addAxis :: Axis -> ChartM ()
addAxis = addAxisToChart
setGrid :: ChartGrid -> ChartM ()
setGrid = set
addShapeMarker :: ShapeMarker -> ChartM ()
addShapeMarker marker | shapeDataSetIdx marker > (- 1) = addMarker marker
| otherwise = do idx <- getDataSetIdx
let newmarker = marker { shapeDataSetIdx = idx }
addMarker marker
addRangeMarker :: RangeMarker -> ChartM ()
addRangeMarker = addMarker
addFinancialMarker :: FinancialMarker -> ChartM ()
addFinancialMarker marker | financeDataSetIdx marker > (- 1) = addMarker marker
| otherwise = do idx <- getDataSetIdx
let newmarker = marker { financeDataSetIdx = idx }
addMarker newmarker
addLineMarker :: LineMarker -> ChartM ()
addLineMarker marker | lineDataSetIdx marker > (- 1) = addMarker marker
| otherwise = do idx <- getDataSetIdx
let newmarker = marker { lineDataSetIdx = idx }
addMarker newmarker
addLineFill :: LineFillType -> Color -> ChartM ()
addLineFill fillType color = addMarker (LineFillMarker fillType color)
setLabels :: [String] -> ChartM ()
setLabels = set . ChartLabels
setLabel :: String -> ChartM ()
setLabel label = set $ ChartLabels [label]
setBarWidthSpacing :: BarChartWidthSpacing -> ChartM ()
setBarWidthSpacing = set
setPieChartOrientation :: Float -> ChartM ()
setPieChartOrientation = set . PCO
addLineStyle :: LineStyle -> ChartM()
addLineStyle = addLineStyleToChart
setFormula :: String -> ChartM ()
setFormula formula = setLabels [formula]
setQREncoding :: QREncoding -> ChartM ()
setQREncoding = set
setQRErrorCorrection :: ErrorCorrectionLevel -> ChartM ()
setQRErrorCorrection ec = set qrLabelData where
qrLabelData = QRLabelData ec defMargin
QRLabelData _ defMargin = defaultQREncodingLabelData
setQRWidth :: Int -> ChartM ()
setQRWidth m = set qrLabelData where
qrLabelData = QRLabelData defEC m
QRLabelData defEC _ = defaultQREncodingLabelData
getChartData :: ChartM () -> Chart
getChartData = getChartDataFromChartM
getChartUrl :: ChartM () -> String
getChartUrl = convertToUrl . getChartData
convertToUrl :: Chart -> String
convertToUrl chart = baseURL ++ intercalate "&" urlparams where
baseURL = "http://chart.apis.google.com/chart?"
urlparams = [urlEnc a ++ "=" ++ urlEnc b | (a,b) <- getParams chart]