Plotting with Purescript

I have an application that uses halogen needs some “light” plotting:

  • Line plots
  • Maybe a histogram
  • Plot controls to zoom in/out would be pretty awesome

I did some light googling and found:

Is there any plottting/charting library I’ve missed?

I’ve never really worked a lot with the FFI or the “lower level” parts of halogen to implement a binding for an existing library such as echarts. Are there any resources that make it easier?

2 Likes

I don’t know (yet) how to do that either but i’m definitely interested in working out how it’s done. I’d recommend looking closely at whether you really need the chart to be anything more than a black box to Halogen - even callbacks for events can probably just be thrown over the wall from the Halogen code without needing to make any kind of comprehensive binding.

I haven’t done any work on this D3 DSL for a while but i’m about to restart on it this month.

5 Likes

I’ve used charting a bit from PureScript and have written FFI bindings myself (using Highcharts/Highstock). For most charting libraries, making comprehensive bindings would be a huge undertaking, and so you’re more likely to see individual projects writing their own FFI for just the properties they need.

I used purescript-options for my FFI, but if I were doing it over again, I would probably try purescript-untagged-union which seems like it’d be simpler (but I have only done toy examples with untagged-union, so there might be pitfalls I’m not aware of). I initially tried to do it by record constraints Union and Nub, and it became a huge mess, so I don’t recommend that route.

1 Like

I agree, completely wrapping a plotting toolkit in Purescript is a big undertaking. That’s why I mentioned what I want to actually do in the post. I’m going to try to wrap just the functionality I need myself.

Here’s a great example of a PureScript project that wraps D3.js as needed via FFI.

5 Likes

Thank you @milesfrain for the example. Not only does this look like an awesome website and a good showcase for Purescript, I also took inspiration from your code and your approach to the problem.

What I did was very thinly wrap the echarts library myself to display the plots. Thanks to Purescript’s records being very transparently forwardable to Javascript, this was very pleasant and safe at the same time.

Thanks for the help guys!