Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed both timescale edges make lockVisibleTimeRangeOnResize turn wrong #814

Closed
thanhlmm opened this issue Aug 5, 2021 · 2 comments · Fixed by #815
Closed

Fixed both timescale edges make lockVisibleTimeRangeOnResize turn wrong #814

thanhlmm opened this issue Aug 5, 2021 · 2 comments · Fixed by #815
Assignees
Labels
bug Unexpected problem or unintended behavior.
Milestone

Comments

@thanhlmm
Copy link

thanhlmm commented Aug 5, 2021

Lightweight Charts Version: 3.5.0

Steps/code to reproduce:

var chart = createChart(container, {
  leftPriceScale: {
    visible: true,
    borderColor: "#EFF2F5",
    drawTicks: false
  },
  timeScale: {
    borderVisible: false,
    fixLeftEdge: true,
    fixRightEdge: true,
    timeVisible: true,
    lockVisibleTimeRangeOnResize: true
  },
  layout: {
    backgroundColor: "#ffffff",
    textColor: "#333"
  },
});

var series = chart.addLineSeries({
  color: "green",
  lineWidth: 2,
  priceScaleId: "left"
});

series.setData(
  data.map((row) => ({
    time: row.time,
    value: row.value * 10
  }))
);

chart.timeScale().subscribeVisibleLogicalRangeChange((range) => {
  console.log(range);
});

chart.timeScale().fitContent();

Actual behavior:
When run chart.timeScale().fitContent(); => The chart change visible range 2 times, the first time is {from: 0, to: 299} and the last one is {from: 0, to: 297.5623003194888}

It happend due to: fitContent => visibleRange change => after change visibleRange => width of axis get updated => visibleRange change again which not cover the full range
Expected behavior:
The final visibleRange should still show the full chart, which is {from: 0, to: 299}

Screenshots:

CodeSandbox/JSFiddle/etc link:
https://codesandbox.io/s/fitcontent-with-fixed-left-and-right-50n1k?file=/src/index.js:15599-16542

@timocov timocov added the bug Unexpected problem or unintended behavior. label Aug 20, 2021
@thanhlmm
Copy link
Author

thanhlmm commented Sep 6, 2021

More information

image

More info: If you look at the last log, the logical range is changed to {from: 0, to: 294.36082474226805}. The expected behavivor should keep it to {from: 0, to: 299}

@timocov
Copy link
Contributor

timocov commented Sep 6, 2021

Yeah, fair enough. Thanks for your contribution!

@timocov timocov added this to the 3.6 milestone Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants