Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Can I define themes and styles in javascript (Read 2995 times)
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Can I define themes and styles in javascript
Sep 8th, 2013 at 6:22am
Print Post  
Hi,

Can I define themes and styles in JavaScript. Could you please give some sample code for this?

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Can I define themes and styles in javascript
Reply #1 - Sep 9th, 2013 at 5:30am
Print Post  
Hi,

This sets the style of a single node:

Code
Select All
var Style = MindFusion.Diagramming.Style;

var style = new Style();
style.setBrush("Orange");
node.setStyle(style); 



This sets the style of all ShapeNodes via a theme:

Code
Select All
var Theme = MindFusion.Diagramming.Theme;

var theme = new Theme();
theme.styles["std:ShapeNode"] = style;
diagram.setTheme(theme); 



You can set style properties via the setBrush, setStroke, setStrokeThickness, setTextColor, setFontName, setFontSize, setShadowColor, setNodeEffects methods of the Style class.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: Can I define themes and styles in javascript
Reply #2 - Oct 2nd, 2013 at 6:13pm
Print Post  
Hi,

If i need to set different styles for each shape node globally, is there any way?
Ie Circle shape i need one style and square shape another style.
Could you please help me?

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Can I define themes and styles in javascript
Reply #3 - Oct 3rd, 2013 at 8:31am
Print Post  
Hi,

There is no built-in support for specifying per-shape styles. However, you could replace the ShapeNode's resolveStyle function with your own version that selects styles based on current shape:

Code
Select All
var globalStyles = [];
globalStyles["Rectangle"] = new Style();
globalStyles["Rectangle"].setBrush("yellow");
globalStyles["Ellipse"] = new Style();
globalStyles["Ellipse"].setBrush("green");

var originalResolver = ShapeNode.prototype.resolveInheritedStyle;
ShapeNode.prototype.resolveInheritedStyle = function (check, theme)
{
	var styleForShape = globalStyles[this.getShape().getId()];
	if (styleForShape && check.apply(styleForShape))
		return styleForShape;

	return originalResolver.apply(this, [check, theme]);
}; 



resolveInheritedStyle is called with lowest priority after checking the node's own style, the diagram's style, and current theme. If you prefer the shape styles to have higher priority, replace the resolveEffectiveStyle function instead.

I hope that helps,
Stoyan
« Last Edit: Oct 3rd, 2013 at 9:44am by Stoyo »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint