-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed locking visible range on resize when fixing left edge is enabled
Fixes #991 1. We couldn't rely on the state while updating the state without a proper verifying that the state is correct. Thus if we change width/barSpacing/rightOffset we have to mark visible range as invalidated to make sure that it will be updated on getting current logical/visible range. 2. To fix left edge to could rely on logical range rather than strict range. Visible range is a range of edges of a bar, not the middle.
- Loading branch information
Showing
3 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/e2e/graphics/test-cases/time-scale/lock-visible-range-on-resize-and-fixing-edges.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function generateData() { | ||
const res = []; | ||
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0)); | ||
for (let i = 0; i < 10; ++i) { | ||
res.push({ | ||
time: time.getTime() / 1000, | ||
value: i, | ||
}); | ||
|
||
time.setUTCDate(time.getUTCDate() + 1); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
function runTestCase(container) { | ||
const chart = LightweightCharts.createChart(container, { | ||
timeScale: { | ||
fixLeftEdge: true, | ||
fixRightEdge: true, | ||
lockVisibleTimeRangeOnResize: true, | ||
}, | ||
}); | ||
|
||
const series = chart.addLineSeries(); | ||
|
||
const data = generateData(); | ||
|
||
series.setData(data); | ||
|
||
chart.timeScale().setVisibleLogicalRange({ from: 0.5, to: data.length - 1.5 }); | ||
|
||
return new Promise(resolve => { | ||
requestAnimationFrame(() => { | ||
chart.applyOptions({ width: 550 }); | ||
|
||
requestAnimationFrame(() => { | ||
chart.applyOptions({ width: 600 }); | ||
|
||
requestAnimationFrame(() => { | ||
const visibleRange = chart.timeScale().getVisibleLogicalRange(); | ||
console.assert(visibleRange.from === 0.5, `from in logical range should be 0.5, but is ${visibleRange.from}`); | ||
console.assert(visibleRange.to === data.length - 1.5, `to in logical range should be ${data.length - 1.5}, but is ${visibleRange.to}`); | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters