Skip to content

Commit

Permalink
Merge pull request #22 from anagrius/rect
Browse files Browse the repository at this point in the history
Add helper for doing rectangle junk, e.g. for selection of ranges.
  • Loading branch information
terezka committed Jan 8, 2018
2 parents 9e070b5 + d6782d2 commit 202073f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/Internal/Svg.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Internal.Svg exposing
( gridDot
, horizontal, vertical
, rectangle
, horizontalGrid, verticalGrid
, xTick, yTick
, Anchor(..), anchorStyle
Expand All @@ -12,6 +13,9 @@ module Internal.Svg exposing
# Lines
@docs horizontal, vertical
# Rectangles
@docs rectangle
# Grids
## Dots
Expand Down Expand Up @@ -88,6 +92,21 @@ vertical system userAttributes x y1 y2 =
]


{-| -}
rectangle : Coordinate.System -> List (Attribute msg) -> Float -> Float -> Float -> Float -> Svg msg
rectangle system userAttributes x1 x2 y1 y2 =
let
attributes =
concat [ Attributes.fill Color.gray ] userAttributes []
in
Path.view system attributes
[ Move { x = x1, y = y1 }
, Line { x = x1, y = y2 }
, Line { x = x2, y = y2 }
, Line { x = x2, y = y1 }
]


{-| -}
horizontalGrid : Coordinate.System -> List (Attribute msg) -> Float -> Svg msg
horizontalGrid system userAttributes y =
Expand Down
16 changes: 14 additions & 2 deletions src/Lines/Junk.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Lines.Junk exposing
( Junk, Layers, none, custom
, Transfrom, transform, move, offset
, vertical, horizontal, text
, vertical, horizontal, rectangle, text
, withinChartArea
)

Expand All @@ -14,7 +14,7 @@ module Lines.Junk exposing
@docs Junk, custom, Layers
# Common junk
@docs vertical, horizontal, text, withinChartArea
@docs vertical, horizontal, rectangle, text, withinChartArea
# Placing helpers
@docs Transfrom, transform, move, offset
Expand Down Expand Up @@ -173,6 +173,18 @@ horizontal system attributes =
Svg.horizontal system (withinChartArea system :: attributes)


{-| A rectangle within the plot area. This can be used for grid bands
and highlighting a range e.g. for selection.
xSelectionArea : Coordinate.System -> (Float, Float) -> Svg msg
xSelectionArea system (startX, endX) =
Junk.rectangle system [ Attributes.fill "rgba(255,0,0,0.1)" ] startX endX system.y.min system.y.max
-}
rectangle : Coordinate.System -> List (Svg.Attribute msg) -> Float -> Float -> Float -> Float -> Svg.Svg msg
rectangle system attributes =
Svg.rectangle system (withinChartArea system :: attributes)


-- HELPERS

Expand Down

0 comments on commit 202073f

Please sign in to comment.