Skip to content

Commit

Permalink
Merge pull request #10 from yang-wei/signal-color
Browse files Browse the repository at this point in the history
Signal color
  • Loading branch information
yang-wei committed Mar 11, 2016
2 parents db2349f + 02475e4 commit daa8c0c
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 108 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
compile:
elm make src/Main.elm --output build/main.js --yes

19 changes: 10 additions & 9 deletions src/Component/Line.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Mouse
import AnimationFrame

import Config.Size exposing (seriesWidth, seriesHeight)
import Config.Color exposing (elmBlue, white)

type Action a
= TimeSignal Time
Expand Down Expand Up @@ -40,11 +39,11 @@ objectMoveX x shape =
moveX startPoint shape -- start from most left instead of origin
|> moveX x

makeBox : Float -> String -> Form
makeBox x value =
makeBox : Float -> String -> Color -> Form
makeBox x value color =
let
point = oval pointWidth pointHeight
|> filled elmBlue
|> filled color
|> objectMoveX x
displayedValue = Text.fromString value
|> text
Expand All @@ -63,10 +62,11 @@ moveXAsTimePassed delta box =
moveXAsNewBoxIsAdded box =
{ box | x = box.x - pointWidth }

toStreamLine : (String -> String) -> Signal a -> Signal Element
toStreamLine f signal =
Signal.map view (transformIntoLine f signal)
toStreamLine : Color -> (String -> String) -> Signal a -> Signal Element
toStreamLine color f signal =
Signal.map (view color) (transformIntoLine f signal)

transformIntoLine : (String -> String) -> Signal a -> Signal (List Box)
transformIntoLine f signal=
let
action =
Expand All @@ -92,9 +92,10 @@ transformIntoLine f signal=


