lightweight-charts icon indicating copy to clipboard operation
lightweight-charts copied to clipboard

Accessing tickMarkFormatter value from outside

Open M4N0JKUM4R opened this issue 2 years ago • 0 comments

Currently the tickMarkFormatter function works when function is passed in as property value.

function String(time) {
  const date = new Date(time.year, time.month, time.day);
  if (e.target.innerText === "YYYY/MM/DD") {
    return (
      date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate()
    );
  } else if (e.target.innerText === "DD/MM/YYYY") {
    return (
      date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear()
    );
  }

  return undefined;
}

const newTimeScale = { ...localValue, tickMarkFormatter: String };

console.log("New time scale", newTimeScale.tickMarkFormatter);

setTimeScale((prevValue) => {
  return {
    ...prevValue,
    tickMarkFormatter: String,
  };
});

setLocalAttributes({
  ...localValue,
  tickMarkFormatter: String,
});    

But is it possible to get the string outside the tickMarkFormatter property so that I can saved the attributes as a string. Currently saving functions as attribute value is not possible in WordPress Gutenberg. Looking for some ideas.

M4N0JKUM4R avatar Jul 15 '22 12:07 M4N0JKUM4R

Just to check: You can only pass 'attributes' to Lightweight charts which are valid json? Thus you can't pass a function as part of the attribute. Is that correct?

This isn't an issue with the library, or a feature request so it would be better to ask this question on the lightweight-charts or Wordpress stackoverflow. So I'm going to close the issue but if you do create a question or discussion on stackoverflow or something similar then please comment below with the link and I'll try have a look at it.

SlicedSilver avatar Aug 26 '22 18:08 SlicedSilver