Skip to content

希望可以修改下render方法,以能支持回调函数的写法 #79

@leacoleaco

Description

@leacoleaco

希望可以修改下render方法,以能支持配置中使用回调函数的写法?

比如:
饼图的Series 里有一个 labelLayout 配置, 这个配置可以写成函数回调的方式:
echarts 支持这么设置:

{
  series:[{
    labelLayout: function (params) {
        const isLeft = params.labelRect.x < myChart.getWidth() / 2;
        const points = params.labelLinePoints;
        // Update the end point.
        points[2][0] = isLeft
          ? params.labelRect.x
          : params.labelRect.x + params.labelRect.width;
        return {
          labelLinePoints: points
        };
      }
   }
  ]
}

但是 PieSeries 只有这样的配置方法

PieSeries().setLabelLayout(LabelLayout())

这样怎么配置都没法做到回调里的那种显示方案。

所以我在想是不是可以弄一个支持回调的类, render 时候可以把这部分渲染为回调函数,以解决这个问题? 比如可以这么配置:

PieSeries()
   .setLabelLayout(CallbackScript(
     "function (params) {" +
     "   const isLeft = params.labelRect.x < myChart.getWidth() / 2;" +
     "   const points = params.labelLinePoints;" +
     "   // Update the end point." +
     "   points[2][0] = isLeft" +
     "     ? params.labelRect.x" +
     "    : params.labelRect.x + params.labelRect.width;" +
     "  return {" +
     "    labelLinePoints: points" +
     "  };" +
     " }" +
     "}"
))

就能在render时得到上面的那个配置

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions