#include "Scatter.h" Scatter& Scatter::SetColor(class::Color _color) { graphColor=_color; return *this; } Scatter& Scatter::SetTitle(String title) { Title=title; return *this; } Scatter& Scatter::SetFontTitle(Font& fontTitle) { FontTitle=fontTitle; return *this; } Scatter& Scatter::SetColorTitle(class::Color colorTitle) { ColorTitle=colorTitle; return *this; } void Scatter::SetLabels(String _xLabel, String _yLabel) { xLabel=_xLabel; yLabel=_yLabel; } Scatter& Scatter::SetLabelX(String _xLabel) { xLabel=_xLabel; return *this; } Scatter& Scatter::SetLabelY(String _yLabel) { yLabel=_yLabel; return *this; } Scatter& Scatter::SetFontLabels(Font& fontLabels) { FontLabels=fontLabels; return *this; } Scatter& Scatter::SetColorLabels(class::Color colorLabels) { ColorLabels=colorLabels; return *this; } Scatter& Scatter::SetPlotAreaPoz(int poz_x, int poz_y) { px=poz_x; py=poz_y; return *this; } Scatter& Scatter::H_Border(int poz_x) { if(poz_x>=0) px=poz_x; return *this; } Scatter& Scatter::V_Border(int poz_y) { if(poz_y>=0) py=poz_y; return *this; } Scatter& Scatter::SetPlotAreaColor(class ::Color p_a_color) { plotAreaColor=p_a_color; return *this; } Scatter& Scatter::SetAxisColor(class::Color axis_color) { axisColor=axis_color; return *this; } Scatter& Scatter::SetAxisWidth(int axis_width) { axisWidth=axis_width; return *this; } Scatter& Scatter::SetGridColor(class::Color grid_color) { gridColor=grid_color; return *this; } Scatter& Scatter::SetGridWidth(int grid_width) { gridWidth=grid_width; return *this; } Scatter& Scatter::ShowHGrid(bool show) { DrawHGrid=show; return *this; } Scatter& Scatter::ShowVGrid(bool show) { DrawVGrid=show; return *this; } Scatter& Scatter::showLegend(bool show) { ShowLegend=show; return *this; } Scatter& Scatter::SetLegendWeight(int weight) { LegendWeight=weight; return *this; } void Scatter::DrawLegend(Draw& w,int scale) { Vector L; L.Append(Legend); L.Append(FLegend); Vector Thick; Thick.Append(PThickness); Thick.Append(FThickness); Vector LC; LC.Append(PColors); LC.Append(FColors); Vector LW; LW.Append(PWidth); Vector MS; MS.Append(MarkStyles); Vector MC; MC.Append(MarkColors); int NMR=int((GetSize().cx-2*px)/LegendWeight);//max number of labels per row if (NMR>0) { int N=L.GetCount();//number of labels int Nc;//number of complete rows int LCR;//number of labels on complete row int R;//number of remaining labels on incomplete row if(NMR>N) {Nc=0; LCR=0; R=N;} else if (NMR==N) {Nc=1; LCR=N; R=0;} else {Nc=N/NMR; LCR=NMR; R=N%NMR;} for(int j=0;j<=Nc;j++) { int start=N-(j+1)*LCR; int end=N-j*LCR; if (j==Nc) {start=0; end=R;} for(int i=start;i & points,String legend,bool join, class::Color pcolor, int width, int thickness) { PointsData.AddPick(points); Join.Add(join); Smooth.Add(false); PColors.Add(pcolor); PWidth.Add(width); PThickness.Add(thickness); Legend.Add(legend); MarkColors.Add(pcolor); ShowMark.Add(true); MarkStyles.Add(CIRCLE); Refresh(); } void Scatter::AddPoint(int j, XY & point) { if(!PointsData.IsEmpty() && PointsData.GetCount()>j) { PointsData[j].AddPick(point); Refresh(); } } void Scatter::InsertPoint(int j, int i, XY & point) { if(!PointsData.IsEmpty() && PointsData.GetCount()>j) { if(!PointsData[j].IsEmpty() && PointsData[j].GetCount()>=i) { PointsData[j].Insert(i,point); Refresh(); } } } void Scatter::RemovePoint(int j, int i) { if(!PointsData.IsEmpty() && PointsData.GetCount()>j) { if(!PointsData[j].IsEmpty() && PointsData[j].GetCount()>i) { PointsData[j].Remove(i); Refresh(); } } } void Scatter::SetData(int j, int i, XY & point) { if(!PointsData.IsEmpty() && PointsData.GetCount()>j) { if(!PointsData[j].IsEmpty() && PointsData[j].GetCount()>i) { PointsData[j][i]=point; Refresh(); } } } void Scatter::SetData(int nbSeries, Vector & points) { PointsData[nbSeries]<<=points; Refresh(); } void Scatter::SetDataColor(int j, class::Color pcolor) { if(!PColors.IsEmpty() && PColors.GetCount()>j) { PColors[j]=pcolor; Refresh(); } } void Scatter::SetFunctColor(int j, class::Color fcolor) { if(!FColors.IsEmpty() && FColors.GetCount()>j) { FColors[j]=fcolor; Refresh(); } } class::Color Scatter::GetDataColor(int j) { if(!PColors.IsEmpty() && PColors.GetCount()>j) { return PColors[j]; } else return Null; } class::Color Scatter::GetFunctColor(int j) { if(!FColors.IsEmpty() && FColors.GetCount()>j) { return FColors[j]; } else return Null; } void Scatter::SetDataThickness(int j, int thick_dots) { if(!PThickness.IsEmpty() && PThickness.GetCount()>j) { PThickness[j]=thick_dots; Refresh(); } } void Scatter::SetFunctThickness(int j, int thick_dots) { if(!FThickness.IsEmpty() && FThickness.GetCount()>j) { FThickness[j]=thick_dots; Refresh(); } } int Scatter::GetDataThickness(int j) { if(!PThickness.IsEmpty() && PThickness.GetCount()>j) { return PThickness[j]; } else return NULL; } int Scatter::GetFunctThickness(int j) { if(!FThickness.IsEmpty() && FThickness.GetCount()>j) { return FThickness[j]; } else return NULL; } void Scatter::SetMarkWidth(int j, int width_dots) { if(!PWidth.IsEmpty() && PWidth.GetCount()>j) { PWidth[j]=width_dots; Refresh(); } } int Scatter::GetMarkWidth(int j) { if(!PWidth.IsEmpty() && PWidth.GetCount()>j) { return PWidth[j]; } else return NULL; } void Scatter::SetMarkStyle(int j, int noStyle) { if(!MarkStyles.IsEmpty() && MarkStyles.GetCount()>j) { MarkStyles[j]=noStyle; Refresh(); } } int Scatter::GetMarkStyle(int j) { if(!MarkStyles.IsEmpty() && MarkStyles.GetCount()>j) { return MarkStyles[j]; } else return NULL; } void Scatter::SetMarkColor(int j, class::Color mcolor) { if(!MarkColors.IsEmpty() && MarkColors.GetCount()>j) { MarkColors[j]=mcolor; Refresh(); } } class ::Color Scatter::GetMarkColor(int j) { if(!MarkColors.IsEmpty() && MarkColors.GetCount()>j) { return MarkColors[j]; } else return Null; } void Scatter::SetShowMark(int j, bool show) { if(!ShowMark.IsEmpty() && ShowMark.GetCount()>j) { ShowMark[j]=show; Refresh(); } } bool Scatter::IsMarkShow(int j) { if(!ShowMark.IsEmpty() && ShowMark.GetCount()>j) { return ShowMark[j]; } else return NULL; } void Scatter::SetJoin(int j, bool join) { if(!Join.IsEmpty() && Join.GetCount()>j) { Join[j]=join; Refresh(); } } bool Scatter::IsJoined(int j) { if(!Join.IsEmpty() && Join.GetCount()>j) { return Join[j]; } else return NULL; } void Scatter::SetSmooth(int j, bool smooth) { if(!Smooth.IsEmpty() && Smooth.GetCount()>j) { Smooth[j]=smooth; Refresh(); } } bool Scatter::IsSmooth(int j) { if(!Smooth.IsEmpty() && Smooth.GetCount()>j) { return Smooth[j]; } else return NULL; } void Scatter::RemoveSeries(int j) { if (PointsData.GetCount()>j) { PointsData.Remove(j); Join.Remove(j); Smooth.Remove(j); PColors.Remove(j); PWidth.Remove(j); PThickness.Remove(j); Legend.Remove(j); MarkColors.Remove(j); ShowMark.Remove(j); MarkStyles.Remove(j); Refresh(); } } void Scatter::plotFunction(double (*f)(double), String legend, class::Color fcolor, int weight) { double x,y; Vector series; for (int i=0;i<=GetNbMax();i++){ x=i*(xRange/GetNbMax())+xMin; y=f(x); series< series; for (int i=0; i<=Np;i++) { t=(double)i/Np; series<j) { FunctionData.Remove(j); FColors.Remove(j); FThickness.Remove(j); FLegend.Remove(j); Refresh(); } } void Scatter::Paint(DrawExtension& we) { Rect r1; Point p1,p2; p1.x=10; p1.y=10; p2.x=90; p2.y=90; r1.Set(p1,p2); //we.DrawRect(r1,Blue); we.DrawPie(r1,Point(90,10),Point(90,90),Null,0,Null); Rect r2(Point(150,5),Point(250,50)); we.DrawRoundRect(r2,50,40, LtBlue,2,White); } Drawing& Scatter::getDrawing() { DrawingDraw ddw(6*GetSize()); SetDrawing (ddw, 6); drawing=ddw; return drawing; } Image& Scatter::getImage(int scale) { ImageDraw idraw(scale*GetSize()); SetDrawing (idraw,scale); img=idraw; return img; } void Scatter::Paint(Draw& w) { SetDrawing(w,1); //w.DrawImage(0,0,GetSize().cx,GetSize().cy,getImage(2)); // a simple AA method } void Scatter::Circle(Draw& w, int scale, Point cp, int size, class::Color markColor) { w.DrawLine(cp,cp,int(scale*size/6),markColor); } void Scatter::Square(Draw& w, int scale, Point cp, int size, class::Color markColor) { Vector p; p< p; p< p; p< Scatter::Cubic(Vector& DataSet, int fineness,double tension) { Vector OutSet; if(DataSet.GetCount()>2){ OutSet<(OutSet); } void Scatter::SetDrawing(Draw& w, int scale) { w.DrawRect(scale*GetSize(),graphColor); Size sz; sz.cx=0; sz.cy=0; if(!Title.IsEmpty()) { Font FontTitle6; FontTitle6=FontTitle; FontTitle6.Height(scale*FontTitle.GetHeight()); FontTitle6.Width(scale*FontTitle.GetWidth()); sz= GetTextSize(Title, FontTitle6); w.DrawText((scale*GetSize().cx-sz.cx)/2,scale*2,Title,FontTitle6,ColorTitle); } w.Offset(Point(scale*px,scale*py+sz.cy)); if(ShowLegend) DrawLegend(w,scale); int l=scale*GetSize().cx-2*scale*px; int h=scale*GetSize().cy-2*scale*py-sz.cy; w.DrawRect(0,-1*scale,l+1*scale,h+1*scale,Gray); w.DrawRect(0,0,l,h,plotAreaColor); w.DrawLine(0,h,l,h,int(axisWidth*scale/6),axisColor); w.DrawLine(0,h,0,0,int(axisWidth*scale/6),axisColor); Font FontLabel6; FontLabel6=FontLabels; FontLabel6.Height(scale*FontLabels.GetHeight()); Size lx=GetTextSize(xLabel,FontLabel6); Size ly=GetTextSize(yLabel,FontLabel6); w.DrawText(int((l-lx.cx)/2),h+scale*py-lx.cy-scale*2,xLabel,FontLabel6,ColorLabels); w.DrawText(scale*2-scale*px,int((h+ly.cx)/2),900,yLabel,FontLabel6,ColorLabels); int nMajorX=int(xRange/xMajorUnit); int nMajorY=int(yRange/yMajorUnit); int nrX=int(l/nMajorX); int nrY=int(h/nMajorY); if (DrawXReticle) for(int i=1; i<=nMajorX;i++){ w.DrawLine(int(i*l/(xRange/xMajorUnit)+0.5), h, int(i*l/(xRange/xMajorUnit)+0.5), h+scale*4, int(scale/2), axisColor); Font Standard6; Standard6.Height(scale*StdFont().GetHeight()); int dx=scale*int(GetTextSize(AsString(i*xMajorUnit+xMin),StdFont()).cx/2); w.DrawText(int(i*l/(xRange/xMajorUnit))-dx,h+scale*4,AsString(i*xMajorUnit+xMin),Standard6,axisColor); } if (DrawYReticle) for(int i=1; i<=nMajorY;i++){ w.DrawLine(-(scale*4), h-int(i*h/(yRange/yMajorUnit)+0.5), 0, h-int(i*h/(yRange/yMajorUnit)+0.5), int(scale/2), axisColor); int dx=scale*GetTextSize(AsString(i*yMajorUnit+yMin),StdFont()).cx; Font Standard6; Standard6.Height(scale*StdFont().GetHeight()); w.DrawText(-dx-scale*6,h-scale*6-int(i*h/(yRange/yMajorUnit)),AsString(i*yMajorUnit+yMin),Standard6,axisColor); } int gW=int(gridWidth*scale/6); if(gridWidth<0) gW=gridWidth; if (DrawVGrid) for(int i=1; i p1; for (int i=0; i2) { Vector p2; Vector v(Cubic(PointsData[j])); for (int i=0; i p1; for (int i=0; i