我刚刚读了一篇很棒的文章,里面有非常糟糕的图表,这让我想到了 Graph 小部件! 我认为这对于可视化应用程序数据非常有用并且相当容易实现(我目前正在完成一个不太远的 XYPad)。
能够传递以下内容也很好:
// in graph.rs
pub enum Type {
Line,
Bar,
Dot,
}
指定它应该被可视化的方式。
这会很好!
三种不同类型的图将采用不同结构的数据集。 条形图的每个数据点都应该有一个标签,而折线图的每条线都应该有一个标签。 点图可能会标记或不标记每个点。
也许:
// Bar graphs are one-dimensional
type BarData<'a, D: Num> = &'a [(D, & 'a str)];
type LineData<'a, D: Num> = &'a [(Vec<(D, D), &'a str>)];
type Dot<D: Num> = (D, D);
pub enum Graph<'a, D> {
Bar(BarData<'a, D>),
Line(LineData<'a, D>),
Dot(Vec<Dot<D>>),
LabeledDot(Vec<(Dot<D>, &'a str)>,
}
这不包括每个条/线/点的颜色。
如果有一个Graph
小部件,那么它可能会减少污染的 API,然后为每个实现了共同特征的数据类型提供适配器,例如Graphable
。
一个粗略的草稿:
pub struct Graph<D: Num> {
min_x: D,
min_y: D,
max_x: D,
max_y: D,
}
impl Graph<D: Num> {
fn draw_point(x: D, y: D, col: Color) {...}
fn draw_label(x: D, y: D, val: &'a str, col: Color) {...}
fn draw_line(x1: D, y1: D, x2: D, y2: D, col: Color) {...}
fn draw_bar(pos: D, height: D, width: D, col: Color) {...}
}
pub trait Graphable {
fn draw(&self, graph: &Graph);
}
pub struct BarGraph<'a, D: Num> {
data: &'a [(D, &'a str, Color)],
}
impl<'a> Graphable for BarGraph<'a> {...}
pub struct LineGraph<'a, D: Num> {
data: &'a [(Vec<(D, D)>, &'a str, Color)],
}
impl<'a> Graphable for LineGraph<'a> {...}
pub enum DotGraph<'a, D: Num> {
Labeled(&'a [(D, D, &'a str, Color)].
Unlabled(&'a [(D, D, Color)],
}
impl<'a> Graphable for DotGraph<'a> {...}
适配器模式的好处是 API 用户可以编写他们自己的Graphable
。
我正在玩一些关于在应用程序中显示图表的代码。 如果时间允许,我很乐意提取它并做出贡献。
上面的例子使用了 Graph 这个词,但我更喜欢使用 Chart。 标题本身将此作为一个选项,我的代码可能会在 CS 意义上操作图形。
我刚刚将我的活塞图 https://github.com/winding-lines/piston-chart 移植到了最新的连杆上。 任何反馈表示赞赏:)
conrod 图表上的状态是什么?
该指南按计划显示图表但未实施,活塞图表回购已消失。
最有用的评论
conrod 图表上的状态是什么?
该指南按计划显示图表但未实施,活塞图表回购已消失。