User (Legacy) Posted September 25, 2001 Report Share Posted September 25, 2001 Hi again, In relation to the Clipped annotations thread, I want to guarantee an aspect ratio in my 2D chart. I've tried this code in the resize event handler on the chart (with scrollable set true): with Chartfx1 .axis(AXIS_X).SetScrollView .Axis(AXIS_X).MIN, .Axis(AXIS_X).MAX .axis(AXIS_Y).SetScrollView .Axis(AXIS_Y).MIN, .Axis(AXIS_Y).MAX ' Some axis-choice-test cut here, here is the guts of one .Axis(AXIS_X).PixPerUnit = .Axis(AXIS_Y).PixPerUnit end with I would think this would work, but it doesn't! You stretch the chart, and the contents loses its aspect ratio! And both pixperunit should(are) be the same, yet its obviously not enforcing it.. Whats going on here? Thanks Paul Link to comment Share on other sites More sharing options...
Software FX Posted September 26, 2001 Report Share Posted September 26, 2001 PixPerUnit means the MINIMUN amount of pixels associated to each logical unit. This is the minimum it can be more if more space is available. To guarantee the same aspect ratio you must: a) Ensure both axes contain exactly the same scale (Min, Max and PixPerUnit). Ensue both axes are the same physical size, you need to play with the chart size and gaps to achieve this. If both these conditions are met, you will get a symmetric chart. Note: Printing the chart resizes its contents which may break the symmetry. Use the Pint method to control chart dimensions when printed. -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
User (Legacy) Posted October 4, 2001 Author Report Share Posted October 4, 2001 ok, I need a little help here: in frmChart_Resize() : ' note frmChart has ChartFX1 in it. with ChartFX1 ratio = (.Axis(AXIS_Y).max - .Axis(AXIS_Y).min) / (.Axis(AXIS_X).max - .Axis(AXIS_X).min) oldscale = frmChart.ScaleMode .Height = frmChart.Height - 1000 .Width = frmChart.Width - 120 .BottomGap = MIN_BOTTOM_GAP frmChart.ScaleMode = vbPixels .RightGap = -(.Height - .TopGap - .BottomGap) / ratio - .LeftGap + .Width frmChart.ScaleMode = oldscale If .RightGap < MIN_RIGHT_GAP Then .RightGap = MIN_RIGHT_GAP frmChart.ScaleMode = vbPixels .BottomGap = -(.Width - .LeftGap - .RightGap) * ratio - .TopGap + .Height frmChart.ScaleMode = oldscale End If ' Turned this off cause it seemed to do nothing for it. '.Scrollable = True '.Axis(AXIS_X).SetScrollView .Axis(AXIS_X).min, .Axis(AXIS_X).max '.Axis(AXIS_Y).SetScrollView .Axis(AXIS_Y).min, .Axis(AXIS_Y).max '.Axis(AXIS_X).PixPerUnit = .Axis(AXIS_Y).PixPerUnit End With This works 90% of the way. Its not perfect on my monitor - one of the axis would be off by about 1cm. Can I make this better? How woulod I enforce a perfect aspect ratio on a print job? Whats the "Pint" method? I looked PrintIt, but thats on a page-by-page basis, and the margins are useless if I can't tell the size of the page! How would I do this? Thanks In article <0wHA#qqRBHA.1444@webserver1.softwarefx.com>, "SoftwareFX Support" <support@softwarefx.com> wrote: > To guarantee the same aspect ratio you must: > > a) Ensure both axes contain exactly the same scale (Min, Max and > PixPerUnit). Ensue both axes are the same physical size, you need to > play with the chart size and gaps to achieve this. > > If both these conditions are met, you will get a symmetric chart. > > Note: Printing the chart resizes its contents which may break the > symmetry. Use the Pint method to control chart dimensions when printed. Link to comment Share on other sites More sharing options...
Software FX Posted October 5, 2001 Report Share Posted October 5, 2001 I ran this code and I get the right proportions. For instance if the Max-Min is the same for X and Y I get a square chart (in pixels). PixPerUnit will only kick in if scrolling is required. Remember PixPerUnit is the Minimum. Your calculations only work if there is no scrollbars, as you are assuming all the range from Min to Max is visible. -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
User (Legacy) Posted October 10, 2001 Author Report Share Posted October 10, 2001 I've come back to the problem to work more on it, and I noticed that it wasn't giving me a square chart. This is because topgap, etc does not count the height of docked toolbar(s) and series legends, and .height of the chart does. I've written yet more code to try and get an accurate aspect ratio on the screen. This code is pasted below. However, there are still more problems, it seems its off by a few millimeters (i can live with this, so thats ok). However, there are more serious deficiencies. If the user zooms in, the aspect ratio is completely lost. Also, there is no event triggered that I can hook into when a zoom occurs so I can resize the chart. Also, if the user zooms in and the chart is resized, the chart unzooms automatically. Also, I wouldn't have counted the height/widths of the scrollbars that appear. I will have to write my own zooming code... I'll be posting more questions as I struggle on... This is the modified code: ----------- ' apply aspect ratio rules ratio = (.Axis(AXIS_Y).max - .Axis(AXIS_Y).min) / _ (.Axis(AXIS_X).max - .Axis(AXIS_X).min) oldscale = frmChart.ScaleMode xy = frmChart.ChartFX1.ToolBarObj.Height xy = AnnotX.ToolBarObj.Height .Height = frmChart.Height - 1680 .BottomGap = MIN_BOTTOM_GAP frmChart.ScaleMode = vbPixels .RightGap = -(.Height - .TopGap - .BottomGap - _ get_height_gaps) / ratio - .LeftGap - get_width_gaps + .Width frmChart.ScaleMode = oldscale If .RightGap < MIN_RIGHT_GAP Then .RightGap = MIN_RIGHT_GAP frmChart.ScaleMode = vbPixels .BottomGap = -(.Width - .LeftGap - .RightGap - _ get_width_gaps) * ratio - .TopGap - get_height_gaps + .Height frmChart.ScaleMode = oldscale End If ---------- note the get_X_gaps functions. these are: Private Function get_height_gaps() As Long Dim gaps As Long gaps = 0 ' we must into account the width of the series legend and toolbars, if ' docked With ChartFX1.SerLegBoxObj If .Docked = TGFP_TOP Or .Docked = TGFP_BOTTOM Then _ gaps = gaps + .Height End With With ChartFX1.ToolBarObj If .Docked = TGFP_TOP Or .Docked = TGFP_BOTTOM Then _ gaps = gaps + .Height End With With AnnotX.ToolBarObj If .Docked = TGFP_TOP Or .Docked = TGFP_BOTTOM Then _ gaps = gaps + .Height End With get_height_gaps = gaps End Function Private Function get_width_gaps() As Long Dim gaps As Long gaps = 0 ' we must into account the width of the series legend and toolbars, if ' docked With ChartFX1.SerLegBoxObj If .Docked = TGFP_LEFT Or .Docked = TGFP_RIGHT Then _ gaps = gaps + .Width End With With ChartFX1.ToolBarObj If .Docked = TGFP_LEFT Or .Docked = TGFP_RIGHT Then _ gaps = gaps + .Width End With With AnnotX.ToolBarObj If .Docked = TGFP_LEFT Or .Docked = TGFP_RIGHT Then _ gaps = gaps + .Width End With get_width_gaps = gaps End Function In article <ZHwWZAbTBHA.1276@webserver1.softwarefx.com>, "SoftwareFX Support" <support@softwarefx.com> wrote: > I ran this code and I get the right proportions. For instance if the > Max-Min is the same for X and Y I get a square chart (in pixels). > > PixPerUnit will only kick in if scrolling is required. Remember > PixPerUnit is the Minimum. > > Your calculations only work if there is no scrollbars, as you are > assuming all the range from Min to Max is visible. > > -- > FP Software FX, Inc. > > bad_label.bmp Link to comment Share on other sites More sharing options...
Software FX Posted October 10, 2001 Report Share Posted October 10, 2001 1) You can use: lDimension = ChartFX1.PaintInfo(CPI_DIMENSION, 0) nWidth = CHART_LOWORD(lDimension) nHeight = CHART_HIWORD(lDimension) To retrieve the size in pixels, without toolbar, legends or data editor, just the chart (including the gaps). 2) Because the rectangle the user selects when it zooms in may not be square, the resulting scale may not be square. You do receive an event right after the zoom rectangle is defined, you receive an LButtonUp event, with the Zoom property being True. You also receive an LButtonDown event when the zoom starts (Zoom property is True). Then you can put your own Zoom code in the LButtonUp making sure you make a square out of the rectangle. I don't know how intuitive this will be to the user though since he/she selected a rectangle and the zoom is made over a bigger or smaller square. Remember that the code you are using to calculate the scale dos not consider scroll bars, instead of Min Max you can use GetScrollView to get the visible Min and Max. -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.