ScatterDraw: Improved legend drawing and avoided aliasing in plots

git-svn-id: svn://ultimatepp.org/upp/trunk@10580 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2016-12-25 16:05:53 +00:00
parent 42459d602a
commit 06c3dc883c
2 changed files with 34 additions and 14 deletions

View file

@ -160,6 +160,7 @@ void ScatterDraw::DrawLegend(Draw& w, const Size &size, int scale) const {
return;
Font scaledFont = GetStdFont();
int rowHeight = scale*GetStdFont().GetHeight();
int rowAscent = scale*GetStdFont().GetAscent();
scaledFont.Height(rowHeight);
int xWidth = scaledFont.GetWidth('X');
int lineLen = 4*xWidth;
@ -173,7 +174,7 @@ void ScatterDraw::DrawLegend(Draw& w, const Size &size, int scale) const {
legends.Add(legend);
legendWidth = max<int>(legendWidth, GetTextSize(legend, scaledFont).cx);
}
legendWidth += lineLen + 3*xWidth;
legendWidth += lineLen + 4*xWidth;
int rowIncSign;
int plotW, plotH;
@ -251,12 +252,12 @@ void ScatterDraw::DrawLegend(Draw& w, const Size &size, int scale) const {
line << Point(lx, ly) << Point(lx + lineLen, ly);
if (series[i].opacity > 0 && series[i].seriesPlot)
DrawPolylineOpa(w, line, scale, 1, series[i].thickness, series[i].color, series[i].dash);
Point mark_p(lx + scale*7, ly);
Point mark_p(lx + xWidth/*scale*7*/, ly);
if (series[i].markWidth >= 1 && series[i].markPlot)
series[i].markPlot->Paint(w, scale, mark_p, series[i].markWidth, series[i].markColor,
series[i].markBorderWidth, series[i].markBorderColor);
Font &font = series[i].primaryY ? scaledFont : italic;
DrawText(w, lx + lineLen + xWidth, ly - scale*6, 0, legends[i], font, series[i].color);
DrawText(w, lx + lineLen + xWidth, ly - int((2*rowAscent)/3)/*scale*6*/, 0, legends[i], font, series[i].color);
}
start += nlr;
}

View file

@ -200,8 +200,8 @@ public:
double GetYMinUnit () const {return yMinUnit;}
double GetYMinUnit2 () const {return yMinUnit2;}
ScatterDraw& SetXYMin(double xmin,double ymin,double ymin2 = 0);
ScatterDraw& SetXYMinLinked(double xmin,double ymin,double ymin2 = 0);
ScatterDraw& SetXYMin(double xmin, double ymin = Null, double ymin2 = Null);
ScatterDraw& SetXYMinLinked(double xmin, double ymin = Null, double ymin2 = Null);
double GetXMin () const {return xMin;}
double GetYMin () const {return yMin;}
double GetYMin2 () const {return yMin2;}
@ -862,13 +862,16 @@ void ScatterDraw::Plot(T& w, const Size &size, int scale)
}
int64 ii;
double maxv = dxpix*npix;
double maxY = yy, minY = yy;
for (ii = 1; i + ii < imax && series[j].PointsData()->x(i + ii) < maxv; ++ii) {
double dd = series[j].PointsData()->y(i + ii);
if (IsNull(dd))
continue;
yy += dd;
//yy += dd;
maxY = max(maxY, dd);
minY = min(minY, dd);
}
yy /= double(ii);
//yy /= double(ii);
xx = series[j].PointsData()->x(i);
if (IsNull(xx)) {
++i;
@ -876,6 +879,22 @@ void ScatterDraw::Plot(T& w, const Size &size, int scale)
}
i += ii;
npix++;
int ix = fround(plotW*(xx - xMin)/xRange);
//int iy;
int iMax, iMin;
if (series[j].primaryY) {
//iy = fround(plotH*(yy - yMin)/yRange);
iMax = fround(plotH*(maxY - yMin)/yRange);
iMin = fround(plotH*(minY - yMin)/yRange);
} else {
//iy = fround(plotH*(yy - yMin2)/yRange2);
iMax = fround(plotH*(maxY - yMin2)/yRange2);
iMin = fround(plotH*(minY - yMin2)/yRange2);
}
points << Point(ix, plotH - iMax);
if (iMax != iMin)
points << Point(ix, plotH - iMin);
//points << Point(ix, plotH - iy);
} else {
xx = series[j].PointsData()->x(i);
yy = series[j].PointsData()->y(i);
@ -884,14 +903,14 @@ void ScatterDraw::Plot(T& w, const Size &size, int scale)
//++i;
continue;
}
int ix = fround(plotW*(xx - xMin)/xRange);
int iy;
if (series[j].primaryY)
iy = fround(plotH*(yy - yMin)/yRange);
else
iy = fround(plotH*(yy - yMin2)/yRange2);
points << Point(ix, plotH - iy);
}
int ix = fround(plotW*(xx - xMin)/xRange);
int iy;
if (series[j].primaryY)
iy = fround(plotH*(yy - yMin)/yRange);
else
iy = fround(plotH*(yy - yMin2)/yRange2);
points << Point(ix, plotH - iy);
}
}
if (!points.IsEmpty() && series[j].seriesPlot)