Skip to content

Fix drawZero for JSXGraph output of the plots macro.#1387

Open
drgrice1 wants to merge 1 commit intoopenwebwork:developfrom
drgrice1:fix-plots-jsxgraph-drawzero
Open

Fix drawZero for JSXGraph output of the plots macro.#1387
drgrice1 wants to merge 1 commit intoopenwebwork:developfrom
drgrice1:fix-plots-jsxgraph-drawzero

Conversation

@drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Mar 24, 2026

Currently if the y axis location is 'left' (or 'box'), or 'right', then the determination that zero is drawn is made by checking that the y axis min or max value. That is incorrect. It should be checking the x axis min or max value. The point is that if the y axis is passing through x = 0, then zero should not be drawn, and otherwise it should be.

Similarly, the y axis drawZero determination is fixed.

You can test this with the following problem code:

DOCUMENT();

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

$graph = Plot(
    xmin           => -2,
    xmax           => 10,
    xtick_distance => 1,
    xminor         => 0,
    xlocation      => 'bottom',
    ymin           => 0,
    ymax           => 10,
    ytick_distance => 1,
    yminor         => 0,
    ylocation      => 'left'
);

BEGIN_PGML
[!graph!]{$graph}{500}
END_PGML

ENDDOCUMENT();

With that example and the develop branch the zero on the x-axis is incorrectly not drawn in JSXGraph output. With this branch it is drawn as it should be. Note that in TikZ output the zero is drawn with this example. So this makes the two output formats consistent.

Copy link
Contributor

@somiaj somiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the bug.

Currently if the y axis location is 'center', 'left' (or 'box'), or
'right', then the determination that zero is drawn is made by checking
that the y axis min or max value.  That is incorrect.  It should be
checking the x axis min or max value.  The point is that if the y axis
is passing through x = 0, then zero should not be drawn, and otherwise
it should be.

Similarly, the y axis `drawZero` determination is fixed.

You can test this with the following problem code:

```
DOCUMENT();

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

$graph = Plot(
    xmin           => -2,
    xmax           => 10,
    xtick_distance => 1,
    xminor         => 0,
    xlocation      => 'bottom',
    ymin           => 0,
    ymax           => 10,
    ytick_distance => 1,
    yminor         => 0,
    ylocation      => 'left'
);

BEGIN_PGML
[!graph!]{$graph}{500}
END_PGML

ENDDOCUMENT();
```

With that example and the develop branch the zero on the x-axis is
incorrectly not drawn in JSXGraph output.  With this branch it is drawn
as it should be. Note that in TikZ output the zero is drawn with this
example. So this makes the two output formats consistent.
@drgrice1 drgrice1 force-pushed the fix-plots-jsxgraph-drawzero branch from 27e05e1 to 995ba8e Compare March 24, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants