Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) TableNode Autosize (Read 6305 times)
murat2912
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Nov 3rd, 2008
TableNode Autosize
Nov 24th, 2008 at 10:52am
Print Post  
Hi.Is there any way to autosize tablenodes.I have many tablenodes with rows.Someone has 10 row,someone has 3 rows.how can set table size automatically?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TableNode Autosize
Reply #1 - Nov 24th, 2008 at 12:10pm
Print Post  
Hi,

Try with this code:

Code
Select All
float newHeight = table.CaptionHeight +
	Constants.GetPixel(diagram.MeasureUnit) +
	3 * table.Pen.Width;
foreach (TableNode.Row row in table.Rows)
	newHeight += row.Height;
table.Resize(table.Bounds.Width, newHeight);
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: TableNode Autosize
Reply #2 - Apr 26th, 2009 at 11:20am
Print Post  
Hi!

Im using your algorithm but I noticed maybe a bug. Last row is not always visible --> http://i40.tinypic.com/351xqb9.jpg
After I resize TableNode to state that caption is on two lines, everything is ok --> http://i41.tinypic.com/119o3mc.jpg


Any hellp?
Thx.

...MUDO...
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: TableNode Autosize
Reply #3 - Apr 26th, 2009 at 11:20am
Print Post  
My code is below. I have my own BehaviorBase. MMSetDefaultProperties is called in InitializeNode event and MMResizeAllToFitTable is called in NodeModifying event.

My settings:
Code
Select All
'setting defaults settings of shape
Public Sub MMSetDefaultProperties()
  Me.Constraints.MinHeight = 10
  Me.Constraints.MinWidth = 20
  Me.Bounds = RectangleVirginCreate(0, 0, 30, 50)
  Me.EnableStyledText = False
  Me.Font = New Font("Arial", 8, FontStyle.Regular)
  Me.OffsetHeaderRows = True
  Me.AnchorPattern = MMCreateAnchorPatternSurrounding(9)

  Me.Brush = New LinearGradientBrush(Color.White, Color.Green, 45)
  Me.Pen = New Pen("0/#FF696969/0/0/0//0/0/10/")
  Me.HandlesStyle = HandlesStyle.EasyMove
  Me.ShadowOffsetX = 0.5
  Me.ShadowOffsetY = 0.5
  Me.CustomDraw = CustomDraw.Additional
  Me.Style = TableStyle.RoundedRectangle
  Me.ConnectionStyle = TableConnectionStyle.Table
  Me.RowHeight = 5
  Me.RowCount = 0
  Me.ColumnCount = 2
  Me.Columns(0).Width = 4
  Me.Columns(0).ColumnStyle = ColumnStyle.FixedWidth
  Me.Columns(1).ColumnStyle = ColumnStyle.AutoWidth
  Me.CellFrameStyle = CellFrameStyle.None
  Me.ImageAlign = ImageAlign.MiddleRight
  Me.CaptionHeight = 6
  Me.CaptionFormat.Alignment = StringAlignment.Center
  Me.CaptionFormat.FormatFlags = StringFormatFlags.NoClip
  Me.CaptionFormat.Trimming = StringTrimming.None
  Me.Caption = "Tabulka" 'the text displayed as caption of the table
End Sub

'resizes heights of caption, all rows and whole table to fit text inside cells and to fit actual width of table. Actual width of table is not changed!
Public Sub MMResizeAllToFitTable()
  MMResizeWidthToFitTable()
  MMResizeHeightToFitTable()
End Sub

'resizes heights of caption and all rows of the table to fit text inside them and to fit actual width of table. Actual width of table is not changed!
Public Sub MMResizeWidthToFitTable()

  Dim LnNewHeight As Single
  Dim LnWidth As Single

  'resizing height of caption
  'maxWidth parameter for MeasureString sub = actual width of caption
  LnWidth = Me.Bounds.Width
  LnNewHeight = Me.Parent.MeasureString(Me.Caption, Me.Font, LnWidth, Me.CaptionFormat).Height

  'setting a new height or keeping minimal height of caption
  Const LnMinimalCaptionHeight As Single = 6

  Me.CaptionHeight = IIf(LnNewHeight > LnMinimalCaptionHeight, LnNewHeight, LnMinimalCaptionHeight)

  'resizing heights of all rows
  'maxWidth parameter for MeasureString sub = actual width of Columns(1)
  LnWidth = Me.Columns(1).Width
  For LiI As Integer = 0 To Me.RowCount - 1


  'calculating new height of row
   LnNewHeight = Me.Parent.MeasureString(Me(1, LiI).Text, Me.Font, LnWidth, Me(1, LiI).TextFormat).Height

  'setting a new height or keeping minimal height of rows (Me.RowHeight)
   Dim LnMinimalRowHeight As Single = Me.RowHeight
   Me.Rows(LiI).Height = IIf(LnNewHeight > LnMinimalRowHeight, LnNewHeight, LnMinimalRowHeight)

  Next
    End Sub

'resizes height of whole table. Actual width of table is not changed!
Public Sub MMResizeHeightToFitTable()

  'Me.Columns(1).ColumnStyle = ColumnStyle.FixedWidth

  Dim LiNewHeight As Integer = Me.CaptionHeight + Constants.GetPixel(Me.Parent.MeasureUnit) + 3 * Me.Pen.Width

  For Each LoRow As TableNode.Row In Me.Rows
     LiNewHeight += LoRow.Height
     Me.Resize(Me.Bounds.Width, LiNewHeight)
  Next
End Sub
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TableNode Autosize
Reply #4 - Apr 27th, 2009 at 8:20am
Print Post  
The default pen width is 0, which Flowchart.NET interprets as a one-pixel thick line, independent from the MeasureUnit and zoom level. Instead of adding 3 * Me.Pen.Width unconditionally, check if the pen width is 0, and if so, add the equivalent to tree pixels in the MeasureUnit you are using.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: TableNode Autosize
Reply #5 - Apr 27th, 2009 at 11:45am
Print Post  
Hi!

So is this OK? It looks like yes.

Code
Select All
Dim LiNewHeight As Integer = Me.CaptionHeight + Constants.GetPixel(Me.Parent.MeasureUnit) + IIf(Me.Pen.Width = 0, Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width * Constants.GetPixel(Me.Parent.MeasureUnit))
 




me.pen means pen of bounds of node, so where is pen for drawing cells? It sholud be considered also for calculating height. I guess...

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TableNode Autosize
Reply #6 - Apr 27th, 2009 at 1:01pm
Print Post  
Hi,

I think it should be:
Me.CaptionHeight + 3 * IIf(Me.Pen.Width = 0, Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width)

3 is for the top, bottom and caption divider lines. The cell borders should be included in the rows' Height and should not add to the height.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: TableNode Autosize
Reply #7 - Apr 27th, 2009 at 5:02pm
Print Post  
Hi!

Now I got it... meaning of "3" and divider lines.
Thx.

...MUDO...
  
Back to top
 
IP Logged
 
TimNZ
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Feb 23rd, 2009
Re: TableNode Autosize
Reply #8 - Aug 10th, 2009 at 10:51pm
Print Post  
Stoyan,

How about a ResizeToContent method?

I'm going to have to implement a recursive model for calculating Height for TreeViewNode (max 2 levels).

Have you got another of your handy code snippets for calculating width (max 2 levels) for TreeViewNode?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TableNode Autosize
Reply #9 - Aug 13th, 2009 at 8:31am
Print Post  
Hi Tim,

Check the PM page for a new build. TreeviewNodes now have a ResizeToFitText method, to keep naming consistent with shape and table nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
TimNZ
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Feb 23rd, 2009
Re: TableNode Autosize
Reply #10 - Aug 13th, 2009 at 9:29am
Print Post  
You and your team are legends.
  
Back to top
 
IP Logged
 
TimNZ
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Feb 23rd, 2009
Re: TableNode Autosize
Reply #11 - Aug 13th, 2009 at 9:41am
Print Post  
Less haste! Tongue

First screenshot is after call to ResizeToFitText method, 2nd is after I resize manually.
As you can see the bounds after ResizeToFitText bear little relation to the content.





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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TableNode Autosize
Reply #12 - Aug 13th, 2009 at 1:42pm
Print Post  
Seems the first implementation used some cached measures, relying on the nodes being rendered at least once. I've uploaded a new build that should do better than that Smiley

Stoyan
  
Back to top
 
IP Logged
 
TimNZ
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Feb 23rd, 2009
Re: TableNode Autosize
Reply #13 - Aug 14th, 2009 at 12:13am
Print Post  
Hi Stoyan,

The node is still rather wider than the contents.

Two screenshots, first with non-styled label, 2nd with styled label.
The first one with non-styled text isn't too bad, but I would like ResizeToFitText to be precise, and then I have the discretion to add some padding afterwards.

Really appreciate your efforts.





« Last Edit: Aug 14th, 2009 at 12:29pm by TimNZ »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint