From 09b083a08cec47d656e3eeeefcae8c537b2a3fd7 Mon Sep 17 00:00:00 2001 From: koldo Date: Mon, 18 Dec 2017 12:54:51 +0000 Subject: [PATCH] ScatterDraw_Demo: Some fixes and improvements git-svn-id: svn://ultimatepp.org/upp/trunk@11579 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- .../ScatterDraw_Demo/ScatterDraw_Demo.cpp | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp b/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp index d96dbe205..0a907b8f5 100644 --- a/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp +++ b/reference/ScatterDraw_Demo/ScatterDraw_Demo.cpp @@ -8,31 +8,56 @@ using namespace Upp; CONSOLE_APP_MAIN { Cout() << "\nScatterDraw_Demo"; - Cout() << "\n\nScatter painted to Image and saved to file"; + Cout() << "\nScatter painted to Image and saved to file"; + + String fileName = AppendFileName(GetDesktopFolder(), "Scatter"); ScatterDraw scatter; Vector s1; - 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"); - double x[] = {20, 30, 40, 50, 60}; double y[] = {34, 45, 49, 44, 56}; - scatter.AddSeries(x, y, 5).Units("ºC", "seg").Legend("Series 2").Stroke(5, Null) - .Dash(LINE_DASHED).MarkStyle().MarkWidth(12); - scatter.ZoomToFit(); + scatter.SerializeData(true); - 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::LEGEND_ANCHOR_RIGHT_TOP); + 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; + } - String fileName = AppendFileName(GetDesktopFolder(), "Scatter.png"); - PNGEncoder().SaveFile(fileName, scatter.GetImage()); + if (loaded) { + Cout() << "\nRead scatter from file"; + fileName = fileName + "+"; + } else { + Cout() << "\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.ZoomToFit(); + + 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::LEGEND_ANCHOR_RIGHT_TOP); + } + PNGEncoder().SaveFile(fileName + ".png", scatter.GetImage()); + StoreAsJsonFile(scatter, fileName + ".json", true); + StoreAsXMLFile(scatter, "Scatter", fileName + ".xml"); + StoreToFile(scatter, fileName + ".bin"); - Cout() << "\n\nSaved '" << ToSystemCharset(fileName) << "'"; - Cout() << "\n\nPress key to end"; - getchar(); + Cout() << "\nSaved '" << fileName << "'"; + Cout() << "\nPress key to end"; + ReadStdIn(); }