UNPKG

@antv/g6

Version:

graph visualization frame work

71 lines (56 loc) 2.42 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * @fileOverview mapper controller * @author huangtonger@aliyun.com */ var Base = require('./base'); var Util = require('../util/'); var CHANNEL_NAMES = ['color', 'shape', 'size', 'label', 'style']; var Controller = function (_Base) { _inherits(Controller, _Base); function Controller(cfg) { _classCallCheck(this, Controller); var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); _this._init(); return _this; } Controller.prototype._init = function _init() { var _this2 = this; var channels = {}; Util.each(CHANNEL_NAMES, function (channel) { channels[channel] = {}; _this2[channel] = function (input) { channels[channel].input = input; return _this2; }; }); this.channels = channels; }; Controller.prototype.addChannels = function addChannels(inputChannels) { var channels = this.channels; Util.each(inputChannels, function (channel, name) { channels[name] = { input: channel }; }); }; /** * @param {object} model origin model */ Controller.prototype.mapping = function mapping(model) { var channels = this.channels; Util.each(channels, function (channel, name) { if (Util.isNil(model[name])) { if (Util.isFunction(channel.input)) { model[name] = channel.input(model); } else if (channel.input) { model[name] = channel.input; } } }); }; return Controller; }(Base); module.exports = Controller;