chunqiuyiyu / ervy

Bring charts to terminal.
https://www.chunqiuyiyu.com/ervy/
MIT License
1.58k stars 45 forks source link

Piechart errors #11

Closed jcubic closed 4 years ago

jcubic commented 4 years ago

Check my demo: https://codepen.io/jcubic/pen/gObPBdP?editors=0010

commands:

pie A:10:green B:20:$ C:30:red

it renders half of the circle

and this one is komplety broken:

pie A:10:green B:20:$ C:30:red d:10:blue

The code just pass the data to ervy.pie.

ervy

chunqiuyiyu commented 4 years ago

@jcubic I think you should add whitespace(' ') to single character when you want to render pie chart. Check the demo code: https://github.com/chunqiuyiyu/ervy/blob/master/demo/index.js#L23

jcubic commented 4 years ago

The first is working but the second is still broken:

chart2

chunqiuyiyu commented 4 years ago

Because the ASCII characters are "rough", sometimes the size of each area cannot be calculated correctly. You must manually add a property: gapChar, for example:

const pieData = [
  { key: 'A', value: 10, style: bg('green', 2) },
  { key: 'B', value: 20, style: '$$' },
  { key: 'C', value: 30, style: bg('red', 2) },
  { key: 'D', value: 10, style: bg('blue', 2) }
]

console.log(pie(pieData, { gapChar: bg('blue', 2)  }))

Result:

image

For automatic processing programs, pie charts sometimes do not display correctly if there are too many blocks inside( your example above).

jcubic commented 4 years ago

How do you know that gap need to be blue without looking the output?

chunqiuyiyu commented 4 years ago

No way to know that before the output. My suggestion is not to deal with this situation.

jcubic commented 4 years ago

So you say, that it randomly create wrong results and to fix the issue, just don't create data that will create this random results?

This is definitely a bug in the library, that should handle edge cased and produce valid results, or if not it's of no use. You never know if pie chart will be correct.

chunqiuyiyu commented 4 years ago

You are right, I have fixed it in version 1.0.5. Now, gapChar would be the style of last value in renderer data.

jcubic commented 4 years ago

But which entry need this, I can add option, it's no difference if I need to guess which item need this gap. This is just not consistent API. it give random values.

chunqiuyiyu commented 4 years ago

You don't need to guess it, now Ervy will auto generate the gapChar.

jcubic commented 4 years ago

I've updated to 1.0.5 and it still, broken, no auto generate: ervy2

chunqiuyiyu commented 4 years ago

How do you update the Ervy? My test for this error is passed.

jcubic commented 4 years ago

I think I did, I've updated the npm package generated the file using browserfiy but it's hard to tell because you don't provide UMD so you can't use https://unpkg.com/ and you don't have version string in your code. So the file can be any version.

jcubic commented 4 years ago

How to create pie correct chart with this data, can you provide the code? Do you need to pun anywhere gapChar? To be sure I've just installed gain the library and generated new file, it's the same. Are you sure that you've commited the changes it look like the diff commit is almost no different the previous code, it only get gapChar from options, there are no any auto generation.

chunqiuyiyu commented 4 years ago

Check this newest commit:https://github.com/chunqiuyiyu/ervy/commit/b7d1bfd197d8ae419051111accf676ebf0131ce1, I remove gapChar from options, and generate it from styles.

jcubic commented 4 years ago

Sorry, I've build the file in wrong way, the pie chart is working also my demo show correct piechart.

jcubic commented 4 years ago

You should update demo file since it's only documentation right now, it still have gapChar as option.