ultimatepp/uppsrc/ScatterCtrl/ScatterCtrl.usc
koldo 65def7d923 ScatterCtrl: Included derivatives
git-svn-id: svn://ultimatepp.org/upp/trunk@14165 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2020-03-14 09:45:02 +00:00

351 lines
No EOL
10 KiB
Text

fn PaintRect(w, left, top, right, bottom, width, color)
{
w.DrawLine(left, top, right, top, width, color);
w.DrawLine(right, top, right, bottom, width, color);
w.DrawLine(right, bottom, left, bottom, width, color);
w.DrawLine(left, bottom, left, top, width, color);
}
enum_property LEGEND_POS {
"0" : "LEGEND_TOP",
"1" : "LEGEND_ANCHOR_LEFT_TOP",
"2" : "LEGEND_ANCHOR_RIGHT_TOP",
"3" : "LEGEND_ANCHOR_LEFT_BOTTOM",
"4" : "LEGEND_ANCHOR_RIGHT_BOTTOM"
};
ctrl ScatterCtrl {
group "Extra";
GetMinSize() {sz.cx=150; sz.cy = 100; return sz; }
GetStdSize() {sz.cx=300; sz.cy = 200; return sz; }
Text SetTitle;
Font SetTitleFont;
Color SetTitleColor = :Black;
int SetPlotAreaLeftMargin = 30;
int SetPlotAreaRightMargin = 30;
int SetPlotAreaTopMargin = 30;
int SetPlotAreaBottomMargin = 30;
Color SetPlotAreaColor = :WhiteGray;
Text SetLabelX;
Text SetLabelY;
Text SetLabelY2;
Font SetLabelsFont;
Color SetLabelsColor = :Black;
Color SetAxisColor = :Black;
double SetAxisWidth = 0.5;
Color SetGridColor = :Color(102,102,102);
double SetGridWidth = 1;
bool ShowHGrid = true;
bool ShowVGrid = true;
bool ShowInfo = true;
bool ShowContextMenu = false;
bool ShowPropertiesDlg = false;
bool ShowProcessDlg = false;
bool ShowButtons = false;
bool ShowLegend = true;
LEGEND_POS SetLegendAnchor;
int SetLegendPosX = 5;
int SetLegendPosY = 5;
int SetLegendNumCols = 1;
int SetLegendRowSpacing = 5;
Color SetLegendFillColor = :White;
Color SetLegendBorderColor = :Black;
bool SetFastViewX = false;
bool SetSequentialXAll = false;
Frame SetFrame;
Color SetColor = :White;
int SetSaveSizeX = 1000;
int SetSaveSizeY = 800;
Paint(w) {
r = GetRect();
w.DrawRect(r, .SetColor);
DrawCtrlFrame(w, r, .SetFrame);
sz = GetSize();
textsize = GetTextSize(.SetTitle, .SetTitleFont);
if(.SetTitle == "")
textsize.cy = 0;
w.DrawRect(.SetPlotAreaLeftMargin - 1,
.SetPlotAreaTopMargin - 1 + textsize.cy,
sz.cx - (.SetPlotAreaLeftMargin + .SetPlotAreaRightMargin) + 2,
- (.SetPlotAreaTopMargin + .SetPlotAreaBottomMargin) + 2 - textsize.cy + sz.cy,
:Gray);
aw = 6;
if(.SetAxisWidth >= 6)
aw = .SetAxisWidth;
w.DrawRect(.SetPlotAreaLeftMargin - int(aw/6), .SetPlotAreaTopMargin + textsize.cy,
- (.SetPlotAreaLeftMargin + .SetPlotAreaRightMargin) + int(aw/6) + sz.cx,
- (.SetPlotAreaTopMargin + .SetPlotAreaBottomMargin) + int(aw/6) - textsize.cy + sz.cy,
.SetAxisColor);
gx0 = .SetPlotAreaLeftMargin;
gy0 = .SetPlotAreaTopMargin + textsize.cy + 1;
gwidth = sz.cx - (.SetPlotAreaLeftMargin + .SetPlotAreaRightMargin);
gheight = sz.cy - (.SetPlotAreaTopMargin + .SetPlotAreaBottomMargin) - textsize.cy - 1;
w.DrawRect(gx0, gy0, gwidth, gheight, .SetPlotAreaColor);
w.DrawLine(gx0, gy0 + gheight, gx0 + gwidth*0.25, gy0 + gheight*0.5, 2, :SLtRed);
w.DrawLine(gx0 + gwidth*0.25, gy0 + gheight*0.5, gx0 + gwidth*0.5, gy0 + gheight*0.75, 2, :SLtRed);
w.DrawLine(gx0 + gwidth*0.5, gy0 + gheight*0.75, gx0 + gwidth*0.75, gy0 + gheight*0.25, 2, :SLtRed);
w.DrawLine(gx0 + gwidth*0.75, gy0 + gheight*0.25, gx0 + gwidth, gy0 + gheight*0.5, 2, :SLtRed);
w.DrawText((sz.cx - textsize.cx)/2, 4, .SetTitle, .SetTitleFont, .SetTitleColor);
lx = GetTextSize(.SetLabelX, .SetLabelsFont);
ly = GetTextSize(.SetLabelY, .SetLabelsFont);
ly2 = GetTextSize(.SetLabelY2, .SetLabelsFont);
w.DrawText(int((sz.cx - lx.cx)/2), sz.cy - (ly.cy + 2), .SetLabelX, .SetLabelsFont, .SetLabelsColor);
w.DrawText(2, int((sz.cy + textsize.cy + ly.cx)/2), 900, .SetLabelY, .SetLabelsFont, .SetLabelsColor);
w.DrawText(sz.cx - textsize.cy, int((sz.cy + textsize.cy + ly.cx)/2), 900, .SetLabelY2, .SetLabelsFont, .SetLabelsColor);
legWidth = 66;
legHeight = 18;
legFont = StdFont(12);
legFontSize = GetTextSize("X", legFont);
legFontHeight = legFontSize.cy;
if (.ShowLegend) {
if (.SetLegendAnchor == "0") {
w.DrawLine(gx0, gy0 - legFontHeight/2, gx0 + 20, gy0 - legFontHeight/2, 2, :SLtRed);
w.DrawText(gx0 + 24, gy0 - legFontHeight, "Series 1", legFont, :SLtRed);
} else {
if (.SetLegendAnchor == "1") {
lgx = gx0 + .SetLegendPosX;
lgy = gy0 + .SetLegendPosY;
} else if (.SetLegendAnchor == "2") {
lgx = gx0 + gwidth - .SetLegendPosX - legWidth;
lgy = gy0 + .SetLegendPosY;
} else if (.SetLegendAnchor == "3") {
lgx = gx0 + .SetLegendPosX;
lgy = gy0 + gheight - .SetLegendPosY - legHeight;
} else if (.SetLegendAnchor == "4") {
lgx = gx0 + gwidth - .SetLegendPosX - legWidth;
lgy = gy0 + gheight - .SetLegendPosY - legHeight;
}
if (.SetLegendPosX > :IntNull && .SetLegendPosY > :IntNull) {
w.DrawRect(lgx, lgy, legWidth, legHeight, .SetLegendFillColor);
PaintRect(w, lgx, lgy, lgx + legWidth, lgy + legHeight, 1, .SetLegendBorderColor);
w.DrawLine(lgx + 2, lgy + legFontHeight/2., lgx + 2 + 20, lgy + legFontHeight/2., 2, :SLtRed);
w.DrawText(lgx + 24, lgy, "Series 1", legFont, :SLtRed);
}
}
}
}
};
fn atan_base(z) {
return z - z*z*z/3 + z*z*z*z*z/5 - z*z*z*z*z*z*z/7 + z*z*z*z*z*z*z*z*z/9
- z*z*z*z*z*z*z*z*z*z*z/11 + z*z*z*z*z*z*z*z*z*z*z*z*z/13;
}
fn atan(z) {
if (z*z < 1)
return atan_base(z);
else if (z > 0)
return Pi()/2 - atan_base(1/z);
else
return 3*Pi()/2 - atan_base(1/z);
}
fn Pi() {
return 3.14159265358979323846;
}
fn ToRad(angle) {
if (angle > 0)
return angle*Pi()/180;
else
return (360+angle)*Pi()/180;
}
fn abs(a) {
if (a > 0)
return a;
else
return -a;
}
fn double(n) {
n += 1.1;
n -= 1.1;
return n;
}
fn PaintEllipse(w, left, top, right, bottom, width, color)
{
if (width < 1)
width = 1;
a = (right-left)/2.;
b = (bottom-top)/2.;
width_2 = width/2.;
delta = Pi()/20.;
maxi = 2.*Pi();
for (i = 0; i < maxi; i += delta) {
if (i == 0) {
x0 = left + a + (a - width_2);
y0 = top + b;
} else {
x0 = x1;
y0 = y1;
}
x1 = left + a + (a - width_2) * cos(i + delta);
y1 = top + b + (b - width_2) * sin(i + delta);
w.DrawLine(x0, y0, x1, y1, width, color);
}
}
fn DrawCircle(w, cx, cy, R, width, color) {
PaintEllipse(w, cx-R-width/2., cy-R-width/2., cx+R+width/2., cy+R+width/2., width, color);
}
fn PaintArc(w, cx, cy, R, ang0, ang1, direction, width, color)
{
if (direction == -1) {
c = ang0;
ang0 = ang1;
ang1 = c;
}
ang0 = ang0*Pi()/180;
ang1 = ang1*Pi()/180;
delta = 3*Pi()/180;
if (ang0 > ang1)
ang1 += 2*Pi();
for (i = ang0; i < ang1; i += delta) {
if (i == ang0) {
x0 = cx + R*cos(i);
y0 = cy - R*sin(i);
} else {
x0 = x1;
y0 = y1;
}
x1 = cx + R*cos(i + delta);
y1 = cy - R*sin(i + delta);
w.DrawLine(x0, y0, x1, y1, width, color);
}
}
fn FillEllipse(w, left, top, right, bottom, background)
{
a = (right-left)/2.;
b = (bottom-top)/2.;
if (a <= 0.5 || b <= 0.5) {
w.DrawLine(left, top, right, bottom, 1, background);
return;
}
delta = Pi()/10.;
x0 = left + a;
y0 = top + b;
for (i = delta; i < Pi()/2.; i += delta) {
x1 = a * cos(i);
y1 = b * sin(i);
w.DrawRect(x0-x1 , y0-y1, 2*x1 , 2*y1, background);
}
width = min(a, b)/4.;
if (width > 1)
PaintEllipse(w, left, top, right, bottom, width, background);
}
fn FillCircle(w, cx, cy, R, color) {
FillEllipse(w, cx-R, cy-R, cx+R, cy+R, color);
}
enum_property titlePosition {
"0" : "BOTTOM",
"1" : "TOP"
};
ctrl PieCtrl {
group "Extra";
GetMinSize() {sz.cx = 50; sz.cy = 50; return sz; }
GetStdSize() {sz.cx = 200; sz.cy = 200; return sz; }
Frame SetFrame @20;
Color SetColor = :White @1;
Text SetTitle @5;
Font SetTitleFont = StdFont(16)@6;
Color SetTitleColor = :Black @7;
titlePosition SetTitlePos = 1;
int SetTitleGap = 2;
bool ShowPercent = true;
Color SetPercentBack = Null;
bool ShowLegend = true;
Font SetLegendFont;
Color SetLegendTextColor = :Black;
Color SetLegendBackColor = Null;
int SetLegendLeft = 10;
int SetLegendTop = Null;
double SetPieAngle = 0;
int SetPieMarginLeft = 40;
int SetPieMarginTop = 40;
int SetPieMarginRight = 40;
int SetPieMarginBottom = 40;
Paint(w) {
r = GetRect();
w.DrawRect(r, .SetColor);
DrawCtrlFrame(w, r, .SetFrame);
sz = GetSize();
textsize = GetTextSize(.SetTitle, .SetTitleFont);
Gap = 0;
if(.SetTitleGap > 0)
Gap = .SetTitleGap;
if(.SetTitlePos == "1")
w.DrawText((sz.cx - textsize.cx)/2, Gap, .SetTitle, .SetTitleFont, .SetTitleColor);
else
w.DrawText((sz.cx - textsize.cx)/2, sz.cy-textsize.cy - Gap, .SetTitle, .SetTitleFont, .SetTitleColor);
if(.SetTitle == "")
textsize.cy = 0;
SetLegendHeight = 120;
SetLegendWidth = 60;
lcx = 0;
lcy = 0;
legendBk = .SetColor;
if(.SetLegendBackColor != Null)
legendBk = .SetLegendBackColor;
if(SetLegendWidth > 0 && .ShowLegend)
lcx = SetLegendWidth;
if(SetLegendHeight > 0 && .ShowLegend)
lcy = SetLegendHeight;
left = - .SetLegendLeft + sz.cx - lcx;
if (.SetLegendTop <= :IntNull)
top = (sz.cy - Gap - textsize.cy - lcy)/2;
else
top = .SetLegendTop;
if(.ShowLegend) {
w.DrawRect(left, top, lcx, lcy, legendBk);
PaintRect(w, left, top, left + lcx, top + lcy, 2, :Gray);
w.DrawText(left + 2, top + 2, "Legend", .SetLegendFont, .SetLegendTextColor);
}
circWidth = sz.cx - .SetPieMarginLeft - .SetPieMarginRight;
if (circWidth < 0)
circWidth = 0;
circHeight = sz.cy - .SetPieMarginTop - textsize.cy - .SetPieMarginBottom;
if (circHeight < 0)
circHeight = 0;
if (circWidth > circHeight)
circ_r = circHeight/2;
else
circ_r = circWidth/2;
circ_x = .SetPieMarginLeft + circWidth/2.;
if(.SetTitlePos == "1")
circ_y = .SetPieMarginTop + textsize.cy + circHeight/2.;
else
circ_y = .SetPieMarginTop + circHeight/2.;
FillCircle(w, circ_x, circ_y, circ_r, Color(150, 255, 150));
DrawCircle(w, circ_x, circ_y, circ_r, 2, :SBlack);
w.DrawLine(circ_x, circ_y, circ_x + circ_r*cos(-.SetPieAngle + 0.5*Pi()), circ_y - circ_r*sin(-.SetPieAngle + 0.5*Pi()), 2, :SBlack);
w.DrawLine(circ_x, circ_y, circ_x + circ_r*cos(-.SetPieAngle - 0.25*Pi()), circ_y - circ_r*sin(-.SetPieAngle - 0.25*Pi()), 2, :SBlack);
w.DrawLine(circ_x, circ_y, circ_x + circ_r*cos(-.SetPieAngle + Pi()), circ_y - circ_r*sin(-.SetPieAngle + Pi()), 2, :SBlack);
}
};