Skip to content

Commit

Permalink
Upgrades to new elm-geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
gampleman committed Sep 16, 2020
1 parent 270e1d2 commit 11f4ff1
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 114 deletions.
9 changes: 5 additions & 4 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "gampleman/elm-visualization",
"summary": "A data visualization package for Elm",
"license": "MIT",
"version": "2.1.1",
"version": "2.1.2",
"exposed-modules": [
"Scale",
"Scale.Color",
Expand All @@ -23,11 +23,12 @@
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm/json": "1.0.0 <= v < 2.0.0",
"elm/svg": "1.0.0 <= v < 2.0.0",
"elm/svg": "1.0.1 <= v < 2.0.0",
"elm/time": "1.0.0 <= v < 2.0.0",
"elm-community/list-extra": "8.0.0 <= v < 9.0.0",
"folkertdev/one-true-path-experiment": "4.0.1 <= v < 5.0.0",
"ianmackenzie/elm-geometry": "1.1.0 <= v < 2.0.0",
"folkertdev/one-true-path-experiment": "5.0.0 <= v < 6.0.0",
"ianmackenzie/elm-geometry": "3.6.0 <= v < 4.0.0",
"ianmackenzie/elm-units-prefixed": "2.0.0 <= v < 3.0.0",
"justinmimbs/time-extra": "1.0.1 <= v < 2.0.0",
"ryannhg/date-format": "2.0.0 <= v < 3.0.0"
},
Expand Down
10 changes: 5 additions & 5 deletions examples/Background.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TypedSvg exposing (circle, g, line, polygon, svg, title)
import TypedSvg.Attributes exposing (class, fill, points, stroke, viewBox)
import TypedSvg.Attributes.InPx exposing (cx, cy, r, strokeWidth, x1, x2, y1, y2)
import TypedSvg.Core exposing (Svg, text)
import TypedSvg.Types exposing (Fill(..))
import TypedSvg.Types exposing (Paint(..))


w : Float
Expand Down Expand Up @@ -117,7 +117,7 @@ linkElement graph edge =
in
line
[ strokeWidth 1
, stroke <| Scale.convert colorScale source.x
, stroke <| Paint <| Scale.convert colorScale source.x
, x1 source.x
, y1 source.y
, x2 target.x
Expand All @@ -144,7 +144,7 @@ hexagon ( x, y ) size attrs =
nodeSize size node =
hexagon ( node.x, node.y )
size
[ fill <| Fill <| Scale.convert colorScale node.x
[ fill <| Paint <| Scale.convert colorScale node.x
]
[ title [] [ text node.value.name ] ]

Expand All @@ -163,8 +163,8 @@ nodeElement node =
[ r 12
, cx node.label.x
, cy node.label.y
, fill FillNone
, stroke <| Scale.convert colorScale node.label.x
, fill PaintNone
, stroke <| Paint <| Scale.convert colorScale node.label.x
]
[]
]
Expand Down
4 changes: 2 additions & 2 deletions examples/BarChartRace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import TypedSvg exposing (g, rect, svg, text_, tspan)
import TypedSvg.Attributes exposing (class, fill, fontWeight, stroke, style, textAnchor, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (height, width, x, y)
import TypedSvg.Core exposing (Svg, text)
import TypedSvg.Types exposing (AnchorAlignment(..), Fill(..), FontWeight(..), Transform(..))
import TypedSvg.Types exposing (AnchorAlignment(..), Paint(..), FontWeight(..), Transform(..))


w : Float
Expand Down Expand Up @@ -355,7 +355,7 @@ viewBars colorScale xScale yScale data =
List.map
(\datum ->
rect
[ fill (Fill (Scale.convert colorScale datum.category |> Maybe.withDefault Color.black))
[ fill (Paint (Scale.convert colorScale datum.category |> Maybe.withDefault Color.black))
, height barSize
, x (Scale.convert xScale 0)
, y (Scale.convert yScale datum.rank)
Expand Down
10 changes: 5 additions & 5 deletions examples/Centroid.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TypedSvg exposing (circle, g, svg)
import TypedSvg.Attributes exposing (fill, stroke, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (cx, cy, r)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


w : Float
Expand Down Expand Up @@ -73,8 +73,8 @@ circular arcs =
let
makeSlice index datum =
Path.element (Shape.arc datum)
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.black
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.black
]

makeDot datum =
Expand All @@ -95,8 +95,8 @@ annular arcs =
let
makeSlice index datum =
Path.element (Shape.arc { datum | innerRadius = radius - 60 })
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.black
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.black
]

makeDot datum =
Expand Down
14 changes: 7 additions & 7 deletions examples/CornerRadius.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TypedSvg exposing (circle, g, svg)
import TypedSvg.Attributes exposing (fill, stroke, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (cx, cy, r)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


w : Float
Expand Down Expand Up @@ -77,8 +77,8 @@ corner angle radius sign =
(sign * cornerRadius * cos angle + sqrt (radius ^ 2 - cornerRadius ^ 2) * sin angle)
(sign * cornerRadius * sin angle - sqrt (radius ^ 2 - cornerRadius ^ 2) * cos angle)
]
, stroke Color.black
, fill FillNone
, stroke <| Paint <| Color.black
, fill PaintNone
]


Expand All @@ -87,8 +87,8 @@ circular arcs =
let
makeSlice index datum =
Path.element (Shape.arc datum)
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.white
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.white
]

makeCorners : { a | startAngle : Float, endAngle : Float, outerRadius : Float } -> List (Svg msg)
Expand All @@ -108,8 +108,8 @@ annular arcs =
let
makeSlice index datum =
Path.element (Shape.arc { datum | innerRadius = mainRadius - 60 })
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.white
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.white
]

makeCorners { startAngle, endAngle, outerRadius, innerRadius } =
Expand Down
8 changes: 4 additions & 4 deletions examples/CrimeViz.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import TypedSvg exposing (g, svg, text_)
import TypedSvg.Attributes exposing (class, dy, fill, fontFamily, stroke, textAnchor, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (fontSize, height, strokeWidth, x, y)
import TypedSvg.Core exposing (Svg, text)
import TypedSvg.Types exposing (AnchorAlignment(..), Fill(..), Transform(..), em)
import TypedSvg.Types exposing (AnchorAlignment(..), Paint(..), Transform(..), em)


w : Float
Expand Down Expand Up @@ -126,9 +126,9 @@ view model =
(List.map
(\{ accessor, label } ->
Path.element (line accessor)
[ stroke (color label)
[ stroke (Paint (color label))
, strokeWidth 3
, fill FillNone
, fill PaintNone
]
)
series
Expand All @@ -141,7 +141,7 @@ view model =
[ Translate (w - padding + 10) (padding + Scale.convert yScale (toFloat (accessor last)))
]
]
[ text_ [ fill (Fill (color label)) ] [ text label ] ]
[ text_ [ fill (Paint (color label)) ] [ text label ] ]
)
series
)
Expand Down
14 changes: 7 additions & 7 deletions examples/Curves.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import TypedSvg exposing (g, line, rect, svg, text_)
import TypedSvg.Attributes as Explicit exposing (fill, fontFamily, stroke, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (height, strokeWidth, width, x, x1, x2, y, y1, y2)
import TypedSvg.Core exposing (Svg, text)
import TypedSvg.Types exposing (Fill(..), Transform(..), percent)
import TypedSvg.Types exposing (Paint(..), Transform(..), percent)


w : Float
Expand Down Expand Up @@ -86,7 +86,7 @@ xGridLine index tick =
, Explicit.y2 (percent 100)
, x1 (Scale.convert xScale tick)
, x2 (Scale.convert xScale tick)
, stroke Color.white
, stroke <| Paint <| Color.white
, strokeWidth (Basics.max (toFloat (modBy 2 index)) 0.5)
]
[]
Expand All @@ -99,7 +99,7 @@ yGridLine index tick =
, Explicit.x2 (percent 100)
, y1 (Scale.convert yScale tick)
, y2 (Scale.convert yScale tick)
, stroke Color.white
, stroke <| Paint <| Color.white
, strokeWidth (Basics.max (toFloat (modBy 2 index)) 0.5)
]
[]
Expand All @@ -113,25 +113,25 @@ drawCurve : ( String, Curve, Color ) -> Svg msg
drawCurve ( name, curve, color ) =
List.map Just preparedPoints
|> Shape.line curve
|> (\path -> Path.element path [ stroke color, fill FillNone, strokeWidth 2 ])
|> (\path -> Path.element path [ stroke (Paint color), fill PaintNone, strokeWidth 2 ])


drawLegend : Int -> ( String, Curve, Color ) -> Svg msg
drawLegend index ( name, curve, color ) =
text_ [ fill (Fill color), fontFamily [ "monospace" ], x padding, y (toFloat index * 20 + padding) ] [ text name ]
text_ [ fill (Paint color), fontFamily [ "monospace" ], x padding, y (toFloat index * 20 + padding) ] [ text name ]


view : List ( String, Curve, Color ) -> Svg String
view model =
div []
[ Example.navigation "Curve type" exampleData
, svg [ viewBox 0 0 w h ]
[ rect [ width w, height h, fill <| Fill <| Color.rgb255 223 223 223 ] []
[ rect [ width w, height h, fill <| Paint <| Color.rgb255 223 223 223 ] []
, g [] <| List.indexedMap yGridLine <| Scale.ticks yScale 10
, g [] <| List.indexedMap xGridLine <| Scale.ticks xScale 20
, g [] <|
List.map drawCurve model
, g [] <| List.map (\( dx, dy ) -> Path.element circle [ fill (Fill Color.white), stroke Color.black, transform [ Translate dx dy ] ]) preparedPoints
, g [] <| List.map (\( dx, dy ) -> Path.element circle [ fill (Paint Color.white), stroke <| Paint <| Color.black, transform [ Translate dx dy ] ]) preparedPoints
, g [] <| List.indexedMap drawLegend <| model
]
]
Expand Down
4 changes: 2 additions & 2 deletions examples/CustomPieChart.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TypedSvg exposing (g, svg, text_)
import TypedSvg.Attributes exposing (dy, fill, stroke, textAnchor, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (height, width)
import TypedSvg.Core exposing (Svg, text)
import TypedSvg.Types exposing (AnchorAlignment(..), Fill(..), Transform(..), em)
import TypedSvg.Types exposing (AnchorAlignment(..), Paint(..), Transform(..), em)


w : Float
Expand Down Expand Up @@ -85,7 +85,7 @@ drawChart config model =
}

makeSlice index datum =
Path.element (Shape.arc datum) [ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors, stroke Color.white ]
Path.element (Shape.arc datum) [ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors, stroke <| Paint <| Color.white ]

makeLabel slice ( label, value ) =
let
Expand Down
8 changes: 4 additions & 4 deletions examples/ForceDirectedGraph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import TypedSvg exposing (circle, g, line, svg, title)
import TypedSvg.Attributes exposing (class, fill, stroke, viewBox)
import TypedSvg.Attributes.InPx exposing (cx, cy, r, strokeWidth, x1, x2, y1, y2)
import TypedSvg.Core exposing (Attribute, Svg, text)
import TypedSvg.Types exposing (Fill(..))
import TypedSvg.Types exposing (Paint(..))


w : Float
Expand Down Expand Up @@ -192,7 +192,7 @@ linkElement graph edge =
in
line
[ strokeWidth 1
, stroke (Color.rgb255 170 170 170)
, stroke (Paint (Color.rgb255 170 170 170))
, x1 source.x
, y1 source.y
, x2 target.x
Expand All @@ -204,8 +204,8 @@ linkElement graph edge =
nodeElement node =
circle
[ r 2.5
, fill (Fill Color.black)
, stroke (Color.rgba 0 0 0 0)
, fill (Paint Color.black)
, stroke (Paint (Color.rgba 0 0 0 0))
, strokeWidth 7
, onMouseDown node.id
, cx node.label.x
Expand Down
4 changes: 2 additions & 2 deletions examples/HistogramChart.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TypedSvg exposing (g, rect, svg)
import TypedSvg.Attributes exposing (class, fill, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (height, width, x, y)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


{-| We use addition here to approximate normal distribution.
Expand Down Expand Up @@ -87,7 +87,7 @@ column yScale { length, x0, x1 } =
, y <| Scale.convert yScale (toFloat length)
, width <| Scale.convert xScale x1 - Scale.convert xScale x0
, height <| h - Scale.convert yScale (toFloat length) - 2 * padding
, fill <| Fill <| Color.rgb255 46 118 149
, fill <| Paint <| Color.rgb255 46 118 149
]
[]

Expand Down
6 changes: 3 additions & 3 deletions examples/LineChart.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TypedSvg exposing (g, svg)
import TypedSvg.Attributes exposing (class, fill, stroke, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (strokeWidth)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


w : Float
Expand Down Expand Up @@ -86,8 +86,8 @@ view model =
, g [ transform [ Translate (padding - 1) padding ] ]
[ yAxis ]
, g [ transform [ Translate padding padding ], class [ "series" ] ]
[ Path.element (area model) [ strokeWidth 3, fill <| Fill <| Color.rgba 1 0 0 0.54 ]
, Path.element (line model) [ stroke (Color.rgb 1 0 0), strokeWidth 3, fill FillNone ]
[ Path.element (area model) [ strokeWidth 3, fill <| Paint <| Color.rgba 1 0 0 0.54 ]
, Path.element (line model) [ stroke (Paint (Color.rgb 1 0 0)), strokeWidth 3, fill PaintNone ]
]
]

Expand Down
6 changes: 3 additions & 3 deletions examples/NorwegianCarSales.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import TypedSvg exposing (g, svg, text_)
import TypedSvg.Attributes exposing (class, fill, fontFamily, transform, viewBox)
import TypedSvg.Attributes.InPx exposing (fontSize)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


exampleConfig : List ( String, StackConfig String )
Expand Down Expand Up @@ -144,7 +144,7 @@ view { values, labels, extent } =
labelElement : String -> Float -> Svg msg
labelElement label yPosition =
g [ transform [ Translate (w - padding - labelsWidth + 10) yPosition ] ]
[ text_ [ fill (sampleColor label |> Fill) ] [ text label ] ]
[ text_ [ fill (sampleColor label |> Paint) ] [ text label ] ]
in
div []
[ titleNavigation
Expand All @@ -170,7 +170,7 @@ titleNavigation =
-}
renderStream : ( ContinuousScale Float, ContinuousScale Float ) -> Color -> List ( Float, Float ) -> Svg msg
renderStream scales color coords =
Path.element (toArea scales coords) [ fill (Fill color) ]
Path.element (toArea scales coords) [ fill (Paint color) ]


{-| Create a svg path string that draws the area between two lines
Expand Down
10 changes: 5 additions & 5 deletions examples/PadAngle.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Shape exposing (Arc, defaultPieConfig)
import TypedSvg exposing (g, svg)
import TypedSvg.Attributes exposing (fill, stroke, transform, viewBox)
import TypedSvg.Core exposing (Svg)
import TypedSvg.Types exposing (Fill(..), Transform(..))
import TypedSvg.Types exposing (Paint(..), Transform(..))


w : Float
Expand Down Expand Up @@ -59,8 +59,8 @@ circular arcs =
let
makeSlice index datum =
Path.element (Shape.arc datum)
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.black
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.black
]
in
g [ transform [ Translate radius radius ] ]
Expand All @@ -73,8 +73,8 @@ annular arcs =
let
makeSlice index datum =
Path.element (Shape.arc { datum | innerRadius = radius - 60 })
[ fill <| Fill <| Maybe.withDefault Color.black <| Array.get index colors
, stroke Color.black
[ fill <| Paint <| Maybe.withDefault Color.black <| Array.get index colors
, stroke <| Paint <| Color.black
]
in
g [ transform [ Translate (3 * radius + 20) radius ] ]
Expand Down
Loading

0 comments on commit 11f4ff1

Please sign in to comment.