WeBWorK Problems

accessing a dynamic images pixel width

accessing a dynamic images pixel width

by Alex Jordan -
Number of replies: 1
As in this simple example:

when defining a graph object, the pixel dimensions can be specified. It's the size parameter in this example:

$gr = init_graph(-1,-1,4,4, axes=>[0,0], grid=>[5,5], size=>[400,400] );

Later, in the problem body when you call the graph, you specify the pixel dimensions that the image should display at:
image( insertGraph($gr), width=>200,height=>200,tex_size=>800 )
These are the width and height parameters. Technically there is no need for these to match the dimensions from when the image was created, but making them match will prevent undesirable stretching/compression in the graph details.

Is there some way to call upon the graph object's size, if it has been specified? I'm thinking of something like:
image( insertGraph($gr), width=>$gr->size[0],height=>$gr->size[1],tex_size=>800 )
Of course this would be nice for avoiding unintended discrepancies. But also it would help with automating good choices for the dimensions in the PreTeXt project I am working on.

In reply to Alex Jordan

Re: accessing a dynamic images pixel width

by Gavin LaRose -

From the WWPlot source, it looks as if $gr->size() will return the pixel size (width, height) of the graph object as an array reference. So I think your call will work if you replace $gr->size[0] with $gr->size()->[0].