diff --git a/uppsrc/ScatterDraw/DrawingFunctions.h b/uppsrc/ScatterDraw/DrawingFunctions.h index 7eee3f185..189c3e686 100644 --- a/uppsrc/ScatterDraw/DrawingFunctions.h +++ b/uppsrc/ScatterDraw/DrawingFunctions.h @@ -3,16 +3,16 @@ void DrawLine(Draw &w, double x0, double y0, double x1, double y1, double width, const Color &color); void DrawLine(Painter &w, double x0, double y0, double x1, double y1, double width, const Color &color); -void DrawLineOpa(Draw& w, int x0, int y0, int x1, int y1, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); -void DrawLineOpa(Painter& w, int x0, int y0, int x1, int y1, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); -void DrawCircleOpa(Draw& w, int x, int y, int r, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); -void DrawCircleOpa(Painter& w, int x, int y, int r, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); +void DrawLineOpa(Draw& w, double x0, double y0, double x1, double y1, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); +void DrawLineOpa(Painter& w, double x0, double y0, double x1, double y1, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); +void DrawCircleOpa(Draw& w, double x, double y, double r, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); +void DrawCircleOpa(Painter& w, double x, double y, double r, int scale, double opacity, double thick, const Color &_color, String pattern, const Color &background = Null); void FillRectangleOpa(Draw &w, double x0, double y0, double x1, double y1, int scale, double opacity, const Color &background, const Color &color); void FillRectangleOpa(Painter &w, double x0, double y0, double x1, double y1, int scale, double opacity, const Color &background, const Color &color); -void DrawPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, double thick, const Color &color, String pattern = "", const Color &background = Null); -void DrawPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, double thick, const Color &color, String pattern = "", const Color &background = Null); -void FillPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor); -void FillPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor); +void DrawPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, double thick, const Color &color, String pattern = "", const Color &background = Null); +void DrawPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, double thick, const Color &color, String pattern = "", const Color &background = Null); +void FillPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor); +void FillPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor); void DrawVArrow(Draw &w, double x0, double y0, double x1, double y1, double width, double aWidth, double aHeight, const Color &color); void DrawVArrow(Painter &w, double x0, double y0, double x1, double y1, double width, double aWidth, double aHeight, const Color &color); void DrawHArrow(Draw &w, double x0, double y0, double x1, double y1, double width, double aWidth, double aHeight, const Color &color); diff --git a/uppsrc/ScatterDraw/ScatterDraw.cpp b/uppsrc/ScatterDraw/ScatterDraw.cpp index 9902ae04c..54bdc1f20 100644 --- a/uppsrc/ScatterDraw/ScatterDraw.cpp +++ b/uppsrc/ScatterDraw/ScatterDraw.cpp @@ -243,14 +243,14 @@ void ScatterDraw::DrawLegend(Draw& w, const Size &size, int scale) const { scaledFont.Bold(); for(int row = 0, start = 0; row <= nrows; row++) { for(int i = start; i < min(start + nlr, nlab); i++) { - int lx = rect.left + (i - start)*legendWidth + xWidth; - int ly = (rowIncSign >= 0 ? rect.top : rect.bottom) + + double lx = rect.left + (i - start)*legendWidth + xWidth; + double ly = (rowIncSign >= 0 ? rect.top : rect.bottom) + rowIncSign*int(rowHeight*(row + 0.6) + loclegendRowSpacing*(row + 0.5)); - Vector line; - line << Point(lx, ly) << Point(lx + lineLen, ly); + Vector line; + line << Pointf(lx, ly) << Pointf(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 + xWidth/*scale*7*/, ly); + Pointf 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); @@ -1710,18 +1710,18 @@ void ClipEnd(Painter &w) { ; } -void DrawLineOpa(Draw& w, int x0, int y0, int x1, int y1, int scale, double opacity, +void DrawLineOpa(Draw& w, double x0, double y0, double x1, double y1, int scale, double opacity, double thick, const Color &_color, String dash, const Color &background) { - Vector p; - p << Point(x0, y0) << Point(x1, y1); + Vector p; + p << Pointf(x0, y0) << Pointf(x1, y1); DrawPolylineOpa(w, p, scale, opacity, thick, _color, dash, background); } -void DrawCircleOpa(Draw& w, int x, int y, int r, int scale, double opacity, +void DrawCircleOpa(Draw& w, double x, double y, double r, int scale, double opacity, double thick, const Color &_color, String dash, const Color &background) { - Vector p; + Vector p; for (double ang = 0; ang <= 2*M_PI; ang += 2*M_PI/50) - p << Point(fround(x + r*cos(ang)), fround(y + r*sin(ang))); + p << Pointf(fround(x + r*cos(ang)), fround(y + r*sin(ang))); DrawPolylineOpa(w, p, scale, opacity, thick, _color, dash, background); } @@ -1742,7 +1742,7 @@ void DashScaled(Painter& w, const String dash, double scale) { } } -void DrawLineOpa(Painter& w, int x0, int y0, int x1, int y1, int scale, +void DrawLineOpa(Painter& w, double x0, double y0, double x1, double y1, int scale, double opacity, double thick, const Color &color, String dash, const Color &background) { w.Move(Pointf(x0, y0)); @@ -1752,7 +1752,7 @@ void DrawLineOpa(Painter& w, int x0, int y0, int x1, int y1, int scale, w.Stroke(thick*scale, color); } -void DrawCircleOpa(Painter& w, int x, int y, int r, int scale, +void DrawCircleOpa(Painter& w, double x, double y, double r, int scale, double opacity, double thick, const Color &color, String dash, const Color &background) { w.Circle(x, y, r); @@ -1780,13 +1780,15 @@ void FillRectangleOpa(Painter &w, double x0, double y0, double x1, double y1, in w.Rectangle(x0, y0, x1 - x0, y1 - y0).Opacity(opacity).Fill(color); } -void DrawPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, +void DrawPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, double thick, const Color &_color, String dash, const Color &background) { ASSERT(!p.IsEmpty()); Color color = GetOpaqueColor(_color, background, opacity) ; - if (dash == LINE_SOLID) - w.DrawPolyline(p, fround(thick*scale), color); - else { + if (dash == LINE_SOLID) { + //w.DrawPolyline(p, fround(thick*scale), color); + for (int i = 1; i < p.GetCount(); ++i) + w.DrawLine(p[i-1], p[i], fround(thick*scale), color); + } else { Vector &pat = GetDashedArray(dash); if (pat.IsEmpty()) return; @@ -1817,7 +1819,7 @@ void DrawPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, } } -void DrawPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, +void DrawPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, double thick, const Color &color, String dash, const Color &background) { ASSERT(!p.IsEmpty()); w.Move(p[0]); @@ -1828,15 +1830,21 @@ void DrawPolylineOpa(Painter& w, const Vector &p, int scale, double opaci w.Stroke(thick*scale, color); } -void FillPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, +void FillPolylineOpa(Draw& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor) { ASSERT(!p.IsEmpty()); Color opacolor = GetOpaqueColor(fillColor, background, opacity) ; - w.DrawPolygon(p, opacolor); + Vector pi; + pi.SetCount(p.GetCount()); + for (int i = 0; i < pi.GetCount(); ++i) { + pi[i].x = (int)p[i].x; + pi[i].y = (int)p[i].y; + } + w.DrawPolygon(pi, opacolor); } -void FillPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, +void FillPolylineOpa(Painter& w, const Vector &p, int scale, double opacity, const Color &background, const Color &fillColor) { ASSERT(!p.IsEmpty()); w.Move(p[0]); diff --git a/uppsrc/ScatterDraw/ScatterDraw.h b/uppsrc/ScatterDraw/ScatterDraw.h index ac7a03a2f..ce8b12e9b 100644 --- a/uppsrc/ScatterDraw/ScatterDraw.h +++ b/uppsrc/ScatterDraw/ScatterDraw.h @@ -117,6 +117,9 @@ protected: static String GetNewDash(int index); static MarkPlot *GetNewMarkPlot(int index); + void WhenPaint(Painter &w) {WhenPainter(w);} + void WhenPaint(Draw &w) {WhenDraw(w);} + public: Callback3 cbModifFormatX; Callback3 cbModifFormatDeltaX; @@ -128,6 +131,8 @@ public: Callback WhenZoomScroll; Callback WhenSetRange; Callback WhenSetXYMin; + Callback1 WhenPainter; + Callback1 WhenDraw; ScatterDraw& SetSize(Size sz) {size = sz; return *this;}; virtual Size GetSize() const {return size;}; @@ -491,6 +496,24 @@ public: ScatterDraw& LinkedWith(ScatterDraw& ctrl); void Unlinked(); + int GetPlotWidth() {return plotW;} + int GetPlotHeight() {return plotH;} + Pointf GetPosPrimary(double x, double y) { + Pointf ret; + ret.x = plotW*(x - xMin)/xRange; + ret.y = plotH - plotH*(y - yMin)/yRange; + return ret; + } + double GetSizeX(double cx) {return plotW*cx/xRange;} + double GetSizeYPrimary(double cy) {return plotH*cy/yRange;} + Pointf GetPosSecondary(double x, double y) { + Pointf ret; + ret.x = plotW*(x - xMin)/xRange; + ret.y = plotH - plotH*(y - yMin2)/yRange2; + return ret; + } + double GetSizeYSecondary(double cy) {return plotH*cy/yRange2;} + protected: ScatterDraw &_AddSeries(DataSource *data); virtual void Refresh() {}; @@ -826,7 +849,7 @@ void ScatterDraw::Plot(T& w, const Size &size, int scale) if (series[j].opacity == 0 || (!series[j].seriesPlot && !series[j].markPlot) || (!series[j].PointsData()->IsExplicit() && series[j].PointsData()->GetCount() == 0)) continue; - Vector points; + Vector points; if (series[j].PointsData()->IsParam()) { double xmin = 0; double xmax = double(series[j].PointsData()->GetCount()); @@ -992,9 +1015,11 @@ void ScatterDraw::Plot(T& w, const Size &size, int scale) ASSERT_(true, error); } } + WhenPaint(w); ClipEnd(w); w.End(); } + #endif diff --git a/uppsrc/ScatterDraw/SeriesPlot.h b/uppsrc/ScatterDraw/SeriesPlot.h index 1f14458ef..b20dac345 100644 --- a/uppsrc/ScatterDraw/SeriesPlot.h +++ b/uppsrc/ScatterDraw/SeriesPlot.h @@ -4,10 +4,10 @@ class SeriesPlot { public: virtual ~SeriesPlot() {}; - virtual void Paint(Draw& w, Vector &p, const int &scale, const double opacity, + virtual void Paint(Draw& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, double fy, int y0) const {}; - virtual void Paint(Painter& w, Vector &p, const int &scale, const double opacity, + virtual void Paint(Painter& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, double fy, int y0) const {}; template @@ -42,15 +42,15 @@ protected: class LineSeriesPlot : public SeriesPlot { private: template - void DoPaint(T& w, Vector &p, const int &scale, const double opacity, + void DoPaint(T& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, int y0) const { if (!IsNull(fillColor)) { - int x = p[0].x; - p.Insert(0, Point(x, y0)); + double x = p[0].x; + p.Insert(0, Pointf(x, y0)); x = p[p.GetCount() - 1].x; - p.Add(Point(x, y0)); + p.Add(Pointf(x, y0)); FillPolylineOpa(w, p, scale, opacity, background, fillColor); p.Remove(0); p.Remove(p.GetCount() - 1); @@ -59,13 +59,13 @@ private: } public: - void Paint(Draw& w, Vector &p, const int &scale, const double opacity, + void Paint(Draw& w, Vector &p, const int &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); } - void Paint(Painter& w, Vector &p, const int &scale, const double opacity, + void Paint(Painter& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, double fy, int y0) const { @@ -77,12 +77,12 @@ public: class StaggeredSeriesPlot : public SeriesPlot { private: template - void DoPaint(T& w, Vector &p, const int &scale, const double opacity, + void DoPaint(T& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, int y0) const { ASSERT(p.GetCount() > 1); - Vector ps; + Vector ps; ps << Pointf(p[0].x - (p[1].x - p[0].x)/2., p[0].y); for (int i = 1; i < p.GetCount(); ++i) { double x = (p[i].x + p[i-1].x)/2.; @@ -91,10 +91,10 @@ private: } ps << Pointf(p[p.GetCount() - 1].x + (p[p.GetCount() - 1].x - p[p.GetCount() - 2].x)/2., p[p.GetCount() - 1].y); if (!IsNull(fillColor)) { - int x = ps[0].x; - ps.Insert(0, Point(x, y0)); + double x = ps[0].x; + ps.Insert(0, Pointf(x, y0)); x = ps[ps.GetCount() - 1].x; - ps.Add(Point(x, y0)); + ps.Add(Pointf(x, y0)); FillPolylineOpa(w, ps, scale, opacity, background, fillColor); ps.Remove(0); ps.Remove(ps.GetCount() - 1); @@ -103,13 +103,13 @@ private: } public: - void Paint(Draw& w, Vector &p, const int &scale, const double opacity, + void Paint(Draw& w, Vector &p, const int &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, thick, color, pattern, background, fillColor, y0); } - void Paint(Painter& w, Vector &p, const int &scale, const double opacity, + void Paint(Painter& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, double fy, int y0) const { @@ -120,13 +120,13 @@ public: class BarSeriesPlot : public SeriesPlot { private: template - void DoPaint(T& w, Vector &p, const int &scale, const double opacity, + void DoPaint(T& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, int y0) const { for (int i = 0; i < p.GetCount(); ++i) { FillRectangleOpa(w, p[i].x - width*fx, y0, p[i].x + width*fx, p[i].y, scale, opacity, background, fillColor); - Vector ps; + Vector ps; ps << Pointf(fround(p[i].x - width*fx), y0) << Pointf(fround(p[i].x - width*fx), p[i].y) << Pointf(fround(p[i].x + width*fx), p[i].y) << Pointf(fround(p[i].x + width*fx), y0); DrawPolylineOpa(w, ps, scale, 1, fround(thick), color, pattern, background); @@ -137,13 +137,13 @@ private: public: BarSeriesPlot(double width) : width(width) {}; BarSeriesPlot() {}; - void Paint(Draw& w, Vector &p, const int &scale, const double opacity, + void Paint(Draw& w, Vector &p, const int &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, thick, color, pattern, background, fillColor, fx, y0); } - void Paint(Painter& w, Vector &p, const int &scale, const double opacity, + void Paint(Painter& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, double fx, double fy, int y0) const {