Skip to content

Plots Improvements - A continutation of #966 #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: PG-2.20
Choose a base branch
from

Conversation

somiaj
Copy link
Contributor

@somiaj somiaj commented Jun 12, 2025

This is the new branch of improvements to the new Plots library after my accidental merge of #966.

drgrice1 and others added 2 commits June 12, 2025 08:28
There were two connected problems.  First, I was not checking the
correct container div size in the "drawPromise" for the dialog version
of the graph. I was always checking the div for the main JSXGraph image
in the page.  Although, that doesn't entirely matter since the real
problem was that the imageview JSXGraph div did not have its size set on
initialization (which I do in all of the other places where I do this
sort of thing with JSXGraph).
@somiaj
Copy link
Contributor Author

somiaj commented Jun 12, 2025

Working on the colors, I think the issue @drgrice1 pointed out was due to contrast, and I do agree that the green doesn't look as good. I took the colors from the W3school color wheel and wanted something that wasn't as stark as just #00ff00. https://www.w3schools.com/colors/colors_wheels.asp

I liked the looks of the RYB color wheel, so I went with that, but I didn't pay close enough attention and noticed that the wheel they draw and the color codes they give do not match, and agree that green is the worst looking. Maybe I'll just grab the colors from the wheel directly. Here is a test problem.

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

$plot = Plot(xvisible => 0, yvisible => 0);
$plot->add_dataset(
    [ -4, 1 ], [ -2, 1 ], [ -2, 3 ], [ -4, 3 ], [ -4, 1 ],
    width      => 5,
    color      => 'red',
    fill       => 'self',
    fill_color => 'red',
);
$plot->add_dataset(
    [ -1, 1 ], [ 1, 1 ], [ 1, 3 ], [ -1, 3 ], [ -1, 1 ],
    width      => 5,
    color      => 'yellow',
    fill       => 'self',
    fill_color => 'yellow',
);
$plot->add_dataset(
    [ 2, 1 ], [ 4, 1 ], [ 4, 3 ], [ 2, 3 ], [ 2, 1 ],
    width      => 5,
    color      => 'blue',
    fill       => 'self',
    fill_color => 'blue',
);
$plot->add_dataset(
    [ -4, -1 ], [ -2, -1 ], [ -2, -3 ], [ -4, -3 ], [ -4, -1 ],
    width      => 5,
    color      => 'orange',
    fill       => 'self',
    fill_color => 'orange',
);
$plot->add_dataset(
    [ -1, -1 ], [ 1, -1 ], [ 1, -3 ], [ -1, -3 ], [ -1, -1 ],
    width      => 5,
    color      => 'green',
    fill       => 'self',
    fill_color => 'green',
);
$plot->add_dataset(
    [ 2, -1 ], [ 4, -1 ], [ 4, -3 ], [ 2, -3 ], [ 2, -1 ],
    width      => 5,
    color      => 'purple',
    fill       => 'self',
    fill_color => 'purple',
);

for ('Tikz', 'JSXGraph') {
    $plot->image_type($_);
    $image{$_} = image($plot);
}

BEGIN_PGML
**Tikz Image:**

[$image{Tikz}]*

**JSXGraph Image:**

[$image{JSXGraph}]*

END_PGML
ENDDOCUMENT();

The green by itself without contrasting with blue doesn't look as bad, but I'll update to the colors shown in the wheel vs the color codes given (unless someone knows some decent color codes for a base pallet, I just thought the RGB codes were a bit much which was why I wanted to change them).

myscrot

And here is what the colors look like if I grab the color codes from the color wheel W3 has vs use the codes they provide.

myscrot

To me I like the red/blue/purple from the first, and the yellow/green/orange from the second image.

@somiaj
Copy link
Contributor Author

somiaj commented Jun 12, 2025

I think I tracked down my initial dislike, seems svg defines #00ff00 as lime green, and that didn't look green to me, just updating green to be #008000 made a lot of difference to me. So here is the primary and secondary colors as defined by svg.

colors

@somiaj somiaj force-pushed the plots-improvements branch 2 times, most recently from b4e8005 to 42fd949 Compare June 12, 2025 17:07
The W3 RYB colors didn't look right, reverting but changing
green to be the SVG/HTML definition `#008000` which looks better
to me than `#00ff00`, which SVG calls lime green. Also adding
the secondary RGB colors `cyan` and `magenta`, but keeping the
RYB secondary colors orange and purple. Add `grey` as an alternative
spelling for `gray` as well.
@somiaj somiaj force-pushed the plots-improvements branch from 42fd949 to 5465185 Compare June 12, 2025 17:14
@somiaj
Copy link
Contributor Author

somiaj commented Jun 12, 2025

Here are the colors I went with, let me know if you would prefer any changes.

colors

* Only show minor grid lines if major grid lines are shown.
* Fix issue with Tikz not hiding tick marks correctly with
  show_ticks set to zero for the appropriate axes.
* Make it so axes will adjust their size to the current view
  when `jsx_navigation` is enabled.
* Fixed a bug with JSXGraph not changing the min/max bounds
  of a function to a number from a string, such '2pi'.
@somiaj
Copy link
Contributor Author

somiaj commented Jun 12, 2025

I have updated the examples for those who want to testing things, I have removed GD from all my test examples, as it has falling behind, and the focus now is JSXGraph for HTML and Tikz for hardcopy.

Plots_examples.tar.gz

@drgrice1
Copy link
Member

Those colors look better.

@somiaj
Copy link
Contributor Author

somiaj commented Jun 13, 2025

Here is a problem to see/test the line style changes.

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

$plot = Plot(xvisible => 0, yvisible => 0);

@linestyles = (
    'solid',        'dashed',
    'short dashes', 'long dashes',
    'dotted',       'long medium dashes',
    'bad line style',
);
for my $i (0 .. 6) {
    $plot->add_dataset(
        [ -4, $i - 3 ], [ 4, $i - 3 ],
        linestyle  => $linestyles[$i],
        start_mark => 'arrow',
        end_mark   => 'arrow',
    );
}

for ('Tikz', 'JSXGraph') {
    $plot->image_type($_);
    $image{$_} = image($plot);
}

BEGIN_PGML
**Tikz Image:**

[$image{Tikz}]*

**JSXGraph Image:**

[$image{JSXGraph}]*
END_PGML
ENDDOCUMENT();

Update the line style options and adjust how the line style is
applied to make the Tikz lines look like the line styles defined
by JSXGraph. The line styles are now 'solid', 'dashed', 'dotted',
'short dashes', 'long dashes', 'long medium dashes', or 'none'.

Also fixed an issue where functions must generate data points
for JSXGraph if the markers are to be drawn.
@somiaj somiaj force-pushed the plots-improvements branch from 63f7eee to 607145a Compare June 13, 2025 00:19
@somiaj
Copy link
Contributor Author

somiaj commented Jun 13, 2025

Updated examples:

Plots_examples.tar.gz

@somiaj somiaj force-pushed the plots-improvements branch 2 times, most recently from ff1d92a to e298619 Compare June 13, 2025 05:17
A new method to add arcs defined by three points.

    $plot->add_arc([$x1, $y1], [$x2, $y2], [$x3, $y3], %options);

In the process reduce some code duplication, by creating a single
get_options method for JSXGraph options as the code for that had
been duplicated a few times, also try to minimize having to test
and fall back to default values when a data style is not defined.
@somiaj somiaj force-pushed the plots-improvements branch from e298619 to ce29e60 Compare June 13, 2025 05:29
This matches the setting used in Tikz and JSXGraph and gives more
control over the rotation of the label.
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