mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
ScatterDraw: PieCtrl legend width and height is automatic
git-svn-id: svn://ultimatepp.org/upp/trunk@10659 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6ba4b11b99
commit
e91394665c
9 changed files with 58 additions and 17 deletions
|
|
@ -51,6 +51,21 @@ double DataSource::Avg(Getdatafun getdata) {
|
|||
return ret/count;
|
||||
}
|
||||
|
||||
double DataSource::RMS(Getdatafun getdata) {
|
||||
double ret = 0;
|
||||
int count = 0;
|
||||
for (int64 i = 0; i < GetCount(); ++i) {
|
||||
double d = Membercall(getdata)(i);
|
||||
if (!IsNull(d)) {
|
||||
ret += d*d;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0)
|
||||
return Null;
|
||||
return sqrt(ret/count);
|
||||
}
|
||||
|
||||
double DataSource::IsSorted(Getdatafun getdata) {
|
||||
int64 num = GetCount();
|
||||
if (num == 0)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ public:
|
|||
virtual double IsSortedX() {return IsSorted(&DataSource::x);}
|
||||
|
||||
virtual double AvgY() {return Avg(&DataSource::y);}
|
||||
virtual double AvgX() {return Avg(&DataSource::x);}
|
||||
virtual double AvgX() {return Avg(&DataSource::x);}
|
||||
virtual double RMSY() {return RMS(&DataSource::y);}
|
||||
virtual double StdDevY(double avg = Null) {return StdDev(&DataSource::y, avg);}
|
||||
virtual double VarianceY(double avg = Null) {return Variance(&DataSource::y, avg);}
|
||||
virtual Vector<int64> UpperEnvelopeY(double width) {return UpperEnvelope(&DataSource::y, &DataSource::x, width);}
|
||||
|
|
@ -61,6 +62,7 @@ public:
|
|||
double Max(Getdatafun getdata, int64& id);
|
||||
double Avg(Getdatafun getdata);
|
||||
double IsSorted(Getdatafun getdata);
|
||||
double RMS(Getdatafun getdata);
|
||||
double StdDev(Getdatafun getdata, double avg = Null);
|
||||
double Variance(Getdatafun getdata, double avg = Null);
|
||||
Vector<int64> UpperEnvelope(Getdatafun getdataY, Getdatafun getdataX, double width);
|
||||
|
|
|
|||
|
|
@ -428,6 +428,7 @@ INITBLOCK {
|
|||
ExplicitEquation::Register<PolynomialEquation5>("PolynomialEquation5");
|
||||
ExplicitEquation::Register<SinEquation>("SinEquation");
|
||||
ExplicitEquation::Register<ExponentialEquation>("ExponentialEquation");
|
||||
ExplicitEquation::Register<RealExponentEquation>("RealExponentEquation");
|
||||
ExplicitEquation::Register<Rational1Equation>("Rational1Equation");
|
||||
ExplicitEquation::Register<FourierEquation1>("FourierEquation1");
|
||||
ExplicitEquation::Register<FourierEquation2>("FourierEquation2");
|
||||
|
|
|
|||
|
|
@ -199,8 +199,8 @@ class ExponentialEquation : public ExplicitEquation {
|
|||
public:
|
||||
ExponentialEquation() {SetCoeff(1, 0);}
|
||||
ExponentialEquation(double c0, double c1) {SetCoeff(c0, c1);}
|
||||
double f(double x) {return coeff[0]*exp(-x) + coeff[1];}
|
||||
virtual String GetName() {return t_("Exponential");}
|
||||
double f(double x) {return coeff[0]*exp(-x) + coeff[1];}
|
||||
virtual String GetName() {return t_("Exponential");}
|
||||
virtual String GetEquation(int numDigits = 3) {
|
||||
String ret = Format("%s*e^-x + %s", FormatCoeff(0, numDigits), FormatCoeff(1, numDigits));
|
||||
ret.Replace("+ -", "- ");
|
||||
|
|
@ -210,6 +210,21 @@ public:
|
|||
void SetDegree(int num) {NEVER();}
|
||||
};
|
||||
|
||||
class RealExponentEquation : public ExplicitEquation {
|
||||
public:
|
||||
RealExponentEquation() {SetCoeff(1, 1);}
|
||||
RealExponentEquation(double a, double b) {SetCoeff(a, b);}
|
||||
double f(double x) {return coeff[0]*pow(x, coeff[1]);}
|
||||
virtual String GetName() {return t_("RealExponent");}
|
||||
virtual String GetEquation(int numDigits = 3) {
|
||||
String ret = Format("%s*x^%s", FormatCoeff(0, numDigits), FormatCoeff(1, numDigits));
|
||||
ret.Replace("+ -", "- ");
|
||||
return ret;
|
||||
}
|
||||
virtual void GuessCoeff(DataSource &series) {}
|
||||
void SetDegree(int num) {NEVER();}
|
||||
};
|
||||
|
||||
class Rational1Equation : public ExplicitEquation {
|
||||
public:
|
||||
Rational1Equation() {SetCoeff(1, 0, 0);}
|
||||
|
|
|
|||
|
|
@ -161,6 +161,17 @@ void PieDraw::PaintPie(Draw& w, int scale) {
|
|||
}
|
||||
}
|
||||
if(showLegend) {
|
||||
Upp::Font scaledFont;
|
||||
scaledFont.Height(scale*legendFont.GetHeight());
|
||||
scaledFont.Width(scale*legendFont.GetWidth());
|
||||
int fh = scale*legendFont.GetHeight();
|
||||
int nr = GetCatCount();
|
||||
int legendWidth = 0;
|
||||
int legendHeight = (1 + nr)*scaledFont.GetHeight();
|
||||
for(int i = 0; i < nr; i++)
|
||||
legendWidth = max<int>(legendWidth, GetTextSize(vNames[i], scaledFont).cx);
|
||||
legendWidth += fround(2.2*fh);
|
||||
|
||||
double leg_x = -legendLeft + sz.cx - legendWidth;
|
||||
double leg_y;
|
||||
if (IsNull(legendTop))
|
||||
|
|
@ -169,14 +180,9 @@ void PieDraw::PaintPie(Draw& w, int scale) {
|
|||
leg_y = legendTop*scale;
|
||||
w.DrawRect(int(leg_x), int(leg_y), scale*legendWidth, scale*legendHeight, legendBackColor);
|
||||
|
||||
int nr = GetCatCount();
|
||||
int dly = scale*legendHeight/nr;
|
||||
for(int i = 0; i < nr; i++) {
|
||||
int fh = scale*(legendFont.GetHeight()-3);
|
||||
w.DrawRect(int(leg_x) + 2*scale, int(leg_y) + i*dly + int(dly/2.) - fh/2, fh, fh, vColors[i]);
|
||||
Upp::Font scaledFont;
|
||||
scaledFont.Height(scale*legendFont.GetHeight());
|
||||
scaledFont.Width(scale*legendFont.GetWidth());
|
||||
w.DrawRect(int(leg_x) + 2*scale, int(leg_y + i*dly + dly/2. - fh/2.), fh, fh, vColors[i]);
|
||||
w.DrawText(int(leg_x) + fround(1.8*fh), int(leg_y) + i*dly + int((dly - scaledFont.GetLineHeight())/2),
|
||||
vNames[i], scaledFont, legendTextColor);
|
||||
}
|
||||
|
|
@ -203,8 +209,8 @@ Image PieDraw::GetImage(int scale) {
|
|||
PieDraw::PieDraw(): backColor(White), titleFont(StdFont(16)), titleColor(Black), titlePos(TOP),
|
||||
titleGap(2), showPercent(true), percentBack(Null),
|
||||
legendFont(StdFont()), legendTextColor(Black), legendBackColor(Null),
|
||||
showLegend(true), legendLeft(10), legendTop(Null), legendWidth(60),
|
||||
legendHeight(120), pieAngle(0), pieMarginLeft(40), pieMarginTop(40),
|
||||
showLegend(true), legendLeft(10), legendTop(Null), pieAngle(0),
|
||||
pieMarginLeft(40), pieMarginTop(40),
|
||||
pieMarginRight(40), pieMarginBottom(40)
|
||||
{}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ public:
|
|||
PieDraw& SetLegendBackColor(const Color& color) {legendBackColor = color; return *this;}
|
||||
PieDraw& SetLegendLeft(const int& left) {legendLeft = left; return *this;}
|
||||
PieDraw& SetLegendTop(const int& top) {legendTop = top; return *this;}
|
||||
PieDraw& SetLegendWidth(const int& width) {legendWidth = width; return *this;}
|
||||
PieDraw& SetLegendHeight(const int& height) {legendHeight = height; return *this;}
|
||||
|
||||
PieDraw& SetPieAngle(const double& angle) {pieAngle = angle; return *this;}
|
||||
PieDraw& SetPieMarginLeft(const int& left) {pieMarginLeft = left; return *this;}
|
||||
|
|
@ -75,7 +73,7 @@ private:
|
|||
Upp::Font legendFont;
|
||||
Color legendTextColor, legendBackColor;
|
||||
bool showLegend;
|
||||
int legendLeft, legendTop, legendWidth, legendHeight;
|
||||
int legendLeft, legendTop;
|
||||
|
||||
double pieAngle;
|
||||
int pieMarginLeft, pieMarginTop, pieMarginRight, pieMarginBottom;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ ublic]_[*@3 ExplicitEquation]&]
|
|||
[s0; &]
|
||||
[s3; &]
|
||||
[ {{10000F(128)G(128)@1 [s0; [* Constructor Detail]]}}&]
|
||||
[s0; &]
|
||||
[s5; &]
|
||||
[s4;:ExponentialEquation`:`:ExponentialEquation`(double`,double`):%- [* ExponentialEqua
|
||||
tion]([@(0.0.255) double]_[*@3 a], [@(0.0.255) double]_[*@3 b])&]
|
||||
[s2; Initializes equation coefficients [%-*@3 a] and [%-*@3 b].&]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
TITLE("class ExponentialEquation : public ExplicitEquation")
|
||||
COMPRESSED
|
||||
120,156,133,146,111,171,155,48,20,198,191,74,96,183,67,187,182,228,156,36,26,35,131,194,110,247,135,193,246,98,236,85,200,170,181,233,144,57,237,170,133,187,149,126,247,37,86,215,203,232,229,250,34,49,241,57,207,121,206,15,53,185,187,163,51,250,130,62,243,168,123,187,203,143,85,103,116,201,185,76,115,20,233,143,143,159,147,212,149,131,43,103,49,48,41,24,112,140,220,2,12,80,32,227,32,49,225,146,49,73,85,219,29,142,69,87,118,246,167,209,21,74,153,162,171,68,87,137,177,64,136,185,228,18,88,44,209,25,32,165,72,99,20,192,153,68,161,182,182,45,140,166,78,206,156,60,137,88,66,129,210,24,128,50,140,41,19,28,128,161,179,192,24,129,10,101,235,237,255,25,125,43,254,108,200,152,170,162,217,218,75,196,247,81,234,59,10,79,70,68,110,254,200,197,225,156,186,82,223,151,51,96,20,153,128,68,68,106,99,191,151,181,209,167,245,121,178,250,52,255,250,133,104,114,58,129,135,182,100,68,183,52,37,122,186,12,16,147,144,147,213,195,190,169,109,221,
|
||||
149,121,181,250,117,204,187,178,169,141,57,159,95,26,221,178,116,50,39,254,5,82,117,67,150,169,76,21,85,222,182,202,201,244,50,160,11,186,64,33,66,210,95,154,181,158,222,52,95,171,245,99,241,254,184,169,202,194,171,93,54,167,119,135,178,251,39,246,221,49,237,67,248,212,120,203,145,28,236,254,96,91,119,217,146,188,38,246,170,32,118,148,228,45,249,77,178,215,36,207,166,54,251,150,205,31,72,246,138,108,204,224,123,25,214,111,35,167,183,1,160,12,223,245,235,18,70,102,228,77,83,95,126,155,230,64,238,109,151,151,213,200,106,112,225,79,146,186,117,29,108,27,55,189,205,102,195,30,246,36,111,99,11,30,67,187,232,7,104,185,153,145,39,63,110,76,56,48,252,80,151,222,176,252,99,219,43,151,162,177,187,157,35,222,195,211,147,249,197,207,97,220,142,167,141,89,92,241,248,49,141,249,11,48,53,14,172,
|
||||
120,156,133,146,221,138,219,48,16,133,95,69,208,77,73,210,36,104,70,146,45,203,20,2,221,244,135,66,123,81,122,37,212,216,113,148,98,234,218,105,228,192,182,33,239,94,201,142,155,165,100,89,95,72,150,124,230,204,153,15,107,114,119,71,103,244,5,125,230,81,247,118,151,31,171,214,232,146,115,153,230,40,210,31,31,63,39,169,47,7,95,206,98,96,82,48,224,24,249,5,24,160,64,198,65,98,194,37,99,146,42,215,30,142,69,91,182,246,167,209,21,74,153,162,175,68,95,137,177,64,136,185,228,18,88,44,209,27,32,165,72,99,20,192,153,68,161,182,214,21,70,83,47,103,94,158,68,44,161,64,105,12,64,25,198,148,9,14,192,208,91,96,140,64,133,178,245,246,255,140,161,21,127,54,100,76,85,209,108,109,31,241,125,148,134,142,34,144,17,145,159,63,242,113,56,167,190,52,244,229,12,24,69,38,32,17,145,218,216,239,101,109,244,105,125,30,173,62,205,191,126,33,154,156,78,16,160,45,25,209,142,166,68,79,151,99,196,100,194,201,234,97,223,212,182,110,
|
||||
203,188,90,253,58,230,109,217,212,198,156,207,47,141,118,44,29,205,73,120,129,84,221,144,101,42,83,69,149,59,167,188,76,47,199,116,65,23,40,196,132,116,151,102,173,167,55,205,215,106,253,88,188,63,110,170,178,8,106,159,205,235,253,161,108,255,137,67,119,76,187,16,33,53,222,114,36,7,187,63,88,231,47,29,201,107,98,175,10,98,7,73,238,200,111,146,189,38,121,54,181,217,183,108,254,64,178,87,100,99,46,190,253,176,97,27,56,189,29,3,202,201,187,110,93,194,192,140,188,105,234,254,183,105,14,228,222,182,121,89,13,172,68,239,194,159,36,117,235,122,188,109,252,244,54,155,93,246,73,71,242,54,182,241,99,104,189,254,2,45,55,51,242,228,199,141,153,92,24,126,168,203,96,88,254,177,238,202,165,104,236,110,231,137,119,240,244,104,222,251,121,140,219,225,180,49,139,43,158,128,193,152,191,52,209,14,177,
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ TOPIC("Rational1Equation$en-us")
|
|||
#include "Rational1Equation$en-us.tppi"
|
||||
END_TOPIC
|
||||
|
||||
TOPIC("RealExponentEquation$en-us")
|
||||
#include "RealExponentEquation$en-us.tppi"
|
||||
END_TOPIC
|
||||
|
||||
TOPIC("ScatterDraw$en-us")
|
||||
#include "ScatterDraw$en-us.tppi"
|
||||
END_TOPIC
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue