mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
ScatterCtrl_Demo: Fixed fit and added UserEquation demo
git-svn-id: svn://ultimatepp.org/upp/trunk@8124 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d679be937f
commit
dda8a728d7
5 changed files with 109 additions and 21 deletions
|
|
@ -168,12 +168,13 @@ public:
|
|||
|
||||
private:
|
||||
Vector<double> s1x, s1y;
|
||||
Vector<double> s2;
|
||||
Vector<double> s2x, s2y;
|
||||
LinearEquation linear;
|
||||
PolynomialEquation poly2, poly4;
|
||||
FourierEquation fourier;
|
||||
ExponentialEquation exponential;
|
||||
Rational1Equation rational1;
|
||||
SinEquation sin;
|
||||
};
|
||||
|
||||
class Tab12 : public WithTab12<ScatterDemo> {
|
||||
|
|
@ -187,6 +188,18 @@ private:
|
|||
Vector<Pointf> s1, s2, s3;
|
||||
};
|
||||
|
||||
class TabUserEquation : public WithTabUserEquation<ScatterDemo> {
|
||||
public:
|
||||
typedef TabUserEquation CLASSNAME;
|
||||
|
||||
virtual void Init();
|
||||
void OnUpdate();
|
||||
virtual ScatterCtrl &Scatter() {return scatter;};
|
||||
|
||||
private:
|
||||
UserEquation userEquation;
|
||||
};
|
||||
|
||||
class TabPie : public WithTabPie<StaticRect> {
|
||||
public:
|
||||
typedef TabPie CLASSNAME;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ LAYOUT(ScatterCtrl_Demo, 624, 352)
|
|||
ITEM(Label, dv___8, SetLabel(t_("Choose example")).LeftPosZ(4, 168).TopPosZ(4, 21))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(Tab1, 380, 292)
|
||||
ITEM(ScatterCtrl, scatter, SetTitle(t_("Basic Test")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaRightMargin(20).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetLegendAnchor(2).HSizePosZ(16, 12).VSizePosZ(16, 16))
|
||||
LAYOUT(Tab1, 428, 296)
|
||||
ITEM(ScatterCtrl, scatter, SetTitle(t_("Basic Test")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaRightMargin(20).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetLegendAnchor(2).HSizePosZ(4, 4).VSizePosZ(4, 4))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(Tab2, 380, 292)
|
||||
|
|
@ -64,6 +64,21 @@ LAYOUT(Tab10, 380, 292)
|
|||
ITEM(ScatterCtrl, scatter, SetTitle(t_("User graph")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetLegendAnchor(2).HSizePosZ(16, 12).VSizePosZ(16, 16))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(TabUserEquation, 764, 276)
|
||||
ITEM(ScatterCtrl, scatter, SetTitle(t_("User equation")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaRightMargin(20).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetLegendAnchor(2).HSizePosZ(4, 4).VSizePosZ(4, 28))
|
||||
ITEM(Label, dv___1, SetLabel(t_("to")).LeftPosZ(560, 16).BottomPosZ(3, 21))
|
||||
ITEM(Label, dv___2, SetLabel(t_("from y =")).LeftPosZ(468, 44).BottomPosZ(3, 21))
|
||||
ITEM(EditDouble, toY, LeftPosZ(580, 44).BottomPosZ(5, 19))
|
||||
ITEM(EditDouble, fromY, LeftPosZ(512, 44).BottomPosZ(5, 19))
|
||||
ITEM(EditString, equation, LeftPosZ(124, 156).BottomPosZ(5, 19))
|
||||
ITEM(Label, dv___6, SetLabel(t_("User equation y = f(x) =")).LeftPosZ(8, 116).BottomPosZ(3, 21))
|
||||
ITEM(Button, update, SetLabel(t_("Update")).RightPosZ(4, 80).BottomPosZ(4, 20))
|
||||
ITEM(Label, dv___8, SetLabel(t_("to")).LeftPosZ(388, 16).BottomPosZ(3, 21))
|
||||
ITEM(Label, dv___9, SetLabel(t_("from x =")).LeftPosZ(296, 44).BottomPosZ(3, 21))
|
||||
ITEM(EditDouble, toX, LeftPosZ(408, 44).BottomPosZ(5, 19))
|
||||
ITEM(EditDouble, fromX, LeftPosZ(340, 44).BottomPosZ(5, 19))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(Tab11, 504, 468)
|
||||
ITEM(ScatterCtrl, scatter, SetAxisWidth(12).SetTitle(t_("Trend Line demo")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaLeftMargin(35).SetPlotAreaTopMargin(20).SetPlotAreaColor(Color(229, 229, 229)).SetLegendAnchor(4).HSizePosZ(8, 8).VSizePosZ(8, 108))
|
||||
ITEM(ArrayCtrl, grid, HSizePosZ(112, 8).BottomPosZ(4, 100))
|
||||
|
|
@ -83,7 +98,7 @@ LAYOUT(Tab13, 420, 236)
|
|||
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(PieCtrl, chart, SetLegendHeight(80).SetLegendBackColor(Color(229, 229, 229)).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
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ file
|
|||
tab10.cpp,
|
||||
tab11.cpp,
|
||||
tab12.cpp,
|
||||
tab14.cpp,
|
||||
tabPie.cpp,
|
||||
symbol.iml;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,14 +11,6 @@ void Tab11::Init()
|
|||
|
||||
scatter.SetMouseHandling(true, true).ShowContextMenu();
|
||||
|
||||
scatter.AddSeries(s1y, s1x).Legend("Series 1").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);
|
||||
scatter.AddSeries(exponential).Legend(exponential.GetFullName()).NoMark().Stroke(2);
|
||||
scatter.AddSeries(rational1).Legend(rational1.GetFullName()).NoMark().Stroke(2);
|
||||
|
||||
grid.AddColumn("Type", 10);
|
||||
grid.AddColumn("Equation", 40);
|
||||
grid.AddColumn("R2", 5);
|
||||
|
|
@ -27,9 +19,9 @@ void Tab11::Init()
|
|||
}
|
||||
|
||||
void Tab11::OnSeries() {
|
||||
double l_r2, p2_r2, p4_r2, f_r2, exp_r2, rat1_r2;
|
||||
double l_r2, p2_r2, p4_r2, f_r2, exp_r2, rat1_r2, s_r2;
|
||||
|
||||
//scatter.RemoveSeries(0);
|
||||
scatter.RemoveAllSeries();
|
||||
grid.Clear();
|
||||
if (seriesList == "Series 1") {
|
||||
scatter.SetRange(5, 1500).SetMajorUnits(1, 250).SetXYMin(-3, 0);
|
||||
|
|
@ -48,14 +40,18 @@ void Tab11::OnSeries() {
|
|||
fourier.SetDegree(3);
|
||||
fourier.Fit(vs1, f_r2);
|
||||
exponential.Fit(vs1, exp_r2);
|
||||
rational1.Fit(vs1, rat1_r2);
|
||||
rational1.Fit(vs1, rat1_r2);
|
||||
sin.GuessCoeff(vs1);
|
||||
sin.Fit(vs1, s_r2);
|
||||
|
||||
// scatter.InsertSeries(0, s1y, s1x).Legend("Series 1").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();
|
||||
scatter.AddSeries(s1x, s1y).Legend("Series 1").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();
|
||||
} else if (seriesList == "Series 2") {
|
||||
s2.Clear();
|
||||
s2 << 121 << 52 << 20 << 12 << 13 << 12 << 8 << 11;
|
||||
s2x.Clear();
|
||||
s2y.Clear();
|
||||
s2y << -0.9 << -1.1 << 2.8 << -3.4 << 2.7 << -0.9 << -1.1 << 2.8 << -3.4 << 2.7 << -0.9 << -1.1 << 2.8 << -3.4 << 2.7 << -0.7 << -1.2;
|
||||
s2x << 0 << 0.6 << 1.2 << 1.8 << 2.5 << 3.1 << 3.7 << 4.3 << 5.0 << 5.6 << 6.2 << 6.9 << 7.5 << 8.1 << 8.7 << 9.4 << 10.0;
|
||||
|
||||
VectorY<double> v2(s2, 0, 1);
|
||||
VectorDouble v2(s2y, s2x);
|
||||
|
||||
linear.Fit(v2, l_r2);
|
||||
poly2.SetDegree(2);
|
||||
|
|
@ -65,10 +61,27 @@ void Tab11::OnSeries() {
|
|||
fourier.SetDegree(3);
|
||||
fourier.Fit(v2, f_r2);
|
||||
exponential.Fit(v2, exp_r2);
|
||||
rational1.Fit(v2, rat1_r2);
|
||||
rational1.Fit(v2, rat1_r2);
|
||||
sin.GuessCoeff(v2);
|
||||
sin.Fit(v2, s_r2);
|
||||
|
||||
scatter.InsertSeries(0, s1y, s1x).Legend("Series 2").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();
|
||||
scatter.AddSeries(s2x, s2y).Legend("Series 2").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();
|
||||
}
|
||||
if (l_r2 > 0.5)
|
||||
scatter.AddSeries(linear).Legend(linear.GetFullName()).NoMark().Stroke(2);
|
||||
if (p2_r2 > 0.5)
|
||||
scatter.AddSeries(poly2).Legend(poly2.GetFullName()).NoMark().Stroke(2);
|
||||
if (p4_r2 > 0.5)
|
||||
scatter.AddSeries(poly4).Legend(poly4.GetFullName()).NoMark().Stroke(2);
|
||||
if (f_r2 > 0.5)
|
||||
scatter.AddSeries(fourier).Legend(fourier.GetFullName()).NoMark().Stroke(2);
|
||||
if (exp_r2 > 0.5)
|
||||
scatter.AddSeries(exponential).Legend(exponential.GetFullName()).NoMark().Stroke(2);
|
||||
if (rat1_r2 > 0.5)
|
||||
scatter.AddSeries(rational1).Legend(rational1.GetFullName()).NoMark().Stroke(2);
|
||||
if (s_r2 > 0.5)
|
||||
scatter.AddSeries(sin).Legend(sin.GetFullName()).NoMark().Stroke(2);
|
||||
scatter.FitToData(true);
|
||||
scatter.Refresh();
|
||||
|
||||
grid.Add(linear.GetFullName(), linear.GetEquation(), FormatDoubleFix(l_r2, 5));
|
||||
|
|
@ -77,6 +90,8 @@ void Tab11::OnSeries() {
|
|||
grid.Add(fourier.GetFullName(), fourier.GetEquation(), FormatDoubleFix(f_r2, 5));
|
||||
grid.Add(exponential.GetFullName(), exponential.GetEquation(), FormatDoubleFix(exp_r2, 5));
|
||||
grid.Add(rational1.GetFullName(), rational1.GetEquation(), FormatDoubleFix(rat1_r2, 5));
|
||||
grid.Add(sin.GetFullName(), sin.GetEquation(), FormatDoubleFix(s_r2, 5));
|
||||
grid.SetSortColumn(2, true);
|
||||
}
|
||||
|
||||
ScatterDemo *Construct11()
|
||||
|
|
|
|||
44
examples/ScatterCtrl_Demo/tab14.cpp
Normal file
44
examples/ScatterCtrl_Demo/tab14.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "ScatterCtrl_Demo.h"
|
||||
|
||||
|
||||
void TabUserEquation::Init()
|
||||
{
|
||||
CtrlLayout(*this);
|
||||
SizePos();
|
||||
|
||||
equation <<= "25 + 10*sin(0.5*x + 5)";
|
||||
fromX <<= 0;
|
||||
toX <<= 100;
|
||||
fromY <<= 0;
|
||||
toY <<= 50;
|
||||
|
||||
update.WhenAction = THISBACK(OnUpdate);
|
||||
scatter.SetMouseHandling(true, true);
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
void TabUserEquation::OnUpdate()
|
||||
{
|
||||
if (fromX >= toX || fromY >= toY) {
|
||||
Exclamation("Wrong limits");
|
||||
return;
|
||||
}
|
||||
|
||||
userEquation.Init("User equation", equation);
|
||||
|
||||
scatter.RemoveAllSeries();
|
||||
scatter.AddSeries(userEquation).Legend(userEquation.GetFullName()).NoMark().Stroke(2);
|
||||
scatter.SetXYMin(fromX, fromY);
|
||||
scatter.SetRange(toX - fromX, toY - fromY);
|
||||
scatter.FitToData(true);
|
||||
}
|
||||
|
||||
ScatterDemo *ConstructUserEquation()
|
||||
{
|
||||
static TabUserEquation tab;
|
||||
return &tab;
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
RegisterExample("User equation", ConstructUserEquation, __FILE__);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue