kikytokamuro/elm-linerbar/1.0.0

NOTE: the latest version is 1.0.1

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/KikyTokamuro/elm-linerbar.

What we checked: The repo moved to github.com/KikyTokamuro/elm-linerbar. Rebuilt with git archive from commit 12297e889f1c of https://github.com/KikyTokamuro/elm-linerbar (zip prefix KikyTokamuro-elm-linerbar-12297e8/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 1f684f6e3590fad340324a35dab3552372da5a66.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/kikytokamuro/elm-linerbar/zipball/1.0.0/

Elm Liner Bar

Small horizontal bar chart library for Elm

sample

How to Install

elm-package install kikytokamuro/elm-linerbar

Demo

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import LinerBar
import Random


type alias Model =
    { linerBarModel : LinerBar.Model
    , seed : Int
    }


type Msg
    = Randomize
    | NewRandomValues (List Int)
    | BarUpdate LinerBar.Msg


exampleData : LinerBar.Data
exampleData =
    { title = Just "LinerBar.elm"
    , items =
        [ { name = "One", value = 30, color = "#6a329f" }
        , { name = "Two", value = 50, color = "#6a649f" }
        , { name = "Three", value = 20, color = "#6ac89f" }
        , { name = "Four", value = 40, color = "#6ac89f" }
        , { name = "Five", value = 40, color = "#6afb9f" }
        ]
    , dark = False
    }


init : () -> ( Model, Cmd Msg )
init _ =
    ( { linerBarModel = LinerBar.init exampleData
      , seed = 12345
      }
    , Cmd.none
    )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Randomize ->
            ( model
            , Random.generate NewRandomValues (Random.list (List.length model.linerBarModel.data.items) (Random.int 10 60))
            )

        NewRandomValues newValues ->
            let
                newItems =
                    List.map2 (\item value -> { item | value = toFloat value }) model.linerBarModel.data.items newValues

                linerBarModelData =
                    model.linerBarModel.data

                linerBarModel =
                    model.linerBarModel

                newData =
                    { linerBarModelData | items = newItems }

                newLinerBarModel =
                    { linerBarModel | data = newData }
            in
            ( { model | linerBarModel = newLinerBarModel, seed = model.seed + 1 }
            , Cmd.none
            )

        BarUpdate linerBarMsg ->
            ( { model | linerBarModel = LinerBar.update linerBarMsg model.linerBarModel }
            , Cmd.none
            )


view : Model -> Html Msg
view model =
    div []
        [ Html.map BarUpdate (LinerBar.view model.linerBarModel)
        , div
            [ style "width" "100%"
            , style "align-items" "center"
            , style "display" "flex"
            , style "justify-content" "center"
            , style "margin-top" "20px"
            ]
            [ button [ onClick Randomize ] [ text "Randomize Data" ] ]
        ]


main : Program () Model Msg
main =
    Browser.element
        { init = init
        , view = view
        , update = update
        , subscriptions = \_ -> Sub.none
        }

Build demo

cd demo
elm make Main.elm --output=main.js
# And open demo/index.html in browser

Documentations

Please see Elm Package for complete documentation.

License

MIT