WeBWorK Problems

Can the Graphtool number line do decimals?

Can the Graphtool number line do decimals?

by Robin Cruz -
Number of replies: 2
Hi, all,
I am trying to write a problem to graph an interval with the Graphtool number line with endpoints that are not integers.  It seems with the minorTicksX option one can see tick marks between integer tick marks, but the Interval's endpoints seems to "lock" onto the closest integer.  Is there a setting to let the endpoints attach to endpoints like 1.5?
Thanks -- rac

---------------------------Code-------------------------------------

DOCUMENT();

loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "PGML.pl",

  "parserGraphTool.pl",

  "contextInequalities.pl"

);

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

# Set-up

Context("Inequalities-Only");

#--part a------------------------------

$na1 = 1.5;

$na2 = random(1,4);

$a1 = Inequality("x > $na1");

$a2 = Inequality("x < $na2");

$ans_a = Inequality("$na1 < x < $na2");

$numberLine_a = GraphTool("{interval, ($na1,$na2)}")->with(

    availableTools =>

        [ 'IntervalTool', 'IncludeExcludePointTool' ],

    numberLine     => 1,

    bBox           => [ -8, 8 ],

    ticksDistanceX => 1,

    minorTicksX    => 4,

    useBracketEnds => 0

);

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

# Main text

BEGIN_PGML

Write the pair of simple statements as a compound statement and illustrate the answer on a number line.


    *Note:* _For [`<`], [`>`], [`\leq`], [`\geq`], [`=`], or [`\neq`]. Enter these as *<*, *>*, *<=*, *>=*, *=*, and *!=*._  


[` [$a1], [$a2] `]  

     Answer: [_]{$ans_a}    [_]{$numberLine_a}

END_PGML

ENDDOCUMENT();        

In reply to Robin Cruz

Re: Can the Graphtool number line do decimals?

by Glenn Rice -
Yes it can, but with limitations. Set snapSizeX to what you need. It must be greater than zero. In fact technically it must be greater than JSXGraphs JXG.Math.eps which is 1e-5 (if I recall correctly). There are some issues with rounding in some cases though, and with small snap sizes it can be hard to place the points at infinity on the number line.  The arrow keys on the keyboard may be necessary in some cases to accurately place points. There are some improvements in https://github.com/openwebwork/pg/pull/1157 that make things a little better for the rounding issues and placing points at the edge of the board. In any case, values such as snapSizeX = 1/2, snapSizeX = 1/5, or snapSizeX = 1/10 should work fine.
In reply to Glenn Rice

Re: Can the Graphtool number line do decimals?

by Robin Cruz -
I don't need very small sizes, so this works as I wanted.

Thanks, Glenn!
--rac