Use ports for rendering in elm -


i use flot.js 2d plot library elm. first thought i'd write native wrapper seems discouraged. therefore want try use ports send values plot javascript (ie call flot.js made on javascript side). possible?

yes, can use ports send data elm plot flot graph. here's rewrite of basic flot example using elm data source.

port flotexample1 : list (list (maybe (list float))) port flotexample1 =   let     halfstepsto14 =       list.map (\x -> x / 2) [0..28]     d1 =       list.map (\x -> [x, sin x]) halfstepsto14     d2 =       list.map [[0, 3], [4, 8], [8, 5], [9, 13]]     d3 =       [just [0, 12], [7, 12], nothing, [7, 2.5], [12, 2.5]]   in     [ d1, d2, d3 ] 

elm conversion of basic elm datatypes in ports javascript types on other side. maybe in function signature above account fact nulls can used separate line segments in flot (see example d3)

    <script>         var app = elm.worker(elm.main);          $(function() {             $.plot("#placeholder", app.ports.flotexample1);         });     </script> 

you can make more complex examples accessing server url elm or tying other signals time or mouse movements (in case port signature signal (list (list (maybe (list float))))), still revolve around ports.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -