[Chart] A bunch of features and fixes.

malcolm.wallace malcolm.wallace at me.com
Wed Feb 1 13:46:44 GMT 2012


> I will shortly push these changes:
 
Thanks.
> I'm not keen on this change:
>
> Tue Jan 31 04:39:14 EST 2012 malcolm.wallace at me.com
> * An easier way of making a log axis.
>
> The PlotValue type class is appropriate for many types (currently there
> are 5 instances). Your new method autoLogAxis is only ever going to be
> implemented for a small subset of these - most likely only Double. What
> was the difficuly in creating a log axis without this change? Test4.hs
> shows this being done the old way.
 
What I am trying to do, is to implement a function with this polymorphic signature:

overlayPlots :: (PlotValue x, PlotValue y)  => [Plot x y] -> AxisOptions x y -> Layout1 x y

where the AxisOptions type includes Boolean flags to choose whether each axis is linear or log.  As things currently stand, without a class method it is impossible to write, because autoScaledLogAxis only works for RealFloat values, not for PlotValues.  I understand of course that e.g. an Indexed axis is not going to be able to implement the log scale properly, but in that case, it would be OK for its instance simply to use a linear scale despite the name of the option.  Code for illustration:

overlayPlots plots options = id
    $ layout1_bottom_axis ^: laxis_generate ^= auto fst
    $ layout1_top_axis    ^: laxis_generate ^= auto fst
    $ layout1_left_axis   ^: laxis_generate ^= auto snd
    $ layout1_plots      ^= map Left (adjust plots (locateAxes options))
    $ setLayout1Foreground (opaque black)
    $ defaultLayout1
  where
    auto proj | proj (loglog options) = autoLogAxis
              | otherwise             = autoAxis

As it happens, I have a very similar problem with polymorphism when it comes to replacing the axis labelling function in LinearAxisParams or LogAxisParams with a custom one supplied (as another AxisOption) by the user of my polymorphic overlayPlots.  It is perfectly easy to change the Params if the axis type is known (and RealFloat), but impossible if the axis type is polymorphic over PlotValue.  I have a separate proposal for that (not yet implemented/tested fully), whereby the autoAxis method of the PlotValue class would change type, to take the Params as an extra argument:

class (Ord a) => PlotValue a where
    toValue  :: a -> Double
    fromValue:: Double -> a
    autoAxis :: AxisParams a -> AxisFn a
    autoLogAxis :: AxisParams a -> AxisFn a

This would also require the unification of LinearAxisParams with LogAxisParams - again with the caveat that some of the values of the Params might be ignored for certain types of axis.  I shall (hopefully) supply a patch for that, in a few days time.

Regards,
    Malcolm


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://projects.haskell.org/pipermail/chart/attachments/20120201/5cf594f8/attachment.htm>


More information about the Chart mailing list