From e0b3fb462ecf220b3380039d5dbc43bfbae2a40d Mon Sep 17 00:00:00 2001 From: koldo Date: Sun, 31 Dec 2017 16:26:53 +0000 Subject: [PATCH] ScatterCtrl_Demo: Included etacked plots git-svn-id: svn://ultimatepp.org/upp/trunk@11643 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h | 18 +++++- .../ScatterCtrl_Demo/ScatterCtrl_Demo.lay | 9 +-- .../ScatterCtrl_Demo/ScatterCtrl_Demo.upp | 5 +- examples/ScatterCtrl_Demo/main.cpp | 11 +--- examples/ScatterCtrl_Demo/tab15_RangePlot.cpp | 7 +-- .../ScatterCtrl_Demo/tab16_StackedPlot.cpp | 58 +++++++++++++++++++ ...16_BubblePlot.cpp => tab17_BubblePlot.cpp} | 4 +- ...ab17_UserPaint.cpp => tab18_UserPaint.cpp} | 4 +- examples/ScatterCtrl_Demo/tab20_Pie.cpp | 4 +- 9 files changed, 94 insertions(+), 26 deletions(-) create mode 100644 examples/ScatterCtrl_Demo/tab16_StackedPlot.cpp rename examples/ScatterCtrl_Demo/{tab16_BubblePlot.cpp => tab17_BubblePlot.cpp} (85%) rename examples/ScatterCtrl_Demo/{tab17_UserPaint.cpp => tab18_UserPaint.cpp} (85%) diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h index 92e199328..2f8473d42 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h @@ -226,8 +226,22 @@ private: Vector idsRange; Vector sdata, smin, smax; VectorPointf dmin, dmax; - DataReverse rev; - DataAppend app; + DataRange range; +}; + +class TabStackedPlot : public WithTabStackedPlot { +public: + typedef TabStackedPlot CLASSNAME; + + void Init(); + virtual ScatterCtrl &Scatter() {return scatter;}; + + void OnPlot(); + +private: + Vector s1, s2, s3; + VectorPointf ds1, ds2, ds3; + DataStackedY stacked; }; class TabBubblePlot : public WithTabBubblePlot { diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay index d3d63337f..f5cf0455e 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay @@ -94,14 +94,15 @@ LAYOUT(Tab12Linked, 456, 464) ITEM(Option, link, SetLabel(t_("Link")).RightPosZ(4, 56).TopPosZ(4, 16)) END_LAYOUT -LAYOUT(Tab13, 420, 236) - ITEM(ScatterCtrl, scatter, SetTitle(t_("Polar Plot")).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(4, 4).VSizePosZ(4, 4)) -END_LAYOUT - LAYOUT(TabRangePlot, 420, 236) ITEM(ScatterCtrl, scatter, SetTitle(t_("Range Plot")).SetPlotAreaLeftMargin(40).SetPlotAreaTopMargin(20).SetPlotAreaBottomMargin(40).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(4, 4).VSizePosZ(4, 4)) END_LAYOUT +LAYOUT(TabStackedPlot, 420, 244) + ITEM(ScatterCtrl, scatter, SetTitle(t_("Stacked Plot")).SetPlotAreaLeftMargin(40).SetPlotAreaTopMargin(20).SetPlotAreaBottomMargin(40).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(4, 4).VSizePosZ(4, 20)) + ITEM(Switch, type, SetLabel(t_("Stacked\nStacked100")).LeftPosZ(4, 160).BottomPosZ(2, 16)) +END_LAYOUT + LAYOUT(TabBubblePlot, 420, 236) ITEM(ScatterCtrl, scatter, SetTitle(t_("Bubble Plot")).SetPlotAreaLeftMargin(40).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(4, 4).VSizePosZ(4, 4)) END_LAYOUT diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp index 5fc0a2427..6eccb169a 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp @@ -25,8 +25,9 @@ file tab12_Linked.cpp, tab14_UserEquation.cpp, tab15_RangePlot.cpp, - tab16_BubblePlot.cpp, - tab17_UserPaint.cpp, + tab16_StackedPlot.cpp, + tab17_BubblePlot.cpp, + tab18_UserPaint.cpp, tab20_Pie.cpp, symbol.iml; diff --git a/examples/ScatterCtrl_Demo/main.cpp b/examples/ScatterCtrl_Demo/main.cpp index 9885be449..0142bfe84 100644 --- a/examples/ScatterCtrl_Demo/main.cpp +++ b/examples/ScatterCtrl_Demo/main.cpp @@ -51,14 +51,7 @@ ScatterCtrl_Demo::ScatterCtrl_Demo() Add((*(Examples()[i].ctrl())).HSizePosZ(180, 4).VSizePosZ(4, 8)); examplesRects.Add(Examples()[i].ctrl()); } -/* for (int i = 0; i < Examples().GetCount(); ++i) { - if (Examples()[i].name == "User equation") { - TabUserEquation &tab = dynamic_cast(*Examples()[i].ctrl()); - EditString &equation = tab.equation; - equation.SetText("HELLO WORLD"); - } - }*/ - + examplesList.Add("Pie chart"); tabPie.Init(); Add(tabPie.HSizePosZ(180, 4).VSizePosZ(4, 8)); @@ -87,7 +80,7 @@ ScatterCtrl_Demo::ScatterCtrl_Demo() SetMode(); examplesList.WhenSel = THISBACK(OnSel); - examplesList.SetCursor(13); + examplesList.SetCursor(14); OnSel(); Sizeable().Zoomable().Icon(MyImages::i1()); diff --git a/examples/ScatterCtrl_Demo/tab15_RangePlot.cpp b/examples/ScatterCtrl_Demo/tab15_RangePlot.cpp index 7de94eb54..3ba6a6012 100644 --- a/examples/ScatterCtrl_Demo/tab15_RangePlot.cpp +++ b/examples/ScatterCtrl_Demo/tab15_RangePlot.cpp @@ -24,11 +24,10 @@ void TabRangePlot::Init() smax << Pointf(sdata[i].x, sdata[i].y + 5 + Random(10)); smin << Pointf(sdata[i].x, sdata[i].y - 5 - Random(10)); } - dmin.Init(smin); - rev.Init(dmin); dmax.Init(smax); - app.Init(dmax, rev); - scatter.AddSeries(app).Legend("Range").Closed(true).Stroke(0).Fill(LtCyan()).Opacity(0.5).NoMark(); + dmin.Init(smin); + range.Init(dmax, dmin); + scatter.AddSeries(range).Legend("Range").Closed(true).Stroke(0).Fill(LtCyan()).Opacity(0.5).NoMark(); scatter.AddSeries(smax).Legend("Max").Stroke(1, Blue()).NoMark(); scatter.AddSeries(smin).Legend("Min").Stroke(1, Blue()).NoMark(); scatter.AddSeries(sdata).Legend("Data").Stroke(4, Blue()).NoMark(); diff --git a/examples/ScatterCtrl_Demo/tab16_StackedPlot.cpp b/examples/ScatterCtrl_Demo/tab16_StackedPlot.cpp new file mode 100644 index 000000000..d60aedd11 --- /dev/null +++ b/examples/ScatterCtrl_Demo/tab16_StackedPlot.cpp @@ -0,0 +1,58 @@ +#include "ScatterCtrl_Demo.h" + +void TabStackedPlot::Init() +{ + CtrlLayout(*this); + SizePos(); + + scatter.SetMouseHandling(true, true).ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg(); + + for (int x = 0; x <= 10; ++x) { + s1 << Pointf(x, Random(50)); + s2 << Pointf(x, Random(50)); + s3 << Pointf(x, Random(50)); + } + ds1.Init(s1); + ds2.Init(s2); + ds3.Init(s3); + stacked.Add(ds1).Add(ds2).Add(ds3); + + scatter.AddSeries(stacked.Get(2)).Legend("s1").Fill(); + scatter.AddSeries(stacked.Get(1)).Legend("s2").Fill(); + scatter.AddSeries(stacked.Get(0)).Legend("s3").Fill(); + + scatter.SetLabelY("Data").SetLabelX("time [seg]"); + scatter.ShowButtons(); + + type = 0; + type.WhenAction = THISBACK(OnPlot); + + OnPlot(); +} + +void TabStackedPlot::OnPlot() +{ + stacked.Set100(type == 1); + scatter.ZoomToFit(true, type != 1, 0.2); + if (type == 1) { + scatter.SetXYMin(-2, -10); + scatter.SetRange(14, 120); + scatter.SetMajorUnits(2, 10); + scatter.SetMinUnits(-2, -10); + } else { + scatter.SetXYMin(-2, Null); + scatter.SetRange(14, Null); + scatter.SetMajorUnits(2, Null); + scatter.SetMinUnits(-2, Null); + } +} + +ScatterDemo *Construct16() +{ + static TabStackedPlot tab; + return &tab; +} + +INITBLOCK { + RegisterExample("StackedPlot", Construct16, __FILE__); +} \ No newline at end of file diff --git a/examples/ScatterCtrl_Demo/tab16_BubblePlot.cpp b/examples/ScatterCtrl_Demo/tab17_BubblePlot.cpp similarity index 85% rename from examples/ScatterCtrl_Demo/tab16_BubblePlot.cpp rename to examples/ScatterCtrl_Demo/tab17_BubblePlot.cpp index 2be8046a5..e6be5c406 100644 --- a/examples/ScatterCtrl_Demo/tab16_BubblePlot.cpp +++ b/examples/ScatterCtrl_Demo/tab17_BubblePlot.cpp @@ -21,12 +21,12 @@ void TabBubblePlot::Init() scatter.ZoomToFit(true, true, 0.2); } -ScatterDemo *Construct16() +ScatterDemo *Construct17() { static TabBubblePlot tab; return &tab; } INITBLOCK { - RegisterExample("BubblePlot", Construct16, __FILE__); + RegisterExample("BubblePlot", Construct17, __FILE__); } \ No newline at end of file diff --git a/examples/ScatterCtrl_Demo/tab17_UserPaint.cpp b/examples/ScatterCtrl_Demo/tab18_UserPaint.cpp similarity index 85% rename from examples/ScatterCtrl_Demo/tab17_UserPaint.cpp rename to examples/ScatterCtrl_Demo/tab18_UserPaint.cpp index 5fd1fb9e3..1999b6b4c 100644 --- a/examples/ScatterCtrl_Demo/tab17_UserPaint.cpp +++ b/examples/ScatterCtrl_Demo/tab18_UserPaint.cpp @@ -18,12 +18,12 @@ void Tab_UserPaint::Init() scatter.WhenDraw = THISBACK(OnDraw); } -ScatterDemo *Construct17() +ScatterDemo *Construct18() { static Tab_UserPaint tab; return &tab; } INITBLOCK { - RegisterExample("User paint", Construct17, __FILE__); + RegisterExample("User paint", Construct18, __FILE__); } diff --git a/examples/ScatterCtrl_Demo/tab20_Pie.cpp b/examples/ScatterCtrl_Demo/tab20_Pie.cpp index 55ff707fb..f12404b9c 100644 --- a/examples/ScatterCtrl_Demo/tab20_Pie.cpp +++ b/examples/ScatterCtrl_Demo/tab20_Pie.cpp @@ -8,5 +8,7 @@ void TabPie::Init() 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)); + chart.AddCategory("Rainy", 2, ::Color(250, 150, 90)); + + chart.SetColor(Null); }