Pre loader

Setting `visibleRange` messes `dataRange`



I’m using SciChart for macOS (v4.4.2.5871 installed via CocoaPods) and one thing that I tried was to implement the an axis to show full extent of data, as described in the first bullet of—get-or-set-visiblerange.html#zooming-to-fit-all-the-data

However, what I’m getting is that after setting the visibleRange to match the dataRange, the dataRange no longer reflects the “true” range, but something else. Also “zoom to extent” no longer works

Attached is a super basic example (project) for this. To reproduce, do the following:

  1. Do a zoom (via pinch)
  2. Click the button titled “Set visibleRange to dataRange” -> this step works as expected
  3. Do a zoom
  4. Click again the button -> “zoom to extent” no longer works, dataRange is messed up
  • You must to post comments

After writing the above ticket (and also, it hit me where the problem is: visibleRange property has a strong semantic, meaning it will point to object passed as parameter and will increment its reference count. Also, most likely the getter of dataRange returns a pointer to the object used internally, not a copy of it.
This means doing visibleRange = dataRange will cause visibleRange and dataRange to point to the same object. Panning or zooming will cause modifications to object referenced by visibleRange, and which is also referenced by dataRange -> hence the dataRange will contain wrong values.
To test the above, I did the following:

xAxis.visibleRange = SCIDoubleRange(min: xAxis.dataRange.minAsDouble, max: xAxis.dataRange.maxAsDouble)
yAxis.visibleRange = SCIDoubleRange(min: yAxis.dataRange.minAsDouble, max: yAxis.dataRange.maxAsDouble)

After this change everything works as expected.

If what I said is true, then my recommendation is to update the documentation, because they will lead into bad behavior, no matter if you do iOS or Mac or Swift or Obj C.

  • Andrew Burnett-Thompson
    Hi Vlad, it is the weekend, but I did see this and you’re absolutely right – it’s generally a good idea to treat all DoubleRange objects as immutable, creating a new one when assigning to a property like visibleRange. Glad you found the solution and point noted about the docs!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies