"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const tslib_es6 = require("../../../node_modules/tslib/tslib.es6.js");
const LineDraw = require("../helper/LineDraw.js");
const EffectLine = require("../helper/EffectLine.js");
const Line = require("../helper/Line.js");
const Polyline = require("../helper/Polyline.js");
const EffectPolyline = require("../helper/EffectPolyline.js");
const LargeLineDraw = require("../helper/LargeLineDraw.js");
const linesLayout = require("./linesLayout.js");
const createClipPathFromCoordSys = require("../helper/createClipPathFromCoordSys.js");
const Chart = require("../../view/Chart.js");
var LinesView = (
  /** @class */
  function(_super) {
    tslib_es6.__extends(LinesView2, _super);
    function LinesView2() {
      var _this = _super !== null && _super.apply(this, arguments) || this;
      _this.type = LinesView2.type;
      return _this;
    }
    LinesView2.prototype.render = function(seriesModel, ecModel, api) {
      var data = seriesModel.getData();
      var lineDraw = this._updateLineDraw(data, seriesModel);
      var zlevel = seriesModel.get("zlevel");
      var trailLength = seriesModel.get(["effect", "trailLength"]);
      var zr = api.getZr();
      var isSvg = zr.painter.getType() === "svg";
      if (!isSvg) {
        zr.painter.getLayer(zlevel).clear(true);
      }
      if (this._lastZlevel != null && !isSvg) {
        zr.configLayer(this._lastZlevel, {
          motionBlur: false
        });
      }
      if (this._showEffect(seriesModel) && trailLength > 0) {
        if (!isSvg) {
          zr.configLayer(zlevel, {
            motionBlur: true,
            lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
          });
        } else if (process.env.NODE_ENV !== "production") {
          console.warn("SVG render mode doesn't support lines with trail effect");
        }
      }
      lineDraw.updateData(data);
      var clipPath = seriesModel.get("clip", true) && createClipPathFromCoordSys.createClipPath(seriesModel.coordinateSystem, false, seriesModel);
      if (clipPath) {
        this.group.setClipPath(clipPath);
      } else {
        this.group.removeClipPath();
      }
      this._lastZlevel = zlevel;
      this._finished = true;
    };
    LinesView2.prototype.incrementalPrepareRender = function(seriesModel, ecModel, api) {
      var data = seriesModel.getData();
      var lineDraw = this._updateLineDraw(data, seriesModel);
      lineDraw.incrementalPrepareUpdate(data);
      this._clearLayer(api);
      this._finished = false;
    };
    LinesView2.prototype.incrementalRender = function(taskParams, seriesModel, ecModel) {
      this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData());
      this._finished = taskParams.end === seriesModel.getData().count();
    };
    LinesView2.prototype.eachRendered = function(cb) {
      this._lineDraw && this._lineDraw.eachRendered(cb);
    };
    LinesView2.prototype.updateTransform = function(seriesModel, ecModel, api) {
      var data = seriesModel.getData();
      var pipelineContext = seriesModel.pipelineContext;
      if (!this._finished || pipelineContext.large || pipelineContext.progressiveRender) {
        return {
          update: true
        };
      } else {
        var res = linesLayout.default.reset(seriesModel, ecModel, api);
        if (res.progress) {
          res.progress({
            start: 0,
            end: data.count(),
            count: data.count()
          }, data);
        }
        this._lineDraw.updateLayout();
        this._clearLayer(api);
      }
    };
    LinesView2.prototype._updateLineDraw = function(data, seriesModel) {
      var lineDraw = this._lineDraw;
      var hasEffect = this._showEffect(seriesModel);
      var isPolyline = !!seriesModel.get("polyline");
      var pipelineContext = seriesModel.pipelineContext;
      var isLargeDraw = pipelineContext.large;
      if (process.env.NODE_ENV !== "production") {
        if (hasEffect && isLargeDraw) {
          console.warn("Large lines not support effect");
        }
      }
      if (!lineDraw || hasEffect !== this._hasEffet || isPolyline !== this._isPolyline || isLargeDraw !== this._isLargeDraw) {
        if (lineDraw) {
          lineDraw.remove();
        }
        lineDraw = this._lineDraw = isLargeDraw ? new LargeLineDraw.default() : new LineDraw.default(isPolyline ? hasEffect ? EffectPolyline.default : Polyline.default : hasEffect ? EffectLine.default : Line.default);
        this._hasEffet = hasEffect;
        this._isPolyline = isPolyline;
        this._isLargeDraw = isLargeDraw;
      }
      this.group.add(lineDraw.group);
      return lineDraw;
    };
    LinesView2.prototype._showEffect = function(seriesModel) {
      return !!seriesModel.get(["effect", "show"]);
    };
    LinesView2.prototype._clearLayer = function(api) {
      var zr = api.getZr();
      var isSvg = zr.painter.getType() === "svg";
      if (!isSvg && this._lastZlevel != null) {
        zr.painter.getLayer(this._lastZlevel).clear(true);
      }
    };
    LinesView2.prototype.remove = function(ecModel, api) {
      this._lineDraw && this._lineDraw.remove();
      this._lineDraw = null;
      this._clearLayer(api);
    };
    LinesView2.prototype.dispose = function(ecModel, api) {
      this.remove(ecModel, api);
    };
    LinesView2.type = "lines";
    return LinesView2;
  }(Chart.default)
);
const LinesView$1 = LinesView;
exports.default = LinesView$1;
