ScatterCtrl_Demo: Plot responsiveness and 2D surfaces added.

git-svn-id: svn://ultimatepp.org/upp/trunk@12445 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2018-11-02 23:12:34 +00:00
parent 124e533048
commit ecb7a3db35
13 changed files with 217 additions and 33 deletions

View file

@ -254,6 +254,7 @@ public:
private:
Vector<Vector <double> > s1;
Vector<int> idsBubble;
Vector<String> labels;
};
class Tab_UserPaint : public WithTabUserPaint<ScatterDemo> {
@ -275,7 +276,7 @@ public:
String text = "Fixed text";
Font font = Arial(30);
Size sz = GetTextSize(text, font);
FillRectangleOpa(w, plotW - sz.cx - 10, 10, plotW - 10, 10 + sz.cy, 1, 0.3, Null, LtGreen());
FillRectangleOpa(w, plotW - sz.cx - 10, 10, plotW - 10, 10 + sz.cy, 0.3, Null, LtGreen());
DrawText(w, plotW - sz.cx - 10, 10, 0, text, font, Black());
if (scatter.GetXMin() < 1 && scatter.GetXMax() > 1) {
@ -292,7 +293,7 @@ public:
double sizex = scatter.GetSizeX(0.2);
FillRectangleOpa(w, posx - sizex/2., posy - sizex/2.,
posx + sizex/2., posy + sizex/2.,
1, 0.8, Null, LtGreen());
0.8, Null, LtGreen());
Vector<Pointf> s;
s << Pointf(posx - sizex/2., posy - sizex/2.)
<< Pointf(posx + sizex/2., posy - sizex/2.)
@ -312,6 +313,29 @@ private:
Vector<Pointf> s1;
};
class Tab19_Surf : public WithTabSurf<ScatterDemo> {
public:
typedef Tab19_Surf CLASSNAME;
virtual void Init();
virtual ScatterCtrl &Scatter() {return scatter;};
void OnChange();
void Init_DatasetSimple();
void Init_Dataset();
void Init_DataExplicit();
private:
ExplicitData funData;
TableDataPoints data;
TableDataAreas dataFun;
Vector<double> zData, xAxis, yAxis;
Vector<double> zDataFun, xAxisFun, yAxisFun;
Vector<Pointf> isolines, numbersPos;
Vector<String> labels;
};
class TabPie : public WithTabPie<StaticRect> {
public:
typedef TabPie CLASSNAME;

View file

@ -15,7 +15,7 @@ LAYOUT(Tab1Basic, 428, 296)
END_LAYOUT
LAYOUT(Tab2Functions, 380, 292)
ITEM(ScatterCtrl, scatter, SetTitle(t_("Functions")).SetPlotAreaRightMargin(110).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetGridWidth(2).SetTitleFont(SansSerifZ(14).Bold()).SetLegendAnchor(2).SetLegendPosX(-107).SetLegendPosY(0).HSizePosZ(16, 12).VSizePosZ(16, 16))
ITEM(ScatterCtrl, scatter, SetTitle(t_("Functions")).SetPlotAreaRightMargin(130).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetGridWidth(2).SetTitleFont(SansSerifZ(14).Bold()).SetLegendAnchor(2).SetLegendPosX(-120).SetLegendPosY(0).HSizePosZ(16, 12).VSizePosZ(16, 16))
END_LAYOUT
LAYOUT(Tab3ParametricFunctions, 384, 284)
@ -98,6 +98,20 @@ 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(TabSurf, 468, 236)
ITEM(ScatterCtrl, scatter, SetTitle(t_("2D Surface")).SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(20).SetPlotAreaTopMargin(20).SetPlotAreaBottomMargin(40).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(132, 4).VSizePosZ(4, 4))
ITEM(LabelBox, dv___1, SetLabel(t_("Data source")).LeftPosZ(4, 124).TopPosZ(0, 64))
ITEM(Switch, dataType, SetLabel(t_("Data set simple\nData set\nExplicit equation")).LeftPosZ(12, 108).TopPosZ(16, 48))
ITEM(EditIntSpin, numColor, Min(0).NotNull(true).LeftPosZ(72, 56).TopPosZ(112, 19))
ITEM(Label, labelInterpolation, SetLabel(t_("Data set interpolation")).LeftPosZ(4, 120).TopPosZ(68, 19))
ITEM(Label, dv___5, SetLabel(t_("Num. color:")).LeftPosZ(4, 68).TopPosZ(112, 19))
ITEM(DropList, interpolation, LeftPosZ(4, 124).TopPosZ(88, 19))
ITEM(Label, dv___7, SetLabel(t_("Rainbow style")).LeftPosZ(4, 100).TopPosZ(156, 19))
ITEM(DropList, rainbow, LeftPosZ(4, 124).TopPosZ(176, 19))
ITEM(Option, zoom, SetLabel(t_("Zoom to fit")).LeftPosZ(4, 104).TopPosZ(200, 16))
ITEM(Option, opContinuous, SetLabel(t_("Continuous")).LeftPosZ(4, 88).TopPosZ(136, 16))
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))

View file

@ -28,9 +28,10 @@ file
tab16_StackedPlot.cpp,
tab17_BubblePlot.cpp,
tab18_UserPaint.cpp,
tab19_Surf.cpp,
tab20_Pie.cpp,
symbol.iml;
mainconfig
"" = "GUI";
"" = "GUI MT";

View file

@ -80,7 +80,7 @@ ScatterCtrl_Demo::ScatterCtrl_Demo()
SetMode();
examplesList.WhenSel = THISBACK(OnSel);
examplesList.SetCursor(14);
examplesList.SetCursor(17);
OnSel();
Sizeable().Zoomable().Icon(MyImages::i1());
@ -101,7 +101,7 @@ void ScatterCtrl_Demo::Preview()
r.Landscape();
Size pageSize = r.GetPageSize();
const Drawing &w = Examples()[examplesList.GetCursor()].ctrl()->Scatter().GetDrawing(Size(800, 600));
const Drawing &w = Examples()[examplesList.GetCursor()].ctrl()->Scatter().GetDrawing();
r.DrawDrawing(0, 0, pageSize.cx, pageSize.cy, w);
Perform(r);

View file

@ -7,9 +7,9 @@
class MyPlot : public SeriesPlot {
private:
template <class T>
void DoPaint(T& w, Vector<Point> &p, const int &scale, const double opacity,
void DoPaint(T& w, const double &scale, Vector<Pointf> &p, const double opacity,
double thick, const Color &color, String pattern, const Color &background,
const Color &fillColor, int y0) const {
const Color &fillColor, double y0) const {
Vector<Pointf> t;
t.SetCount(3);
for (int i = 0; i < p.GetCount(); ++i) {
@ -25,31 +25,34 @@ private:
}
public:
void Paint(Draw& w, Vector<Point> &p, const int &scale, const double opacity,
void Paint(Draw& w, Vector<Pointf> &p, const double &scale, const double opacity,
double thick, const Color &color, String pattern, const Color &background,
const Color &fillColor, double fx, double fy, int y0) const {
DoPaint(w, p, scale, opacity, fround(thick), color, pattern, background, fillColor, y0);
const Color &fillColor, double fx, double fy, double y0, double width,
bool isClosed) const {
DoPaint(w, scale, p, opacity, fround(thick), color, pattern, background, fillColor, y0);
}
void Paint(Painter& w, Vector<Point> &p, const int &scale, const double opacity,
void Paint(Painter& w, Vector<Pointf> &p, const double &scale, const double opacity,
double thick, const Color &color, String pattern, const Color &background,
const Color &fillColor, double fx, double fy, int y0) const {
DoPaint(w, p, scale, opacity, fround(thick), color, pattern, background, fillColor, y0);
const Color &fillColor, double fx, double fy, double y0, double width,
bool isClosed) const {
DoPaint(w, scale, p, opacity, fround(thick), color, pattern, background, fillColor, y0);
}
};
class MyMark : public MarkPlot {
private:
template <class T>
void DoPaint(T& w, const int& scale, const Point& cp, const double& size, const Color& markColor) const {
w.DrawImage(cp.x-8, cp.y-8, Symbol::bug());
void DoPaint(T& w, const double& scale, const Point& cp, const double& size, const Color& markColor) const {
Size bugSize = Symbol::bug().GetSize()*scale;
w.DrawImage(cp.x - bugSize.cx/2, cp.y - bugSize.cy/2, bugSize.cx, bugSize.cy, Symbol::bug());
}
public:
void Paint(Draw &p, const int& scale, const Point& cp, const double& size, const Color& markColor,
void Paint(Draw &p, const double& scale, const Point& cp, const double& size, const Color& markColor,
const double&, const Color&) const {
DoPaint(p, scale, cp, size, markColor);
}
void Paint(Painter &p, const int& scale, const Point& cp, const double& size, const Color& markColor,
void Paint(Painter &p, const double& scale, const Point& cp, const double& size, const Color& markColor,
const double&, const Color&) const {
DoPaint(p, scale, cp, size, markColor);
}
@ -62,10 +65,11 @@ void Tab10_User::Init()
sy[0] = 18; sy[1] = 29; sy[2] = 23; sy[3] = 25; sy[4] = 20;
sx[0] = 10; sx[1] = 20; sx[2] = 30; sx[3] = 40; sx[4] = 50;
scatter.AddSeries(sx, sy, 5).Legend("Series").PlotStyle<MyPlot>().MarkStyle<MyMark>().Stroke(3, LtGreen()).Fill(LtGray());
scatter.AddSeries(sx, sy, 5).Legend("Series").PlotStyle<MyPlot>().MarkStyle<MyMark>()
.Stroke(3, LtGreen()).Fill(LtGray());
scatter.SetRange(60, 50).SetMajorUnits(10, 10);
scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg();
scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg().Responsive();
}
ScatterDemo *Construct10()

View file

@ -9,7 +9,8 @@ void Tab11_Trend::Init()
seriesList = "Series 1";
seriesList.WhenAction = THISBACK(OnSeries);
scatter.SetMouseHandling(true, true).ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg();
scatter.SetMouseHandling(true, true).ShowContextMenu().ShowPropertiesDlg()
.ShowProcessDlg().Responsive();
grid.AddColumn("Type", 10);
grid.AddColumn("Equation", 40);

View file

@ -21,8 +21,8 @@ void TabStackedPlot::Init()
scatter.AddSeries(stacked.Get(1)).Legend("s2").Fill();
scatter.AddSeries(stacked.Get(0)).Legend("s1").Fill();
scatter.SetLabelY("Data").SetLabelX("time [seg]");
scatter.ShowButtons();
scatter.SetLabelY("Data").SetLabelX("time [seg]")
.ShowButtons().Responsive();
type = 0;
type.WhenAction = THISBACK(OnPlot);

View file

@ -10,14 +10,19 @@ void TabBubblePlot::Init()
for (double size = 0; size <= 10; size += 2.) {
Vector<double> &data = s1.Add();
data << size << (10 + 10*Random(30)*size) << Random(80);
double x = size;
double y = (10 + 10*Random(30)*size);
double diameter = Random(80);
data << x << y << diameter;
labels << Format("%.0f cm", diameter);
}
idsBubble << 2;
static Vector<int> idVoid;
scatter.AddSeries(s1, 0, 1, idVoid, idVoid, idsBubble).Legend("Importance").MarkStyle<BubblePlot>()
.NoPlot().MarkColor(Green()).MarkBorderColor(LtRed()).MarkBorderWidth(3);
scatter.SetLabelY("Size");
.MarkColor(Green()).MarkBorderColor(LtRed()).MarkBorderWidth(3)
.AddLabelSeries(labels, 0, 0, StdFont().Height(15).Bold(), ALIGN_CENTER);
scatter.SetLabelY("Size").Responsive();
scatter.ZoomToFit(true, true, 0.2);
}

View file

@ -12,7 +12,7 @@ void Tab_UserPaint::Init()
scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg().
SetMouseHandling(true, true);
scatter.SetLegendPos(Point(20, 20)).SetLegendAnchor(ScatterDraw::LEGEND_ANCHOR_RIGHT_BOTTOM);
scatter.SetLegendPos(Point(20, 20)).SetLegendAnchor(ScatterDraw::RIGHT_BOTTOM);
scatter.ZoomToFit(true, true);
scatter.WhenPainter = THISBACK(OnPainter);
scatter.WhenDraw = THISBACK(OnDraw);

View file

@ -0,0 +1,136 @@
#include "ScatterCtrl_Demo.h"
void Tab19_Surf::Init()
{
CtrlLayout(*this);
SizePos();
numColor <<= 4;
numColor <<= THISBACK(OnChange);
opContinuous <<= true;
opContinuous <<= THISBACK(OnChange);
dataType = 0;//2;
dataType << THISBACK(OnChange);
rainbow.Add(BLUE_YELLOW_RED, "BLUE_YELLOW_RED").Add(RED_YELLOW_BLUE, "RED_YELLOW_BLUE")
.Add(GREEN_YELLOW_RED, "GREEN_YELLOW_RED").Add(RED_YELLOW_GREEN, "RED_YELLOW_GREEN")
.Add(WHITE_BLACK, "WHITE_BLACK").Add(BLACK_WHITE, "BLACK_WHITE");
rainbow = scatter.SurfRainbow();
rainbow << THISBACK(OnChange);
interpolation.Add(TableData::NO, "NO").Add(TableData::BILINEAR, "BILINEAR");
interpolation = TableData::BILINEAR;
interpolation << THISBACK(OnChange);
zoom = true;
zoom << THISBACK(OnChange);
scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg()
.SetMouseHandling(true, true).Responsive(true)
.SetRainbowPaletteSize(Size(20, 200))
.SetRainbowPaletteAnchor(ScatterDraw::LEGEND_POS::LEFT_TOP)
.SetRainbowPalettePos(Point(20, 20))
.SetRainbowPaletteFont(StdFont().Height(10))
.SurfUnits("kg").SurfUnitsPos(ScatterDraw::UNITS_LEFT)
.SurfLegendPos(ScatterDraw::LEGEND_RIGHT);
for (double x = 0; x <= 5; x += 1)
xAxis << x;
yAxis << 0 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15;
zData << 0 << 0 << 0 << 0 << 0 << 0
<< 0 << 402 << 2501 << 2099 << 48231 << 89315
<< 0 << 1835 << 9889 << 36124 << 78603 << 101067
<< 0 << 4627 << 24211 << 61689 << 117905 << 151600
<< 0 << 7170 << 37887 << 96988 << 185785 << 239028
<< 0 << 7144 << 39134 << 106627 << 213241 << 277208
<< 0 << 6290 << 33302 << 95397 << 196494 << 256218
<< 0 << 6931 << 32175 << 84656 << 165247 << 211670
<< 0 << 6117 << 27070 << 68657 << 130224 << 165038
<< 0 << 3849 << 17985 << 47400 << 91425 << 116321
<< 0 << 2390 << 12142 << 33214 << 65323 << 83722
<< 0 << 1741 << 9541 << 26098 << 51917 << 67241
<< 0 << 1337 << 7783 << 21287 << 42703 << 55722;
data.Init(zData, xAxis, yAxis, TableData::BILINEAR);
Vector<double> vals;
for (double val = 50000; val <= 250000; val += 50000)
vals << val;
isolines = data.GetIsolines(vals, Rectf(0, 16, 5, 0), 0.1, 0.1);
Vector<Pointf> numbersWhere;
numbersWhere << Pointf(4.7, 8) << Pointf(1, 14);
numbersPos = Intersection(numbersWhere, isolines);
for (int i = 0; i < vals.GetCount(); ++i)
labels << Format("%.0f kg", vals[i]);
for (double x = -10; x <= 10; x += 1)
xAxisFun << x;
for (double y = -10; y <= 10; y += 1)
yAxisFun << y;
zDataFun.SetCount((xAxisFun.GetCount()-1)*(yAxisFun.GetCount()-1));
for (int iy = 0; iy < yAxisFun.GetCount()-1; iy++) {
double y = (yAxisFun[iy] + yAxisFun[iy+1])/2.;
for (int ix = 0; ix < xAxisFun.GetCount()-1; ix++) {
double x = (xAxisFun[ix] + xAxisFun[ix+1])/2.;
zDataFun[ix + iy*(xAxisFun.GetCount() - 1)] = sin(sqrt(x*x + y*y + 64))/sqrt(x*x + y*y + 64);
}
}
dataFun.Init(zDataFun, xAxisFun, yAxisFun, TableData::BILINEAR);
funData.Init([=](double x, double y) {return sin(sqrt(x*x + y*y + 64))/sqrt(x*x + y*y + 64);}, -10, 10, -10, 10);
OnChange();
}
void Tab19_Surf::OnChange() {
labelInterpolation.Enable(dataType != 2);
interpolation.Enable(dataType != 2);
scatter.SurfNumColor(~numColor, ~opContinuous).SurfRainbow((RAINBOW)int(rainbow.GetKey(rainbow.GetIndex())));
if (dataType == 0)
Init_DatasetSimple();
else if (dataType == 1)
Init_Dataset();
else
Init_DataExplicit();
if (zoom)
scatter.ZoomToFit(true, true);
scatter.Refresh();
}
void Tab19_Surf::Init_DatasetSimple() {
scatter.RemoveAllSeries();
scatter.AddSeries(isolines).Legend("Isoline").Stroke(0.5, White).ShowSeriesLegend(false).NoMark();
scatter.AddSeries(numbersPos).Stroke(0).AddLabelSeries(labels, 0, 0, StdFont().Bold(), ALIGN_CENTER, White())
.ShowSeriesLegend(false).NoMark();
data.Inter((TableData::Interpolate)int(interpolation.GetKey(interpolation.GetIndex())));
scatter.AddSurf(data)
.SetRainbowPaletteTextColor(White)
.SetSurfMinZ(0).SetSurfMaxZ(300000);
}
void Tab19_Surf::Init_Dataset() {
scatter.RemoveAllSeries();
dataFun.Inter((TableData::Interpolate)int(interpolation.GetKey(interpolation.GetIndex())));
scatter.AddSurf(dataFun);
scatter.SetRainbowPaletteTextColor(Black);
scatter.ZoomToFitZ();
}
void Tab19_Surf::Init_DataExplicit() {
scatter.RemoveAllSeries();
scatter.AddSurf(funData);
scatter.SetRainbowPaletteTextColor(Black);
scatter.ZoomToFitZ();
}
ScatterDemo *Construct19()
{
static Tab19_Surf tab;
return &tab;
}
INITBLOCK {
RegisterExample("2D Surface", Construct19, __FILE__);
}

View file

@ -7,7 +7,6 @@ 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 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));}
void para3p(Pointf& xy, double t, double a) {xy = Pointf(a+(0.5+t)*cos(6*M_PI*t),(0.5+t)*sin(6*M_PI*t));}
@ -21,13 +20,13 @@ void Tab3_ParametricFunctions::Init()
scatter.SetMajorUnits(0.5, 0.5);
scatter.SetXYMin(-2, -2);
scatter.AddSeries(&opara1, 20).Legend("Circle 1");//.NoMark();
scatter.AddSeries(&opara1, 20).Legend("Circle 1");
scatter.AddSeries(&para1, 100).Legend("Circle 2").NoMark();
scatter.AddSeries(&para2, 100).Legend("Coil").NoMark();
scatter.AddSeries(&para3, 150).Legend("Spiral 1").NoMark();
scatter.AddSeries(STDBACK1(para3p, 2.5), 150, 0, 1).Legend("Spiral 2").NoMark();
scatter.AddSeries(&para4, 2).Legend("VLine").NoMark();
scatter.AddSeries(&para5, 2).Legend("HLine").NoMark();
scatter.AddSeries([=](Pointf &xy, double t) {xy = Pointf(-0.25+0.5*t, 0);}, 2).Legend("HLine").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();
}

View file

@ -17,7 +17,7 @@ void Tab6_Logarithmic::Init()
void Tab6_Logarithmic::FormatX(String& s, int i, double d)
{
s = FormatDoubleExp(pow(10., d), 1);
s = FormatDouble(pow(10., d), 0);
}
ScatterDemo *Construct6()

View file

@ -17,7 +17,7 @@ void Tab8_Secondary::Init()
scatter.AddSeries(s1).Legend("Temperature").Units("ºC").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);
scatter.AddSeries(s2).Legend("Pressure").Units("mBar").Stroke(3, Null).Dash("15 6 6 6 3 6 6 6").SetDataPrimaryY(false);
scatter.AddSeries(s2).Legend("Pressure").Units("mBar").Stroke(3, Null).Dash("15 6 6 6 3 6 6 6").SetDataSecondaryY();
scatter.SetDrawY2Reticle();
scatter.cbModifFormatX = THISBACK(MyFormat);