1 module plot2d.chart.line;
2 
3 import plot2d.chart.base;
4 
5 ///
6 class LineChart : BaseChart!Point
7 {
8 protected:
9     override void expandViewport(ref const Elem val, ref bool[2] inited)
10     {
11         if (!inited[0])
12         {
13             vp = Viewport.initial(val);
14             inited[0] = true;
15         }
16         else vp.expand(val);
17     }
18 
19 public:
20     ///
21     Color stroke;
22     ///
23     double[] dash = [];
24     ///
25     double dashOffset = 0;
26 
27     ///
28     this(Color stroke, BufferFiller fd)
29     {
30         this.stroke = stroke;
31         super(fd);
32     }
33 
34     override void draw(Ctx cr, Trtor tr)
35     {
36         if (buffer.data.length == 0) return;
37 
38         cr.setLineWidth(style.number.get("linewidth", 2));    
39         cr.setDash(dash, dashOffset);
40         cr.setColor(stroke);
41         
42         cr.clipViewport(tr.inPadding);
43 
44         cr.moveToP(tr.toDA(buffer.data.front));
45         foreach (val; buffer.data[1..$])
46             cr.lineToP(tr.toDA(val));
47 
48         cr.stroke();
49     }
50 }