Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
0.9-updates (#13)
Browse files Browse the repository at this point in the history
* 0.9-updates
* dep bumps
  • Loading branch information
cryogenian authored Jul 28, 2016
1 parent 178242a commit b6e57f9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 106 deletions.
11 changes: 5 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
"package.json"
],
"dependencies": {
"purescript-echarts": "^0.7.0",
"purescript-halogen": "^0.8.0",
"purescript-halogen-css": "^0.5.0"
"purescript-echarts": "^1.0.0",
"purescript-halogen": "^0.10.0",
"purescript-halogen-css": "^2.0.0"
},
"devDependencies": {
"purescript-debug": "^0.1.2",
"purescript-generics": "^0.7.0",
"purescript-random": "^0.2.3"
"purescript-debug": "^1.0.0",
"purescript-random": "^1.0.0"
}
}
53 changes: 26 additions & 27 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ module Main where
import Prelude

import Control.Bind ((=<<))
import Control.Monad.Aff (Aff())
import Control.Monad.Eff (Eff())
import Control.Monad.Eff.Exception (EXCEPTION())
import Control.Monad.Eff.Random (randomInt, RANDOM())
import Control.Monad.Aff (Aff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Random (randomInt, RANDOM)

import Data.Array ((!!), length, snoc, sort, reverse, head, filter)
import Data.Functor.Coproduct (Coproduct())
import Data.Functor.Coproduct (Coproduct)
import Data.Maybe (Maybe(..), maybe)
import Data.NaturalTransformation (Natural())

import Halogen as H
import Halogen.ECharts as EC
Expand All @@ -22,16 +21,16 @@ import Halogen.Util (runHalogenAff, awaitBody)

import Options (options)

randomInArray :: forall e a.Array a -> Eff (random :: RANDOM|e) (Maybe a)
randomInArray e a. Array a Eff (random RANDOM|e) (Maybe a)
randomInArray arr = do
n <- randomInt 0 (length arr - 1)
n randomInt 0 (length arr - 1)
pure $ arr !! n

type State =
{ arr :: Array Int
}
{ arr Array Int }

initialState :: State

initialState State
initialState = { arr: [ ] }

data Query a
Expand All @@ -45,19 +44,19 @@ type StateP = H.ParentState State EC.EChartsState Query EC.EChartsQuery AffChart
type QueryP = Coproduct Query (H.ChildF Slot EC.EChartsQuery)

type AppEffects = EC.EChartsEffects
( err :: EXCEPTION
, random :: RANDOM
( err EXCEPTION
, random RANDOM
)

type AffCharts = Aff AppEffects

type HTML = H.ParentHTML EC.EChartsState Query EC.EChartsQuery AffCharts Slot
type DSL = H.ParentDSL State EC.EChartsState Query EC.EChartsQuery AffCharts Slot

comp :: H.Component StateP QueryP AffCharts
comp H.Component StateP QueryP AffCharts
comp = H.parentComponent { render, eval, peek: Just peek }

render :: State -> HTML
render State HTML
render state =
HH.div_
$ [ HH.h1_ [ HH.text "purescript-halogen-echarts" ]
Expand All @@ -71,7 +70,7 @@ render state =
HH.div
[ HP.key ("echarts-" <> show ix) ]
[ HH.div_
[ HH.slot ix \_ ->
[ HH.slot ix \_
{ component: EC.echarts
, initialState: EC.initialEChartsState 400 300
}
Expand All @@ -84,27 +83,27 @@ render state =
[ HH.text "Remove" ]
]

eval :: Natural Query DSL
eval Query ~> DSL
eval (SetRandomOption ix next) = do
mbopt <- H.fromEff $ randomInArray options
mbopt H.fromEff $ randomInArray options
case mbopt of
Nothing -> pure unit
Just opt -> void $ H.query ix $ H.action (EC.Set opt)
Nothing pure unit
Just opt void $ H.query ix $ H.action (EC.Set opt)
pure next
eval (AddChart next) = do
H.modify (\x -> x{arr = snoc x.arr (maybe 0 (add one) $ head $ reverse $ sort x.arr)})
H.modify (\x x{arr = snoc x.arr (maybe 0 (add one) $ head $ reverse $ sort x.arr)})
pure next
eval (RemoveChart ix next) = do
H.modify (\x -> x{arr = filter (/= ix) x.arr})
H.modify (\x x{arr = filter (_ /= ix) x.arr})
pure next

peek :: forall x. H.ChildF Int EC.EChartsQuery x -> DSL Unit
peek x. H.ChildF Int EC.EChartsQuery x DSL Unit
peek (H.ChildF ix (EC.Init _)) = do
mbopt <- H.fromEff $ randomInArray options
mbopt H.fromEff $ randomInArray options
case mbopt of
Nothing -> pure unit
Just opt -> void $ H.query ix $ H.action (EC.Set opt)
Nothing pure unit
Just opt void $ H.query ix $ H.action (EC.Set opt)
peek _ = pure unit

main :: Eff AppEffects Unit
main Eff AppEffects Unit
main = runHalogenAff $ H.runUI comp (H.parentState initialState) =<< awaitBody
22 changes: 11 additions & 11 deletions example/src/Options.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import ECharts.Series as ES
import ECharts.Toolbox as ETB
import ECharts.Tooltip as ETT

simpleData :: Number -> ItemData
simpleData Number ItemData
simpleData = Value <<< Simple

lineOptions :: Option
lineOptions Option
lineOptions = Option $ optionDefault {
tooltip = Just $ ETT.Tooltip ETT.tooltipDefault {trigger = Just ETT.TriggerAxis},
legend = Just $ EL.Legend EL.legendDefault {
Expand Down Expand Up @@ -113,7 +113,7 @@ lineOptions = Option $ optionDefault {
}


chordOptions :: Option
chordOptions Option
chordOptions = Option $ optionDefault {
series = Just $ Just <$> [
ES.ChordSeries {
Expand Down Expand Up @@ -143,15 +143,15 @@ chordOptions = Option $ optionDefault {
}


indicator :: String -> Number -> EA.Indicator
indicator String Number EA.Indicator
indicator text max =
EA.Indicator $ EA.indicatorDefault{text = Just text, max = Just max}

datPair :: Array Number -> String -> ItemData
datPair Array Number String ItemData
datPair val name =
Dat $ (dataDefault $ Many val) {name = Just name}

radarOptions :: Option
radarOptions Option
radarOptions = Option $ optionDefault {
polar = Just $ [EA.Polar EA.polarDefault {
indicator = Just [
Expand All @@ -178,12 +178,12 @@ radarOptions = Option $ optionDefault {



hloc :: Number -> Number -> Number -> Number -> ItemData
hloc Number Number Number Number ItemData
hloc o c l h = Value $ HLOC {
h: h, l: l, o: o, c: c
}

kOptions :: Option
kOptions Option
kOptions = Option $ optionDefault {
xAxis = Just $ EA.OneAxis $ EA.Axis EA.axisDefault {
"type" = Just EA.CategoryAxis,
Expand Down Expand Up @@ -213,11 +213,11 @@ kOptions = Option $ optionDefault {



simpleDat :: Number -> String -> ItemData
simpleDat Number String ItemData
simpleDat val nam =
Dat $ (dataDefault $ Simple val) {name = Just nam}

funnelOptions :: Option
funnelOptions Option
funnelOptions = Option $ optionDefault {
series = Just $ Just <$> [
ES.FunnelSeries {
Expand All @@ -237,7 +237,7 @@ funnelOptions = Option $ optionDefault {



options :: Array Option
options Array Option
options = [ lineOptions
, chordOptions
, radarOptions
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"clean": "rm -rf output .pulp-cache example/dist/test.js example/dist/echarts-all.js",
"build": "pulp build --censor-lib --strict",
"example": "pulp browserify --include example/src --to example/dist/test.js"
"copy-echarts": "cp bower_components/echarts/build/dist/echarts-all.js example/dist/echarts-all.js",
"example": "npm run clean && npm run copy-echarts && pulp browserify --include example/src --to example/dist/test.js"
},
"dependencies": {
"pulp": "^9.0.1",
"purescript": "^0.9.2",
"purescript-psa": "^0.3.9",
"virtual-dom": "^2.1.1"
},
"devDependencies": {
"pulp": "^8.1.0",
"purescript": "^0.8.5",
"purescript-psa": "^0.3.8",
"rimraf": "^2.5.2"
}
}
Loading

0 comments on commit b6e57f9

Please sign in to comment.