From ef0dece1ada12c91d02ce87d395530eef69fba44 Mon Sep 17 00:00:00 2001 From: koldo Date: Wed, 23 Sep 2020 14:59:36 +0000 Subject: [PATCH] ScatterDraw_Demo: Added spline git-svn-id: svn://ultimatepp.org/upp/trunk@15127 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- .../ScatterDraw_Demo/ScatterDraw_Demo.cpp | 71 ++++++++----------- .../ScatterDraw_Demo/ScatterDraw_Demo.upp | 3 +- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp b/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp index 0118b171b..c0b7aa358 100644 --- a/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp +++ b/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp @@ -3,6 +3,7 @@ using namespace Upp; #include +#include CONSOLE_APP_MAIN @@ -10,57 +11,43 @@ CONSOLE_APP_MAIN StdLogSetup(LOG_COUT|LOG_FILE); UppLog() << "\nScatterDraw_Demo"; - UppLog() << "\nScatter painted to Image and saved to file"; String fileName = GetExeDirFile("Scatter"); ScatterDraw scatter; - Vector s1; - double x[] = {20, 30, 40, 50, 60}; - double y[] = {34, 45, 49, 44, 56}; + Vector s1 = {{10,14}, {20,65}, {30,29}, {40,32}, {50,12}}; + Vector x = {20, 30, 40, 50, 60}; + Vector y = {34, 85, 49, 72, 56}; - scatter.SerializeData(true); + UppLog() << "\nPreparing scatter"; - bool loaded = false; - if (FileExists(fileName + ".xml")) { - LoadFromXMLFile(scatter, fileName + ".xml"); - loaded = true; - } else if (FileExists(fileName + ".json")) { - LoadFromJsonFile(scatter, fileName + ".json"); - loaded = true; - } else if (FileExists(fileName + ".bin")) { - LoadFromFile(scatter, fileName + ".bin"); - loaded = true; - } + scatter.AddSeries(s1).Legend("Series 1").NoPlot().Units("ºC", "seg"); + + scatter.AddSeries(x, y).Units("ºC", "seg").Legend("Series 2").Stroke(5, Null) + .Dash(LINE_DASHED).MarkStyle().MarkWidth(12); + + SplineEquation spline; + VectorPointf s1data(s1); + spline.Fit(s1data); + scatter.AddSeries(spline).Legend("Series 1 Softened").NoMark().Dash(LINE_SOLID).Stroke(1.5); + + scatter.SetXYMin(10, 0).SetRange(50, 100).SetMinUnits(20, 0).SetMajorUnits(10, 20); // Done by hand + + scatter.SetTitle("ScatterDraw_Demo").SetTitleFont(SansSerif(14).Bold()); + scatter.SetLabelY("Temperature").SetLabelX("Time").SetLabelsFont(SansSerif(12)); + scatter.SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(30).SetPlotAreaTopMargin(40).SetPlotAreaBottomMargin(50); + scatter.SetSize(Size(1000, 500)); + scatter.SetMode(ScatterDraw::MD_ANTIALIASED); + scatter.SetPlotAreaLeftMargin(70); + scatter.SetLegendAnchor(ScatterDraw::RIGHT_TOP); - if (loaded) { - UppLog() << "\nRead scatter from file"; - fileName = fileName + "+"; - } else { - UppLog() << "\nPreparing scatter"; - - s1 << Pointf(10,14) << Pointf(20,25) << Pointf(30,29) << Pointf(40,24) << Pointf(50,36); - - scatter.AddSeries(s1).Legend("Series 1").NoMark().Units("ºC", "seg"); - - scatter.AddSeries(x, y, 5).Units("ºC", "seg").Legend("Series 2").Stroke(5, Null) - .Dash(LINE_DASHED).MarkStyle().MarkWidth(12); - - scatter.SetXYMin(10, 0).SetRange(50, 100).SetMinUnits(20, 0).SetMajorUnits(10, 20); // Done by hand - //scatter.ZoomToFit(); // Done automatically - - scatter.SetTitle("ScatterDraw_Demo").SetTitleFont(SansSerif(14).Bold()); - scatter.SetLabelY("Temperature").SetLabelX("Time").SetLabelsFont(SansSerif(12)); - scatter.SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(30).SetPlotAreaTopMargin(40).SetPlotAreaBottomMargin(50); - scatter.SetSize(Size(1000, 500)); - scatter.SetMode(ScatterDraw::MD_ANTIALIASED); - scatter.SetLegendAnchor(ScatterDraw::RIGHT_TOP); - } PNGEncoder().SaveFile(fileName + ".png", scatter.GetImage()); - StoreAsJsonFile(scatter, fileName + ".json", true); - StoreAsXMLFile(scatter, "Scatter", fileName + ".xml"); - StoreToFile(scatter, fileName + ".bin"); + PdfDraw pdf(Size(1000, 500)); + scatter.SetSize(Size(1000, 500)); + scatter.SetDrawing(pdf, false); + SaveFile(fileName + ".pdf", pdf.Finish()); + UppLog() << "\nSaved '" << fileName << "'"; #ifdef flagDEBUG Cout() << "\nPress enter key to end"; diff --git a/reference/ScatterDraw_Demo/ScatterDraw_Demo.upp b/reference/ScatterDraw_Demo/ScatterDraw_Demo.upp index f1c8619ff..8493d3fbc 100644 --- a/reference/ScatterDraw_Demo/ScatterDraw_Demo.upp +++ b/reference/ScatterDraw_Demo/ScatterDraw_Demo.upp @@ -3,7 +3,8 @@ description "Scatter series without GUI\377"; uses Core, ScatterDraw, - plugin\png; + plugin\png, + PdfDraw; file ScatterDraw_Demo.cpp;