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 » Developing U++ » UppHub » Scatter : getDrawing !!!! help !!!!
Scatter : getDrawing !!!! help !!!! [message #29013] Sat, 02 October 2010 00:37 Go to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi all,

I'm trying to use the scatter ctrl in order to retreive the drawing that I will insert in a report.

When I put a scatter class in the layout designer, all displays right.
But when I use GetDrawing on another scatter instance with same data and config, all fonts are very small and the data points aren't visible any more (to small I think).

What method should be called in order get the same results as displayed on the screen when used as a control ?

I have to admit I don't understand anything about the zoom functions in controls FontZ, xxxxZ, .....
How does all this work ?
Re: Scatter : getDrawing !!!! help !!!! [message #29022 is a reply to message #29013] Sat, 02 October 2010 14:05 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Didier

Maybe this could serve you:

Report r;

r.NewPage();
Topic t = GetTopic("topic://MyPackage/MyReport$en-en");
String qtf = t.text;	
Image image = scatter.GetImage(2);
{
	DrawingDraw dw(width, height);
	dw.DrawImage(0, 0, width, height, image);
	QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(width, height), Size(width, height)));

	String qtfG;
	String token = "[Graph]"
	int pos = qtf.Find(DeQtf(token));
	qtfG << qtf.Left(pos) << pict << qtf.Mid(token.GetCount());
	
	r << qtfG;
}


The report design is done in Topic t, that contains a "[Graph]" to be replaced by the Scatter in image.


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29027 is a reply to message #29022] Sat, 02 October 2010 17:14 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

As a matter of fact , I added a 'AddDrawing' method to my report generator package:

void ReportGenerator::replaceDrawing(const StringType& label, const Upp::Drawing& inputDrw, Upp::Size destSize )
{
	Upp::String s;
	if (!inputDrw.IsNullInstance() )
	{
		if (destSize.cy != 0)
		{
			if ( inputDrw.GetSize().cx*100/inputDrw.GetSize().cy > destSize.cx*100/destSize.cy )
			{
				s << AsQTF(CreateDrawingObject(inputDrw, destSize.cx,0));
			}
			else
			{
				s << AsQTF(CreateDrawingObject(inputDrw, 0, destSize.cy));
			}
		}
		else
		{
			s << AsQTF(CreateDrawingObject(inputDrw));
		}
	}
	else
	{
		replaceImage(label, ReportGeneratorImg::EMPTY_IMG(), destSize);
	}
	replaceVar(label,s);
};


The code is inspired from another Upp package from Sergei I think.
I preferred to use the a DrawingObject object instead of passing by an intermediate Image like in you're example: this keeps the pdf files as light as possible.

This works very well with the PieChart ctrl (see the sample report I joined ) but with the Scatter ctrl, it doesn't work: I see the graph but the points are to small to appear and the fonts are almost unreadable Sad

I know something is done when CtrlLayoutxxx() methods are called but I don't understand the philosophy of the 'xxxZxxx()' methods which are used to counter the problem I have and since the PieChart and Scatter don't behave the same ... I'm stuck for the moment

BTW: the report joined is completely generated from SQL data including images and charts.

[Updated on: Sat, 02 October 2010 17:29]

Report message to a moderator

