Skip to content
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

Adjust Meclib behaviour to STACK setting of decimal separator #51

Open
mkraska opened this issue Jul 30, 2024 · 2 comments
Open

Adjust Meclib behaviour to STACK setting of decimal separator #51

mkraska opened this issue Jul 30, 2024 · 2 comments

Comments

@mkraska
Copy link
Owner

mkraska commented Jul 30, 2024

STACK 4.6 has a question-wide option "decimal separator", which can be set to "." or ",".

If it is set to , then the comma becomes the decimal separator and the semicolon ; becomes the argument separator in functions and lists.

The required modifications are:

  • Detect the separator setting in the question
  • Change the format of the contents of the names input field (unidirectional, JSXGraph to STACK only)
  • Change the format of the infobox (dynamic display of coordinates)
  • Change the format of tick labels on axes

Detect the separator setting in the question

The brute force option is to add a constant in the `[[JSXGraph]] block and set it manually to the value of the separator option in the question.

const decsep = ",";

This must be defined manually according to the question setting, unless there is a CAS variable in STACK which reflects that setting.

EDIT 2024-10-19: Actually there is such a variable: stackfltsep. It is a string.

Format of the names input field

Adjustment of the output format is done in the Meclib function update().

  for (m of objects) {
    dfield.push(m.data());
    if (names != "[") { names = names.concat(",") }
    names = names.concat(m.name()); }
  names = names.concat("]");
  // adjust separators 
  if (decsep == ",") {
    names = names.replace(/,/g, ';');
    names = names.replace(/\./g, ',');}

This adjustment is required as long as STACK doesn't provide a forgiving mode, where both versions are accepted

Format of the Infobox

The Infobox is customized using the function

board.highlightInfobox = function(x, y , el) {
    let ref = [0,0];
    let scale = [xscale,yscale];
    let dp = [dpx,dpy];
    let lbl = '';
    if (typeof (el.ref) == 'function') {ref = el.ref()} 
    else if (typeof(el.ref) != 'undefined') {ref = el.ref}
    if (typeof (el.scale) != 'undefined') {scale = el.scale}
    if (typeof (el.dp) != 'undefined') {dp = el.dp}
    if (typeof (el.infoboxlabel) == 'string') {lbl = el.infoboxlabel}
    this.infobox.setText( 
        lbl+'('+((parseFloat(x)-ref[0])*scale[0]).toFixed(dp[0]) + ', ' + ((parseFloat(y)-ref[1])*scale[1]).toFixed(dp[1])+ ')')
};

The modification could probably be done using JS native localization methods.

Format of the tick labels

The tick labels are also already customized in the [["grid"]] object.

  this.xaxis = board.create('axis', [[0, 0], [1,0]], 
    {name:toTEX(data[1]), withLabel: true, label: labelopt, layer:0,
    ticks: { label:{layer:3}, generateLabelValue:function(p1,p2) {
      return ((p1.usrCoords[1]-p2.usrCoords[1])*fx).toFixed(Math.max(...[0,dpx-1]))}} });}

The modification could probably be done using JS native localization methods.

@mkraska
Copy link
Owner Author

mkraska commented Jul 30, 2024

Formatting of the output is tested in TM2 03 T02 V2 Mohr's circle (stress) (Meclib, localized)

@mkraska
Copy link
Owner Author

mkraska commented Aug 4, 2024

Here https://jsfiddle.net/7k0a4jbv/3/ you can find a meclib version with german locale. Infobox and axes tick labels are adjusted.

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

No branches or pull requests

1 participant