how to draw and keep circular plot when window is resized

Q&A for C, C++, and/or C# developers using DPlot

Moderator: DPlotAdmin

Post Reply
redsun
Posts: 5
Joined: Tue Feb 10, 2009 2:33 am

how to draw and keep circular plot when window is resized

Post by redsun »

Hi,

would you please help me to solve this problem: when I'm trying to use the dplotlib.dll in C++ to draw a polar plot, I can not control the plot size. i.e. the plot always changes its shape when the window is changed manually ( resize the window). after all, what I need is a circular plot but not an elliptical one!

By the way, I have tried the "[PolarPlotStyle(0x0004)]" to force a circular plot, but it is no use for me.

thanks,

redsun
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

By the way, I have tried the "[PolarPlotStyle(0x0004)]" to force a circular plot, but it is no use for me.
"no use" because it doesn't work? Or no use because for whatever reason you can't call DPlot_Command? I tried it just now to make sure I hadn't botched something up and it worked as expected.

In case you may be one of the unlucky ones to have downloaded a version in which I fouled up interpreting hex numbers, try [PolarPlotStyle(4)].

You can accomplish the (very nearly) same thing with [Size(1,w,h,0)], where w and h should be equal and are the size in inches. The only real difference between using PolarPlotStyle and Size is that the fonts may be sized differently when you size the plot, depending on whether w and h fit within the document window.
Visualize Your Data
support@dplot.com
redsun
Posts: 5
Joined: Tue Feb 10, 2009 2:33 am

Post by redsun »

Hi, David Hyde,

Thank you for your immediate reply.

I have tried the [PolarPlotStyle(4)] and [Size(1,w,h,0)], but both of them also do not work. I guess that these two macro commands have been properly executed( there is no error information indicated), however, the plot is elliptical and changes its shape with the window resizing.

My program is based on the example program Ctest4.c, which uses DPlot_GetEnhMetaFile and dPlot_Plot functions.

best regards,

redsun
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Ah! Now I get it.

I can explain what's going on but I don't have a good answer at the moment. Regardless of what dimensions you specify for the metafile, DPlot changes the dimensions to get rid of extra white space and that definitely isn't what you want in this case. If you request (for example) a metafile that's 7" wide and 3" tall you might get back a metafile that is roughly 3"x3" (in the case of polar plots with PolarPlotStyle[4]). Using the STM_SETIMAGE message to set the picture for the frame ends up stretching the metafile to fill the frame. I tried using styles SS_REALSIZEIMAGE and SS_CENTERIMAGE on that frame, but that had no effect. Those settings apparently only apply to icons.

I'll look into not performing the cropping that DPlot is currently doing when the metafile is requested by another application. I think the best short-term solution will be to change how the frame picture is drawn - instead of using STM_SETIMAGE, handle all of the painting manually. IOW erase the background, get the actual metafile dimensions, and call PlayEnhMetafile to draw it. The only problem I can see with doing this is that it is a one-time deal: if you cover up your app's window and uncover it, the metafile won't be redrawn unless you take steps to handle WM_PAINT messages.
Visualize Your Data
support@dplot.com
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

This is fixed in version 2.2.4.7. DPlot will no longer crop metafiles that are requested by another application.

There's another problem (not related to polar plots) with the ctest4 demo you started with, though, and that will require changes at your end. Both programs set the requested picture width to 5" and the height is made proportional. But DPlot forces both dimensions to be at least 3". If the picture frame is more than 5/3 wide as it is tall in ctest4 (which it might be if you resize the window), the requested height will be less than 3". But you'll get back a metafile that is 3" tall. STM_SETIMAGE maps the metafile extents to the extents of the picture frame, so you'll get a picture that is stretched in the horizontal direction (or squashed in the vertical - take your pick). This is especially noticeable with fonts.

The ctest4 and btest4 demo programs distributed with DPlot Jr have been updated to fix this one. The requested size is now the actual physical size of the frame.

Edit: And now that I've written this down, of course, I realize there's one other check that should be made in those demos that I neglected to make. Both dimensions should be at least 3", and if one or the other isn't then it should be set to 3" and the other dimension scaled accordingly.
Last edited by DPlotAdmin on Sat May 02, 2009 5:45 pm, edited 1 time in total.
Visualize Your Data
support@dplot.com
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

One thing I neglected to mention which you've probably figured out:

When you resize the ctest4 window the picture frame is resized as well, which causes it to be repainted. But it is repainted with the original metafile, which will result in a distorted picture. Other than fonts being stretched out this isn't a serious problem for most plot types. But for polar plots you'll get an elliptical shape rather than a circle. There are a couple of ways to get around this:

a) When receiving a WM_SIZE message, regenerate the metafile so that the new picture has the correct aspect ratio.

b) Instead of using STM_SETIMAGE (which maps the metafile extents to the frame extents): Fill the picture frame with the background color, then draw the metafile yourself using PlayEnhMetafile, with the target rectangle being some subset of the frame rectangle that is proportional to the metafile dimensions.

I hope all of that is clear - if not let me know.
Visualize Your Data
support@dplot.com
Post Reply