Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ScatterDraw & ScatterCtrl » Entirely Null series is drawn as a random constant line
Entirely Null series is drawn as a random constant line [message #56108] Wed, 27 January 2021 14:12 Go to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
Hi,

If you plot a series consisting of only Null values, it draws a constant line from x = -inf to inf at a random constant y value.
I am using AddSeries(double *, double *, size_t)

Since the data I plot is user-controlled, I would like it to just not plot anything in this case (but probably still have it in the legend).
I could pre-check for it myself, but I think it would be good to have this behaviour corrected in the library.
Re: Entirely Null series is drawn as a random constant line [message #56112 is a reply to message #56108] Thu, 28 January 2021 09:23 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hi Maginor

I have to recognize that a data series with only Nulls is a extreme case.
I couldn't reproduce the behaviour you say. However some changes have been done to improve the robustness to stand this case.

Please check it and tell us your feedback.
Thank you for inform us about this.


Best regards
Iñaki
Re: Entirely Null series is drawn as a random constant line [message #56125 is a reply to message #56108] Fri, 29 January 2021 13:53 Go to previous messageGo to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
That particular problem seems to have been fixed, but I have a new one:

When I draw lines and there are holes (Nulls) in the series, the holes are now filled with a line. I rely on the behaviour that this had before, where no lines are drawn between two values if there is a Null in between.

It also gets weirder, because if there is a hole at some point, values at later points where there are no holes sometimes also get janky.

I think this problem was not introduced now, but earlier last year (I have not updated upp since maybe January 2019) because another person who attempted to build my application with the upp distribution from some time in the autumn of 2020 reported this problem.


Examples:

Correct behaviour from the old version:
https://github.com/NIVANorge/Mobius/blob/master/Documentation/img/bug/old_tdp.png?raw=true

New behaviour on the same time series as above:
https://github.com/NIVANorge/Mobius/blob/master/Documentation/img/bug/new_tdp.png?raw=true

Correct behaviour from the old version:
https://github.com/NIVANorge/Mobius/blob/master/Documentation/img/bug/old_q.png?raw=true

New behaviour on the same time series as above:
https://github.com/NIVANorge/Mobius/blob/master/Documentation/img/bug/new_q.png?raw=true

Edit:
I right clicked and looked at Scatter Data to confirm that the actual background data is the same in both versions, so the problem is with the plotting.

Edit:
I don't really understand the jankyness that is displayed in the second example. It may not be related to the hole issue at all. It seems like it begins happening at a random point in the time series. Some times that is at the beginning of the time series, other times it starts in the middle somewhere. However it seems like that if two series have the same set of X values, the jankiness tends to begin at the same X value for both.
What I call the "jankyness" here is that it puts two y values for each X value (which is not how the data are), and it skips points in between.

Note that I use pretty high X values (they are number of seconds since a reference date, and the series can go over many years). So if values are somehow rounded to float or something like that, maybe that could be an issue, but that is just random guessing.


These are all added using
AddSeries(double *, double *, int);

Note that I use
SetFastViewX(true);
SetSequentialXAll(true);

[Updated on: Fri, 29 January 2021 15:18]

Report message to a moderator

Re: Entirely Null series is drawn as a random constant line [message #56135 is a reply to message #56125] Sun, 31 January 2021 09:52 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Maginor

I am not sure what is the best behaviour, if joining broken lines or not, although I think it may be 40/60 in favour to the second option.
About the weird plot, I would ask you to send me the data to try to reproduce that result.


Best regards
Iñaki
Re: Entirely Null series is drawn as a random constant line [message #56140 is a reply to message #56135] Sun, 31 January 2021 14:37 Go to previous messageGo to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
If you don't settle on having gaps in the line as a default, it would be very good to have it as an option. As I said, I rely on that in my application.

I have attached the data as a csv. Note that it is around 10'000 lines, and only the last 2/3 of the indexes have y-data in them. The ones that don't have any y-data should be given a y value of Null when you parse them.

You can parse it using something like the below (Sorry for not being upp idiomatic)

std::vector<double> xs, ys;

std::ifstream infile("data.csv");

std::string line;

std::getline(infile, line); //ignore first line

while (std::getline(infile, line))
{
    std::istringstream iss(line);
    double x, y;
    char c;
    if (iss >> x) 
    { xs.push_back(x); }
    else break;
    iss >> c;   //eat the semicolon
    if(iss >> y)
    { ys.push_back(y); }
    else ys.push_back(Null);
}
infile.close();

Plot.AddSeries(xs.data(), ys.data(), xs.size());
  • Attachment: data.csv
    (Size: 205.04KB, Downloaded 129 times)
Re: Entirely Null series is drawn as a random constant line [message #56153 is a reply to message #56140] Mon, 01 February 2021 11:21 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Maginor

I have uploaded the changes. The Null, NaN, Inf values are not plotted so the scatter area with them is empty, although you have to consider these cases:
- SetFastViewX(false) (default), if either X or Y are Null, the area between adjacent points will not be plotted
- SetFastViewX(true), as it requires, for being faster, that X values are valid:
-- if Y is Null, the area between adjacent points will not be plotted
-- if X is Null, adjacent valid points will be joined

A demo about this is included in ScatterDraw_demo.


Best regards
Iñaki
Re: Entirely Null series is drawn as a random constant line [message #56162 is a reply to message #56153] Tue, 02 February 2021 10:29 Go to previous messageGo to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
Hi,

Thank you for that! The gaps in the line are correct now.

The other problem (where it draws 2 Y values for one X value, then skips 9 points and does the same thing again) still happens on the series I sent you.
When I right click the series to see the underlying data, the data is correct.

Only Y values can be Null, all X values are valid.

It only happens with SetFastViewX(true). The skipping of points for fast view is correct when it is zoomed out, but it still happens when I zoom in, and it skips multiple pixels.

The plotting tends to be fast enough with fast view off, so I can just do that for now.

[Updated on: Tue, 02 February 2021 10:30]

Report message to a moderator

Re: Entirely Null series is drawn as a random constant line [message #56166 is a reply to message #56162] Tue, 02 February 2021 18:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Dear Maginor

I couldn't reproduce your results using your data in ScatterDraw. However reading you I suppose the problem is in ScatterCtrl.

Because of this especially in this special cases it is very important to include full code samples.

I will try to reproduce this problem with ScatterCtrl.


Best regards
Iñaki
Re: Entirely Null series is drawn as a random constant line [message #56167 is a reply to message #56166] Tue, 02 February 2021 19:12 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Dear Maginor

I couldn't reproduce your behaviour with ScatterCtrl. However I have fixed an error in CArray class.
Please check it again

index.php?t=getfile&id=6368&private=0


Best regards
Iñaki
Re: Entirely Null series is drawn as a random constant line [message #56172 is a reply to message #56108] Wed, 03 February 2021 11:02 Go to previous messageGo to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
Hi, sorry. I did not want to post my main code here since it is pretty entangled. I did not have time to produce a separate bug reproduction before now:

The styling on the line is not essential.
Compiled using Clang64 on Windows.
Using the 2021-02-02 nightly build.

The image is what it looks like when you zoom in using the mouse wheel.
index.php?t=getfile&id=6369&private=0


ScatterCtrlTest.lay:
LAYOUT(ScatterCtrlTestLayout, 916, 488)
	ITEM(Upp::ScatterCtrl, Plot, HSizePosZ(4, 4).VSizePosZ(4, 4))
END_LAYOUT



ScatterCtrlTest.h:
#ifndef _ScatterCtrlTest_ScatterCtrlTest_h
#define _ScatterCtrlTest_ScatterCtrlTest_h

#include <CtrlLib/CtrlLib.h>
#include <ScatterCtrl/ScatterCtrl.h>

using namespace Upp;

#define LAYOUTFILE <ScatterCtrlTest/ScatterCtrlTest.lay>
#include <CtrlCore/lay.h>

class ScatterCtrlTest : public WithScatterCtrlTestLayout<TopWindow> {
public:
	ScatterCtrlTest();
	
	std::vector<double> xs, ys;
};

#endif


ScatterCtrlTest.cpp:
#include "ScatterCtrlTest.h"

#include <fstream>

ScatterCtrlTest::ScatterCtrlTest()
{
	CtrlLayout(*this, "Window title");
	
	
	Plot.SetFastViewX(true);
	Plot.SetSequentialXAll(true);


	std::ifstream infile("data.csv");
	
	if(!infile) PromptOK("Failed opening file");
	
	std::string line;
	
	std::getline(infile, line); //ignore first line
	
	while (std::getline(infile, line))
	{
	    std::istringstream iss(line);
	    double x, y;
	    char c;
	    if (iss >> x) 
	    { xs.push_back(x); }
	    else break;
	    iss >> c;   //eat the semicolon
	    if(iss >> y)
	    { ys.push_back(y); }
	    else ys.push_back(Null);
	}
	infile.close();
	
	Color GraphColor(0, 130, 200);
	Plot.AddSeries(xs.data(), ys.data(), xs.size()).NoMark().Stroke(1.5, GraphColor).Dash("");
	Plot.ZoomToFit();
	Plot.Refresh();
}

GUI_APP_MAIN
{
	ScatterCtrlTest().Run();
}

Re: Entirely Null series is drawn as a random constant line [message #56173 is a reply to message #56172] Wed, 03 February 2021 12:41 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you Maginor for the test. It has been key to detect the problem. Hopefully fixed.

Best regards
Iñaki

[Updated on: Wed, 03 February 2021 15:50]

Report message to a moderator

Re: Entirely Null series is drawn as a random constant line [message #56266 is a reply to message #56108] Mon, 15 February 2021 10:10 Go to previous messageGo to next message
Maginor is currently offline  Maginor
Messages: 44
Registered: May 2019
Member
By the way, you left some code in the examples related to testing this... Smile

https://github.com/ultimatepp/ultimatepp/blob/master/example s/ScatterCtrl_Demo/tab14_UserEquation.cpp
Re: Entirely Null series is drawn as a random constant line [message #56272 is a reply to message #56266] Mon, 15 February 2021 18:04 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you for finding this error in the text message. However this is > 1 year older.

Best regards
Iñaki
Previous Topic: ScatterDraw::ExplicitRange
Next Topic: CtrlLib and ScatterDraw Layout Error.
Goto Forum:
  


Current Time: Thu Mar 28 18:56:47 CET 2024

Total time taken to generate the page: 0.01616 seconds