Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Add icon and additional text to node (Read 12247 times)
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Add icon and additional text to node
Mar 3rd, 2017 at 8:46am
Print Post  
Hello. I'd like to add to shape node an icon and additional text. How do I start? Maybe is there any sample?
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #1 - Mar 3rd, 2017 at 8:46am
Print Post  
The result I want
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #2 - Mar 3rd, 2017 at 9:31am
Print Post  
Do you need to use any shapes other than rounded rectangle? If not, you can get this out of the box using TableNode. Set the table's Shape property to SimpleShape.RoundedRectangle and CellFrameStyle to CellFrameStyle.None. The Review text from your image could be assigned to node's Text, and any additional icons and texts to respective properties of table cells.

edit: check the spanning cells sample from this page, it's an improved version of the one distributed with the library - http://mindfusion.eu/products/javascript/diagramming/samples

Regards,
Slavcho
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #3 - Mar 3rd, 2017 at 9:53am
Print Post  
Thank your for your reply. But I have to use ShapeNodes, not TableNode. Can I add TableNode to ShapeNode?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #4 - Mar 3rd, 2017 at 11:01am
Print Post  
Here's how you could custom-draw extra text -
Code
Select All
var Alignment = MindFusion.Diagramming.Alignment;
var Text = MindFusion.Drawing.Text;

ShapeNode.prototype.onUpdateVisuals = function ()
{
	var content = this.graphicsContainer.content;

	var extraText = new Text(
		"User B",	// replace with this.yourFieldName
		this.getBounds().clone());
	extraText.textAlignment = Alignment.Center;
	extraText.lineAlignment = Alignment.Far;
	extraText.fitInBounds = true;
	extraText.font = this.getEffectiveFont();
	content.push(extraText);
}; 



If the icon includes some empty padding space, you could assign it to standard Image property and set ImageAlign to BottomLeft. Alternatively you can adjust image position from same onUpdateVisuals function as shown here -
http://mindfusion.eu/Forum/YaBB.pl?num=1439580359/1#1

If you need to add more images to same node -

Code
Select All
var imageObj = new Image();
imageObj.src = "icon1.png";

// in onUpdateVisuals
var image2 = new MindFusion.Drawing.Image(
	new MindFusion.Drawing.Rect(this.bounds.x + 2, this.bounds.bottom() - 7, 5, 5));
image2.image = imageObj;
image2.loaded = imageObj.complete;
content.push(image2); 



Instead of custom drawing, you could add extra images and texts by showing them in Transparent ShapeNodes attached to main node using attachTo method. That will let your users adjust their positions if desired, or you could set node.Locked to prevent that.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #5 - Mar 3rd, 2017 at 12:17pm
Print Post  
Thanks, it's worked. But you see, I may have multiple lines on shapenode. I tried to add some Text() objects by content.push(text1), content.push(text2).

And it resulted in


I want something like that


Also I'd like, that users would be shown just after "Review" text.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #6 - Mar 3rd, 2017 at 1:29pm
Print Post  
You can specify text bounding rectangles as second argument of Text constructor, e.g.

Code
Select All
ShapeNode.prototype.onUpdateVisuals = function ()
{
	var content = this.graphicsContainer.content;

	for (var i = 0; i < 3; i++)
	{
		// assume primary text is top-aligned
		var index = i + 1;
		var rect = this.getBounds().clone();
		rect.height = 2 * this.getEffectiveFontSize();
		rect.y += index * rect.height;
		var extraText = new Text(
			"User B", // replace with this.yourFieldName
			rect);
		extraText.textAlignment = Alignment.Center;
		extraText.lineAlignment = Alignment.Far;
		extraText.fitInBounds = true;
		extraText.font = this.getEffectiveFont();
		content.push(extraText);
	}
}; 

  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #7 - Mar 6th, 2017 at 9:06am
Print Post  
Hi, It's worked. But I have two another problems.
1. I want to hide inner text elements when resizing height and ShapeNode height become small. I can't find any property like visible/enabled
2. I want to forbid resizing ShapeNode width if it's getting smaller than text's width. But I can't find any property related to inner texts width.



Could you help me with that?
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #8 - Mar 6th, 2017 at 10:02am
Print Post  
Or is it possible to hide part of text?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #9 - Mar 6th, 2017 at 10:18am
Print Post  
Code
Select All
extraText.clipPath = this.shapeRenderer.getOutline(); 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #10 - Mar 6th, 2017 at 10:56am
Print Post  
Thanks a lot. The only thing left is to hide node's primary text (in my case "Review")

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #11 - Mar 6th, 2017 at 11:48am
Print Post  
Its Text object is stored in DiagramItem.text field, so you could set this.text.clipPath = ...

Regards,
Slavcho
  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #12 - Mar 6th, 2017 at 1:12pm
Print Post  
Is it possible for additional text to have different font than main text?

I set extraText.font.style.bold = false and extraText.font.style.size = 7

But "Review" text also became non-bold and with changed size.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Add icon and additional text to node
Reply #13 - Mar 6th, 2017 at 1:19pm
Print Post  
The Text objects are sharing same Font instance after this assignment -
Code
Select All
extraText.font = this.getEffectiveFont(); 



Replace it with this -
Code
Select All
extraText.font = new MindFusion.Drawing.Font(name, size, bold, italic, underline); 

  
Back to top
 
IP Logged
 
friedel
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 31
Joined: Mar 3rd, 2017
Re: Add icon and additional text to node
Reply #14 - Mar 31st, 2017 at 10:52am
Print Post  
Hi. Is it possible somehow get "icon1.png" original width and height?

Code (Javascript)
Select All
var imageObj = new Image();
imageObj.src = "icon1.png";

// in onUpdateVisuals
var image2 = new MindFusion.Drawing.Image(
	new MindFusion.Drawing.Rect(this.bounds.x + 2, this.bounds.bottom() - 7, 5, 5));
image2.image = imageObj;
image2.loaded = imageObj.complete;
content.push(image2);
 

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint