import { __extends } from "../../../node_modules/tslib/tslib.es6.mjs";
import { map } from "../../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.mjs";
import ChartView from "../../view/Chart.mjs";
import * as graphic from "../../util/graphic.mjs";
import { setStatesStylesFromModel, toggleHoverEmphasis } from "../../util/states.mjs";
import Path from "../../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/Path.mjs";
import { saveOldStyle } from "../../animation/basicTransition.mjs";
var BoxplotView = (
  /** @class */
  function(_super) {
    __extends(BoxplotView2, _super);
    function BoxplotView2() {
      var _this = _super !== null && _super.apply(this, arguments) || this;
      _this.type = BoxplotView2.type;
      return _this;
    }
    BoxplotView2.prototype.render = function(seriesModel, ecModel, api) {
      var data = seriesModel.getData();
      var group = this.group;
      var oldData = this._data;
      if (!this._data) {
        group.removeAll();
      }
      var constDim = seriesModel.get("layout") === "horizontal" ? 1 : 0;
      data.diff(oldData).add(function(newIdx) {
        if (data.hasValue(newIdx)) {
          var itemLayout = data.getItemLayout(newIdx);
          var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
          data.setItemGraphicEl(newIdx, symbolEl);
          group.add(symbolEl);
        }
      }).update(function(newIdx, oldIdx) {
        var symbolEl = oldData.getItemGraphicEl(oldIdx);
        if (!data.hasValue(newIdx)) {
          group.remove(symbolEl);
          return;
        }
        var itemLayout = data.getItemLayout(newIdx);
        if (!symbolEl) {
          symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
        } else {
          saveOldStyle(symbolEl);
          updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
        }
        group.add(symbolEl);
        data.setItemGraphicEl(newIdx, symbolEl);
      }).remove(function(oldIdx) {
        var el = oldData.getItemGraphicEl(oldIdx);
        el && group.remove(el);
      }).execute();
      this._data = data;
    };
    BoxplotView2.prototype.remove = function(ecModel) {
      var group = this.group;
      var data = this._data;
      this._data = null;
      data && data.eachItemGraphicEl(function(el) {
        el && group.remove(el);
      });
    };
    BoxplotView2.type = "boxplot";
    return BoxplotView2;
  }(ChartView)
);
var BoxPathShape = (
  /** @class */
  function() {
    function BoxPathShape2() {
    }
    return BoxPathShape2;
  }()
);
var BoxPath = (
  /** @class */
  function(_super) {
    __extends(BoxPath2, _super);
    function BoxPath2(opts) {
      var _this = _super.call(this, opts) || this;
      _this.type = "boxplotBoxPath";
      return _this;
    }
    BoxPath2.prototype.getDefaultShape = function() {
      return new BoxPathShape();
    };
    BoxPath2.prototype.buildPath = function(ctx, shape) {
      var ends = shape.points;
      var i = 0;
      ctx.moveTo(ends[i][0], ends[i][1]);
      i++;
      for (; i < 4; i++) {
        ctx.lineTo(ends[i][0], ends[i][1]);
      }
      ctx.closePath();
      for (; i < ends.length; i++) {
        ctx.moveTo(ends[i][0], ends[i][1]);
        i++;
        ctx.lineTo(ends[i][0], ends[i][1]);
      }
    };
    return BoxPath2;
  }(Path)
);
function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  var ends = itemLayout.ends;
  var el = new BoxPath({
    shape: {
      points: isInit ? transInit(ends, constDim, itemLayout) : ends
    }
  });
  updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  return el;
}
function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  var seriesModel = data.hostModel;
  var updateMethod = graphic[isInit ? "initProps" : "updateProps"];
  updateMethod(el, {
    shape: {
      points: itemLayout.ends
    }
  }, seriesModel, dataIndex);
  el.useStyle(data.getItemVisual(dataIndex, "style"));
  el.style.strokeNoScale = true;
  el.z2 = 100;
  var itemModel = data.getItemModel(dataIndex);
  var emphasisModel = itemModel.getModel("emphasis");
  setStatesStylesFromModel(el, itemModel);
  toggleHoverEmphasis(el, emphasisModel.get("focus"), emphasisModel.get("blurScope"), emphasisModel.get("disabled"));
}
function transInit(points, dim, itemLayout) {
  return map(points, function(point) {
    point = point.slice();
    point[dim] = itemLayout.initBaseline;
    return point;
  });
}
const BoxplotView$1 = BoxplotView;
export {
  BoxplotView$1 as default
};
