1 module plot2d.chart.base; 2 3 public import plot2d.chart.types; 4 public import plot2d.drawable; 5 6 /// 7 interface Chart : Drawable 8 { 9 @property 10 { 11 /// 12 ref const(Viewport) viewport() const; 13 /// 14 bool visible() const; 15 } 16 17 /// update buffered data and viewport 18 void update(); 19 } 20 21 /// 22 class BaseChart(T) : Chart, Stylized 23 { 24 mixin StylizedHelper; 25 protected: 26 /// 27 Viewport vp; 28 29 Appender!(Elem[]) buffer; 30 BufferFiller fillData; 31 32 abstract void expandViewport(ref const Elem val, ref bool[2] inited); 33 34 public: 35 36 alias Elem = T; 37 alias BufferFiller = void delegate(ref Appender!(Elem[])); 38 39 this(BufferFiller fillData) { this.fillData = fillData; } 40 41 override const @property 42 { 43 bool visible() { return !buffer.data.empty; } 44 ref const(Viewport) viewport() { return vp; } 45 } 46 47 /// 48 override void update() 49 { 50 buffer.clear(); 51 vp = Viewport(DimSeg(0, 1), DimSeg(0, 1)); 52 53 fillData(buffer); 54 55 if (buffer.data.length == 0) 56 { 57 .warning("buffer is empty"); 58 return; 59 } 60 61 bool[2] inited; 62 foreach (ref const t; buffer.data) 63 expandViewport(t, inited); 64 } 65 66 /// 67 abstract void draw(Ctx cr, Trtor tr); 68 }