Skip to content

Instantly share code, notes, and snippets.

@TwistingTwists
Created March 2, 2019 08:07
Show Gist options
  • Save TwistingTwists/58e1c26bb21697249b7ff37dcf47de8a to your computer and use it in GitHub Desktop.
Save TwistingTwists/58e1c26bb21697249b7ff37dcf47de8a to your computer and use it in GitHub Desktop.
mindmapping in elm
-- Reference: http://freemind.cvs.sourceforge.net/viewvc/freemind/freemind/freemind.xsd?pathrev=fm_0_9_0_beta2&revision=1.1.2.4
module Main exposing (Hook(..), Icon(..), Map(..), Model(..), Node(..), NodeAttributes, NodeChild(..), Position(..))
-- import Maybe exposing (Maybe(Just, Nothing))
-- import Color
-- import Time
import Basics exposing (..)
import Browser
import Debug
import Html exposing (..)
import Html.Events exposing (..)
import List
import Platform exposing (Program)
import Platform.Cmd as Cmd exposing (Cmd)
import Platform.Sub as Sub exposing (Sub)
import Result exposing (..)
import String
import Tuple
type Map
= Map (List Node)
type Node
= Node
{ label : String
, attributes : NodeAttributes
, children : List Node
}
type alias NodeAttributes =
{ backgroundColor : Maybe Color
, color : Maybe Color
, folded : Bool
, id : Maybe String
, link : Maybe String
, position : Maybe Position
, style : Maybe String
, created : Maybe Time
, modified : Maybe Time
, spacing :
{ horizontalGap : Maybe Int
, verticalGap : Maybe Int
, verticalShift : Maybe Int
}
, encryptedContent : Maybe String
}
type Position
= Left
| Right
| Anywhere
rootNode =
Node
{ label = "Start here! "
, attributes = defaultNodeAttributes
, children = ()
}
defaultNodeAttributes =
{ backgroundColor = "yellow"
, color = "black"
, folded = True
, id = "ROOT"
, link = Nothing
, position = Nothing
, style = Nothing
, created = Nothing
, modified = Nothing
, spacing =
{ horizontalGap = Nothing
, verticalGap = Nothing
, verticalShift = Nothing
}
, encryptedContent = Nothing
}
selectionAttributes =
{ defaultNodeAttributes | backgroundColor = "grey" }
--MODEL
type Model
= HasRoot Map
init : rootNode -> ( Model, Cmd Msg )
init rootNode =
( Model HasRoot (List rootNode)
, Cmd.none
)
-- MAIN
main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
-- UPDATE
type Msg
= NewNode String NodeAttributes
| EditNode Node String NodeAttributes
| SelectNode Node
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NewNode str attr ->
( createNode str attr
, Cmd.none
)
EditNode node str attr ->
( editNode node str attr
-- TODO : change defaultNodeAttributes to attributes of current node
, Cmd.none
)
SelectNode node ->
( selectNode node
, Cmd.none
)
createNode : String -> NodeAttributes -> Node
createNode str attr =
Node
{ label = str
, attributes = attr
, children = List ()
}
editNode : Node -> String -> NodeAttributes -> Node
editNode node str attr =
{ node | label = str, attributes = attr }
selectNode : Node -> Node
selectNode node =
{ node | attr = selectionAttributes }
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
-- VIEW
view : Model -> Html Msg
view model =
div []
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment