Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion htdocs/js/Plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,17 @@ const PGplots = {
options.xAxis.overrideOptions ?? {}
)
));
xAxis.defaultTicks.generateLabelText = plot.generateLabelText;

xAxis.defaultTicks.formatLabelText = plot.formatLabelText;

if (options.xAxis.ticks?.customLabels) {
xAxis.defaultTicks.generateLabelText = function (tick) {
return options.xAxis.ticks.customLabels[tick.usrCoords[1] / options.xAxis.ticks.distance - 1];
};
} else {
xAxis.defaultTicks.generateLabelText = plot.generateLabelText;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove all changes to this file. This pull request no longer should have any changes to this file.

if (options.xAxis.location !== 'middle' && options.xAxis.name !== '') {
plot.xLabel = board.create(
'text',
Expand Down
1 change: 1 addition & 0 deletions lib/Plots/Axes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ sub axis_defaults {
tick_labels => 1,
tick_label_format => 'decimal',
tick_label_digits => 2,
tick_label_custom => undef, # NEW: Array of custom labels
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this. It should not be here anymore.

tick_distance => 0,
tick_scale => 1,
tick_scale_symbol => '',
Expand Down
4 changes: 2 additions & 2 deletions lib/Plots/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ stored in the C<< $data->{function} >> hash, though other data is stored as a st
);

Note, the first argument must be $self->context when called from C<Plots::Plot>
to use a single context for all C<Plost::Data> objects.
to use a single context for all C<Plots::Data> objects.

This is also used to set a two variable function (used for slope or vector fields):

Expand Down Expand Up @@ -116,7 +116,7 @@ Takes a MathObject C<$formula> and replaces the function with either
a JavaScript or PGF function string. If the function contains any function
tokens not supported, a warning and empty string is returned.

$formula The mathobject formula object, either $self->{function}{Fx} or $self->{function}{Fy}.
$formula The MathObject formula object, either $self->{function}{Fx} or $self->{function}{Fy}.
$type 'js' or 'PGF' (falls back to js for any input except 'PGF').
$xvar The x-variable name, $self->{function}{xvar}.
$yvar The y-variable name, $self->{function}{yvar}, for vector fields.
Expand Down
28 changes: 18 additions & 10 deletions lib/Plots/JSXGraph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,29 @@ sub HTML {
$options->{mathJaxTickLabels} = $axes->style('mathjax_tick_labels') if $xvisible || $yvisible;

if ($xvisible) {
$options->{xAxis}{name} = $axes->xaxis('label');
$options->{xAxis}{ticks}{show} = $axes->xaxis('show_ticks');
$options->{xAxis}{ticks}{labels} = $axes->xaxis('tick_labels');
$options->{xAxis}{ticks}{labelFormat} = $axes->xaxis('tick_label_format');
$options->{xAxis}{ticks}{labelDigits} = $axes->xaxis('tick_label_digits');
$options->{xAxis}{name} = $axes->xaxis('label');
$options->{xAxis}{ticks}{show} = $axes->xaxis('show_ticks');
$options->{xAxis}{ticks}{labels} = $axes->xaxis('tick_labels');
if ($axes->xaxis('tick_label_custom')) {
$options->{xAxis}{ticks}{customLabels} = $axes->xaxis('tick_label_custom');
} else {
$options->{xAxis}{ticks}{labelFormat} = $axes->xaxis('tick_label_format');
$options->{xAxis}{ticks}{labelDigits} = $axes->xaxis('tick_label_digits');
}
Comment on lines +131 to +139
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert all changes to this file. This pull request should not have any changes to this file anymore.

$options->{xAxis}{ticks}{scaleSymbol} = $axes->xaxis('tick_scale_symbol');
$options->{xAxis}{arrowsBoth} = $axes->xaxis('arrows_both');
$options->{xAxis}{overrideOptions} = $axes->xaxis('jsx_options') if $axes->xaxis('jsx_options');
}
if ($yvisible) {
$options->{yAxis}{name} = $axes->yaxis('label');
$options->{yAxis}{ticks}{show} = $axes->yaxis('show_ticks');
$options->{yAxis}{ticks}{labels} = $axes->yaxis('tick_labels');
$options->{yAxis}{ticks}{labelFormat} = $axes->yaxis('tick_label_format');
$options->{yAxis}{ticks}{labelDigits} = $axes->yaxis('tick_label_digits');
$options->{yAxis}{name} = $axes->yaxis('label');
$options->{yAxis}{ticks}{show} = $axes->yaxis('show_ticks');
$options->{yAxis}{ticks}{labels} = $axes->yaxis('tick_labels');
if ($axes->yaxis('tick_label_custom')) {
$options->{yAxis}{ticks}{customLabels} = $axes->yaxis('tick_label_custom');
} else {
$options->{yAxis}{ticks}{labelFormat} = $axes->yaxis('tick_label_format');
$options->{yAxis}{ticks}{labelDigits} = $axes->yaxis('tick_label_digits');
}
$options->{yAxis}{ticks}{scaleSymbol} = $axes->yaxis('tick_scale_symbol');
$options->{yAxis}{arrowsBoth} = $axes->yaxis('arrows_both');
$options->{yAxis}{overrideOptions} = $axes->yaxis('jsx_options') if $axes->yaxis('jsx_options');
Expand Down
18 changes: 18 additions & 0 deletions lib/Plots/Plot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,24 @@ sub add_arc {
return $self->_add_arc(@data);
}

sub _add_rectangle {
my ($self, $pt0, $pt2, %options) = @_;
unless (ref($pt0) eq 'ARRAY' && @$pt0 == 2 && ref($pt2) eq 'ARRAY' && @$pt2 == 2) {
warn 'A rectangle requires two points defined by length two array references.';
return;
}
$options{fill} = 'self' if $options{fill_color} && !defined $options{fill};
return $self->_add_dataset($pt0, [ $pt2->[0], $pt0->[1] ], $pt2, [ $pt0->[0], $pt2->[1] ], $pt0, %options);
}

sub add_rectangle {
my ($self, @data) = @_;
if (ref($data[0]) eq 'ARRAY' && ref($data[0][0]) eq 'ARRAY') {
return [ map { $self->_add_rectangle(@$_) } @data ];
}
return $self->_add_rectangle(@data);
}

sub add_vectorfield {
my ($self, @options) = @_;
my $data = Plots::Data->new(name => 'vectorfield');
Expand Down
7 changes: 2 additions & 5 deletions macros/core/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ sub image {
);
next;
}
if (ref $image_item eq 'Plots::Plot') {
if (ref $image_item eq 'Plots::Plot' || ref $image_item eq 'Plots::StatPlot') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be worthwhile to make this more general, for future extension macros. Maybe call your package Plots::Plot::StatPlot, and then have this only check if ref $image_item starts with Plots::Plot, that way this won't have to be updated each time someone wants to extend Plots?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also think there are some other places that might need to be updated, I recall having to modify a few places to check for the ref being equal to Plots::Plot beyond just this place (for some older image macros).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally this would be an isa call. Then any object that derives from a Plots::Plot object would work here. Unfortunately, to properly do that you need the Scalar::Util::blessed method which is not available here. The correct way to check if an object, say $object, derives from a particular class is if (blessed($object) && $object->isa('Parent::Package')).

When I was creating the SimpleGraph.pl macro, I almost made that package derive from the Plots::Plot package, and then wanted to make this code that way, but ran into the issue with the lack of the blessed method availability. I ended up going a different direction with the SimpleGraph.pl macro though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, line 2946 below needs to check the ref also.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DO NOT add this ref check to either macros/core/VectorField2D.pl or macros/graph/unionImage.pl. There are checks for the Plots::Plot object in those macros.

The VectorField2D.pl macro usage doesn't make sense for this statistical graph macro.

As to the unionImage.pl one, I told @somiaj not to add that there. It should be removed. No one should be using that macro anymore, and it should be moved into the deprecated folder.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wondering what to do with this. When you say that the Scalar::Util::blessed method isn't available, is this a safe issue?

Suggestions for updating this?

# Update image attributes as needed.
$image_item->{width} = $width if $out_options{width};
$image_item->{height} = $height if $out_options{height};
Expand All @@ -2942,10 +2942,7 @@ sub image {
$width_ratio = 0.001 * $image_item->{tex_size};
}
$image_item = insertGraph($image_item)
if (ref $image_item eq 'WWPlot'
|| ref $image_item eq 'Plots::Plot'
|| ref $image_item eq 'PGlateximage'
|| ref $image_item eq 'PGtikz');
if (grep { ref $image_item eq $_ } ('WWPlot', 'Plots::Plot', 'Plots::StatPlot', 'PGlateximage', 'PGtikz'));
my $imageURL = alias($image_item) // '';
$imageURL = ($envir{use_site_prefix}) ? $envir{use_site_prefix} . $imageURL : $imageURL;
my $id = $main::PG->getUniqueName('img');
Expand Down
Loading
Loading