Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to 0.16 #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions D3JS_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2010-2015, Michael Bostock
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* The name Michael Bostock may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"exposed-modules": ["D3", "D3.Event"],
"native-modules": true,
"dependencies": {
"elm-lang/core": "2.1.0 <= v < 3.0.0"
"elm-lang/core": "3.0.0 <= v < 4.0.0"
},
"elm-version": "0.15.1 <= v < 0.16.0"
"elm-version": "0.16.0 <= v < 0.17.0"
}
4 changes: 2 additions & 2 deletions examples/Circles.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ svg ds ms =

-- Move the mouse to the left to right to remove or add circles. Move the mouse
-- up and down to change the brightness of the circles.
circles : D3 (number, number) number
circles : D3 (Int, Int) Int
circles =
selectAll "circle"
|= (\(x, y) -> List.repeat (x // 50) y)
Expand All @@ -40,7 +40,7 @@ circles =
|- exit
|. remove

color : number -> number -> String
color : Int -> Int -> String
color y i =
let steelBlue = D3.Color.fromString "steelblue"
magnitude = (2 * toFloat y / toFloat dims.height) ^ (toFloat i / 2)
Expand Down
6 changes: 3 additions & 3 deletions examples/Clicks.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ transform : Pos -> Model -> Model
transform pos c =
let incr m = m + 1 in
case pos of
Left -> { c | left <- incr c.left }
Middle -> { c | middle <- incr c.middle }
Right -> { c | right <- incr c.right }
Left -> { c | left = incr c.left }
Middle -> { c | middle = incr c.middle }
Right -> { c | right = incr c.right }

controller : Signal Model
controller =
Expand Down
6 changes: 3 additions & 3 deletions examples/Counters.elm
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ handler : Event -> Model -> Model
handler e m = case e of
Create -> let next' = m.next + 1 in
{ next = next', dict = Dict.insert next' 0 m.dict }
Increment i -> { m | dict <- increment i m.dict }
Decrement i -> { m | dict <- decrement i m.dict }
Remove i -> { m | dict <- Dict.remove i m.dict }
Increment i -> { m | dict = increment i m.dict }
Decrement i -> { m | dict = decrement i m.dict }
Remove i -> { m | dict = Dict.remove i m.dict }

events : Stream Event
events = stream ()
Expand Down
24 changes: 12 additions & 12 deletions examples/Todo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ type alias Model = {
--
setStatus : Model -> Int -> Bool -> Model
setStatus m i b =
{ m | items <- imap (\(t, s) j -> (t, if j == i then b else s)) m.items }
{ m | items = imap (\(t, s) j -> (t, if j == i then b else s)) m.items }

-- Sets the description of the item at index `i` to the value `d`.
--
setDescription : Model -> Int -> String -> Model
setDescription m i d =
{ m | items <- imap (\(t, s) j -> (if j == i then d else t, s)) m.items }
{ m | items = imap (\(t, s) j -> (if j == i then d else t, s)) m.items }

-- Start editing the item at index `i`.
--
Expand All @@ -107,15 +107,15 @@ startEdit m i =
Nothing -> Debug.crash "assert false"
Just (x, _) -> x
in
{ m | editing <- Just (description, i) }
{ m | editing = Just (description, i) }

-- Change the description of the current edit item to the value `d`.
--
changeEdit : Model -> String -> Model
changeEdit m d =
case m.editing of
Nothing -> Debug.crash "trying to edit while not editing"
Just (_, i) -> { m | editing <- Just (d, i) }
Just (_, i) -> { m | editing = Just (d, i) }

-- Complete editing by setting the description of the current edit item to the
-- modified description, and returning the model to non-edit state.
Expand All @@ -124,7 +124,7 @@ commitEdit : Model -> Model
commitEdit m =
case m.editing of
Nothing -> Debug.crash "trying to finishing editing while not editing"
Just (t, i) -> let m' = setDescription m i t in { m' | editing <- Nothing }
Just (t, i) -> let m' = setDescription m i t in { m' | editing = Nothing }


-------------------------------------------------------------------------------
Expand Down Expand Up @@ -168,16 +168,16 @@ type Event
transform : Event -> Model -> Model
transform e m =
case e of
AddInput -> { m | input <- ""
, items <- (m.input, False)::m.items }
ChangeInput i -> { m | input <- i }
Filter f -> { m | filter <- f }
Toggle onoff -> { m | items <- List.map (\(d,_) -> (d, onoff)) m.items }
Delete index -> { m | items <- ifilter (\_ j -> j /= index) m.items }
AddInput -> { m | input = ""
, items = (m.input, False)::m.items }
ChangeInput i -> { m | input = i }
Filter f -> { m | filter = f }
Toggle onoff -> { m | items = List.map (\(d,_) -> (d, onoff)) m.items }
Delete index -> { m | items = ifilter (\_ j -> j /= index) m.items }
Edit index -> startEdit m index
ChangeEdit d -> changeEdit m d
CommitEdit -> commitEdit m
CancelEdit -> { m | editing <- Nothing }
CancelEdit -> { m | editing = Nothing }
Check index -> setStatus m index True
Uncheck index -> setStatus m index False
Noop -> m
Expand Down
24 changes: 11 additions & 13 deletions examples/Voronoi.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import String
import Time exposing (inMilliseconds, timestamp)

import Graphics.Element exposing (Element)
import Signal exposing ((<~), (~), constant)
import Signal exposing (map, map2, constant)

-- Type declaractions for records that represent dimensions and margins.
--
Expand Down Expand Up @@ -104,21 +104,18 @@ translate x y = "translate(" ++ (toString x) ++ "," ++ (toString y) ++ ")"
--
genPoints : Int -> Generator (List D3.Voronoi.Point)
genPoints n =
let points =
customGenerator <| \seed ->
let (x, seed') = generate (float 0 dims.width ) seed in
let (y, seed'') = generate (float 0 dims.height) seed' in
({ x = x, y = y }, seed'')
in
list n points
list n (Random.map (\(x, y) -> {x = x, y = 1}) (pair (float 0 dims.width) (float 0 dims.height)))

genPoints' : Int -> Seed -> List D3.Voronoi.Point
genPoints' n s = fst (generate (genPoints n) s)
genPoints' n s = fst (generate (genPoints n) s)

-- Hoops to get a random seed.
--
seed : Signal Seed
seed = (\(time, _) -> initialSeed (floor (inMilliseconds time))) <~ (timestamp (constant ()))
seed =
Signal.map
(\(time, _) -> initialSeed (floor (inMilliseconds time)))
(timestamp (constant ()))

vis dims margin =
svg dims margin
Expand All @@ -128,7 +125,8 @@ vis dims margin =
main : Signal Element
main =
let mouse (x, y) = { x = (toFloat x) - margin.left, y = (toFloat y) - margin.top }
randomPoints = genPoints' 100 <~ seed
points = (\m ps -> mouse m :: ps) <~ Mouse.position ~ randomPoints
randomPoints = Signal.map (genPoints' 100) seed
-- randomPoints = Signal.map (\(x, y) -> {x = x, y = y}) randomPair
points = Signal.map2 (\m ps -> mouse m :: ps) Mouse.position randomPoints
in
render dims.width dims.height (vis dims margin) <~ points
Signal.map (render dims.width dims.height (vis dims margin)) points
1 change: 1 addition & 0 deletions src/D3.elm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import Graphics.Element exposing (Element)
import Json.Encode exposing (Value)
import String

import Native.D3.D3
import Native.D3.Render
import Native.D3.Selection
import Native.D3.Transition
Expand Down
5 changes: 5 additions & 0 deletions src/Native/D3/D3.js

Large diffs are not rendered by default.