1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! 描画プリミティブの中間表現。幾何 + スタイルのみを持ち、解釈は含まない。
use crate::ir::Color;
/// テキストの水平アンカー。
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Anchor {
Start,
Middle,
End,
}
/// 描画プリミティブ。SVG要素に1対1で対応する。
#[derive(Clone, Debug, PartialEq)]
pub enum Prim {
Rect {
x: f64,
y: f64,
w: f64,
h: f64,
fill: Color,
},
Line {
x1: f64,
y1: f64,
x2: f64,
y2: f64,
stroke: Color,
stroke_width: f64,
},
/// 折れ線(塗りなし)。
Polyline {
points: Vec<(f64, f64)>,
stroke: Color,
stroke_width: f64,
},
/// 任意パス。area塗り・pie扇形・曲線に使う。fill/strokeは任意。
Path {
/// SVG path data。`fmt_num` 整形済みのトークンとパスコマンドのみを含むこと。
/// 生のユーザ文字列(系列名・ラベル等)を補間してはならない(無エスケープで出力される)。
d: String,
fill: Option<Color>,
stroke: Option<Color>,
stroke_width: f64,
},
/// 水平リニアグラデーションで塗る任意パス。sankey のリボンに使う。
/// グラデーションは userSpace の x0→x1 で stop0→stop1 に補間する(y 方向は一定)。
/// d は `Prim::Path` と同じく fmt_num 整形済みトークンのみを含むこと。
GradientPath {
d: String,
/// グラデーション開始 x(stop0 の位置、ユーザ座標)。
x0: f64,
/// グラデーション終了 x(stop1 の位置、ユーザ座標)。
x1: f64,
stop0: Color,
stop1: Color,
},
Circle {
cx: f64,
cy: f64,
r: f64,
fill: Color,
stroke: Color,
stroke_width: f64,
},
Text {
x: f64,
y: f64,
size: f64,
anchor: Anchor,
fill: Color,
content: String,
rotate_deg: Option<f64>, // Some(deg) → SVG transform="rotate(deg,x,y)"
},
}
/// 1枚のチャート画像。
#[derive(Clone, Debug, PartialEq)]
pub struct Scene {
pub width: f64,
pub height: f64,
pub items: Vec<Prim>,
}