@@ -110,15 +110,17 @@ to add / change the styles.
110
110
111
111
$data->style(color => 'blue', width => 3);
112
112
113
- =item C<< $str = $data->function_string($coord , $type, $nvars ); >>
113
+ =item C<< $str = $data->function_string($formula , $type, $xvar, $yvar ); >>
114
114
115
- Takes a MathObject function string and replaces the function with either
115
+ Takes a MathObject C< $formula > and replaces the function with either
116
116
a JavaScript or PGF function string. If the function contains any function
117
117
tokens not supported, a warning and empty string is returned.
118
118
119
- $coord 'x' or 'y' coordinate function.
120
- $type 'js' or 'PGF' (falls back to js for any input except 'PGF').
121
- $nvars 1 (single variable functions) or 2 (used for slope/vector fields).
119
+ $formula The mathobject formula object, either $self->{function}{Fx} or $self->{function}{Fy}.
120
+ $type 'js' or 'PGF' (falls back to js for any input except 'PGF').
121
+ $xvar The x-variable name, $self->{function}{xvar}.
122
+ $yvar The y-variable name, $self->{function}{yvar}, for vector fields.
123
+ Leave undefined for single variable functions.
122
124
123
125
=item C<< $data->update_min_max >>
124
126
@@ -185,7 +187,7 @@ sub style {
185
187
map { $self -> {styles }{$_ } = $style_hash {$_ } } keys %style_hash ;
186
188
return ;
187
189
}
188
- return $self -> {styles }{ $styles [0] };
190
+ return $self -> {styles }{ $styles [0] } // ' ' ;
189
191
}
190
192
191
193
sub get_math_object {
@@ -249,22 +251,22 @@ sub update_min_max {
249
251
}
250
252
251
253
sub function_string {
252
- my ($self , $coord , $type , $nvars ) = @_ ;
253
- my $f = $self -> {function };
254
- my $MO = $coord eq ' y' ? $f -> {Fy } : $f -> {Fx };
255
- return ' ' if ref ($MO ) eq ' CODE' ;
254
+ my ($self , $formula , $type , $xvar , $yvar , $xtransform ) = @_ ;
255
+ return ' ' unless Value::isFormula($formula );
256
+ my %vars = ($xvar => $xtransform || ' x' , $yvar ? ($yvar => ' y' ) : ());
256
257
257
258
# Ensure -x^2 gets print as -(x^2), since JavaScript finds this ambiguous.
258
- my $extraParens = $MO -> context-> flag(' showExtraParens' );
259
- $MO -> context-> flags-> set(showExtraParens => 2);
260
- my $func = $MO -> string;
259
+ my $extraParens = $formula -> context-> flag(' showExtraParens' );
260
+ my $format = $formula -> context-> {format }{number };
261
+ $formula -> context-> flags-> set(showExtraParens => 2);
262
+ $formula -> context-> {format }{number } = " %f #" ;
263
+ my $func = $formula -> string;
261
264
$func =~ s /\s // g ;
262
- $MO -> context-> flags-> set(showExtraParens => $extraParens );
265
+ $formula -> context-> flags-> set(showExtraParens => $extraParens );
266
+ $formula -> context-> {format }{number } = $format ;
263
267
264
- $nvars = 1 unless $nvars ;
265
268
my %tokens ;
266
269
if ($type eq ' PGF' ) {
267
- my %vars = ($nvars == 2 ? ($f -> {xvar } => ' x' , $f -> {yvar } => ' y' ) : ($f -> {xvar } => ' x' ));
268
270
%tokens = (
269
271
sqrt => ' sqrt' ,
270
272
pow => ' pow' ,
@@ -302,7 +304,6 @@ sub function_string {
302
304
%vars
303
305
);
304
306
} else {
305
- my %vars = ($nvars == 2 ? ($f -> {xvar } => ' x' , $f -> {yvar } => ' y' ) : ($f -> {xvar } => ' t' ));
306
307
%tokens = (
307
308
sqrt => ' Math.sqrt' ,
308
309
cbrt => ' Math.cbrt' ,
@@ -367,6 +368,8 @@ sub function_string {
367
368
}
368
369
}
369
370
371
+ $out =~ s /\[ / (/ g ;
372
+ $out =~ s /\] / )/ g ;
370
373
return $out ;
371
374
}
372
375
0 commit comments