Giter VIP home page Giter VIP logo

Comments (4)

gtktsc avatar gtktsc commented on August 11, 2024

Hey @tonka3000! Thank you very much and thanks for raising this issue, good idea! I've included this functionality in a new formatter in the latest version. Is this what you need?

from ascii-chart.

tonka3000 avatar tonka3000 commented on August 11, 2024

Hey @gtktsc ,

This is exactly what I was hoping for 😊.

But one thing is strange: When I use your test-data values the switch to K postfix works, but when I use my numbers it don't switch to K mode.

Plotcode

const chart = plot(coords, { "height": 12, width: 60, "hideXAxis": true});

Your test-data

const coords: Coordinates = [
    [-9000, 2000],
    [-8000, -3000],
    [-2000, -2000],
    [2000, 2000],
    [3000, 1500],
    [4000, 5000],
    [10000, 1400],
    [11000, 20000],
    [12000, 30000],
  ];

Output:

CleanShot 2022-06-22 at 19 10 21@2x

My example data

const coords: Coordinates = [
  [ 0, 6000 ],      [ 100, 9000 ],
  [ 200, 9100 ],   [ 300, 9200 ],
  [ 400, 9344 ],   [ 500, 9877 ],
  [ 600, 10200 ],  [ 700, 15000 ],
  [ 800, 9100 ],   [ 900, 9200 ],
  [ 1000, 9344 ],  [ 1100, 9877 ],
  [ 1200, 10001 ], [ 1300, 9000 ],
  [ 1400, 9100 ],  [ 1500, 9200 ],
  [ 1600, 9344 ],  [ 1700, 9877 ],
  [ 1800, 10001 ], [ 1900, 9000 ],
  [ 2000, 9100 ],  [ 2100, 9200 ],
  [ 2200, 9344 ],  [ 2300, 9877 ],
  [ 2400, 10001 ], [ 2500, 10001 ],
  [ 2600, 9000 ],  [ 2700, 9100 ],
  [ 2800, 9200 ],  [ 2900, 9344 ],
  [ 3000, 9877 ],  [ 3100, 10001 ]
];

Output:

CleanShot 2022-06-22 at 19 13 47@2x

from ascii-chart.

gtktsc avatar gtktsc commented on August 11, 2024

Hello @tonka3000

Yes, that's because I've added additional transformation for small numbers, but apparently it wasn't good enough. It's gone now, please try out the newest release - should work out of the box.

Alternatively, you can add custom formatter:

const coords: Coordinates = [
  [0, 6000],
  [100, 9000],
  [200, 9100],
  [300, 9200],
  [400, 9344],
  [500, 9877],
  [600, 10200],
  [700, 15000],
  [800, 9100],
  [900, 9200],
  [1000, 9344],
  [1100, 9877],
  [1200, 10001],
  [1300, 9000],
  [1400, 9100],
  [1500, 9200],
  [1600, 9344],
  [1700, 9877],
  [1800, 10001],
  [1900, 9000],
  [2000, 9100],
  [2100, 9200],
  [2200, 9344],
  [2300, 9877],
  [2400, 10001],
  [2500, 10001],
  [2600, 9000],
  [2700, 9100],
  [2800, 9200],
  [2900, 9344],
  [3000, 9877],
  [3100, 10001],
];

const chart = plot(coords, {
  height: 12,
  width: 60,
  hideXAxis: true,
  formatter: (value) => {
    if (Math.abs(value) > 1000) return `${value / 1000}k`;
    return value;
  },
});

Thanks!

from ascii-chart.

tonka3000 avatar tonka3000 commented on August 11, 2024

@gtktsc Works perfect. Thank you very much.

CleanShot 2022-06-24 at 08 24 05@2x

from ascii-chart.

Related Issues (4)

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.