"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var util_1 = require("@antv/util");
var global_1 = require("../../base/global");
var view_layer_1 = tslib_1.__importDefault(require("../../base/view-layer"));
var factory_1 = require("../../components/factory");
var factory_2 = require("../../geoms/factory");
var scale_1 = require("../../util/scale");
require("../../geoms/heatmap/linear");
var components_1 = require("./components");
var EventParser = tslib_1.__importStar(require("./event"));
var DensityHeatmapLayer = /** @class */ (function (_super) {
    tslib_1.__extends(DensityHeatmapLayer, _super);
    function DensityHeatmapLayer() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.type = 'densityHeatmap';
        _this.plotComponents = [];
        return _this;
    }
    DensityHeatmapLayer.getDefaultOptions = function () {
        return util_1.deepMix({}, _super.getDefaultOptions.call(this), {
            xAxis: {
                visible: true,
                autoRotateTitle: false,
                grid: {
                    visible: false,
                },
                line: {
                    visible: true,
                },
                tickLine: {
                    visible: true,
                },
                label: {
                    visible: true,
                    autoHide: true,
                    autoRotate: true,
                },
                title: {
                    visible: false,
                    offset: 12,
                },
            },
            yAxis: {
                visible: true,
                autoRotateTitle: true,
                grid: {
                    visible: false,
                },
                line: {
                    visible: true,
                },
                tickLine: {
                    visible: true,
                },
                label: {
                    visible: true,
                    autoHide: true,
                    autoRotate: false,
                },
                title: {
                    visible: false,
                    offset: 12,
                },
            },
            tooltip: {
                visible: true,
                showCrosshairs: true,
                crosshairs: {
                    type: 'xy',
                    line: {
                        style: {
                            stroke: '#000000',
                            lineWidth: 1,
                            opacity: 0.5,
                        },
                    },
                },
                showMarkers: false,
            },
            legend: {
                visible: true,
                position: 'bottom-center',
            },
            color: [
                'rgba(33,102,172,0)',
                'rgb(103,169,207)',
                'rgb(209,229,240)',
                'rgb(253,219,199)',
                'rgb(239,138,98)',
                'rgb(178,24,43)',
            ],
            interactions: [{ type: 'tooltip' }],
        });
    };
    DensityHeatmapLayer.prototype.afterRender = function () {
        this.renderPlotComponents();
        _super.prototype.afterRender.call(this);
    };
    DensityHeatmapLayer.prototype.destroy = function () {
        util_1.each(this.plotComponents, function (component) {
            component.destroy();
        });
        _super.prototype.destroy.call(this);
    };
    DensityHeatmapLayer.prototype.scale = function () {
        var props = this.options;
        var scales = {};
        /** 配置x-scale */
        scales[props.xField] = {};
        if (util_1.has(props, 'xAxis')) {
            scale_1.extractScale(scales[props.xField], props.xAxis);
        }
        /** 配置y-scale */
        scales[props.yField] = {};
        if (util_1.has(props, 'yAxis')) {
            scale_1.extractScale(scales[props.yField], props.yAxis);
        }
        this.setConfig('scales', scales);
        _super.prototype.scale.call(this);
    };
    DensityHeatmapLayer.prototype.coord = function () {
        return;
    };
    DensityHeatmapLayer.prototype.geometryParser = function () {
        return 'heatmap';
    };
    DensityHeatmapLayer.prototype.addGeometry = function () {
        if (this.options.data.length > 1) {
            var config = {
                type: 'linearheatmap',
                position: {
                    fields: [this.options.xField, this.options.yField],
                },
                color: {
                    fields: [this.options.colorField],
                    values: this.options.color,
                },
                cfg: {
                    intensity: this.options.intensity,
                    radius: this.options.radius,
                },
            };
            if (this.options.radius) {
                config.radius = this.options.radius;
            }
            if (this.options.intensity) {
                config.intensity = this.options.intensity;
            }
            if (this.options.tooltip && (this.options.tooltip.fields || this.options.tooltip.formatter)) {
                this.geometryTooltip(config);
            }
            this.setConfig('geometry', config);
            this.addPoint();
        }
    };
    DensityHeatmapLayer.prototype.addPoint = function () {
        var props = this.options;
        var defaultConfig = { visible: false, size: 0 };
        if (props.point && props.point.visible) {
            props.point = util_1.deepMix(defaultConfig, props.point);
        }
        else {
            props.point = defaultConfig;
        }
        var point = factory_2.getGeom('point', 'guide', {
            plot: this,
        });
        point.active = false;
        // point.label = this.extractLabel();
        this.setConfig('geometry', point);
    };
    DensityHeatmapLayer.prototype.extractLabel = function () {
        var props = this.options;
        var label = props.label;
        if (label && label.visible === false) {
            return false;
        }
        var labelConfig = factory_1.getComponent('label', tslib_1.__assign({ plot: this, labelType: 'scatterLabel', fields: [props.xField, props.yField], position: 'middle', offset: 0 }, label));
        return labelConfig;
    };
    DensityHeatmapLayer.prototype.legend = function () {
        this.setConfig('legends', false);
    };
    DensityHeatmapLayer.prototype.geometryTooltip = function (config) {
        config.tooltip = {};
        var tooltipOptions = this.options.tooltip;
        if (tooltipOptions.fields) {
            config.tooltip.fields = tooltipOptions.fields;
        }
        if (tooltipOptions.formatter) {
            config.tooltip.callback = tooltipOptions.formatter;
            if (!tooltipOptions.fields) {
                config.tooltip.fields = [this.options.xField, this.options.yField];
                if (this.options.colorField) {
                    config.tooltip.fields.push(this.options.colorField);
                }
            }
        }
    };
    DensityHeatmapLayer.prototype.parseEvents = function () {
        _super.prototype.parseEvents.call(this, EventParser);
    };
    DensityHeatmapLayer.prototype.renderPlotComponents = function () {
        var _this = this;
        util_1.each(this.plotComponents, function (component) {
            component.destroy();
        });
        var componentsType = ['legend', 'background'];
        util_1.each(componentsType, function (t) {
            var cfg = tslib_1.__assign({ view: _this.view, plot: _this }, _this.options[t]);
            var component = components_1.getPlotComponents(_this, t, cfg);
            if (component) {
                component.render();
                _this.plotComponents.push(component);
            }
        });
    };
    return DensityHeatmapLayer;
}(view_layer_1.default));
exports.default = DensityHeatmapLayer;
global_1.registerPlotType('densityHeatmap', DensityHeatmapLayer);
//# sourceMappingURL=layer.js.map