Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Percentage node (Read 1125 times)
lyrock
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Sep 12th, 2011
Percentage node
Nov 28th, 2012 at 9:18pm
Print Post  
Is there a way to create a "percentage" node, whose value/display can be modified as shown as below.
Thanks.
Yan

  

PercentageNode.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Percentage node
Reply #1 - Nov 29th, 2012 at 7:08am
Print Post  
Yes, use a custom-drawn ShapeNode or a derived node class that implements the Draw method like this:

Code
Select All
using System.Drawing;

using MindFusion.Diagramming;
using MindFusion.Drawing;


namespace MyApp
{
	class PercentageNode : DiagramNode
	{
		public PercentageNode(Diagram parent) : base(parent)
		{
			Value = 50;
			base.Font = new Font("Arial", 10);
		}

		public override void DrawLocal(IGraphics graphics, RenderOptions options)
		{
			// draw background
			var rect = GetLocalBounds();
			graphics.FillRectangle(Brushes.White, rect);

			// draw progress
			var valueRect = rect;
			valueRect.Width *= Value / 100;
			graphics.FillRectangle(Brushes.Green, valueRect);

			// draw frame
			graphics.DrawRectangle(Pens.Black, rect);

			// value label
			var format = new StringFormat
			{
				Alignment = StringAlignment.Near,
				LineAlignment = StringAlignment.Center
			};
			graphics.DrawString(ValueString,
				Font, Brushes.Black, rect.Right + 2, rect.Height / 2, format);
		}

		public override RectangleF GetRepaintRect(bool includeConnected)
		{
			var rect = base.GetRepaintRect(includeConnected);
			rect.Width += 3 + Parent.MeasureString(
				ValueString, Font, int.MaxValue, new StringFormat()).Width;
			return rect;
		}

		public float Value { get; set; }

		private string ValueString
		{
			get { return Value + "%";  }
		}
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint