Commits: 4
Remove tree from the examples model, messages and subscriptions.
The tree is static now.
index e4d98a5..94e0a3f 100644
--- a/src/Examples.elm
+++ b/src/Examples.elm
@@ -21,7 +21,6 @@ type alias Model =
= , nestedTransformations : Examples.NestedTransformations.Model
= , cartesianCoordinates : Examples.CartesianCoordinates.Model
= , polarCoordinates : Examples.PolarCoordinates.Model
- , tree : Maybe Examples.Tree.Model
= , viewBox : Examples.ViewBox.Model
= }
=
@@ -32,8 +31,6 @@ type Msg
= | NestedTransformationsMsg Examples.NestedTransformations.Msg
= | CartesianCoordinatesMsg Examples.CartesianCoordinates.Msg
= | PolarCoordinatesMsg Examples.PolarCoordinates.Msg
- | ToggleTree (Maybe Examples.Tree.Model)
- | TreeMsg Examples.Tree.Msg
= | ViewBoxMsg Examples.ViewBox.Msg
=
=
@@ -44,7 +41,6 @@ init =
= , nestedTransformations = Examples.NestedTransformations.init
= , cartesianCoordinates = Examples.CartesianCoordinates.init
= , polarCoordinates = Examples.PolarCoordinates.init
- , tree = Nothing
= , viewBox = Examples.ViewBox.init
= }
= , Cmd.none
@@ -91,32 +87,10 @@ update msg model =
= , Cmd.none
= )
=
- ToggleTree tree ->
- ( { model | tree = tree }, Cmd.none )
-
- TreeMsg m ->
- case model.tree of
- Just tree ->
- Examples.Tree.update m tree
- |> (\( newTree, treeCmd ) ->
- ( { model | tree = Just newTree }
- , Cmd.map TreeMsg treeCmd
- )
- )
-
- Nothing ->
- ( model, Cmd.none )
-
= ViewBoxMsg m ->
= ( { model | viewBox = Examples.ViewBox.update m model.viewBox }, Cmd.none )
=
=
=subscriptions : Model -> Sub Msg
=subscriptions model =
- case model.tree of
- Nothing ->
- Sub.none
-
- Just tree ->
- Examples.Tree.subscriptions tree
- |> Sub.map TreeMsg
+ Sub.noneExpose Rule and defaults from Examples.Tree module
index 26d559e..88234ae 100644
--- a/src/Examples/Tree.elm
+++ b/src/Examples/Tree.elm
@@ -1,7 +1,9 @@
=module Examples.Tree exposing
= ( Axiom
= , Config
+ , Rule
= , Segment
+ , defaults
= , main
= , ui
= )Make the default tree more beautiful.
index 88234ae..8fee380 100644
--- a/src/Examples/Tree.elm
+++ b/src/Examples/Tree.elm
@@ -17,45 +17,27 @@ import Svg.Attributes
=defaults : Config
=defaults =
= { axiom =
- { color = "brown"
+ { color = "purple"
= , rotation = -90
- , age = 8
+ , age = 7
= }
= , rules =
- [ ( "brown"
- , [ { color = "green"
- , rotation = 45
- }
- , { color = "green"
- , rotation = 20
- }
- , { color = "green"
- , rotation = -20
- }
+ [ ( "purple"
+ , [ { color = "green", rotation = 0.0 }
+ , { color = "green", rotation = 30 }
+ , { color = "green", rotation = -30 }
= ]
= )
= , ( "green"
- , [ { color = "purple"
- , rotation = 0
- }
- , { color = "purple"
- , rotation = -90
- }
- , { color = "purple"
- , rotation = -20
- }
+ , [ { color = "brown", rotation = 0.0 }
+ , { color = "brown", rotation = 30 }
+ , { color = "brown", rotation = -30 }
= ]
= )
- , ( "purple"
- , [ { color = "orange"
- , rotation = 0
- }
- , { color = "orange"
- , rotation = 60
- }
- , { color = "brown"
- , rotation = -20
- }
+ , ( "brown"
+ , [ { color = "green", rotation = 0.0 }
+ , { color = "green", rotation = 30 }
+ , { color = "green", rotation = -30 }
= ]
= )
= ]WIP tree block for our markup
We believe that our code is correct but there is a bug in the mdgriffith/elm-markup package.
index 03acab1..17c4bf3 100644
--- a/content/day-4.txt
+++ b/content/day-4.txt
@@ -18,8 +18,63 @@
=| Header
= The Problem
=
-| Monospace
- TODO: Static tree example
+| Note
+ FIXME: The tree example is broken.
+
+| Window
+ | Tree
+ | Axiom
+ color = green
+ rotation = 0
+ age = 9
+
+ | Rule
+ | Parent
+ purple
+
+ | Child
+ color = green
+ rotation = 0.0
+
+ | Child
+ color = green
+ rotation = 30
+
+ | Child
+ color = green
+ rotation = -30
+
+ | Rule
+ | Parent
+ green
+
+ | Child
+ color = brown
+ rotation = 0.0
+
+ | Child
+ color = brown
+ rotation = 30
+
+ | Child
+ color = brown
+ rotation = -30
+
+ | Rule
+
+ | Parent
+ brown
+
+ | Child
+ color = green
+ rotation = 0.0
+ | Child
+ color = green
+ rotation = 30
+ | Child
+ color = green
+ rotation = -30
+
=
=The tree is built from segments: a line and a dot. In this respect it is similar to the connected dots we created yesterday. If we group the dot and a line, we will have the building block for our tree. We can do it with {Code|Svg.g} function ({Code|g} is an abbreviation of "group"). Just like {Code|Svg.svg}, it takes list of attributes and list of children. We can use it like that:
=index a0c8d8f..2b7617c 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -685,20 +685,52 @@ document =
= tree : Mark.Block (Examples.Model -> Element Msg)
= tree =
= let
- render model =
- model.tree
- |> Maybe.map Examples.Tree.ui
- |> Maybe.withDefault Element.none
- |> Element.el
- [ Element.height (Element.px 600)
- , Element.width Element.fill
- ]
- |> BrowserWindow.window []
- |> Element.map Examples.TreeMsg
- |> Element.map ExamplesMsg
+ render : Examples.Tree.Config -> Examples.Model -> Element Msg
+ render config model =
+ Examples.Tree.ui config
+
+ axiom : Mark.Block Examples.Tree.Axiom
+ axiom =
+ Mark.record3 "Axiom"
+ Examples.Tree.Axiom
+ (Mark.field "color" Mark.string)
+ (Mark.field "rotation" Mark.float)
+ (Mark.field "age" Mark.float)
+
+ rules : Mark.Block (List Examples.Tree.Rule)
+ rules =
+ Mark.manyOf [ rule ]
+
+ rule =
+ Mark.startWith Tuple.pair
+ parent
+ (Mark.manyOf [ child ])
+
+ -- FIXME: Parser breaks with empty list of dead ends
+ -- Mark.stub "Rule" ( "green", [ Examples.Tree.Segment "green" 30 ] )
+ -- Mark.manyOf [ child ]
+ -- |> Mark.map (Tuple.pair "green")
+ parent =
+ Mark.block "Parent" identity Mark.string
+
+ -- Mark.stub "Parent" "green"
+ child =
+ Mark.record2 "Child"
+ Examples.Tree.Segment
+ (Mark.field "color" Mark.string)
+ (Mark.field "rotation" Mark.float)
= in
- Mark.stub "Tree" render
+ Mark.block "Tree"
+ render
+ (Mark.startWith Examples.Tree.Config
+ axiom
+ rules
+ )
=
+ -- Mark.Block Examples.Tree.Config
+ -- result = Examples.Tree.Config
+ -- start = Axiom
+ -- rest = List Rule
= viewBox : Mark.Block (Examples.Model -> Element Msg)
= viewBox =
= let