question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

financeDiscontinuousScale- Help with specifying an initial index -persisting lines

See original GitHub issue

I’m trying use discontinuousTimeScaleProviderBuilder() to take advantage of persisting the position of a line. I found that I could maybe use the indexCalculator, and just persist a ‘zero-day’ value, and maintain the same position throughout the lifetime of the persistance of a chart.

Eventually I get a

financeDiscontinuousScale.js:85 Uncaught TypeError: Cannot read property 'level' of undefined

Here is some code

    //we should find the 0-day in our data  and work from there
   //zeroDay is a string, we need to convert to a date and find it in our inputData
   var {data: inputData,defaultBarsDisplayed,zeroDay}=props;
   var barsDisplayed=defaultBarsDisplayed||100
    var zeroDayDate=new Date(zeroDay)
    var zeroIndex = inputData.findIndex(function (x) {
      return x.date.getTime() === zeroDayDate.getTime();
    });
    
    var initialIndex=-zeroIndex+inputData.length-barsDisplayed
    var indexCalculator = discontinuousTimeScaleProviderBuilder().initialIndex(initialIndex).indexCalculator();
    var { index, interval } = indexCalculator(dataToCalculate.slice(-barsDisplayed));
    var xScaleProvider = discontinuousTimeScaleProviderBuilder().withIndex(index).withInterval(interval)
    var { data: stateData, xScale, xAccessor, displayXAccessor } = xScaleProvider(dataToCalculate.slice(-barsDisplayed))
    return { stateData, xScale, xAccessor, displayXAccessor }

Some vars at the breakpoint image

statedata[0],statedata[1] image

financeDiscontinuousScale (j=342, which is out of bounds, but it should be 171, which I specified ) image

Is there a potential way around the Math.max, or a better way? https://github.com/rrag/react-stockcharts/blob/master/src/lib/scale/financeDiscontinuousScale.js#L76

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
itsjimbocommented, Nov 9, 2016

I think I figured out my problem, I can’t do arithmetic! 😃

    var zeroDayDate=new Date(zeroDay)
    //find the zero-th date in our input 
    var zeroIndex = inputData.findIndex(function (x) {
      return x.date.getTime() === zeroDayDate.getTime();
    });
    //create an initial computation slice
    initialSlice=initialSlice>inputData.length?inputData.length:initialSlice
    zeroIndex=zeroIndex-(inputData.length- initialSlice)
    console.log('zeroIndex',zeroIndex)
0reactions
rragcommented, Nov 20, 2016

@itsjimbo sorry I missed your last comment

j iterates the integer values inside the xdomain so for e.g. if the xDomain is from say -200 to 300 j iterates between these values, the important part to remember here is that the scale always needs the complete index. Even if you append more data to the beginning or end, you need a new index [] for the complete data. To put it differently, index [].length and data[].length must always match

i always iterates between 17 to 0 (atleast for now)

I dont see any changes needed in that block of code.

It does get confusing when you want to lazy load data before the 0 index, but I see that as a documentation problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found