Lasso Soft Inc. > Home

[flashchart]

Linkflashchart
AuthorJason Huck
CategoryData Type
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted26 Apr 2006
Updated05 Oct 2006
More by this author...

Description

This custom type will generate an XML configuration file for use with XML/SWF Charts [more info | download]. The instance variables match the node and attribute names given in the online reference. Nodes with attributes but no children are generated from maps. Nodes with children are generated from arrays. This covers all items except series_switch, which is a boolean.

There is only one member tag, ->output, which returns the data in XML format. Be sure to switch the content type of the serving page to text/xml when using this type.

[flashchart_embed] provides a shortcut for generating the HTML code to display the flash movie and include the XML file.

Sample Usage

var('myChart') = flashchart;	
$myChart->chart_type = '3d column';

$myChart->chart_value = map(
	'position' = 'top'
);

$myChart->axis_value = map(
	'max' = 100,
	'steps' = 5
);

$myChart->chart_transition = map(
	'type' = 'dissolve',
	'delay' = 1,
	'duration' = 2,
	'order' = 'series'
);

var('chartData') = array(
	array(	null,		'Column A',	'Column B',	'Column C'	),
	array(	'Row 1',	20,			40, 		60			),
	array(	'Row 2', 	10, 		30, 		50			)
);

$myChart->chart_data = $chartData;

content_type('text/xml; charset=utf8');		
$myChart->output;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_type(
	'flashchart',
	-prototype,
	-description='Creates a Flash chart.'
);
	local(
		'axis_category' = map,
		'axis_ticks' = map,
		'axis_value' = map,
		'axis_value_text' = map,
		'chart_border' = map,
		'chart_data' = array,
		'chart_grid_h' = map,
		'chart_grid_v' = map,
		'chart_pref' = map,
		'chart_rect' = map,
		'chart_transition' = map,
		'chart_type' = array,
		'chart_value' = map,
		'chart_value_text' = array,
		'draw' = array,
		'legend_label' = map,
		'legend_rect' = map,
		'legend_transition' = map,
		'license' = string,
		'link' = array,
		'link_data' = map,
		'live_update' = map,
		'series_color' = array,
		'series_explode' = array,
		'series_gap' = map,
		'series_switch' = boolean
	);

	define_tag('onCreate');
		iterate(self->properties->first, local('i'));
			local_defined(#i->first) ? self->(#i->first) = #i->second;
		/iterate;
	/define_tag;
	
	define_tag('output');
		local('out' = '\n');
		
		iterate(self->properties->first, local('i'));
			select(#i->first);
				case('chart_data');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\t\n';
							
							iterate(#row, local('field'));
								select(true);
									case(#field == '' || #field == null);
										#tmp += '\t\t\t\n';
										
									case(#field->isa('string'));
										#tmp += '\t\t\t' + encode_xml(#field) + '\n';
										
									case((: 'integer', 'decimal') >> #field->type);
										#tmp += '\t\t\t' + #field + '\n';
										
								/select;
							/iterate;
							
							#tmp += '\t\t\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
					
				case('chart_type');
					if(#i->second->isa('string'));
						#out += '\t' + encode_xml(#i->second) + '\n';
						
					else(#i->second->isa('array'));
						if(#i->second->size == 1);
							#out += '\t' + encode_xml(#i->second->first) + '\n';
							
						else;
							local('tmp') = '\t\n';
						
							iterate(#i->second, local('j'));
								#tmp += '\t\t' + encode_xml(#j) + '\n';
							/iterate;
						
							#tmp += '\t\n';
							#out += #tmp;
						/if;
						
					/if;
					
				case('chart_value_text');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\t\n';
							
							iterate(#row, local('field'));
								select(true);
									case(#field == null);
										#tmp += '\t\t\t\n';
										
									case(#field->isa('string'));
										#tmp += '\t\t\t' + encode_xml(#field)->replace('\r\n','\r')&replace('\n','\r')& + '\n';
																					
								/select;
							/iterate;
							
							#tmp += '\t\t\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
				
				case('draw');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\t<' + #row->first + ' ';
							
							iterate(#row->second->keys, local('j'));
								#tmp += #j + '="' + encode_xml(#row->second->find(#j)) + '" ';
							/iterate;
							
							#tmp += '/>\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
				
				case('license');
					local('tmp' = '\t' + #i->second + '\n');
					#out += #tmp;
				
				case('link');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\tkeys, local('j'));
								#tmp += #j + '="' + encode_xml(#row->second->find(#j)) + '" ';
							/iterate;
							
							#tmp += '/>\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
				
				case('series_color');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\t' + #row + '\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
				
				case('series_explode');
					if(#i->second->size);
						local('tmp' = '\t\n');
						
						iterate(#i->second, local('row'));
							#tmp += '\t\t' + #row + '\n';
						/iterate;
						
						#tmp += '\t\n';
						#out += #tmp;
					/if;
				
				case('series_switch');
					if(#i->second != null && #i->second->type == 'boolean');
						#out += '\t' + string(#i->second) + '\n';
					/if;
				
				case;
					if(#i->second->isa('map') && #i->second->size);
						local('tmp' = '\t<' + #i->first + ' ');
					
						iterate(#i->second->keys, local('j'));
							#tmp += #j + '="' + encode_xml(#i->second->find(#j)) + '" ';
						/iterate;
					
						#tmp += '/>\n';
						#out += #tmp;
					/if;
					
			/select;
		/iterate;			
		
		#out += '\n';
		return(@#out);
	/define_tag;
/define_type;

Related Tags

Comments

30 Apr 2006, Jason Huck

Bug Fix

Fixed a bug where specifying compound chart types would not generate the correct XML.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft