VisActor / VChart

VChart, more than just a cross-platform charting library, but also an expressive data storyteller.
https://www.visactor.io/vchart
MIT License
915 stars 62 forks source link

[Feature] 环形进度图最大值与最小值相等时,优化绘制效果 #2811

Open skie1997 opened 3 months ago

skie1997 commented 3 months ago

What problem does this feature solve?

环形进度图最大值 = 最小值,应该有兜底绘图策略,比如,直接不绘制 image

What does the proposed API look like?

null

mengxi-ream commented 3 months ago

Hi team, I'm working on this issue. Can I ask some questions before doing the further work?

My idea is to detect the min and max values and throw the error when min >= max. something like:

    const domain = angleAxis.getScale().domain();
    // min >= max
    if (domain[0] >= domain[1]) {
      throw new Error('Invalid domain: min value should be less than max value.');
    }

I've created a draft PR (WIP) but I think I need further assistance to improve it. Thank you for all the help!

Question 1:

For my current PR, I believe it's not a good way to assert domain[0] >= domain[1] in protected _getAngleAxis() because it violates the single responsibility principle of that function.

I tried calling _getAngleAxis() in gauge.ts and asserting that domain[0] >= domain[1] in initData() here. However, it seems that initData() does not run when I create a gauge chart (like in the example provided in the draft PR).

Can anyone tell me the better place to do the assertion domain[0] >= domain[1]?

Question 2:

Raising an error when min >= max may not be the best practice. Do you have any other suggestions?

xiaoluoHe commented 3 months ago

@Crayon-ShinChan Exactly as what you said in Question2, in a utility library, exceptions should not be overused. I think it would be better to consider optimizing the chart display in this case rather than directly throwing an exception.

mengxi-ream commented 3 months ago

@Crayon-ShinChan Exactly as what you said in Question2, in a utility library, exceptions should not be overused. I think it would be better to consider optimizing the chart display in this case rather than directly throwing an exception.

Thanks for the reply. Could you elaborate "optimizing the chart"? For example, like show text "Please set min value to be less than max value" to users?

Actually, there are several situations:

  1. min = max
    1. data point value = min = max (In this case, we may draw something, like "optimizing the chart display" as you said?)
    2. data point value != min = max (In this case, the data and config should be considered as invalid and I think we shouldn't show any chart to users)
  2. min > max (invalid config, and we shouldn't show any chart to users)

If "optimizing the chart" means show some chart to users, we may only consider the 1.(i) condition?

skie1997 commented 3 months ago

@Crayon-ShinChan Exactly as what you said in Question2, in a utility library, exceptions should not be overused. I think it would be better to consider optimizing the chart display in this case rather than directly throwing an exception.

Thanks for the reply. Could you elaborate "optimizing the chart"? For example, like show text "Please set min value to be less than max value" to users?

Actually, there are several situations:

  1. min = max

    1. data point value = min = max (In this case, we may draw something, like "optimizing the chart display" as you said?)
    2. data point value != min = max (In this case, the data and config should be considered as invalid and I think we shouldn't show any chart to users)
  2. min > max (invalid config, and we shouldn't show any chart to users)

If "optimizing the chart" means show some chart to users, we may only consider the 1.(i) condition?

good question, actually we don't care data point value and only consider about domain, we classify it into the following situations:

  1. min = max, it cannot be a range to map data, it is a unreasonable chart so we cannot draw anything.(maybe we should also throw error in browser console)
  2. min < max, it is a reasonable range and we can draw a normal gauge chart
  3. min > max, it is also a reasonable range and we can draw a reverse gauge, just like this: image