import { __extends } from "../../../node_modules/tslib/tslib.es6.mjs";
import SeriesModel from "../../model/Series.mjs";
import createGraphFromNodeEdge from "../helper/createGraphFromNodeEdge.mjs";
import Model from "../../model/Model.mjs";
import { createTooltipMarkup } from "../../component/tooltip/tooltipMarkup.mjs";
var SankeySeriesModel = (
  /** @class */
  function(_super) {
    __extends(SankeySeriesModel2, _super);
    function SankeySeriesModel2() {
      var _this = _super !== null && _super.apply(this, arguments) || this;
      _this.type = SankeySeriesModel2.type;
      return _this;
    }
    SankeySeriesModel2.prototype.getInitialData = function(option, ecModel) {
      var links = option.edges || option.links;
      var nodes = option.data || option.nodes;
      var levels = option.levels;
      this.levelModels = [];
      var levelModels = this.levelModels;
      for (var i = 0; i < levels.length; i++) {
        if (levels[i].depth != null && levels[i].depth >= 0) {
          levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
        } else {
          if (process.env.NODE_ENV !== "production") {
            throw new Error("levels[i].depth is mandatory and should be natural number");
          }
        }
      }
      if (nodes && links) {
        var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
        return graph.data;
      }
      function beforeLink(nodeData, edgeData) {
        nodeData.wrapMethod("getItemModel", function(model, idx) {
          var seriesModel = model.parentModel;
          var layout = seriesModel.getData().getItemLayout(idx);
          if (layout) {
            var nodeDepth = layout.depth;
            var levelModel = seriesModel.levelModels[nodeDepth];
            if (levelModel) {
              model.parentModel = levelModel;
            }
          }
          return model;
        });
        edgeData.wrapMethod("getItemModel", function(model, idx) {
          var seriesModel = model.parentModel;
          var edge = seriesModel.getGraph().getEdgeByIndex(idx);
          var layout = edge.node1.getLayout();
          if (layout) {
            var depth = layout.depth;
            var levelModel = seriesModel.levelModels[depth];
            if (levelModel) {
              model.parentModel = levelModel;
            }
          }
          return model;
        });
      }
    };
    SankeySeriesModel2.prototype.setNodePosition = function(dataIndex, localPosition) {
      var nodes = this.option.data || this.option.nodes;
      var dataItem = nodes[dataIndex];
      dataItem.localX = localPosition[0];
      dataItem.localY = localPosition[1];
    };
    SankeySeriesModel2.prototype.getGraph = function() {
      return this.getData().graph;
    };
    SankeySeriesModel2.prototype.getEdgeData = function() {
      return this.getGraph().edgeData;
    };
    SankeySeriesModel2.prototype.formatTooltip = function(dataIndex, multipleSeries, dataType) {
      function noValue(val) {
        return isNaN(val) || val == null;
      }
      if (dataType === "edge") {
        var params = this.getDataParams(dataIndex, dataType);
        var rawDataOpt = params.data;
        var edgeValue = params.value;
        var edgeName = rawDataOpt.source + " -- " + rawDataOpt.target;
        return createTooltipMarkup("nameValue", {
          name: edgeName,
          value: edgeValue,
          noValue: noValue(edgeValue)
        });
      } else {
        var node = this.getGraph().getNodeByIndex(dataIndex);
        var value = node.getLayout().value;
        var name_1 = this.getDataParams(dataIndex, dataType).data.name;
        return createTooltipMarkup("nameValue", {
          name: name_1 != null ? name_1 + "" : null,
          value,
          noValue: noValue(value)
        });
      }
    };
    SankeySeriesModel2.prototype.optionUpdated = function() {
    };
    SankeySeriesModel2.prototype.getDataParams = function(dataIndex, dataType) {
      var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
      if (params.value == null && dataType === "node") {
        var node = this.getGraph().getNodeByIndex(dataIndex);
        var nodeValue = node.getLayout().value;
        params.value = nodeValue;
      }
      return params;
    };
    SankeySeriesModel2.type = "series.sankey";
    SankeySeriesModel2.defaultOption = {
      // zlevel: 0,
      z: 2,
      coordinateSystem: "view",
      left: "5%",
      top: "5%",
      right: "20%",
      bottom: "5%",
      orient: "horizontal",
      nodeWidth: 20,
      nodeGap: 8,
      draggable: true,
      layoutIterations: 32,
      label: {
        show: true,
        position: "right",
        fontSize: 12
      },
      edgeLabel: {
        show: false,
        fontSize: 12
      },
      levels: [],
      nodeAlign: "justify",
      lineStyle: {
        color: "#314656",
        opacity: 0.2,
        curveness: 0.5
      },
      emphasis: {
        label: {
          show: true
        },
        lineStyle: {
          opacity: 0.5
        }
      },
      select: {
        itemStyle: {
          borderColor: "#212121"
        }
      },
      animationEasing: "linear",
      animationDuration: 1e3
    };
    return SankeySeriesModel2;
  }(SeriesModel)
);
const SankeySeriesModel$1 = SankeySeriesModel;
export {
  SankeySeriesModel$1 as default
};
