Currently, I gradually think we have to make some change
about the practice that we have been trading the props
that needed to be normalized or calculated inside.
The way that I've been using is not a good practice:

Set the calculated value to the original prop directly
and erase the original value.

Use some pseudocode to describe it clearly:

Suppose `clac` is the function that normalizes/calculates the
original value specified and get the result.

When `chart.setOption` or `chart.dispatchAction`, we need to:
`option[propForAssigning] = specifiedValue;`

When `chart.setOption` or `chart.dispatchAction` or go though the main
process, we need to:
`option[propForCalculating] = calc( option[propForAssigning] );`

If we make `propForCalculating === propForAssigning`,
and `calc( calc( propForAssigning ) ) !== calc( propForAssigning )`

we will lose the original value but get result not expected.


There is one example we meet just now:

`dataZoom` has props `start` `end` `startValue` `endValue`,
These four props can be set by user (via `chart.setOption` or
`chart.dispatchAction`)
or by components (via `api.dispatchAction`).

But the specified value needs to be calculated and get the final value,
which is usually not the same as the original specified value, but in
most cases, not different so much.
(The calculation depends on the data extent, `dataZoom.minSpan`,
`dataZoom.maxSpan`
and some other factors)
Users need to read the final value, so I write the final value to
these props, erasing the original value.

But some bad case occurs:
If the user uses `toolbox.dataZoom` to zoom Y-axis, and then click
the `legend`, and then click the `legend` again, the chart can not
return to the original state.
The reason is:
The original value of `dataZoom.startValue` and `dataZoom.endValue`
is erased by the value that calculated in the main process triggered
by clicking legend.

There were some other similar cases.
CSS distinguish the "style" and "computed style".
We probably also need to settle a best practice for that.

For example:
If a calculated prop need to be set to `option` and the
normalizer/calculater
(say, `calc`) do not meet the condition:

`calc( calc( propForAssigning ) ) !== calc( propForAssigning )`

we should not use the original prop, but use a new prop, like:

`dataZoom.calculatedStartValue`, `dataZoom.calculatedEndValue`...

(An example that meets the condition:
canvas.font = 'xxx';
)

But that would be a little break change...

Any idea about all the issue and possible solution above?




Thanks,
------------------------------
 Su Shuang (100pah)
------------------------------

Reply via email to