Re: Scatter : getDrawing !!!! help !!!! [message #29030 is a reply to message #29027] Sat, 02 October 2010 21:26 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Sorry Didier

I cannot see where is the Scatter in your code.

Could you include a test case?


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29031 is a reply to message #29030] Sat, 02 October 2010 22:21 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I've been looking in to it this after noon, and there is a bug in Scatter.

The CIRCLE mark seems to malfunction in some circumstances: other marks look good while circle doesn't appear ??.
As far as I've looked, it seems that there are some "magic numbers" in the Scatter ctrl.

Foe example:
Drawing Scatter::GetDrawing() const
{
	DrawingDraw ddw(6*GetSize());
	SetDrawing (ddw, 6);
	return ddw;
}


What is the '6' value for ???
While in the 'GetImage()' function, there is a scale parameter...

I'll make a test case (some other magic numbers are hanging around I think).

Asta luego
Re: Scatter : getDrawing !!!! help !!!! [message #29032 is a reply to message #29031] Sat, 02 October 2010 23:48 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Didier

I have included GetDrawing() (excellent idea, the pdfs are smaller now Smile), and it have worked very well for me, including circles. I have changed the Drawing scale and the results have been the same, I cannot find "magic" numbers Smile.

The previous code is now simpler:

Report r;

r.NewPage();
Topic t = GetTopic("topic://MyPackage/MyReport$en-en");
String qtf = t.text;	
Drawing drw = scatter.GetDrawing();
{
	QtfRichObject pict(CreateDrawingObject(drw, Size(width, height), Size(width, height)));

	String qtfG;
	String token = "[Graph]"
	int pos = qtf.Find(DeQtf(token));
	qtfG << qtf.Left(pos) << pict << qtf.Mid(token.GetCount());
	
	r << qtfG;
}


I think scaling is much less important in a Drawing than in a Image.

Could you include a simple test case?





Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29042 is a reply to message #29032] Sun, 03 October 2010 11:40 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

In fact I had two problems:
- One with the font sizes ==> I corrected this one by adding
graph1.SetRect(0,0,600,350);

the default size was to big, so when resizing ... the fonts got to small Embarassed

- Display of CIRCLE marks: ==> this one is still hanging around.

I'm doing a test case and it works for the moment ....
I think my problem is linked to the fact that the image is inserted inside a table.

A small correction in scatter makes it work again:
void Scatter::Circle(Draw& w, const int& scale, const Point& cp, const int& size, const class::Color& markColor)const
{
	Point cp2 = cp;
	cp2.x++;
	w.DrawLine(cp,cp2,fround(scale*size/6),markColor);
}


I will enhance my test case and check this today ...



Re: Scatter : getDrawing !!!! help !!!! [message #29043 is a reply to message #29042] Sun, 03 October 2010 12:53 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I've finished my test case but it still works as it should ?!?

I also modified my app in order to execute the same code when displaying the report and I have some differences:
- the lines don't get displayed the same way (and circles are drawn using lines)

I joined an image to show what I'm talking about.
index.php?t=getfile&id=2864&private=0

It loks like my app has some different settings ( DPI or something like that ??) which modifies line drawing.
But I never touch such parameters (at least not intentionally )

What do you think ?
Re: Scatter : getDrawing !!!! help !!!! [message #29056 is a reply to message #29043] Sun, 03 October 2010 20:43 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Didier

To answer you something useful I need desperately a test sample Smile.


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29057 is a reply to message #29056] Sun, 03 October 2010 21:03 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I found the problem: it's linked with the Painter package.

I made a test case:
- without Painter : all is OK
- With Painter ... Points are not displayed and grid isn't displayed correctly.

NB: A complete rebuild must be done when adding/removing Painter package in order to see the effects.

In my test case I use Replace() function to get as close as possible to Report generation.

So is it a Scatter bug, a Painter bug ???

Re: Scatter : getDrawing !!!! help !!!! [message #29063 is a reply to message #29057] Mon, 04 October 2010 10:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Didier

Well done!. Now it has been easier to find the problem.

This the old circle implementation:
w.DrawLine(cp,cp,fround(scale*size/6),markColor);

and this is the new:
w.DrawLine(cp.x,cp.y,cp.x+1,cp.y,fround(scale*size/6),markColor);

As line length was 0, Draw painted it but Painter does not Smile.


Best regards
Iñaki

[Updated on: Mon, 04 October 2010 10:24]

Report message to a moderator

Re: Scatter : getDrawing !!!! help !!!! [message #29094 is a reply to message #29063] Mon, 04 October 2010 23:18 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

Thank's for the quick reply, but ... I already tried this one:
{
	Point cp2 = cp;
	cp2.x++;
	w.DrawLine(cp,cp2,fround(scale*size/6),markColor);
}

And although it seems to work at first, some points don't get drawn (because of rounding probably).
So it's not sufficient and anyway the grid doesn't display correctly neither.
==> Maybe this is more a Painter issue with line drawing.

Also drawing a real circle, although much less efficient, would be a better solution for the CIRCLE mark I think

One good point: no matter if Painter is here or not, the Pdf export function creates the same output (which is correct).


Re: Scatter : getDrawing !!!! help !!!! [message #29099 is a reply to message #29094] Tue, 05 October 2010 08:10 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Didier

some points don't get drawn
I will draw circles instead of short lines.

and anyway the grid doesn't display correctly neither
I think you say gray grid is straight lines, without dashes in Painter and Pdf...I know why Smile. It is not a problem of Painter or Scatter. This is because Draw does not support dashed lines... well yes, with a trick in the color.
Today I will insert real dashed lines Smile.


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29113 is a reply to message #29099] Tue, 05 October 2010 19:03 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

Fantastic Cool

I didn't known Draw didn't support dashed lines.

What is the trick with dashes and colors ?
Re: Scatter : getDrawing !!!! help !!!! [message #29115 is a reply to message #29113] Tue, 05 October 2010 23:32 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Didier wrote on Tue, 05 October 2010 19:03

Hi Koldo,

Fantastic Cool

I didn't known Draw didn't support dashed lines.

What is the trick with dashes and colors ?

Hello Didier

Sorry, it is not colors, it is line width. A line with negative width means that is dashed.

Look at http://www.ultimatepp.org/src$Draw$Draw$en-us.html in DrawLineOp().

However this Draw behavior is lost in Painter and Pdf. This is the reason the grid was lost.


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29134 is a reply to message #29115] Wed, 06 October 2010 22:24 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

Now even with Painter package, CIRCLE and grid polyline work

I have to admit I didn't expect you would go into drawing each individal dash Wink

Tchao !
Re: Scatter : getDrawing !!!! help !!!! [message #29136 is a reply to message #29134] Thu, 07 October 2010 08:29 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Yes Didier

I have to admit I didn't expect you would go into drawing each individual dash
If somebody wants dashed lines and works in Draw, s/he can take the code from Scatter. The code also cares that dashed lines goes "softly" in polylines.


Best regards
Iñaki
Re: Scatter : getDrawing !!!! help !!!! [message #29156 is a reply to message #29136] Thu, 07 October 2010 22:43 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

After taking a look at PlotCtrl, I saw that it had dashes while having Painter.
So I looked at the code and found out that Painter supports dashes (they are drawn exactly the same way you did):
inline Painter& Painter::Dash(const Vector<double>& dash, double start)
{
	if(dash.GetCount() & 1) {
		Vector<double> dash1;
		dash1.Append(dash);
		dash1.Append(dash);
		DashOp(dash1, start);
	}
	else
		DashOp(dash, start);
	return *this;
}


Though you would appreciate this info Wink

Re: Scatter : getDrawing !!!! help !!!! [message #29158 is a reply to message #29156] Fri, 08 October 2010 08:23 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Didier wrote on Thu, 07 October 2010 22:43

Hi Koldo,

After taking a look at PlotCtrl, I saw that it had dashes while having Painter.
So I looked at the code and found out that Painter supports dashes (they are drawn exactly the same way you did):
inline Painter& Painter::Dash(const Vector<double>& dash, double start)
{
	if(dash.GetCount() & 1) {
		Vector<double> dash1;
		dash1.Append(dash);
		dash1.Append(dash);
		DashOp(dash1, start);
	}
	else
		DashOp(dash, start);
	return *this;
}


Though you would appreciate this info Wink



Hello Didier

Quote:

If somebody wants dashed lines and works in Draw
Yes, I know Painter includes dashes Smile. As Draw does not include them, I added them.

To be as fast as possible, Scatter uses Draw.


Best regards
Iñaki
Previous Topic: Scatter: Propose to add new methods
Next Topic: Themes
Goto Forum:
  


Current Time: Fri Mar 29 05:56:20 CET 2024

Total time taken to generate the page: 0.01726 seconds