Fraction tick labels

127 views
Skip to first unread message

Jesus Cital

unread,
Mar 1, 2024, 8:03:27 PM3/1/24
to JSXGraph
I have this code to use fractions as the name of the ticks when the point is clicked on. If this is possible how would I be able to run this as defaut text on the ticks? 

I can click on my end but the fiddle doesn't seem to work when clicked.  


I have found Alberts way to use MathJax however that is a predefined axis range and I need the labels to be dyamic as the axis will change.  

Hope it makes sense.

Thanks


Murray

unread,
Mar 4, 2024, 5:31:16 AM3/4/24
to JSXGraph
Hello Jesus

What you were trying to do looked overly complicated to me. Also, be careful calling both MathJax and KaTeX in the one script, as they will surely not play nicely.

I'm not sure what you mean by "I can click on my end but the fiddle doesn't seem to work when clicked."

I think I can see what you are wanting to end up with. Essentially, what you can do is:

1. Create the array of ticks you want
2. Compare the values from the array to the "v" in the usrCoords step in a loop.
2. Get MathJax to render the fractions (you need to tell it to do so after each time you change the ticks).

I've put the ticks creation part in a function so we can call it multiple times, and I've given you a slider so you can change tick distances easily.

Note: Some of the fractions ended up in funky positions, but settled into the correct places on a user action.

BTW, you can't use the $0$ approach in this case - it needs to be \( 0 \).

Here it is:


Hope it helps
Regards
Murray

Alfred Wassermann

unread,
Mar 4, 2024, 7:12:12 AM3/4/24
to JSXGraph
This feature is now implemented: the next version (will be released in a few days) comes with the attribute "toFraction", which does exactly this.
Then you will be able to do something like this:

        var board = JXG.JSXGraph.initBoard('jxgbox', {
            boundingbox: [-1.2, 2.3, 1.2, -2.3],
            axis: true,
            defaultAxes: {
                x: {
                    ticks: {
                        label: {
                            useMathJax: true,
                            display: 'html',
                            toFraction: true
                        }
                    }
                },
                y: {
                    ticks: {
                        label: {
                            useMathJax: true,
                            display: 'html',
                            toFraction: true
                        }
                    }
                }
            }
        });
        board.create('text', [0.5, -0.5, 2 / 17], { toFraction: true, useMathjax: true });

See the appended picture.screenshot2.png

Best wishes, Alfred


Jesus Cital

unread,
Mar 4, 2024, 10:43:09 AM3/4/24
to JSXGraph
Awesome, Thanks to both of you!  I love your function Murray; I was thinking I needed to simplify that.  

Can't wait for this update! 

Regards

Jesus

Murray

unread,
Mar 4, 2024, 8:41:23 PM3/4/24
to JSXGraph
Hi Alfred

The fractions on the negative x-axis appear to be positive, while the -1 is correct.

Regards
Murray

Alfred Wassermann

unread,
Mar 5, 2024, 3:38:28 AM3/5/24
to JSXGraph
Hi Murray,
oops, how stupid! Thanks a lot for this bug report. It is fixed now.
Best wishes,
Alfred

Murray

unread,
Mar 5, 2024, 7:24:05 PM3/5/24
to JSXGraph
Another consideration with this. Normally, if the interval is 1/6, I'd want the following (or at least the choice):

0 1/6 1/3 1/2 2/3 5/6 1

Is this assumed, or is it going to be like my solution, which is the non-cancelled versions?

Regards
Murray

Alfred Wassermann

unread,
Mar 6, 2024, 2:20:18 AM3/6/24
to JSXGraph
Hi Murray,
at the moment, the default is to display

0 1/6 1/3 1/2 2/3 5/6 1

The non-cancelled version has still to be implemented (if there is a demand for it).
The labels are generated by the new method JXG.toFraction(number, useTeX) which in turn calls JXG.Math.decToFraction(number).
The function JXG.Math.decToFraction returns an array [sign, integer, nominator, denominator], where nominator, denominator
are computed as the convergents of the continued fraction expansion of the number.

Today, I released v1.7.1-beta, so you can try it out by loading
The updated API docs is at https://jsxgraph.org/beta/docs

Best wishes,
Alfred

Jesus Cital

unread,
Mar 6, 2024, 10:19:50 AM3/6/24
to JSXGraph
Seems to work like a charm!  AWESOME! 

Thanks 

Jesus 

Jesus Cital

unread,
Mar 7, 2024, 11:49:57 AM3/7/24
to JSXGraph
Is this still on schedule to go live?

Thanks

Jesus

On Wednesday, March 6, 2024 at 1:20:18 AM UTC-6 Alfred.W...@uni-bayreuth.de wrote:

Alfred Wassermann

unread,
Mar 8, 2024, 7:01:17 AM3/8/24
to JSXGraph
v1.8.0 is just has been released.

Jesus Cital

unread,
Jun 22, 2024, 1:03:20 PM6/22/24
to JSXGraph
OK, I am trying it here and the axis don't display mixed numbers as your version up top.


Thanks, 

Alfred Wassermann

unread,
Jun 23, 2024, 2:28:38 PM6/23/24
to JSXGraph
Oops, what a shame. This bug has been introduced recently together with a brilliant improvement...
It is fixed now in the sources, v1.9.2 will be published later this week.

Thanks for pointing this out,
Alfred


Reply all
Reply to author
Forward
0 new messages