<commit_before>module TranslateSquare (Model, Action, init, update, view) where

import Easing exposing (ease, easeOutElastic, float)
import Effects exposing (Effects)
import Html exposing (Html)
import Svg exposing (svg, rect, g, text, text')
import Svg.Attributes exposing (..)
import Svg.Events exposing (onClick)
import Time exposing (Time, second)


-- MODEL

type alias Model =
    { xTranslation : Float
    , animationState : AnimationState
    }


type alias AnimationState =
    Maybe { prevClockTime : Time, elapsedTime : Time }


init : (Model, Effects Action)
init =
  ( { xTranslation = 0, animationState = Nothing }
  , Effects.none
  )


xTranslation = 100
duration = second



-- UPDATE

type Action
    = XTranslate
    | Tick Time


update : Action -> Model -> (Model, Effects Action)
update msg model =
  case msg of
    XTranslate ->
      case model.animationState of
        Nothing ->
          ( model, Effects.tick Tick )

        Just _ ->
          ( model, Effects.none )

    Tick clockTime ->
      let
        newElapsedTime =
          case model.animationState of
            Nothing ->
              0

            Just {elapsedTime, prevClockTime} ->
              elapsedTime + (clockTime - prevClockTime)
      in
        if newElapsedTime > duration then
          ( { xTranslation = model.xTranslation + xTranslation
            , animationState = Nothing
            }
          , Effects.none
          )
        else
          ( { xTranslation = model.xTranslation
            , animationState = Just { elapsedTime = newElapsedTime, prevClockTime = clockTime }
            }
          , Effects.tick Tick
          )


-- VIEW

toOffset : AnimationState -> Float
toOffset animationState =
  case animationState of
    Nothing ->
      0

    Just {elapsedTime} ->
      ease easeOutElastic float 0 xTranslation duration elapsedTime


view : Signal.Address Action -> Model -> Html
view address model =
  let
    xTranslation =
      model.xTranslation + toOffset model.animationState
  in
    svg
      [ width "200", height "200", viewBox "0 0 300 300" ]
      [ g [ transform ("translate(100, 100) translate(" ++ toString xTranslation ++ ", 0)")
          , onClick (Signal.message address XTranslate)
          ]
          [ rect
              [ x "-50"
              , y "-50"
              , width "100"
              , height "100"
              , rx "15"
              , ry "15"
              , style "fill: #60B5CC;"
              ]
              []
          , text' [ fill "white", textAnchor "middle" ] [ text "Click me!" ]
          ]
      ]<commit_msg>Displaying diamonds w/ '*' as label.  Yay<commit_after>module TranslateSquare (Model, Action, init, update, view) where

import Easing exposing (ease, easeOutElastic, float)
import Effects exposing (Effects)
import Html exposing (Html)
import Svg exposing (svg, rect, polygon, g, text, text')
import Svg.Attributes exposing (..)
import Svg.Events exposing (onClick)
import Time exposing (Time, second)


-- MODEL

type alias Model =
    { xTranslation : Float
    , animationState : AnimationState
    }


type alias AnimationState =
    Maybe { prevClockTime : Time, elapsedTime : Time }


init : (Model, Effects Action)
init =
  ( { xTranslation = 0, animationState = Nothing }
  , Effects.none
  )


xTranslation = 100
duration = second



-- UPDATE

type Action
    = XTranslate
    | Tick Time


update : Action -> Model -> (Model, Effects Action)
update msg model =
  case msg of
    XTranslate ->
      case model.animationState of
        Nothing ->
          ( model, Effects.tick Tick )

        Just _ ->
          ( model, Effects.none )

    Tick clockTime ->
      let
        newElapsedTime =
          case model.animationState of
            Nothing ->
              0

            Just {elapsedTime, prevClockTime} ->
              elapsedTime + (clockTime - prevClockTime)
      in
        if newElapsedTime > duration then
          ( { xTranslation = model.xTranslation + xTranslation
            , animationState = Nothing
            }
          , Effects.none
          )
        else
          ( { xTranslation = model.xTranslation
            , animationState = Just { elapsedTime = newElapsedTime, prevClockTime = clockTime }
            }
          , Effects.tick Tick
          )


-- VIEW

toOffset : AnimationState -> Float
toOffset animationState =
  case animationState of
    Nothing ->
      0

    Just {elapsedTime} ->
      ease easeOutElastic float 0 xTranslation duration elapsedTime


view : Signal.Address Action -> Model -> Html
view address model =
  let
    xTranslation =
      model.xTranslation + toOffset model.animationState
  in
    svg
      [ width "200", height "200", viewBox "0 0 300 300" ]
      [ g [ transform ("translate(100, 100) translate(" ++ toString xTranslation ++ ", 0)")
          , onClick (Signal.message address XTranslate)
          ]
          [
             polygon
               [ fill "#F0AD00",
                 points "0,-50 50,0 0,50 -50,0"
               ]
               [],
             text' [ fill "white", textAnchor "middle" ] [ text "*" ]
          ]
      ]
{'fraction_non_alphanumeric': 0.09060923554520761, 'fraction_numerical': 0.017074117190531625, 'mean_word_length': 1.9239931934203063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4510197', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1385, 'n_words': 432}