Idea: Merge Line and Scatter, and maybe Function
Ploppz opened this issue · 2 comments
I think it might make sense to merge Line
and Scatter
types into a more general type.
They have common fields data: Vec<(f64, f64)>
, style: SomeStyle
, and in the future legend: Option<String>
.
My suggestion is to then distinguish between a line plot and a scatter plot, only through the style struct. The style struct could either be an enum or hold an enum - it needs some form of polymorphism. One idea could be (fast sketch):
struct Style {
color: String,
width: f64,
geometry:
}
enum Geometry {
Lines,
Circle,
Square,
Cross,
}
or enum Style { Lines {width: f64, .......}, Points {.....}}
is another idea.
My second suggestion is to get rid of Function
which is very similar to Line
, and instead just implement a fn on Line
for example pub fn from_function(f: Fn(f64) -> f64) -> Line
I personally like both of these ideas. Perhaps we can go a step further with the lines and allowing the Style
struct both a MarkerStyle
and LineStyle
sub-structs. Fundemantally they both represent the same sort of thing. The MarkerStyle
could include Circle
, Square
etc., and the LineStyle
can include a hidden
type i.e. no lines. That way the following options are available:
- lines but no points
- points but no lines
- points and lines
I also like the function idea.
I like your idea!
I wonder, if you have a scatter plot that's not just an y = f(x) function but arbitrary points, and you choose to draw lines between points, would it be best if we draw lines in the order that the points are given, or in the order of increasing x?
Actually in a project I'm working on now, the former might be convenient, because I would like to see the trajectory in (x,y).