    import VisualVariable from './VisualVariable'
    import { defaultValue } from '../../../util'
    import VisualVariableType from '../../../base/enum/VisualVariableType'
    import OpacityStop from './support/OpacityStop'
    import { Zondy } from '../../../base'
    /**
     * opacity视觉变量
     * @class OpacityVariable
     * @moduleEX RendererModule
     * @param {Object} options 初始化参数
     * @param {Array<OpacityStop>} [options.stops] 透明度分段数组
     * @example 透明度视觉变量的使用方式
     * // 获取layer上renderer对象
     *  const renderer = layer.renderer
     * // 根据FID取值设置透明度
     * // FID取值小于0时，设置符号颜色透明度为0.2
     * // FID取值大于300时 ，设置符号颜色透明度为1.0
     * // FID取值在0-300之间时，显示符号颜色透明度过渡值
     *  renderer.visualVariables = [{
                type: "opacity",
                valueExpression: "$feature.FID",
                stops: [
                  {
                    opacity: 0.2,
                    value: 0,
                  },
                  {
                    opacity: 1.0,
                    value:300,
                  },
                ],
              }]
     *
     */
    class OpacityVariable extends VisualVariable {
      constructor(options) {
        super(options)
        options = defaultValue(options, {})
        this.type = VisualVariableType.opacity
        /**
         * 透明度分段数组
         * @member {Array<OpacityStop>} OpacityVariable.prototype.stops
         */
        this.stops = defaultValue(options.stops, [])
        this.stops = this.stops.map((v) => OpacityStop.fromJSON(v))
      }

      /**
       * 通过json构造OpacityVariable对象
       * @return {OpacityVariable} json对象
       * */
      static fromJSON(json) {
        return new OpacityVariable(json)
      }

      /**
       * 导出为json对象
       * @return {Object} json对象
       * */
      toJSON() {
        const json = super.toJSON()
        json.type = this.type
        json.normalizationField = this.normalizationField
        json.stops = this.stops.map((v) => v.toJSON())
        return json
      }

      /**
       * 克隆对象
       * @return {OpacityVariable} 克隆后的OpacityVariable对象
       */
      clone() {
        return new OpacityVariable(this.toJSON())
      }
    }

    Zondy.Renderer.VisualVariable.OpacityVariable = OpacityVariable
    export default OpacityVariable