Code Monkey home page Code Monkey logo

Comments (5)

marzolfb avatar marzolfb commented on May 19, 2024 2

The "format function" already exists here and is embodied in the labelFunction option (in the example app, the StockLineChartDynamicTickLabels example illustrates the use of this option).

While its true each user of this library could address the floating point problem in this issue by implementing their own rounding routine in that labelFunction function, I think this is a more universal problem that occurs often enough that we would want to address it for everyone.

from react-native-pathjs-charts.

marzolfb avatar marzolfb commented on May 19, 2024

FYI - I've tracked this done to the usage of lodash's range method with floating point values in Axis.js. The difficulties we are dealing with here are documented in this issue from Oct 2015 in the lodash repo. Thinking about possible ways to deal with this. Open to ideas. Plenty of ideas here. My immediate reaction is to work with integers for the range values (and then convert back).

from react-native-pathjs-charts.

marzolfb avatar marzolfb commented on May 19, 2024

Ok, I'm looking for some design feedback before starting a PR on this one. I generally think the "Method 3" technique offered here is usable to solve the issue.

The only question in my mind is how do you determine what a suitable default for the number of decimal places to target (and therefore shift to the left of the decimal point to round before converting back to the target number of decimal places)?

Here's a jsfiddle to illustrate the issue - how does one specify the decimalPlaces parameter to pass to the fixFloats function in all of the example ranges? I assume we add another chart option for both the x and y axis for a target decimalPlaces that would take effect when you have floating point values in your data set but then what would be a suitable default for decimalPlaces if the chart creator didn't specify that configuration option (which maintains backward compatibility)? I see several possible options:

  • Set it to a static number of places (like 2)?
  • Use the number of decimal places on the first element of the data set?
  • Try to dynamically determine a suitable default by evaluating the number of decimal places in use in the data set? How?
    • Use the number of decimal places that are used by a majority of numbers?
    • Use the max number decimal places found smaller then some threshold like 10 decimal places?

A lot of this feels like a big hack and all of these approaches are problematic in various regards so I'm trying to pick the one that "sucks the least". Any thoughts? Any approaches I haven't considered here that are better?

from react-native-pathjs-charts.

Cody-G-G avatar Cody-G-G commented on May 19, 2024

The decimalPlaces parameter sounds nice, and I think the default for it is fine as a static number, 2 making the most sense since for graphs to be displayed on mobile devices the required precision would very rarely exceed that. However, I believe it should take effect not only when you have floating point values in your data set, but all the time. This is because it doesn't really have much to do with what the number of decimal places are for the elements in the dataset, since my dataset could be something like (1, 50), (2, 85), and so even though my X axis datapoints don't have any decimal places, there will be numbers with decimal places in between them that will be displayed along the axis after those are calculated.

from react-native-pathjs-charts.

katscott avatar katscott commented on May 19, 2024

What about a format function that can be overridden? Use a default with perhaps 2 decimal places, but otherwise allow a user to format however they like (such as with currency symbols). That would be the most robust.

from react-native-pathjs-charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.