|
| 1 | +function runTestCase(container) { |
| 2 | + const chart = window.chart = LightweightCharts.createChart(container, { layout: { attributionLogo: false } }); |
| 3 | + |
| 4 | + const lineSeries = chart.addSeries(LightweightCharts.LineSeries); |
| 5 | + |
| 6 | + lineSeries.setData([ |
| 7 | + { time: '1990-04-24', value: 0 }, |
| 8 | + { time: '1990-04-25', value: 1 }, |
| 9 | + { time: '1990-04-26', value: 2 }, |
| 10 | + { time: '1990-04-27', value: 3 }, |
| 11 | + { time: '1990-04-28', value: 4, color: 'green' }, |
| 12 | + { time: '1990-04-29', value: 5, color: 'red' }, |
| 13 | + ]); |
| 14 | + |
| 15 | + chart.timeScale().fitContent(); |
| 16 | + chart.timeScale().scrollToPosition(-1); |
| 17 | + |
| 18 | + return new Promise(resolve => { |
| 19 | + requestAnimationFrame(() => { |
| 20 | + const lastValueInView = lineSeries.lastValueData(false); |
| 21 | + console.assert( |
| 22 | + lastValueInView.noData === false, |
| 23 | + 'expected to find data for last value in view' |
| 24 | + ); |
| 25 | + console.assert( |
| 26 | + lastValueInView.price === 4, |
| 27 | + `expected to find price 4 as last value in view, but found ${lastValueInView.price}` |
| 28 | + ); |
| 29 | + console.assert( |
| 30 | + lastValueInView.color === 'green', |
| 31 | + `expected to find color green as last value in view, but found ${lastValueInView.color}` |
| 32 | + ); |
| 33 | + |
| 34 | + const lastValueGlobal = lineSeries.lastValueData(true); |
| 35 | + console.assert( |
| 36 | + lastValueGlobal.noData === false, |
| 37 | + 'expected to find data for last value globally' |
| 38 | + ); |
| 39 | + console.assert( |
| 40 | + lastValueGlobal.price === 5, |
| 41 | + `expected to find price 5 as last value globally, but found ${lastValueGlobal.price}` |
| 42 | + ); |
| 43 | + console.assert( |
| 44 | + lastValueGlobal.color === 'red', |
| 45 | + `expected to find color red as last value globally, but found ${lastValueGlobal.color}` |
| 46 | + ); |
| 47 | + |
| 48 | + resolve(); |
| 49 | + }); |
| 50 | + }); |
| 51 | +} |
0 commit comments