From b6e57f94761ad3b4d589625032238415afa49bdc Mon Sep 17 00:00:00 2001 From: Maxim Zimaliev Date: Fri, 29 Jul 2016 00:08:04 +0300 Subject: [PATCH] 0.9-updates (#13) * 0.9-updates * dep bumps --- bower.json | 11 ++--- example/src/Main.purs | 53 ++++++++++----------- example/src/Options.purs | 22 ++++----- package.json | 14 +++--- src/Halogen/ECharts.purs | 100 ++++++++++++++++++--------------------- 5 files changed, 94 insertions(+), 106 deletions(-) diff --git a/bower.json b/bower.json index 68b686e..46f9a43 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/example/src/Main.purs b/example/src/Main.purs index 310d581..fa4ca6c 100644 --- a/example/src/Main.purs +++ b/example/src/Main.purs @@ -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 @@ -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 @@ -45,8 +44,8 @@ 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 @@ -54,10 +53,10 @@ 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" ] @@ -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 } @@ -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 diff --git a/example/src/Options.purs b/example/src/Options.purs index c54df46..1199114 100644 --- a/example/src/Options.purs +++ b/example/src/Options.purs @@ -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 { @@ -113,7 +113,7 @@ lineOptions = Option $ optionDefault { } -chordOptions :: Option +chordOptions ∷ Option chordOptions = Option $ optionDefault { series = Just $ Just <$> [ ES.ChordSeries { @@ -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 [ @@ -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, @@ -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 { @@ -237,7 +237,7 @@ funnelOptions = Option $ optionDefault { -options :: Array Option +options ∷ Array Option options = [ lineOptions , chordOptions , radarOptions diff --git a/package.json b/package.json index f9afa82..d8b9686 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/Halogen/ECharts.purs b/src/Halogen/ECharts.purs index f470329..25304a5 100644 --- a/src/Halogen/ECharts.purs +++ b/src/Halogen/ECharts.purs @@ -13,7 +13,6 @@ import Control.Monad.Aff.Free (class Affable) import Data.Int (toNumber) import Data.Maybe (Maybe(..)) -import Data.NaturalTransformation (Natural) import DOM (DOM) import DOM.HTML.Types (HTMLElement) @@ -21,9 +20,7 @@ import DOM.HTML.Types (HTMLElement) import CSS.Geometry (width, height) import CSS.Size (px) -import ECharts.Chart as EC -import ECharts.Effects as EE -import ECharts.Options as EO +import ECharts as E import Halogen as H import Halogen.HTML.CSS.Indexed (style) @@ -31,14 +28,14 @@ import Halogen.HTML.Indexed as HH import Halogen.HTML.Properties.Indexed as HP type EChartsState = - { element :: Maybe HTMLElement - , option :: Maybe EO.Option - , chart :: Maybe EC.EChart - , width :: Int - , height :: Int + { element ∷ Maybe HTMLElement + , option ∷ Maybe E.Option + , chart ∷ Maybe E.EChart + , width ∷ Int + , height ∷ Int } -initialEChartsState :: Int -> Int -> EChartsState +initialEChartsState ∷ Int → Int → EChartsState initialEChartsState w h = { element: Nothing , option: Nothing @@ -51,25 +48,20 @@ data EChartsQuery a = SetElement (Maybe HTMLElement) a | Init a | Dispose a - | Set EO.Option a + | Set E.Option a | Resize a | Refresh a | Clear a | SetHeight Int a | SetWidth Int a - | GetOptions (Maybe EO.Option -> a) - | GetWidth (Int -> a) - | GetHeight (Int -> a) + | GetOptions (Maybe E.Option → a) + | GetWidth (Int → a) + | GetHeight (Int → a) type EChartsEffects eff = - ( echartInit :: EE.ECHARTS_INIT - , echartSetOption :: EE.ECHARTS_OPTION_SET - , echartDispose :: EE.ECHARTS_DISPOSE - , echartResize :: EE.ECHARTS_RESIZE - , echartRefresh :: EE.ECHARTS_REFRESH - , echartClear :: EE.ECHARTS_CLEAR - , dom :: DOM - , avar :: AVAR + ( echarts ∷ E.ECHARTS + , dom ∷ DOM + , avar ∷ AVAR | eff ) @@ -77,9 +69,9 @@ type HTML = H.ComponentHTML EChartsQuery type DSL g = H.ComponentDSL EChartsState EChartsQuery g echarts - :: forall eff g + ∷ ∀ eff g . (Affable (EChartsEffects eff) g) - => H.Component EChartsState EChartsQuery g + ⇒ H.Component EChartsState EChartsQuery g echarts = H.lifecycleComponent { render , eval @@ -87,7 +79,7 @@ echarts = H.lifecycleComponent , finalizer: Nothing } -render :: EChartsState -> HTML +render ∷ EChartsState → HTML render state = HH.div [ HP.ref (H.action <<< SetElement) @@ -98,65 +90,65 @@ render state = [] eval - :: forall eff g - . (Affable (EChartsEffects eff) g) - => Natural EChartsQuery (DSL g) + ∷ ∀ eff g + . (Affable (EChartsEffects eff) g) + ⇒ EChartsQuery ~> (DSL g) eval (SetElement el next) = do H.modify (_ { element = el }) pure next eval (Init next) = do - state <- H.get + state ← H.get case state.element of - Nothing -> pure unit - Just el -> do - chart <- H.fromEff $ EC.init Nothing el + Nothing → pure unit + Just el → do + chart ← H.fromEff $ E.init Nothing el H.modify (_{chart = pure chart}) pure next eval (Dispose next) = do - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.dispose chart + Nothing → pure unit + Just chart → H.fromEff $ E.dispose chart pure next eval (Set opts next) = do - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> do - chart' <- H.fromEff $ EO.setOption opts true chart + Nothing → pure unit + Just chart → do + chart' ← H.fromEff $ E.setOption opts true chart H.modify (_{ chart = pure chart', option = pure opts }) pure next eval (Resize next) = do - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.resize chart + Nothing → pure unit + Just chart → H.fromEff $ E.resize chart pure next eval (Refresh next) = do - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.refresh chart + Nothing → pure unit + Just chart → H.fromEff $ E.refresh chart pure next eval (Clear next) = do - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.clear chart + Nothing → pure unit + Just chart → H.fromEff $ E.clear chart pure next eval (SetHeight h next) = do H.modify (_{height = h}) - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.resize chart + Nothing → pure unit + Just chart → H.fromEff $ E.resize chart pure next eval (SetWidth w next) = do H.modify (_{width = w}) - state <- H.get + state ← H.get case state.chart of - Nothing -> pure unit - Just chart -> H.fromEff $ EC.resize chart + Nothing → pure unit + Just chart → H.fromEff $ E.resize chart pure next eval (GetOptions continue) = do map continue $ H.gets _.option