Description
If the chart is defined to accept same data type, even though the axis is using different types of decorator, those chart types should be cvt into a trait object.
====
Original issue (one of valid use case)
First, many thanks for providing this great library!
Learning Rust for 2 weeks now and not really grasping the type system yet, this may be more of a Rust question than a plotters question.
I try to create a chart context with optional log-scaled y axis:
let mut cc = if y_log {
ChartBuilder::on(&root)
.build_ranged(
(xlim.0)..(xlim.1),
LogRange((ylim.0)..(ylim.1)),
).unwrap()
} else {
ChartBuilder::on(&root)
.build_ranged(
(xlim.0)..(xlim.1),
(ylim.0)..(ylim.1),
).unwrap()
}
Now, my problem is that this doesn't compile due to:
expected type `plotters::chart::context::ChartContext<'_, _, plotters::coord::ranged::RangedCoord<_, plotters::coord::numeric::RangedCoordf64>>`
found struct `plotters::chart::context::ChartContext<'_, _, plotters::coord::ranged::RangedCoord<_, plotters::coord::logarithmic::LogCoord<f64>>>`
When I use the condition in build_ranged
if y_log { LogRange((ylim.0)..(ylim.1)) } else { (ylim.0)..(ylim.1) }
I get a type mismatch between std::ops::Range
and plotters::coord::logarithmic::LogRange
.
I understand that I probably have to specify an explicit type for cc
, probably with some dyn Trait
in ChartContext's generics. However, due to my still very limited Rust experience, I can't get it to work.
Many thanks for your help!