Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: f350150d1e
Fetching contributors…

Cannot retrieve contributors at this time

172 lines (134 sloc) 6.406 kb
module Graphics.GChart.Types where
import Control.Monad.State
-- size
data ChartSize = Size Int Int deriving Show
-- type
data ChartType = Line |
Sparklines |
LineXY |
BarHorizontalStacked |
BarVerticalStacked |
BarHorizontalGrouped |
BarVerticalGrouped |
Pie |
Pie3D |
PieConcentric |
Venn |
ScatterPlot |
Radar |
GoogleOMeter deriving Show
--title
type ChartTitle = String
-- data
data ChartData = Simple [[Int]] | Text [[Float]] | Extended [[Int]] deriving Show
-- colors
type Color = String
data ChartColors = ChartColors [Color] deriving Show
-- fills
type Angle = Float
type Offset = Float
type Width = Float
data FillKind = Solid Color |
LinearGradient Angle [(Color,Offset)] |
LinearStripes Angle [(Color,Width)] deriving Show
data FillType = Background | Area | Transparent deriving Show
data Fill = Fill FillKind FillType deriving Show
type ChartFills = [Fill]
-- legend
data LegendPosition = LegendBottom | LegendTop | LegendVBottom | LegendVTop | LegendRight | LegendLeft deriving Show
data ChartLegend = Legend [String] (Maybe LegendPosition) deriving Show
-- axis
data AxisType = AxisBottom | AxisTop | AxisLeft | AxisRight deriving Show
type AxisLabel = String
type AxisPosition = Float
data AxisRange = Range (Float,Float) (Maybe Float) deriving (Show,Eq)
type FontSize = Int
data AxisStyleAlignment = AxisStyleLeft | AxisStyleCenter | AxisStyleRight deriving (Show,Eq)
data DrawingControl = DrawLines | DrawTicks | DrawLinesTicks deriving (Show,Eq)
data AxisStyle = Style { axisColor :: Color,
axisFontSize :: Maybe FontSize,
axisStyleAlign :: Maybe AxisStyleAlignment,
axisDrawingControl :: Maybe DrawingControl,
tickMarkColor :: Maybe Color } deriving (Show,Eq)
data Axis = Axis { axisType :: AxisType,
axisLabels :: Maybe [AxisLabel],
axisPositions :: Maybe [AxisPosition],
axisRange :: Maybe AxisRange,
axisStyle :: Maybe AxisStyle } deriving Show
type ChartAxes = [Axis]
data ChartGrid = ChartGrid { xAxisStep :: Float,
yAxisStep :: Float,
lineSegmentLength :: Maybe Float,
blankSegmentLength :: Maybe Float,
xOffset :: Maybe Float,
yOffset :: Maybe Float } deriving Show
data ShapeType = ShapeArrow | ShapeCross | ShapeDiamond | ShapeCircle | ShapeSquare | VerticalLine | VerticalLineFull | HorizontalLine | ShapeX deriving Show
data ShapeDataPoint = DataPoint Int | DataPointEvery | DataPointEveryN Int | DataPointEveryNRange Int Int Int | DataPointXY Float Float deriving Show
data RangeMarkerType = RangeMarkerHorizontal | RangeMarkerVertical deriving Show
data ChartMarker = ShapeMarker { shapeType :: ShapeType,
shapeColor :: Color,
shapeDataSetIdx :: Int,
shapeDataPoint :: ShapeDataPoint,
shapeSize :: Int,
shapePriority :: Int
} |
RangeMarker { rangeType :: RangeMarkerType,
rangeColor :: Color,
rangeSpan :: (Float,Float) } deriving Show
type ChartMarkers = [ChartMarker]
-- labels
data ChartLabels = ChartLabels [String] deriving Show
-- chart
data Chart = Chart { chartSize :: ChartSize,
chartType :: ChartType,
chartData :: ChartData,
chartTitle :: Maybe ChartTitle,
chartColors :: Maybe ChartColors,
chartFills :: Maybe ChartFills,
chartLegend :: Maybe ChartLegend,
chartAxes :: Maybe ChartAxes,
chartGrid :: Maybe ChartGrid,
chartMarkers :: Maybe ChartMarkers,
chartLabels :: Maybe ChartLabels } deriving Show
-- Monad
type ChartM a = State Chart a
-- Typeclass abstracting all the fields in a chart
class ChartItem c where
-- set the field
set :: c -> ChartM ()
-- encode the field into string params
encode :: c -> [(String,String)]
-- Default value of a chart
defaultChart = Chart { chartSize = Size 320 200,
chartType = Line,
chartData = Simple [],
chartTitle = Nothing,
chartColors = Nothing,
chartFills = Nothing,
chartLegend = Nothing,
chartAxes = Nothing,
chartGrid = Nothing,
chartMarkers = Nothing,
chartLabels = Nothing }
defaultAxis = Axis { axisType = AxisBottom,
axisLabels = Nothing,
axisPositions = Nothing,
axisRange = Nothing,
axisStyle = Nothing }
defaultAxisStyle = Style { axisColor = "0000DD",
axisFontSize = Nothing,
axisStyleAlign = Nothing,
axisDrawingControl = Nothing,
tickMarkColor = Nothing }
defaultGrid = ChartGrid { xAxisStep = 20,
yAxisStep = 20,
lineSegmentLength = Nothing,
blankSegmentLength = Nothing,
xOffset = Nothing,
yOffset = Nothing }
defaultShapeMarker = ShapeMarker { shapeType = ShapeCircle,
shapeColor = "0000DD",
shapeDataSetIdx = 0,
shapeDataPoint = DataPointEvery,
shapeSize = 5,
shapePriority = 0 }
Jump to Line
Something went wrong with that request. Please try again.