WeBWorK Main Forum

graphs not showing in problem viewer

graphs not showing in problem viewer

by Larry Riddle -
Number of replies: 2

I am writing a WeBWorK problem that uses dynamic generated graphs. I do this by loading the problem in the Library Browser, then clicking on the edit button to open the Editor. However, when I select "View" and click "take action", I do not see the graph in the Problem Viewer, just the text I have written. I *can* see the graph if I first check the box "open in new window". I can also see the graph if I view the problem in the Library Browser. It is only in the Problem Viewer that the graph does not appear.

This happens using both Firefox and Safari browsers, so it does not seem to be a browser issue. Is it a bug in WeBWorK?

In reply to Larry Riddle

Re: graphs not showing in problem viewer

by Glenn Rice -

What version of webwork and pg are you using?  What kind of dynamically generated graphs are you using?  Are you using the PGtikz.pl macro, the PGlateximage.pl macro, the PGgraphmacros.pl macro, or something else?

In reply to Glenn Rice

Re: graphs not showing in problem viewer

by Larry Riddle -
WW/pg 2.16
PGgraphmacros.pl

Here's one I've been working on.

##DESCRIPTION
## Point-slope form of a linear function
## Two points are randomly chosen to form the line. The points and
## the line are plotted.
##
##ENDDESCRIPTION
## DBsubject(Algebra)
## DBchapter(Linear equations and functions)
## DBsection(Equations of lines: point-slope form)
## Level(2)
## KEYWORDS('linear function', 'point-slope form')

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
"contextFraction.pl",
"PGML.pl",
"PGcourse.pl"
);

$refreshCachedImages=1;

TEXT(beginproblem());
Context("Fraction");
Context()->noreduce("(-x)-y");
Context()->noreduce('-n');

######################################

$xmin = -5;
$ymin = -5;
$xmax = 5;
$ymax = 5;

# Choose two points so that:
# neither is on the y-axis
# each at least 2 units apart in each direction
# the line through the points does not go through the origin
# the slope is not +1 or -1
do {
$x1 = non_zero_random(-4,4,1);
$b1 = random(-4,4,1);
do {$x2 = non_zero_random(-4,4,1);} until (abs($x2-$x1)>1);
do {$b2 = random(-4,4,1);} until ((abs($b2-$b1)>1) and ($b1*$x2-$b2*$x1 !=0));
$a1 = min($x1,$x2);
$a2 = max($x1,$x2);
$m = Fraction($b2-$b1,$a2-$a1);
} until (abs($m) != 1);

$f = Formula("$m*(x-$a1)+$b1")->reduce;
$f1 = Formula("$m*(x-$a2)+$b2")->reduce;
$f2 = Formula("$b2-$m*$a2 + $m*x")->reduce;

#----Build the graph
$graph = init_graph($xmin,$ymin,$xmax,$ymax,axes=>[0,0],size=>[400,400],grid=>[10,10]);
$graph->lb('reset');
add_functions( $graph,"$f for x in [$xmin,$xmax] using color:red and weight=2");
$graph->stamps( closed_circle($a1,$b1,'blue') );
$graph->stamps( closed_circle($a2,$b2,'blue') );

$i = 0; # Number the axes
do {
$xtick = $i + $xmin + 1;
$labelx[$i] = new Label($xtick,0, "$xtick",'black','center');
if ($xtick!=0) {$graph->lb($labelx[$i]);}
$i =$i+1;
} while ($i<($xmax-$xmin)-1);

$i = 0;
do {
$ytick = $i +$ymin + 1;
$labely[$i] = new Label(-.2,$ytick+.2, "$ytick",'black','center');
if ($ytick!=0) {$graph->lb($labely[$i]);}
$i =$i+1;
} while ($i<($ymax-$ymin)-1);

######################################

BEGIN_PGML

[@ image(insertGraph($graph),width=>400, height=>400, tex_size=>400) @]*

Use the graph given above to find the slope and equation for the line. Give the slope as an integer or fraction, no decimal values.

a) The slope of the line is [`m =`][______]{$m}

b) The equation of the line is [`y =`][__________________]{$f}

END_PGML

BEGIN_PGML_SOLUTION

Use the coordinates of the two blue dots to find the slope [`\ \displaystyle \frac{\Delta y}{\Delta x} = [$m]`]. The slope and one of the blue dots can be used to find the equation of the line using the point-slope form.

The solution, after simplifying, is [`y = [$f2]`]. Note: it is *not* necessary to simplify your equation.

END_PGML_SOLUTION

ENDDOCUMENT();