-- VIEW
view series =
view : Color -> List Box -> Element
view color series =
let
boxes = List.map (\{x, value} -> makeBox x value) series
boxes = List.map (\{x, value} -> makeBox x value color) series
in
collage seriesWidth seriesHeight
([ timeAxisTick
Expand Down
24 changes: 12 additions & 12 deletions src/Component/Sandbox.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Graphics.Element as Element exposing (Element, show, flow, up, down, left
-- STYLING
import String
import Text
import Color
import Color exposing (Color)
import List

-- COMPONENT
Expand All @@ -21,8 +21,8 @@ import Config.Color exposing (elmBlue)
name latest value previous value latest value
--}

signalSandbox : Signal a -> (String -> String) -> String -> Signal Element
signalSandbox signal f signalName =
signalSandbox : Signal a -> (String -> String) -> String -> Color -> Signal Element
signalSandbox signal f signalName color =
let
smallHorizontalSpace = signalSpacer 10 1
smallVerticalSpace = signalSpacer 1 10
Expand All @@ -35,9 +35,9 @@ signalSandbox signal f signalName =
bottomDisplay =
Extra.mapMany (flow right)
[ mediumHorizontalSpace
, toStreamLine f signal
, toStreamLine color f signal
, smallHorizontalSpace
, signalValue signal
, signalValue color signal
, mediumHorizontalSpace
]
in
Expand All @@ -46,13 +46,13 @@ signalSandbox signal f signalName =
displaySimpleSandbox signals =
let
sandboxes =
List.map (\(signal, name) -> simpleSignalSandbox signal name) signals
List.map (\(signal, name, color) -> simpleSignalSandbox signal name color) signals
in
Extra.mapMany (flow down) sandboxes

simpleSignalSandbox : Signal a -> String -> Signal Element
simpleSignalSandbox signal signalName =
signalSandbox signal identity signalName
simpleSignalSandbox : Signal a -> String -> Color -> Signal Element
simpleSignalSandbox signal signalName color =
signalSandbox signal identity signalName color

-- For e.g: Mouse.clicks
signalLabel : String -> Signal Element
Expand All @@ -68,14 +68,14 @@ signalLabel name =
Signal.constant displayName

-- For e.g: ()
signalValue : Signal a -> Signal Element
signalValue value =
signalValue : Color -> Signal a -> Signal Element
signalValue color value =
let
display value =
container seriesValueWidth seriesHeight middle
(toString value
|> Text.fromString
|> Text.color elmBlue
|> Text.color color
|> Element.justified
|> Element.width seriesValueWidth)
in
Expand Down
18 changes: 16 additions & 2 deletions src/Config/Color.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
module Config.Color(elmBlue, white) where
module Config.Color(elmBlue, white, green, orange, yellow) where

import Color exposing (rgb)
import Color exposing (rgb, Color)

elmBlue : Color
elmBlue =
rgb 96 181 204

green : Color
green =
rgb 130 215 54

orange : Color
orange =
rgb 255 105 70

yellow : Color
yellow =
rgb 255 203 70

white : Color
white =
rgb 255 255 255
9 changes: 5 additions & 4 deletions src/Page/KeyboardSignal.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Page.KeyboardSignal (view) where
module Page.KeyboardSignal (view, keyboardPressesElement) where

import Signal.Extra as Extra
import Graphics.Element as Element exposing (Element, flow, down)
Expand All @@ -7,6 +7,7 @@ import Keyboard

-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Config.Color exposing (orange)


-- VIEW
Expand All @@ -20,12 +21,12 @@ view =

keyboardArrowsElement : Signal Element
keyboardArrowsElement =
displaySimpleSandbox [ ( Keyboard.arrows, "Keyboard.arrows : Signal { x : Int, y : Int }" ) ]
displaySimpleSandbox [ ( Keyboard.arrows, "Keyboard.arrows : Signal { x : Int, y : Int }", orange ) ]

keyboardWasdElement : Signal Element
keyboardWasdElement =
displaySimpleSandbox [ ( Keyboard.wasd, "Keyboard.wasd : Signal { x : Int, y : Int }") ]
displaySimpleSandbox [ ( Keyboard.wasd, "Keyboard.wasd : Signal { x : Int, y : Int }", orange) ]

keyboardPressesElement : Signal Element
keyboardPressesElement =
displaySimpleSandbox [ ( Keyboard.presses, "Keyboard.presses : Signal KeyCode") ]
displaySimpleSandbox [ ( Keyboard.presses, "Keyboard.presses : Signal KeyCode", orange) ]
7 changes: 4 additions & 3 deletions src/Page/MouseSignal.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Page.MouseSignal (view) where
module Page.MouseSignal (view, mouseClicksElement, mouseIsDownElement) where

import Signal.Extra as Extra
import Graphics.Element as Element exposing (Element, flow, down)
Expand All @@ -7,6 +7,7 @@ import Mouse

-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Config.Color exposing (yellow)


-- VIEW
Expand All @@ -22,8 +23,8 @@ mouseClicksSignal = Mouse.clicks

mouseClicksElement : Signal Element
mouseClicksElement =
displaySimpleSandbox [ ( mouseClicksSignal, "Mouse.clicks : Signal ()" ) ]
displaySimpleSandbox [ ( mouseClicksSignal, "Mouse.clicks : Signal ()", yellow ) ]

mouseIsDownElement : Signal Element
mouseIsDownElement =
displaySimpleSandbox [ ( Mouse.isDown, "Mouse.isDown : Signal Bool" ) ]
displaySimpleSandbox [ ( Mouse.isDown, "Mouse.isDown : Signal Bool", yellow ) ]
8 changes: 3 additions & 5 deletions src/Page/SignalDropRepeats.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Keyboard
-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Component.Note exposing (signalNote)
import Config.Color exposing (elmBlue)
import Page.KeyboardSignal exposing (keyboardPressesElement)

-- VIEW
view : Signal Element
Expand All @@ -18,10 +20,6 @@ view =
, dropRepeatsPressesElement
]

keyboardPressesElement : Signal Element
keyboardPressesElement =
displaySimpleSandbox [ ( Keyboard.presses, "Keyboard.presses : Signal KeyCode") ]

dropRepeatsPresses : Signal Int
dropRepeatsPresses =
Signal.dropRepeats Keyboard.presses
Expand All @@ -32,4 +30,4 @@ dropRepeatsPressesNote =

dropRepeatsPressesElement : Signal Element
dropRepeatsPressesElement =
displaySimpleSandbox [ ( dropRepeatsPresses, "dropRepeatsPresses : Signal Int") ]
displaySimpleSandbox [ ( dropRepeatsPresses, "dropRepeatsPresses : Signal Int", elmBlue) ]
11 changes: 4 additions & 7 deletions src/Page/SignalFilter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Char
-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Component.Note exposing (signalNote)

import Page.KeyboardSignal exposing (keyboardPressesElement)
import Config.Color exposing (orange, green, elmBlue)

-- VIEW
view : Signal Element
Expand All @@ -22,10 +23,6 @@ view =
, keyboardDigitElement
]

keyboardPressesElement : Signal Element
keyboardPressesElement =
displaySimpleSandbox [ ( Keyboard.presses, "Keyboard.presses : Signal KeyCode") ]

keyboardCharNote : Signal Element
keyboardCharNote =
signalNote "keyboardChar = Signal.map Char.fromCode Keyboard.presses"
Expand All @@ -36,7 +33,7 @@ keyboardChar =

keyboardCharElement : Signal Element
keyboardCharElement =
displaySimpleSandbox [ ( keyboardChar, "keyboardChar: Signal Char" ) ]
displaySimpleSandbox [ ( keyboardChar, "keyboardChar: Signal Char", orange ) ]

keyboardDigit : Signal Char
keyboardDigit =
Expand All @@ -48,4 +45,4 @@ keyboardDigitNote =

keyboardDigitElement : Signal Element
keyboardDigitElement =
displaySimpleSandbox [ (keyboardDigit, "keyboardDigit : Signal Bool")]
displaySimpleSandbox [ (keyboardDigit, "keyboardDigit : Signal Bool", elmBlue)]
15 changes: 5 additions & 10 deletions src/Page/SignalFoldp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Mouse
-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Component.Note exposing (signalNote)
import Page.MouseSignal exposing (mouseClicksElement)
import Config.Color exposing (elmBlue)

-- VIEW
view : Signal Element
Expand All @@ -17,21 +19,14 @@ view =
, counter
]

mouseClicksSignal : Signal ()
mouseClicksSignal = Mouse.clicks

mouseClicksElement : Signal Element
mouseClicksElement =
displaySimpleSandbox [ ( mouseClicksSignal, "Mouse.clicks : Signal ()" ) ]

clicksCounter : Signal Int
clicksCounter =
Signal.foldp (\_ count -> count + 1) 0 mouseClicksSignal
Signal.foldp (\_ count -> count + 1) 0 Mouse.clicks

clicksCounterNote : Signal Element
clicksCounterNote =
signalNote "counter = Signal.foldp (\\_ n -> n + 1) 0 mouseClicksSignal"
signalNote "counter = Signal.foldp (\\_ n -> n + 1) 0 Mouse.clicks"

counter : Signal Element
counter =
displaySimpleSandbox [ ( clicksCounter, "counter : Signal Int" ) ]
displaySimpleSandbox [ ( clicksCounter, "counter : Signal Int", elmBlue ) ]
9 changes: 3 additions & 6 deletions src/Page/SignalMap.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Char
-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Component.Note exposing (signalNote)

import Config.Color exposing (elmBlue)
import Page.KeyboardSignal exposing (keyboardPressesElement)

-- VIEW
view : Signal Element
Expand All @@ -20,10 +21,6 @@ view =
, keyboardCharElement
]

keyboardPressesElement : Signal Element
keyboardPressesElement =
displaySimpleSandbox [ ( Keyboard.presses, "Keyboard.presses : Signal KeyCode") ]

keyboardCharNote : Signal Element
keyboardCharNote =
signalNote "keyboardChar = Signal.map Char.fromCode Keyboard.presses"
Expand All @@ -34,4 +31,4 @@ keyboardChar =

keyboardCharElement : Signal Element
keyboardCharElement =
displaySimpleSandbox [ ( keyboardChar, "keyboardChar: Signal Char" ) ]
displaySimpleSandbox [ ( keyboardChar, "keyboardChar: Signal Char", elmBlue ) ]
8 changes: 4 additions & 4 deletions src/Page/SignalMap2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Char
-- COMPONENT
import Component.Sandbox exposing (displaySimpleSandbox)
import Component.Note exposing (signalNote)

import Config.Color exposing (orange, elmBlue)

-- VIEW
view : Signal Element
Expand All @@ -23,8 +23,8 @@ view =
keyboardEnterElement : Signal Element
keyboardEnterElement =
displaySimpleSandbox
[ ( Keyboard.enter, "Keyboard.enter : Signal Bool")
, ( Keyboard.space, "Keyboard.space : Signal Bool")
[ ( Keyboard.enter, "Keyboard.enter : Signal Bool", orange)
, ( Keyboard.space, "Keyboard.space : Signal Bool", orange)
]

keyboardCharNote : Signal Element
Expand All @@ -40,4 +40,4 @@ isEnterAndSpacePressed =

isEnterAndSpacePressedElement : Signal Element
isEnterAndSpacePressedElement =
displaySimpleSandbox [ ( isEnterAndSpacePressed, "isEnterAndSpacePressed : Signal Bool") ]
displaySimpleSandbox [ ( isEnterAndSpacePressed, "isEnterAndSpacePressed : Signal Bool", elmBlue) ]

0 comments on commit daa8c0c

Please sign in to comment.