From d2085bb3bb2bf088610ae14efacb4c899ef22254 Mon Sep 17 00:00:00 2001 From: koldo Date: Thu, 16 Dec 2010 21:34:58 +0000 Subject: [PATCH] Scatter: Included new callback functions git-svn-id: svn://ultimatepp.org/upp/trunk@2912 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Scatter/Scatter.cpp | 45 ++++++++++++++++++++++++++++++++++++-- bazaar/Scatter/Scatter.h | 6 +++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bazaar/Scatter/Scatter.cpp b/bazaar/Scatter/Scatter.cpp index c282a7f03..c43eb67fd 100644 --- a/bazaar/Scatter/Scatter.cpp +++ b/bazaar/Scatter/Scatter.cpp @@ -767,13 +767,13 @@ void Scatter::RemoveAllSeries() Refresh(); } - void Scatter::PlotFunction(double (*f)(double), const String& legend, const class::Color& fcolor, const int& weight) { Vector series; vFunctionData.AddPick(series); vAdress.Add(f); + vAdressPF.Add(PlotFunc()); vFColors.Add(fcolor); vFThickness.Add(weight); @@ -782,6 +782,23 @@ void Scatter::PlotFunction(double (*f)(double), const String& legend, const clas vFPattern.Add(LINE_SOLID); Refresh(); } + +void Scatter::PlotFunction(PlotFunc f, const String& legend, const class::Color& fcolor, const int& weight) +{ + Vector series; + vFunctionData.AddPick(series); + + vAdressPF.Add(f); + vAdress.Add(fAdress()); + + vFColors.Add(fcolor); + vFThickness.Add(weight); + vFLegend.Add(legend); + vFPrimaryY.Add(true); + vFPattern.Add(LINE_SOLID); + Refresh(); +} + void Scatter::PlotParaFunction(XY (*pf)(double), const String& legend, const class::Color& fcolor, const int& weight,const int& Np) { double t;//t must be choosed between [0,1] @@ -800,6 +817,24 @@ void Scatter::PlotParaFunction(XY (*pf)(double), const String& legend, const cla Refresh(); } +void Scatter::PlotParaFunction(PlotParamFunc pf, const String& legend, const class::Color& fcolor, const int& weight,const int& Np) +{ + double t;//t must be choosed between [0,1] + Vector series; + for (int i=0; i<=Np;i++) + { + t=(double)i/Np; + pf(series.Add(), t); + } + vFColors.Add(fcolor); + vFThickness.Add(weight); + vFunctionData.AddPick(series); + vFPrimaryY.Add(true); + vFPattern.Add(LINE_SOLID); + vFLegend.Add(legend); + Refresh(); +} + Scatter &Scatter::SetFunctPattern(const String pattern) { vFPattern[vFPattern.GetCount()-1] = pattern; @@ -1490,7 +1525,13 @@ void Scatter::Plot(Draw& w, const int& scale,const int& l,const int& h)const { double x=xMin+i*(xRange/l); if (vFPrimaryY[j]) - iy=fround(h*(vAdress[nf](x)-yMin)/yRange); + if (vAdressPF[nf] == PlotFunc()) + iy=fround(h*(vAdress[nf](x)-yMin)/yRange); + else { + double y; + vAdressPF[nf](y, x); + iy = fround(h*(y-yMin)/yRange); + } else iy=fround(h*(vAdress[nf](x)-yMin2)/yRange2); p1< & GetPLegend() const {return vLegend;} const Vector & GetFLegend() const {return vFLegend;} + + typedef Callback2 PlotFunc; //y = f(x) + typedef Callback2 PlotParamFunc;// (x,y) = f(t) + void PlotFunction(PlotFunc, const String& legend="", const class::Color& fcolor=Green,const int& weight=6); + void PlotParaFunction(PlotParamFunc, const String& legend="", const class::Color& fcolor=Green,const int& weight=6,const int& Np=100); void PlotFunction(double (*f)(double),const String& legend="", const class::Color& fcolor=Green,const int& weight=6); void PlotParaFunction(XY (*pf)(double),const String& legend="", const class::Color& fcolor=Green,const int& weight=6,const int& Np=100); @@ -273,6 +278,7 @@ private: Vector vFPattern, vPPattern; typedef double (*fAdress)(double); Vector vAdress; + Vector vAdressPF; Vector vPColors,vFColors; Vector vFThickness,vPThickness; Vector vPWidth;