gwak commented on issue #17138:
URL: https://github.com/apache/echarts/issues/17138#issuecomment-1232866679

   Maybe how [PlottableJs](https://github.com/palantir/plottable) handles 
property updates can be of help for you to decide which API is best. For each 
property that you can set in 
[PlottableJs](https://github.com/palantir/plottable), you have the choice of 
either give the value statically or give an accessor function:
   
   
https://github.com/palantir/plottable/blob/develop/src/core/interfaces.ts#L13-L19
   ```ts
   /**
    * Accesses a specific datum property. Users supply Accessors to their
    * plots' .x, .y, .attr, etc. functions.
    */
   export interface IAccessor<T> {
       (datum: any, index: number, dataset: Dataset): T; // Inputs should be 
replaced by charts specific dataset data structures
   }
   ```
   
   Then when creating a Plot in Plottable:
   ```ts
   const stackedBarPlot = new Plottable.Plots.StackedBar()
         .datasets(datasets)
         .attr('fill', (d: any, I: number, dataset: Dataset) => 
dataset.metadata().color);
   ```
   
   How it would look like in echarts:
   ```ts
   export interface LineSeriesOption .... {
     lineStyle: LineStyleOption | IAccessor<LineStyleOption>;
   ...
   }
   ```
   Then in user-land:
   ```ts
   const baseLineStyle = {...};
   ...
   
   lineStyle: (datum: any, index: number, dataset: Dataset) => {
     return {... baseLineStyle, dashOffset: index > 10 ? 0 : 4 };
   }
   ...
   ```
   
   That way a user of the library can very easily create its own logic, that 
even reusable because it's a simple function.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to