Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic $get("canvas") function does not work well? (Read 9505 times)
Florin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Apr 2nd, 2012
$get("canvas") function does not work well?
Apr 2nd, 2012 at 12:24am
Print Post  
Hi,

I noticed that all Javascript examples on the main page use the statement diagram = $create(Diagram, null, null, null, $get("diagram")); in order to bound the diagram to the area defined by the canvas "diagram".

At the same time in all the examples the diagrams have a vertical scroll bar, I was wondering how can I get the diagram to occupy only the browser's viewing area and get rid of the scroll bar(s).

I changed the canvas width and height in the main html file yet the diagram's boundary goes beyond the bottom of the screen.

Not sure how to make it fit exactly the canvas's boundaries. Anyone?

Thanks
Florin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: $get("canvas") function does not work well?
Reply #1 - Apr 2nd, 2012 at 6:26am
Print Post  
Hi,

During the $create call, the canvas is automatically resized to match the diagram.Bounds size. I think the default Bounds value is A4 size.

You could place the canvas inside a div with overflow:none where the div has the size you want. Or call diagram.clientToDoc({x : pxWidth, y : pxHeight}) to find what size corresponds to your pixel width/height for the current measure unit, and then call diagram.setBounds to resize the diagram area and canvas.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Florin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Apr 2nd, 2012
Re: $get("canvas") function does not work well?
Reply #2 - Apr 3rd, 2012 at 1:35am
Print Post  
Hi Stoyan,
Thanks for your help. Unfortunatelly, I am a beginner Javascript developer, and have a hard time understanding the clientToDoc call.

Essentially I wrote a function that provides me with the screen's width and height in pixels. Then I invoked SetBounds using these dimensions and although the diagram has been readjusted is now  much larger than the width and the height of the screen.

So I just assume that before invoking SetBounds() I need to divide my height and width by the pixel ratio. Yet I don't know how to declare the parameters for the clientToDoc() function, and how to refer to them. I am sure this is very easy for you to explain.

Meanwhile, this is the function that I use to retrieve the browser's size (results are stored in winW, winH)

Thanks
Florin

var winW =0, winH =0;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: $get("canvas") function does not work well?
Reply #3 - Apr 3rd, 2012 at 8:27am
Print Post  
Hi Florin,

Try the following:

Code
Select All
Sys.Application.add_load(function (sender, args)
{

	// create a Diagram component that wraps the "diagram" canvas
	var diagram = $create(MindFusion.Diagramming.Diagram,
        null, null, null, $get("diagram"));

	var winW = 0, winH = 0;
	if (document.body && document.body.offsetWidth)
	{
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	}
	if (document.compatMode == 'CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth)
	{
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight)
	{
		winW = window.innerWidth;
		winH = window.innerHeight;
	}

	var mmSize = diagram.clientToDoc({ x: winW, y: winH });
	diagram.setBounds(new Rect(0, 0, mmSize.x, mmSize.y));
});
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Florin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Apr 2nd, 2012
Re: $get("canvas") function does not work well?
Reply #4 - Apr 3rd, 2012 at 7:27pm
Print Post  
Hi Stoyan,

It works like a charm. Thanks for helping me out.

I was just wondering, is there a place where I can see code examples, the documentation seems to lack examples in that sense..

For example, a statement such as
var nodeBrush = { type: "PathGradientBrush", color1: "Yellow", color2: "Red"};

should work, since it's similar to its equivalent in C#, yet the browser doesn't understand it.

Thanks again,
Florin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: $get("canvas") function does not work well?
Reply #5 - Apr 4th, 2012 at 6:05am
Print Post  
Hi,

You can find some examples in the samples folder when you unzip https://mindfusion.eu/JsDiagramTrial.zip.

You can use only solid colors or linear gradients at this time. The canvas element itself does not support path gradients, but you could probably show path gradients using bitmap images.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint