chird / meteoJS

Javascript Library for meteorological and atmospheric tools
Apache License 2.0
28 stars 6 forks source link

Is there a way to change wind speed unit in m/s in the wind speed profile? #60

Closed github0013 closed 2 years ago

github0013 commented 2 years ago
Screen Shot 2022-06-09 at 9 49 31
const diagram = new meteoJS.ThermodynamicDiagram({
  renderTo,
  windspeedProfileAxis: {
    labels: {
      unit: "m/s",
      prefix: "m/s",
    },
  },
})

I could change windspeed x-axis label unit in m/s like that above. However, it seems not possible to change the windspeed unit on hover?

https://github.com/chird/meteoJS/blob/0a76e1eb720a88e193a6942ac68a3ddfc8805ada/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js#L296

Is this the part showing the hover text? hard coded in knot?

chird commented 2 years ago

Yes, it is hardcoded (yet).

But theirs an option to override the full function, which draws the hover label.

const diagram = new meteoJS.ThermodynamicDiagram({
  renderTo,
  windspeedProfile: {
    hoverLabels: {
      insertLabelsFunc: (sounding, levelData, group) => {
        …
      }
    },
  },
})

You could basically copy this function (but have to replace this):

https://github.com/chird/meteoJS/blob/0a76e1eb720a88e193a6942ac68a3ddfc8805ada/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js#L253..L304

And then you could change your highlighted line to something like that:

`${Math.round(levelData.wspd*10)/10} m/s`
masterfabela commented 2 years ago

I have the same issue i want to change the kn default hover labels to km/h but the _makeInsertLabelsFunc function that generates that labels have dependencies like this and windspeed how i can replace this function without this values? or how can I obtain the this and windspeedin the new ThermodynamicDiagram() context?

function generateNewThermodinamicDiagram (htmlContainer) {
  const meteojs = require('meteojs')
  return new meteojs.ThermodynamicDiagram({
    renderTo: htmlContainer,
    windspeedProfileAxis: {
      labels: {
        unit: 'km/h',
        prefix: 'km/h'
      }
    },
    windspeedProfile: {
      hoverLabels: {
        insertLabelsFunc: function (sounding, levelData, group) {
          // this = undefined
          // windspeed = undefined
        }
      }
    }
  })
}
chird commented 2 years ago

A first brief answer: I try to prepare a release 1.16.2 soon. With this release the unit will be configurable.

chird commented 2 years ago

I just released 1.17.0 with the new options. Now you can do something like this:

const diagram = new meteoJS.ThermodynamicDiagram({
  renderTo,
  windspeedProfile: {
    hoverLabels: {
      windspeed: {
        windspeed: {
          unit: 'm/s',
          decimalPlaces: 1,
          prefix: ' m/s'
        }
      }
    }
  }
});
github0013 commented 2 years ago

It feels like to me, if it was suffix instead of prefix, it would sound more intuitive.

chird commented 2 years ago

Oh, of course. Thank you for the hint. I have adopted the options without thinking about it so far. It was already incorrect before. I will introduce the suffix option in the next release, backwards compatible of course.