WeBWorK Problems

Feature request for GraphTool

Feature request for GraphTool

by Robin Cruz -
Number of replies: 6

Hi, all,

I would like to write problems on simple translations for the middle school project I'm working on and having the GraphTool do triangles and quadrilaterals would be really great.  

Any help on this would be appreciated --rac

In reply to Robin Cruz

Re: Feature request for GraphTool

by Glenn Rice -

I have created graph tools and graph objects for triangles and quadrilaterals.  They are in the attached zip file. The zip file is designed so that you can upload into the root directory of your course and extract it and it will put all of the files where they need to go.

In the zip file are the files:

  • html/js/GraphTool/triangle.js
  • html/js/GraphTool/triangle.svg
  • html/js/GraphTool/triangle.css
  • html/js/GraphTool/quadrilateral.js
  • html/js/GraphTool/quadrilateral.svg
  • html/js/GraphTool/quadrilateral.css
  • templates/macros/GraphToolTriangle.pl
  • templates/macros/GraphToolQuadrilateral.pl
  • templates/Examples/Triangle.pg
  • templates/Examples/Quadrilateral.pg
The last two files are problems that demonstrate the usage of the macros that add tools and graph objects. Note that both macros can be used together in the same problem if desired.

I will plan to put in a pull request to add these to the parserGraphTool.pl macro for the next release of PG.  So after that release you can delete all of the html and macros files, and just load the parserGraphTool.pl macro instead of the GraphToolTriangle.pl and GraphToolQuadrilateral.pl macros.

In reply to Glenn Rice

Re: Feature request for GraphTool

by Glenn Rice -
There was a bug in the triangle regarding usage with the fill tool. Here is an updated zip with the fixed version.
In reply to Glenn Rice

Re: Feature request for GraphTool

by Robin Cruz -

Hi, Glen,

Wow! GraphTool with the triangle and quadralateral objects works great! Thank you! 

Is there an option to change the color of the graphed object?  I didn't see anything about it in the documentation, so perhaps not.  As an example, I want to show a triangle and ask the student to graph a reflection of it.  A different color is not essential. (I could make it "dashed".)  It would look nice having the given image be different from the "answer" image.  I've included the code below.

Thanks, again--rac

---------------------------------------------------------------------------------

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'GraphToolTriangle.pl', 'PGcourse.pl');

$x1 = random(1, 4);   $y1 = random(1, 8);

$x2 = random(6, 8);   $y2 = random(1, 8);

do { 

  $x3 = random(0, 8);   $y3 = random(-8, 8) 

   }

 until ($y3 - $y1) * ($x2 - $x1) != ($y2 - $y1) * ($x3 - $x1) && abs($y2-$y3)>1 && abs($y1-$y3)>1;

 $rx1 = -1*$x1;   $ry1 = $y1;

 $rx2 = -1*$x2;   $ry2 = $y2;

 $rx3 = -1*$x3;   $ry3 = $y3;

$gt = GraphTool("{ triangle, solid, ($rx1, $ry1), ($rx2, $ry2), ($rx3, $ry3) }")

    ->with(

    bBox           => [ -10, 10, 10, -10 ],

    availableTools => [ 'TriangleTool' ],

    staticObjects => ["{triangle, solid, ($x1, $y1), ($x2, $y2), ($x3, $y3)}"]);

BEGIN_PGML

The vertices of the triangle shown below are [`([$x1], [$y1])`], [`([$x2], [$y2])`] and [`([$x3], [$y3])`].  Draw on the same axes the image of the triangle under the reflection in the [`y`]-axis.

[_]{$gt}

END_PGML

ENDDOCUMENT();

In reply to Robin Cruz

Re: Feature request for GraphTool

by Glenn Rice -

Unfortunately there isn't a way to set the colors of the things that are graphed.  Perhaps that could be implemented someday, but it would be challenging to figure out how to pass such an option from Perl to JavaScript in a reasonable way.

In reply to Glenn Rice

Re: Feature request for GraphTool

by Robin Cruz -
OK, thanks for getting back on this. Thought I'd check. The GraphTool is great and I've already written quite a few problems using the new objects.

Thanks!
--rac
In reply to Robin Cruz

Re: Feature request for GraphTool

by Alex Jordan -

Maybe static objects and user-created objects should have different colors? Or at least an option to have different colors?