ScatterCtrl_Demo: Added trend line and pie demos

git-svn-id: svn://ultimatepp.org/upp/trunk@6007 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2013-05-01 06:35:40 +00:00
parent 9f61696a29
commit 4bd2c2f825
10 changed files with 134 additions and 33 deletions

View file

@ -2,6 +2,7 @@
#define _ScatterCtrl_Demo_ScatterCtrl_Demo_h
#include <ScatterCtrl/ScatterCtrl.h>
#include <ScatterCtrl/PieCtrl.h>
using namespace Upp;
@ -156,6 +157,28 @@ private:
double sx[5], sy[5];
};
class Tab11 : public WithTab11<ScatterDemo> {
public:
typedef Tab11 CLASSNAME;
Tab11() {};
void Init();
virtual ScatterCtrl &Scatter() {return scatter;};
private:
Vector<double> sx, sy;
LinearEquation linear;
PolynomialEquation poly2, poly4;
FourierEquation fourier;
};
class TabPie : public WithTabPie<StaticRect> {
public:
typedef TabPie CLASSNAME;
void Init();
};
class ScatterCtrl_Demo : public WithScatterCtrl_Demo<TopWindow> {
typedef ScatterCtrl_Demo CLASSNAME;
@ -170,6 +193,8 @@ public:
#endif
void CopyClipboard();
void SetMode();
TabPie tabPie;
};
#endif

View file

@ -10,30 +10,30 @@ LAYOUT(ScatterCtrl_Demo, 624, 392)
END_LAYOUT
LAYOUT(Tab1, 380, 292)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Basic Test")).SetTitleFont(SansSerifZ(14).Bold()).SetLabelsFont(StdFontZ(11)).HSizePosZ(16, 12).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Basic Test")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab2, 380, 292)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Functions")).SetTitleFont(SansSerifZ(14).Bold()).SetLabelsFont(StdFontZ(11)).SetGridWidth(2).HSizePosZ(16, 12).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Functions")).SetTitleFont(SansSerifZ(14).Bold()).SetGridWidth(2).HSizePosZ(16, 12).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab3, 384, 284)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Parametric functions demo")).SetTitleFont(SansSerifZ(14).Bold()).SetTitleColor(White).SetPlotAreaColor(Black).SetColor(Black).SetLabelsColor(White).SetAxisColor(Color(28, 212, 0)).SetAxisWidth(12).SetGridColor(Color(28, 127, 0)).HSizePosZ(16, 16).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetTitle(t_("Parametric functions demo")).SetTitleFont(SansSerifZ(14).Bold()).SetTitleColor(White).SetPlotAreaColor(Color(229, 229, 229)).SetColor(Color(198, 212, 255)).SetLabelsColor(White).SetAxisColor(Color(28, 212, 0)).SetAxisWidth(12).SetGridColor(Color(28, 127, 0)).HSizePosZ(16, 16).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab4, 400, 316)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Temperature Average. X Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaLeftMargin(40).SetLabelX(t_("Month")).SetLabelsFont(SansSerifZ(11)).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetLabelsFont(SansSerifZ(11)).SetTitle(t_("Temperature Average. X Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaLeftMargin(40).SetLabelX(t_("Month")).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab5, 400, 288)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Dynamic")).SetTitleFont(StdFontZ(14).Bold()).SetLabelX(t_("time[s]")).HSizePosZ(16, 12).VSizePosZ(12, 36))
ITEM(Button, bStart, SetLabel(t_("Start")).LeftPosZ(16, 42).BottomPosZ(5, 15))
ITEM(Button, bStop, SetLabel(t_("Stop")).LeftPosZ(64, 42).BottomPosZ(5, 15))
ITEM(Button, bReset, SetLabel(t_("Reset")).LeftPosZ(112, 42).BottomPosZ(5, 15))
ITEM(Button, bPgDown, SetLabel(t_("<<")).RightPosZ(166, 42).BottomPosZ(5, 15))
ITEM(Button, bPgUp, SetLabel(t_(">>")).RightPosZ(114, 42).BottomPosZ(5, 15))
ITEM(Button, bPlus, SetLabel(t_("+")).RightPosZ(62, 42).BottomPosZ(5, 15))
ITEM(Button, bMinus, SetLabel(t_("-")).RightPosZ(14, 42).BottomPosZ(5, 15))
ITEM(Button, bStart, SetLabel(t_("Start")).LeftPosZ(16, 42).BottomPosZ(5, 23))
ITEM(Button, bStop, SetLabel(t_("Stop")).LeftPosZ(64, 42).BottomPosZ(5, 23))
ITEM(Button, bReset, SetLabel(t_("Reset")).LeftPosZ(112, 42).BottomPosZ(5, 23))
ITEM(Button, bPgDown, SetLabel(t_("<<")).RightPosZ(122, 30).BottomPosZ(5, 23))
ITEM(Button, bPgUp, SetLabel(t_(">>")).RightPosZ(86, 30).BottomPosZ(5, 23))
ITEM(Button, bPlus, SetLabel(t_("+")).RightPosZ(50, 30).BottomPosZ(5, 23))
ITEM(Button, bMinus, SetLabel(t_("-")).RightPosZ(14, 30).BottomPosZ(5, 23))
END_LAYOUT
LAYOUT(Tab6, 400, 280)
@ -49,17 +49,28 @@ LAYOUT(Tab7, 388, 300)
END_LAYOUT
LAYOUT(Tab8, 400, 316)
ITEM(ScatterCtrl, scatter, SetLabelY2(t_("Legend Y2")).SetTitle(t_("Temperature & Pressure Averages. X-Y Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(15).Bold()).SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(70).SetPlotAreaTopMargin(50).SetPlotAreaBottomMargin(50).SetLabelX(t_("Month")).SetLabelY(t_("Legend Y")).SetLabelsFont(SansSerifZ(11)).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetLabelsFont(SansSerifZ(11)).SetTitle(t_("Temperature & Pressure Averages. X-Y Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(15).Bold()).SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(70).SetPlotAreaTopMargin(50).SetPlotAreaBottomMargin(50).SetLabelX(t_("Month")).SetLabelY(t_("Legend Y")).SetLabelY2(t_("Legend Y2")).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab9, 380, 348)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Big dataset")).SetTitleFont(SansSerifZ(14).Bold()).SetLabelsFont(StdFontZ(11)).HSizePosZ(16, 12).VSizePosZ(16, 76))
ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Big dataset")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 76))
ITEM(Option, sequentialX, SetLabel(t_("SetSequentialX")).LeftPosZ(112, 92).BottomPosZ(8, 16))
ITEM(Option, fastView, SetLabel(t_("SetFastView")).LeftPosZ(16, 84).BottomPosZ(8, 16))
ITEM(Label, dv___3, SetLabel(t_("It includes two series with 100000 points.\nTo work with Painter it requires SetFastView and SetSequentialX to be true. \nIf not the program could get stuck.")).HSizePosZ(16, 4).BottomPosZ(28, 44))
END_LAYOUT
LAYOUT(Tab10, 380, 292)
ITEM(ScatterCtrl, scatter, SetTitle(t_("User graph")).SetTitleFont(SansSerifZ(14).Bold()).SetLabelsFont(StdFontZ(11)).HSizePosZ(16, 12).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("User graph")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab11, 504, 468)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Trend Line demo")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaColor(Color(229, 229, 229)).SetAxisWidth(12).HSizePosZ(8, 8).VSizePosZ(8, 108))
ITEM(ArrayCtrl, grid, HSizePosZ(112, 8).BottomPosZ(4, 100))
ITEM(Label, dv___2, SetLabel(t_("Trend Lines Details:")).LeftPosZ(8, 100).BottomPosZ(83, 21))
END_LAYOUT
LAYOUT(TabPie, 536, 440)
ITEM(PieCtrl, chart, SetLegendBackColor(Color(229, 229, 229)).SetLegendHeight(80).SetTitle(t_("Average Weather")).SetFrame(ThinInsetFrame()).HSizePosZ(8, 12).VSizePosZ(40, 12))
ITEM(Label, dv___1, SetLabel(t_(" EXPERIMENTAL")).SetFrame(ThinInsetFrame()).LeftPosZ(8, 84).TopPosZ(8, 24))
END_LAYOUT

View file

@ -21,6 +21,8 @@ file
tab8.cpp,
tab9.cpp,
tab10.cpp,
tab11.cpp,
tabPie.cpp,
symbol.iml;
mainconfig

View file

@ -38,6 +38,7 @@ GUI_APP_MAIN
ScatterCtrl_Demo demo;
demo.tabPie.Init();
demo.Run();
}
@ -48,6 +49,8 @@ ScatterCtrl_Demo::ScatterCtrl_Demo()
for (int i = 0; i < Examples().GetCount(); ++i)
tab.Add(*(Examples()[i].ctrl()), Examples()[i].name);
tab.Add(tabPie, "Pie chart");
bPreview <<= THISBACK(Preview);
bSavePNG <<= THISBACK(SavePNG);
bSaveJPG <<= THISBACK(SaveJPG);

View file

@ -32,10 +32,8 @@ void Tab1::Init()
int barWidth = 4;
scatter.AddSeries(s5).Legend("Series 5").PlotStyle<BarSeriesPlot>(barWidth).Dash("").NoMark().Fill();
//scatter.AddTrendline(SERIE2, 100, LINE); // To come :-)
//scatter.AddTrendline(SERIE2, 100, POLINOMIAL, 3);
scatter.SetRange(60, 50).SetMajorUnits(10, 10);
scatter.ShowInfo().ShowContextMenu().ShowEditDlg().SetPopText("h", "v", "v2");
scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().SetPopText("h", "v", "v2");
}
ScatterDemo *Construct1()

View file

@ -0,0 +1,48 @@
#include "ScatterCtrl_Demo.h"
void Tab11::Init()
{
CtrlLayout(*this);
HSizePos().VSizePos();
scatter.SetRange(5, 1500).SetMajorUnits(1, 250).SetXYMin(-3, 0);
scatter.SetMouseHandling(true, true).ShowContextMenu().SetLegendWidth(160);
sx << -3.067E0 << -2.981E0 << -2.921E0 << -2.912E0 << -2.840E0 << -2.797E0 << -2.702E0 << -2.699E0 << -2.633E0 << -2.481E0 << -2.363E0 << -2.322E0 << -1.501E0 << -1.460E0 << -1.274E0 << -1.212E0 << -1.100E0 << -1.046E0 << -0.915E0 << -0.714E0 << -0.566E0 << -0.545E0 << -0.400E0 << -0.309E0 << -0.109E0 << -0.103E0 << 0.010E0 << 0.119E0 << 0.377E0 << 0.790E0 << 0.963E0 << 1.006E0 << 1.115E0 << 1.572E0 << 1.841E0 << 2.047E0 << 2.200E0;
sy << 80.574E0 << 84.248E0 << 87.264E0 << 87.195E0 << 89.076E0 << 89.608E0 << 89.868E0 << 90.101E0 << 92.405E0 << 95.854E0 << 100.696E0 << 101.060E0 << 401.672E0 << 390.724E0 << 567.534E0 << 635.316E0 << 733.054E0 << 759.087E0 << 894.206E0 << 990.785E0 << 1090.109E0 << 1080.914E0 << 1122.643E0 << 1178.351E0 << 1260.531E0 << 1273.514E0 << 1288.339E0 << 1327.543E0 << 1353.863E0 << 1414.509E0 << 1425.208E0 << 1421.384E0 << 1442.962E0 << 1464.350E0 << 1468.705E0 << 1447.894E0 << 1457.628E0;
VectorDouble vs1(sy, sx);
double l_r2, p2_r2, p4_r2, f_r2;
linear.Fit(vs1, l_r2);
poly2.SetDegree(2);
poly2.Fit(vs1, p2_r2);
poly4.SetDegree(4);
poly4.Fit(vs1, p4_r2);
fourier.SetDegree(3);
fourier.Fit(vs1, f_r2);
scatter.AddSeries(sx, sy).Legend("Series").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();
scatter.AddSeries(linear).Legend(linear.GetFullName()).NoMark().Stroke(2);
scatter.AddSeries(poly2).Legend(poly2.GetFullName()).NoMark().Stroke(2);
scatter.AddSeries(poly4).Legend(poly4.GetFullName()).NoMark().Stroke(2);
scatter.AddSeries(fourier).Legend(fourier.GetFullName()).NoMark().Stroke(2);
grid.AddColumn("Type", 10);
grid.AddColumn("Equation", 40);
grid.AddColumn("R2", 5);
grid.Add(linear.GetFullName(), linear.GetEquation(), FormatDoubleFix(l_r2, 5));
grid.Add(poly2.GetFullName(), poly2.GetEquation(), FormatDoubleFix(p2_r2, 5));
grid.Add(poly4.GetFullName(), poly4.GetEquation(), FormatDoubleFix(p4_r2, 5));
grid.Add(fourier.GetFullName(), fourier.GetEquation(), FormatDoubleFix(f_r2, 5));
}
ScatterDemo *Construct11()
{
static Tab11 tab;
return &tab;
}
INITBLOCK {
RegisterExample(t_("Trend Lines"), Construct11, __FILE__);
}

View file

@ -16,9 +16,13 @@ void Tab2::Init()
scatter.SetRange(12, 60).SetXYMin(-6, -30).SetMajorUnits(2, 10);
scatter.SetMouseHandling(true);
scatter.AddSeries(&funct1).Legend("y = 3");
scatter.AddSeries(&funct2).Legend("x^2-5");
scatter.AddSeries(&funct3).Legend("-x^2-5");
scatter.AddSeries(&funct1).Legend("y = 3").NoMark();
scatter.AddSeries(&funct2).Legend("y = x^2-5").NoMark();
scatter.AddSeries(&funct3).Legend("y = -x^2-5").NoMark();
scatter.AddSeries(&vfunct1).Legend("y = 0").NoMark();
scatter.AddSeries(&vfunct2).Legend("y = x^2").NoMark();
scatter.AddSeries(&vfunct3).Legend("y = -x^2").NoMark();
}
ScatterDemo *Construct2()
@ -28,5 +32,5 @@ ScatterDemo *Construct2()
}
INITBLOCK {
RegisterExample("Functions", Construct2, __FILE__);
RegisterExample("Explicit Functions", Construct2, __FILE__);
}

View file

@ -1,15 +1,12 @@
#include "ScatterCtrl_Demo.h"
void funct1p(double& y, double x, double a, double c) {y = a*(x*x)+c;}
void funct3p(double& y, double x, double m) {y = m*x;}
Pointf opara1(double t) {return Pointf(0.5*cos(2*M_PI*t), 0.5*sin(2*M_PI*t));}
void para1(Pointf& xy, double t) {xy = Pointf(cos(2*M_PI*t), sin(2*M_PI*t));}
void para2(Pointf& xy, double t) {xy = Pointf(0.5*cos(6*M_PI*t)+3*t-1, 1.5+0.5*sin(6*M_PI*t));}
void para3(Pointf& xy, double t) {xy = Pointf(3+(0.5+t)*cos(6*M_PI*t), (0.5+t)*sin(6*M_PI*t));}
void para4(Pointf& xy, double t) {xy = Pointf(0,-0.25+0.5*t);}
void para4(Pointf& xy, double t) {xy = Pointf(0, -0.25+0.5*t);}
void para5(Pointf& xy, double t) {xy = Pointf(-0.25+0.5*t, 0);}
void para1p(Pointf& xy, double t, double a, double b) {xy = Pointf(a*cos(2*M_PI*t),b*sin(2*M_PI*t));}
@ -23,15 +20,15 @@ void Tab3::Init()
scatter.SetMajorUnits(0.5, 0.5);
scatter.SetXYMin(-2, -2);
scatter.AddSeries(&opara1, 50).Legend("Circle").NoMark();
scatter.AddSeries(STDBACK(para1), 100).Legend("Circle").NoMark();
scatter.AddSeries(&opara1, 20).Legend("Circle 1");//.NoMark();
scatter.AddSeries(STDBACK(para1), 100).Legend("Circle 2").NoMark();
scatter.AddSeries(STDBACK(para2), 100).Legend("Coil").NoMark();
scatter.AddSeries(STDBACK(para3), 150).Legend("Spiral").NoMark();
scatter.AddSeries(STDBACK1(para3p, 2.5), 150, 0, 1).Legend("Spiral").NoMark();
scatter.AddSeries(STDBACK(para3), 150).Legend("Spiral 1").NoMark();
scatter.AddSeries(STDBACK1(para3p, 2.5), 150, 0, 1).Legend("Spiral 2").NoMark();
scatter.AddSeries(STDBACK(para4), 2).Legend("VLine").NoMark();
scatter.AddSeries(STDBACK(para5), 2).Legend("HLine").NoMark();
scatter.AddSeries(STDBACK2(para1p, 4.0, 0.25), 50, 0, 1).Legend("Circle2").NoMark();
scatter.AddSeries(STDBACK2(para1p, 2.0, 0.5), 50, 0, 1).Legend("Circle2").NoMark();
scatter.AddSeries(STDBACK2(para1p, 4.0, 0.25), 50, 0, 1).Legend("Ellipse 1").NoMark();
scatter.AddSeries(STDBACK2(para1p, 2.0, 0.5), 50, 0, 1).Legend("Ellipse 2").NoMark();
}
ScatterDemo *Construct3()
@ -41,5 +38,5 @@ ScatterDemo *Construct3()
}
INITBLOCK {
RegisterExample(t_("Parametric Functions"), Construct3, __FILE__);
RegisterExample("Parametric Functions", Construct3, __FILE__);
}

View file

@ -14,7 +14,7 @@ void Tab8::Init()
double barWidth = 0.4;
scatter.AddSeries(s3).Legend("Device 1").PlotStyle<BarSeriesPlot>(barWidth).NoMark().Stroke(2, Gray()).Dash(LINE_SOLID).Fill(LtGray());
s1<<Pointf(1,-6)<<Pointf(2,-4)<<Pointf(3,2)<<Pointf(4,8)<<Pointf(5,8)<<Pointf(6,15)<<Pointf(7,20)<<Pointf(8,25)<<Pointf(9,14)<<Pointf(10,10)<<Pointf(11,3)<<Pointf(12,-11);;
s1<<Pointf(1,-6)<<Pointf(2,-4)<<Pointf(3,2)<<Pointf(4,8)<<Pointf(5,8)<<Pointf(6,15)<<Pointf(7,20)<<Pointf(8,30)<<Pointf(9,14)<<Pointf(10,10)<<Pointf(11,3)<<Pointf(12,-11);
scatter.AddSeries(s1).Legend("Temperature").Stroke(3, Null).Dash(LINE_DASHED).MarkStyle<SquareMarkPlot>();
s2 <<Pointf(1,1008)<<Pointf(2,1012)<<Pointf(3,1016)<<Pointf(4,1012)<<Pointf(5,1008)<<Pointf(6,1016)<<Pointf(7,1012)<<Pointf(8,1004)<<Pointf(9,1000)<<Pointf(10,1001)<<Pointf(11,1000)<<Pointf(12,1002);

View file

@ -0,0 +1,13 @@
#include "ScatterCtrl_Demo.h"
void TabPie::Init()
{
CtrlLayout(*this);
HSizePos().VSizePos();
chart.ShowPercent();
chart.AddCategory("Sunny", 8, ::Color(90, 150, 255));
chart.AddCategory("Cloudy", 4, ::Color(90, 255, 150));
chart.AddCategory("Rainy", 2, ::Color(250, 150, 90));
}