/*
@license
Webix Pivot v.4.0.0
This software is covered by Webix Trial License.
Usage without proper license is prohibited.
(c) XB Software Ltd.
*/
! function(e) {
    function t(n) {
        if (i[n]) return i[n].exports;
        var o = i[n] = {
            exports: {},
            id: n,
            loaded: !1
        };
        return e[n].call(o.exports, o, o.exports, t), o.loaded = !0, o.exports
    }
    var i = {};
    return t.m = e, t.c = i, t.p = "/codebase/", t(0)
}([function(e, t, i) {
    "use strict";
    i(3), i(5), i(6), i(7), i(11)
}, , , function(e, t) {
    "use strict"
}, , function(e, t) {
    "use strict";
    webix.i18n.pivot = webix.extend(webix.i18n.pivot || {}, {
        apply: "Apply",
        bar: "Bar",
        cancel: "Cancel",
        chartType: "Chart type",
        columns: "Columns",
        count: "count",
        date: "date",
        fields: "Fields",
        filters: "Filters",
        groupBy: "Group By",
        line: "Line",
        logScale: "Logarithmic scale",
        max: "max",
        min: "min",
        multiselect: "multi-select",
        operationNotDefined: "Operation is not defined",
        layoutIncorrect: "pivotLayout should be an Array instance",
        pivotMessage: "[Click to configure]",
        popupHeader: "Pivot Settings",
        radar: "Radar",
        radarArea: "Area Radar",
        rows: "Rows",
        select: "select",
        settings: "Settings",
        stackedBar: "Stacked Bar",
        sum: "sum",
        text: "text",
        total: "Total",
        values: "Values",
        valuesNotDefined: "Values or Group field are not defined",
        windowTitle: "Pivot Configuration",
        windowMessage: "move fields into a required sector"
    })
}, function(e, t) {
    "use strict";
    webix.protoUI({
        name: "webix_pivot_popup",
        _selected: null,
        $init: function(e) {
            webix.extend(e, this._get_ui(e)), this.$ready.push(this._after_init)
        },
        _get_ui: function(e) {
            return {
                body: {
                    id: "list",
                    view: "list",
                    borderless: !0,
                    autoheight: !0,
                    template: "#title#",
                    data: e.data
                }
            }
        },
        _after_init: function() {
            this.attachEvent("onItemClick", function(e) {
                this._selected = this.$eventSource.getItem(e), this.hide()
            })
        },
        getSelected: function() {
            return this._selected
        }
    }, webix.ui.popup, webix.IdSpace)
}, function(e, t, i) {
    "use strict";

    function n(e) {
        if (e && e.__esModule) return e;
        var t = {};
        if (null != e)
            for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
        return t["default"] = e, t
    }
    var o = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
            return typeof e
        } : function(e) {
            return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e
        },
        s = i(8),
        a = n(s);
    i(9), i(10), webix.protoUI({
        name: "pivot",
        version: "{{version}}",
        defaults: {
            fieldMap: {},
            yScaleWidth: 300,
            columnWidth: 150,
            filterLabelAlign: "right",
            filterWidth: 300,
            filterMinWidth: 150,
            filterLabelWidth: 100,
            format: function(e) {
                return e && "0" != e ? parseFloat(e).toFixed(3) : e
            }
        },
        $divider: "_'_",
        $init: function(e) {
            this.data.provideApi(this, !0), e.structure || (e.structure = {}), webix.extend(e.structure, {
                rows: [],
                columns: [],
                values: [],
                filters: []
            }), this.$view.className += " webix_pivot", webix.extend(e, this._get_ui(e)), this.$ready.push(this.render), this.data.attachEvent("onStoreUpdated", webix.bind(function() {
                this.$$("data") && this.render()
            }, this))
        },
        _get_ui: function(e) {
            var t = {
                    id: "filters",
                    view: "toolbar",
                    hidden: !0,
                    cols: [{}]
                },
                i = {
                    view: "treetable",
                    id: "data",
                    select: "row",
                    navigation: !0,
                    leftSplit: 1,
                    resizeColumn: !0,
                    on: {
                        onHeaderClick: function(e) {
                            var t = this.getTopParentView();
                            0 !== this.getColumnIndex(e.column) || t.config.readonly || t.configure()
                        }
                    },
                    columns: [{}]
                };
            return e.datatable && "object" == o(e.datatable) && (delete e.datatable.id, webix.extend(i, e.datatable, !0)), {
                rows: [t, i]
            }
        },
        configure: function() {
            if (!this._config_popup) {
                var e = {
                    view: "webix_pivot_config",
                    operations: [],
                    pivot: this.config.id
                };
                webix.extend(e, this.config.popup || {}), this._config_popup = webix.ui(e), this.callEvent("onPopup", [this._config_popup]), this._config_popup.attachEvent("onApply", webix.bind(function(e) {
                    this.define("structure", e), this.render()
                }, this))
            }
            var t = [];
            for (var i in this.operations) t.push({
                name: i,
                title: this._apply_locale(i)
            });
            this._config_popup.define("operations", t);
            var n = webix.html.offset(this.$$("data").getNode());
            this._config_popup.setPosition(n.x + 10, n.y + 10), this._config_popup.define("data", this.getFields()), this._config_popup.show()
        },
        render: function(e) {
            var t = this._process_data(this.data.pull, this.data.order);
            if (this.config.footer && this._add_footer(t.header), e || (t.filters = this._process_filters()), this.callEvent("onBeforeRender", [t]), t.filters) {
                var i = t.filters;
                i.length > 0 ? (this.$$("filters").show(), this.$$("filters").define("cols", i), this._filter_events()) : this.$$("filters").hide()
            }
            this.config.totalColumn && this.$$("data").define("math", !0), this.$$("data").config.columns = t.header, this.$$("data").refreshColumns(), this.$$("data").clearAll(), this.$$("data").parse(t.data)
        },
        _add_footer: function(e) {
            var t, i, n, s, a = this.config.format;
            for (i = this.$$("data"), i.define("footer", !0), e.length && (e[0].footer = this._apply_locale("total")), n = 1; n < e.length; n++) t = null, "sumOnly" == this.config.footer && (s = e[n].id.split(this.$divider), "sum" != s[s.length - 2] && (t = " ")), t || (t = {
                content: "pivotSumColumn",
                template: webix.bind(function(e) {
                    var t = e.value;
                    return t && "0" != t && !this.format ? a(t) : t
                }, e[n])
            }), e[n].footer = t, "object" == o(this.config.footer) && webix.extend(e[n].footer, this.config.footer, !0)
        },
        $exportView: function(e) {
            return webix.extend(e, {
                filterHTML: !0
            }), this.$$("data")
        },
        _apply_locale: function(e) {
            return webix.i18n.pivot[e] || e
        },
        _apply_map: function(e) {
            return this.config.fieldMap[e] || e
        },
        _process_filters: function() {
            for (var e = this.config.structure.filters || [], t = [], i = 0; i < e.length; i++) {
                var n = e[i],
                    o = {
                        value: n.value,
                        label: this._apply_map(n.name),
                        field: n.name,
                        view: n.type,
                        labelAlign: this.config.filterLabelAlign,
                        labelWidth: this.config.filterLabelWidth,
                        minWidth: this.config.filterMinWidth,
                        maxWidth: this.config.filterWidth
                    };
                "select" != n.type && "multiselect" != n.type || (o.options = this._distinct_values(n.name, "multiselect" != n.type)), t.push(o)
            }
            return t
        },
        _distinct_values: function(e, t) {
            var i = [];
            t && i.push({
                value: "",
                id: ""
            });
            var n = this.data.pull,
                o = {};
            for (var s in n) {
                var a = n[s][e];
                webix.isUndefined(a) || o[a] || (i.push({
                    value: a,
                    id: a
                }), o[a] = !0)
            }
            var r = function(e) {
                return !isNaN(parseFloat(e))
            };
            return i.sort(function(e, t) {
                var i = e.value,
                    n = t.value;
                return n ? i ? (r(i) && r(n) || (i = i.toString().toLowerCase(), n = n.toString().toLowerCase()), i > n ? 1 : n > i ? -1 : 0) : -1 : 1
            }), i
        },
        _filter_events: function() {
            var e = this.$$("filters");
            e.reconstruct();
            for (var t = e.getChildViews(), i = this, n = 0; n < t.length; n++) {
                var o = t[n];
                "select" == o.name || "multiselect" == o.name || "datepicker" == o.name ? o.attachEvent("onChange", function(e) {
                    i._set_filter_value(this.config.field, e)
                }) : o.attachEvent("onTimedKeyPress", function() {
                    i._set_filter_value(this.config.field, this.getValue())
                })
            }
        },
        _set_filter_value: function(e, t) {
            for (var i = this.config.structure.filters, n = 0; n < i.length; n++)
                if (i[n].name == e) return i[n].value = t, this.render(!0), !0;
            return !1
        },
        _process_data: function(e, t) {
            this._init_filters();
            var i = this.config.structure;
            i._header = [], i._header_hash = {};
            for (var n = 0; n < i.values.length; n++) i.values[n].operation = i.values[n].operation || ["sum"], webix.isArray(i.values[n].operation) || (i.values[n].operation = [i.values[n].operation]);
            for (var s = [], a = 0; a < i.columns.length; a++) s[a] = "object" == o(i.columns[a]) ? i.columns[a].id || a : i.columns[a];
            var r = i.rows.concat(s),
                l = this._group(e, t, r),
                u = {};
            return i.rows.length > 0 ? l = this._process_rows(l, i.rows, i, u) : (this._process_columns(l, s, i, u), l = []), u = this._process_header(u), {
                header: u,
                data: l
            }
        },
        _groupItem: function(e, t, i) {
            if (i.length) {
                var n = t[i[0]];
                webix.isUndefined(e[n]) && (e[n] = {}), this._groupItem(e[n], t, i.slice(1))
            } else e[t.id] = t
        },
        _group: function(e, t, i) {
            var n, o, s, a = {};
            for (s = 0; s < t.length; s++) n = t[s], o = e[n], o && this._filter_item(o) && this._groupItem(a, o, i);
            return a
        },
        _process_rows: function(e, t, i, n) {
            var o = [];
            if (t.length > 1) {
                for (var s in e) e[s] = this._process_rows(e[s], t.slice(1), i, n);
                var a = i._header;
                for (var r in e) {
                    for (var l = {
                            data: e[r]
                        }, u = 0; u < l.data.length; u++)
                        for (var h = 0; h < a.length; h++) {
                            var c = a[h];
                            webix.isUndefined(l[c]) && (l[c] = []), l[c].push(l.data[u][c])
                        }
                    l = this._calculate_item(l, i), l = this._minmax_in_row(l, i), l.name = r, l.open = !0, o.push(l)
                }
            } else
                for (var p in e) {
                    var d = this._process_columns(e[p], this.config.structure.columns, i, n);
                    d.name = p, d = this._calculate_item(d, i), d = this._minmax_in_row(d, i), o.push(d)
                }
            return o
        },
        _process_columns: function(e, t, i, n, o, s) {
            var a;
            if (o = o || {}, t.length > 0) {
                s = s || "";
                for (var r in e) n[r] || (n[r] = {}), e[r] = this._process_columns(e[r], t.slice(1), i, n[r], o, (s.length > 0 ? s + this.$divider : "") + r)
            } else {
                var l = this.config.structure.values;
                for (var u in e)
                    for (var h = 0; h < l.length; h++)
                        for (var c = 0; c < l[h].operation.length; c++) a = s ? s + this.$divider + l[h].operation[c] + this.$divider + l[h].name : l[h].operation[c] + this.$divider + l[h].name, i._header_hash[a] || (i._header.push(a), i._header_hash[a] = !0), webix.isUndefined(o[a]) && (o[a] = [], n[l[h].operation[c] + this.$divider + l[h].name] = {}), o[a].push(e[u][l[h].name])
            }
            return o
        },
        _sort_header: function(e) {
            for (var t = this.config.structure.columns, i = !1, n = !1, s = 0; s < t.length && !n; s++) "object" == o(t[s]) && t[s].sort && (n = !0);
            if (!n) return !1;
            if (e.sort(function(e, n) {
                    for (var s, a = null, r = 0; r < t.length && null === a; r++) {
                        var l = t[r];
                        if ("object" == ("undefined" == typeof l ? "undefined" : o(l)) && l.sort) {
                            var u = l.sort;
                            "string" == typeof l.sort && (u = webix.DataStore.prototype.sorting.as[l.sort]), s = u(e[r].text, n[r].text), (s || r == t.length - 1) && (i = !0, "desc" == l.sortDir && (s = -1 * s), a = s)
                        } else a = 0
                    }
                    return a
                }), e[0])
                for (var a = e[0].length - 2; a >= 0;) {
                    for (var r = "", l = 0, u = 0; u < e.length; u++) r != e[u][a].text ? (l = u, r = e[u][a].text, e[u][a].colspan = 1) : (delete e[u][a].colspan, e[l][a].colspan++);
                    a--
                }
        },
        _process_header: function(e) {
            e = this._render_header(e), this._sort_header(e);
            for (var t, i = this.config.structure.values, n = 0; n < e.length; n++) {
                for (var o = [], s = 0; s < e[n].length; s++) o.push(e[n][s].name);
                t = null;
                for (var a = o[o.length - 1].split(this.$divider), r = 0; r < i.length && !t; r++)
                    if (i[r].operation)
                        for (var l = 0; l < i[r].operation.length; l++) i[r].name == a[1] && i[r].operation[l] == a[0] && (t = i[r]);
                e[n] = {
                    id: o.join(this.$divider),
                    header: e[n],
                    sort: "int",
                    width: this.config.columnWidth
                }, e[n].format = t && t.format ? t.format : this.config.format
            }
            this.callEvent("onHeaderInit", [e]), this.config.totalColumn && e.length && (e = this._add_total_columns(e));
            var u = "<div class='webix_pivot_config_msg'>" /*+ webix.i18n.pivot.pivotMessage*/ + "</div>";
            return this.config.readonly && (u = this.config.readonlyTitle || "", this.$$("data").$view.className += " webix_pivot_readonly"), e.splice(0, 0, {
                id: "name",
                exportAsTree: !0,
                template: "{common.treetable()} #name#",
                header: {
                    text: u
                },
                width: this.config.yScaleWidth
            }), e
        },
        _add_total_columns: function(e) {
            var t, i, n, o, s, a, r, l, u, h = 0,
                c = [];
            if (a = e[0].header.length, 2 > a) return e;
            for (t = {}, o = 0; o < e.length; o++) u = e[o].id.split(this.$divider), r = u.pop(), l = u.pop(), "sumOnly" == this.config.totalColumn && "sum" != l || (i = l + this.$divider + r, t[i] || (h++, t[i] = {
                indexes: [],
                format: e.format
            }), t[i].indexes.push(o));
            for (i in t) {
                for (n = {
                        id: "$webixtotal" + this.$divider + i,
                        header: [],
                        sort: "int",
                        width: this.config.columnWidth
                    }, o = 0; a - 1 > o; o++) o || c.length ? n.header.push("") : n.header.push({
                    name: "total",
                    text: this._apply_locale("total"),
                    rowspan: a - 1,
                    colspan: h
                });
                for (u = i.split(this.$divider), n.header.push({
                        name: i,
                        text: this._apply_map(u[1]) + " (" + this._apply_locale(u[0]) + ")"
                    }), n.math = "", s = t[i].indexes, o = 0; o < s.length; o++) n.math += (o ? "+" : "") + "[$r,:" + (s[o] + 1) + "]";
                n.format = t[i].format || this.config.format, c.push(n)
            }
            return e.concat(c)
        },
        _render_header: function(e) {
            var t = [];
            for (var i in e) {
                var n = !0;
                for (var o in e[i]) {
                    n = !1;
                    break
                }
                if (n) {
                    var s = i.split(this.$divider);
                    s.length > 1 ? t.push([{
                        name: i,
                        text: this._apply_map(s[1]) + " (" + this._apply_locale(s[0]) + ")"
                    }]) : t.push([{
                        name: i,
                        text: i
                    }])
                } else {
                    e[i] = this._render_header(e[i]);
                    for (var a = !1, r = 0; r < e[i].length; r++) {
                        var l = e[i][r];
                        l.splice(0, 0, {
                            name: i,
                            text: i
                        }), a || (l[0].colspan = e[i].length, a = !0), t.push(l)
                    }
                }
            }
            return t
        },
        _get_key_leaves: function(e, t, i) {
            for (var n = 0; n < e.length; n++) e[n].data ? this._get_key_leaves(e[n].data, t, i) : i.push(e[n][t])
        },
        _calculate_item: function(e, t) {
            var i, n, o, s, a, r;
            for (i = 0; i < t._header.length; i++)
                if (n = t._header[i], a = n.split(this.$divider), s = a[a.length - 2], r = e[n], o = this._operationOptions[s] && this._operationOptions[s].leavesOnly, o && e.data && (r = [], this._get_key_leaves(e.data, n, r)), r) {
                    for (var l = [], u = 0; u < r.length; u++)(r[u] || "0" == r[u]) && l.push(r[u]);
                    l.length ? e[n] = this.operations[s].call(this, l, n, e) : e[n] = ""
                } else e[n] = "";
            return e
        },
        _minmax_in_row: function(e, t) {
            if (!this.config.min && !this.config.max) return e;
            var i = this.config.structure.values;
            e.$cellCss || (e.$cellCss = {});
            for (var n = 0; n < i.length; n++) {
                for (var o = i[n], s = [], a = -99999999, r = [], l = 99999999, u = 0; u < t._header.length; u++) {
                    var h = t._header[u];
                    window.isNaN(e[h]) || -1 !== h.indexOf(o.name, this.length - o.name.length) && (this.config.max && e[h] > a ? (s = [h], a = e[h]) : e[h] == a && s.push(h), this.config.min && e[h] < l ? (r = [h], l = e[h]) : e[h] == l && r.push(h))
                }
                for (var c = 0; c < r.length; c++) e.$cellCss[r[c]] = "webix_min";
                for (var p = 0; p < s.length; p++) e.$cellCss[s[p]] = "webix_max"
            }
            return e
        },
        _operationOptions: {},
        operations: {
            sum: function r(e) {
                for (var r = 0, t = 0; t < e.length; t++) {
                    var i = e[t];
                    i = parseFloat(i, 10), window.isNaN(i) || (r += i)
                }
                return r
            },
            count: function l(e, t, i) {
                var l = 0;
                if (i.data)
                    for (var n = 0; n < i.data.length; n++) l += i.data[n][t] || 0;
                else l = e.length;
                return l
            },
            max: function(e) {
                return 1 == e.length ? e[0] : Math.max.apply(this, e)
            },
            min: function(e) {
                return 1 == e.length ? e[0] : Math.min.apply(this, e)
            }
        },
        addOperation: function(e, t, i) {
            this.operations[e] = t, i && (this._operationOptions[e] = i)
        },
        getFields: function() {
            for (var e = [], t = {}, i = {}, n = 0; n < Math.min(this.data.count() || 5); n++) {
                var s = this.data.getItem(this.data.getIdByIndex(n));
                for (var a in s) t[a] || (e.push(a), t[a] = webix.uid())
            }
            for (var r = this.config.structure, l = {
                    fields: [],
                    rows: [],
                    columns: [],
                    values: [],
                    filters: []
                }, u = 0; u < (r.filters || []).length; u++) {
                var h = r.filters[u];
                if (!webix.isUndefined(t[h.name])) {
                    var c = this._apply_map(h.name);
                    l.filters.push({
                        name: h.name,
                        text: c,
                        type: h.type,
                        value: h.value,
                        id: t[h.name]
                    })
                }
            }
            for (var p = 0; p < r.rows.length; p++) {
                var d = r.rows[p];
                webix.isUndefined(t[d]) || (l.rows.push({
                    name: d,
                    text: this._apply_map(d),
                    id: t[d]
                }), i[d] = !0)
            }
            for (var f = 0; f < r.columns.length; f++) {
                var v = "object" == o(r.columns[f]) ? r.columns[f].id || f : r.columns[f];
                !webix.isUndefined(t[v]) && webix.isUndefined(i[v]) && l.columns.push({
                    name: v,
                    text: this._apply_map(v),
                    id: t[v]
                })
            }
            for (var _ = 0; _ < r.values.length; _++) {
                var g = r.values[_];
                if (!webix.isUndefined(t[g.name])) {
                    var m = this._apply_map(g.name);
                    l.values.push({
                        name: g.name,
                        text: m,
                        operation: g.operation,
                        id: t[g.name]
                    })
                }
            }
            for (var b = 0; b < e.length; b++) {
                var w = e[b];
                webix.isUndefined(t[w]) || l.fields.push({
                    name: w,
                    text: this._apply_map(w),
                    id: t[w]
                })
            }
            return l
        },
        _init_filters: function() {
            var e = this.config.structure.filters || [];
            a.init(e)
        },
        _filter_item: function(e) {
            var t = this.config.structure.filters || [];
            return a.filterItem(t, e)
        },
        setStructure: function(e) {
            this.define("structure", e), this.render()
        },
        getStructure: function() {
            return this.config.structure
        },
        getConfigWindow: function() {
            return this._config_popup
        },
        profile_setter: function(e) {
            var t = window.console;
            e && (this.attachEvent("onBeforeLoad", function() {
                t.time("data loading")
            }), this.data.attachEvent("onParse", function() {
                t.timeEnd("data loading"), t.time("data parsing")
            }), this.data.attachEvent("onStoreLoad", function() {
                t.timeEnd("data parsing"), t.time("data processing")
            }), this.$ready.push(function() {
                this.$$("data").attachEvent("onBeforeRender", function() {
                    this.count() && (t.timeEnd("data processing"), t.time("data rendering"))
                }), this.$$("data").attachEvent("onAfterRender", function() {
                    this.count() && webix.delay(function() {
                        t.timeEnd("data rendering")
                    })
                })
            }))
        }
    }, webix.IdSpace, webix.ui.layout, webix.DataLoader, webix.EventSystem, webix.Settings)
}, function(e, t) {
    "use strict";

    function i(e, t, i) {
        if ("object" == ("undefined" == typeof e ? "undefined" : s(e))) {
            for (var n = 0; n < e.length; n++)
                if (e[n] = window.parseFloat(e[n]), window.isNaN(e[n])) return !0
        } else if (e = window.parseFloat(e), window.isNaN(e)) return !0;
        return window.isNaN(t) ? !1 : i(e, t)
    }

    function n(e) {
        for (var t = 0; t < e.length; t++) {
            var i = e[t],
                n = i.value || "";
            webix.isDate(n) ? n = webix.i18n.parseFormatStr(n) : "string" == typeof n && n.trim && (n = n.trim()), "=" == n.substr(0, 1) ? (i.func = a.equal, n = n.substr(1)) : "<>" == n.substr(0, 2) ? (i.func = a.not_equal, n = n.substr(2)) : ">=" == n.substr(0, 2) ? (i.func = a.more_equal, n = n.substr(2)) : ">" == n.substr(0, 1) ? (i.func = a.more, n = n.substr(1)) : "<=" == n.substr(0, 2) ? (i.func = a.less_equal, n = n.substr(2)) : "<" == n.substr(0, 1) ? (i.func = a.less, n = n.substr(1)) : n.indexOf("...") > 0 ? (i.func = a.range, n = n.split("...")) : n.indexOf("..") > 0 ? (i.func = a.range_inc, n = n.split("..")) : "multiselect" == i.type ? i.func = a.multi : "datepicker" == i.type ? i.func = function(e, t) {
                return e == t
            } : i.func = a.contains, i.fvalue = n
        }
    }

    function o(e, t) {
        for (var i = 0; i < e.length; i++) {
            var n = e[i];
            if (n.fvalue) {
                if (webix.isUndefined(t[n.name])) return !1;
                var o = t[n.name].toString().toLowerCase(),
                    s = n.func(n.fvalue, o);
                if (!s) return !1
            }
        }
        return !0
    }
    t.__esModule = !0;
    var s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
        return typeof e
    } : function(e) {
        return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e
    };
    t.init = n, t.filterItem = o;
    var a = t.rules = {
        contains: function(e, t) {
            return t.indexOf(e.toString().toLowerCase()) >= 0
        },
        equal: function(e, t) {
            return i(e, t, function(e, t) {
                return e == t
            })
        },
        not_equal: function(e, t) {
            return i(e, t, function(e, t) {
                return e != t
            })
        },
        less: function(e, t) {
            return i(e, t, function(e, t) {
                return e > t
            })
        },
        less_equal: function(e, t) {
            return i(e, t, function(e, t) {
                return e >= t
            })
        },
        more: function(e, t) {
            return i(e, t, function(e, t) {
                return t > e
            })
        },
        more_equal: function(e, t) {
            return i(e, t, function(e, t) {
                return t >= e
            })
        },
        multi: function(e, t) {
            var i = !1;
            e = e.split(",");
            for (var n = 0; n < e.length; n++) i = i || t.indexOf(e[n].toString().toLowerCase()) >= 0;
            return i
        },
        range: function(e, t) {
            return i(e, t, function(e, t) {
                return t < e[1] && t >= e[0]
            })
        },
        range_inc: function(e, t) {
            return i(e, t, function(e, t) {
                return t <= e[1] && t >= e[0]
            })
        }
    }
}, function(e, t) {
    "use strict";
    webix.ui.datafilter.pivotSumColumn = webix.extend({
        refresh: function(e, t, i) {
            var n = 0;
            e.mapCells(null, i.columnId, null, 1, function(t, i) {
                return isNaN(t) || 1 != e.getItem(i).$level || (n += 1 * t), t
            }), i.format && (n = i.format(n)), i.template && (n = i.template({
                value: n
            })), t.firstChild.innerHTML = n
        }
    }, webix.ui.datafilter.summColumn)
}, function(e, t) {
    "use strict";
    webix.protoUI({
        name: "webix_pivot_config",
        $init: function(e) {
            this.$view.className += " webix_popup webix_pivot", webix.extend(e, this.defaults), webix.extend(e, this._get_ui(e)), this.$ready.push(this._after_init)
        },
        defaults: {
            padding: 8,
            height: 500,
            width: 700,
            cancelButtonWidth: 100,
            applyButtonWidth: 100,
            fieldsColumnWidth: 180,
            head: !1,
            modal: !0,
            move: !0
        },
        _get_ui: function(e) {
            return {
                head: {
                    view: "toolbar",
                    cols: [{
                        id: "config_title",
                        view: "label",
                        label: webix.i18n.pivot.windowTitle || ""
                    }, {
                        view: "button",
                        id: "cancel",
                        label: webix.i18n.pivot.cancel,
                        width: e.cancelButtonWidth
                    }, {
                        view: "button",
                        id: "apply",
                        type: "form",
                        label: webix.i18n.pivot.apply,
                        width: e.applyButtonWidth
                    }]
                },
                body: {
                    type: "wide",
                    rows: [{
                        cols: [{
                            width: e.fieldsColumnWidth,
                            rows: [{
                                id: "fieldsHeader",
                                data: {
                                    value: "fields"
                                },
                                css: "webix_pivot_header_fields",
                                template: this._popup_templates.popupHeaders,
                                height: 45
                            }, {
                                id: "fields",
                                css: "webix_pivot_fields",
                                view: "list",
                                scroll: !0,
                                type: {
                                    height: "auto"
                                },
                                drag: !0,
                                template: "<span class='webix_pivot_list_marker'></span>#text#",
                                on: {
                                    onBeforeDrop: webix.bind(this._dropField, this)
                                }
                            }]
                        }, {
                            type: "space",
                            rows: [{
                                type: "wide",
                                rows: [{
                                    css: "webix_pivot_transparent",
                                    borderless: !0,
                                    template: "<div class='webix_pivot_fields_msg'>" + webix.i18n.pivot.windowMessage || "</div>",
                                    height: 25
                                }, {
                                    type: "wide",
                                    cols: [{
                                        rows: [{
                                            id: "filtersHeader",
                                            data: {
                                                value: "filters",
                                                icon: "filter"
                                            },
                                            template: this._popup_templates.popupIconHeaders,
                                            css: "webix_pivot_popup_title",
                                            height: 40
                                        }, {
                                            id: "filters",
                                            view: "list",
                                            scroll: !1,
                                            drag: !0,
                                            css: "webix_pivot_values",
                                            template: function(e) {
                                                return e.type = e.type || "select", "<a class='webix_pivot_link'>" + e.text + " <span class='webix_link_selection'>" + e.type + "</span></a> "
                                            },
                                            type: {
                                                height: 35
                                            },
                                            onClick: {
                                                webix_pivot_link: webix.bind(this._filter_selector, this)
                                            },
                                            on: {
                                                onBeforeDrop: webix.bind(this._dropField, this)
                                            }
                                        }]
                                    }, {
                                        rows: [{
                                            id: "columnsHeader",
                                            data: {
                                                value: "columns",
                                                icon: "columns"
                                            },
                                            template: this._popup_templates.popupIconHeaders,
                                            css: "webix_pivot_popup_title",
                                            height: 40
                                        }, {
                                            id: "columns",
                                            view: "list",
                                            scroll: !1,
                                            drag: !0,
                                            type: {
                                                height: 35
                                            },
                                            template: "#text#",
                                            on: {
                                                onBeforeDrop: webix.bind(this._dropField, this)
                                            }
                                        }]
                                    }]
                                }, {
                                    type: "wide",
                                    cols: [{
                                        rows: [{
                                            id: "rowsHeader",
                                            data: {
                                                value: "rows",
                                                icon: "list"
                                            },
                                            template: this._popup_templates.popupIconHeaders,
                                            css: "webix_pivot_popup_title",
                                            height: 40
                                        }, {
                                            id: "rows",
                                            view: "list",
                                            scroll: !1,
                                            drag: !0,
                                            template: "#text#",
                                            type: {
                                                height: 35
                                            },
                                            on: {
                                                onBeforeDrop: webix.bind(this._dropField, this)
                                            }
                                        }]
                                    }, {
                                        rows: [{
                                            id: "valuesHeader",
                                            data: {
                                                value: "values",
                                                icon: !1,
                                                iconContent: "<b>&Sigma;</b>"
                                            },
                                            template: this._popup_templates.popupIconHeaders,
                                            css: "webix_pivot_popup_title",
                                            height: 40
                                        }, {
                                            id: "values",
                                            view: "list",
                                            scroll: !0,
                                            drag: !0,
                                            css: "webix_pivot_values",
                                            type: {
                                                height: "auto"
                                            },
                                            template: webix.bind(this._function_template, this),
                                            onClick: {
                                                webix_pivot_link: webix.bind(this._function_selector, this),
                                                webix_pivot_plus: webix.bind(this._function_add, this),
                                                webix_pivot_minus: webix.bind(this._function_remove, this)
                                            },
                                            on: {
                                                onBeforeDrop: webix.bind(this._dropField, this)
                                            }
                                        }]
                                    }]
                                }]
                            }]
                        }]
                    }]
                }
            }
        },
        _popup_templates: {
            popupHeaders: function(e) {
                return webix.i18n.pivot[e.value]
            },
            popupIconHeaders: function(e) {
                return e.icon ? "<span class='webix_pivot_header_icon webix_icon fa-" + e.icon + "'></span>" + webix.i18n.pivot[e.value] : "<span class='webix_pivot_header_icon'>" + e.iconContent + "</span>" + webix.i18n.pivot[e.value]
            }
        },
        _lists: ["filters", "columns", "rows", "values"],
        _dropField: function(e) {
            var t, i = e.from,
                n = e.to;
            return n && n != i ? (t = webix.copy(i.getItem(e.start)), n == this.$$("fields") ? this._removeListField(this.innerId(i.config.id), t) : this._addListField(this.innerId(n.config.id), t, e.index), !1) : void 0
        },
        _addListField: function(e, t, i) {
            this._handlers[e].call(this, e, t, i)
        },
        _removeListField: function(e, t) {
            this.$$(e).remove(t.id);
            for (var i = this._lists, n = !1, o = 0; !n && o < i.length; o++) this.$$(i[o]).data.each(function(e) {
                e.name == t.name && (n = e)
            });
            n || this._setPivotFieldCss(t.name, "")
        },
        _setPivotFieldCss: function(e, t) {
            this.$$("fields").data.each(function(i) {
                i.name == e && (i.$css = t, this.refresh(i.id))
            })
        },
        _handlers: {
            filters: function(e, t) {
                var i = !1,
                    n = t.name,
                    o = this.$$(e);
                o.data.each(function(e) {
                    e.name == n && (i = !0)
                }), i || (delete t.id, o.add(t), this._setPivotFieldCss(n, "webix_pivot_field_selected"), this._correctLists(n, ["columns", "rows"]))
            },
            rows: function(e, t) {
                var i = !1,
                    n = t.name,
                    o = this.$$(e);
                o.data.each(function(e) {
                    e.name == n && (i = !0)
                }), i || (delete t.id, o.add(t), this._setPivotFieldCss(n, "webix_pivot_field_selected"), this._correctLists(n, ["rows" == e ? "columns" : "rows", "filters"]))
            },
            columns: function(e, t) {
                this._handlers.rows.call(this, e, t)
            },
            values: function(e, t, i) {
                var n = this.$$(e);
                n.getItem(t.id) ? this._function_add({}, t.id) : (this._setPivotFieldCss(t.name, "webix_pivot_field_selected"), n.add(webix.copy(t), i))
            }
        },
        _correctLists: function(e, t) {
            var i, n;
            for (i = 0; i < t.length; i++) n = null, this.$$(t[i]).data.each(function(t) {
                t.name == e && (n = t)
            }), n && this.$$(t[i]).remove(n.id)
        },
        _after_init: function() {
            this.attachEvent("onItemClick", function(e) {
                var t = this.innerId(e);
                if ("cancel" == t || "apply" == t) {
                    var i = this.getStructure();
                    webix.$$(this.config.pivot).callEvent("onBefore" + t, [i]) && (this.callEvent("on" + t, [i]), this.hide())
                }
            })
        },
        _function_template: function(e) {
            e.operation = e.operation || ["sum"], webix.isArray(e.operation) || (e.operation = [e.operation]);
            for (var t = [], i = webix.$$(this.config.pivot)._apply_locale, n = 0; n < e.operation.length; n++) {
                var o = "<span class='webix_pivot_link' webix_operation='" + n + "'>";
                o += "<span>" + e.text + "</span>", o += "<span class='webix_link_selection'>" + i(e.operation[n]) + "</span>", o += "<span class='webix_pivot_minus webix_icon fa-times'></span>", o += "</span>", t.push(o)
            }
            return t.join(" ")
        },
        _function_selector: function(e, t) {
            var i = {
                    view: "webix_pivot_popup",
                    autofit: !0,
                    width: 150,
                    data: this.config.operations || []
                },
                n = webix.ui(i);
            n.show(e), n.attachEvent("onHide", webix.bind(function() {
                var i = webix.html.locate(e, "webix_operation"),
                    o = n.getSelected();
                null !== o && (this.$$("values").getItem(t).operation[i] = o.name, this.$$("values").updateItem(t)), n.close()
            }, this))
        },
        _function_add: function(e, t) {
            var i = this.$$("values").getItem(t);
            i.operation.push("sum"), this.$$("values").updateItem(t), webix.delay(function() {
                for (var e = i.operation.length - 1, n = this.$$("values").getItemNode(t).childNodes, o = null, s = 0; s < n.length; s++)
                    if (o = n[s], o.getAttribute) {
                        var a = o.getAttribute("webix_operation");
                        if (!webix.isUndefined(a) && a == e) break
                    }
                null !== o && this._function_selector(o, t)
            }, this)
        },
        _function_remove: function(e, t) {
            var i = webix.html.locate(e, "webix_operation"),
                n = this.$$("values").getItem(t);
            return n.operation.length > 1 ? (n.operation.splice(i, 1), this.$$("values").updateItem(t)) : this.$$("values").remove(t), !1
        },
        _filter_selector: function(e, t) {
            var i = webix.$$(this.config.pivot)._apply_locale,
                n = {
                    view: "webix_pivot_popup",
                    autofit: !0,
                    height: 150,
                    width: 150,
                    data: [{
                        name: "datepicker",
                        title: i("date")
                    }, {
                        name: "multiselect",
                        title: i("multiselect")
                    }, {
                        name: "select",
                        title: i("select")
                    }, {
                        name: "text",
                        title: i("text")
                    }]
                },
                o = webix.ui(n);
            o.show(e), o.attachEvent("onHide", webix.bind(function() {
                var e = o.getSelected();
                if (null !== e) {
                    var i = this.$$("filters").getItem(t);
                    i.type = e.name, this.$$("filters").updateItem(t)
                }
                o.close()
            }, this))
        },
        data_setter: function(e) {
            var t, i = e.fields,
                n = this._lists;
            i.forEach(function(i) {
                n.forEach(function(n) {
                    t = e[n], t.forEach(function(e) {
                        e.name == i.name && (i.$css = "webix_pivot_field_selected")
                    })
                })
            }), this.$$("fields").clearAll(), this.$$("fields").parse(i), this.$$("fields").filter(function(e) {
                return "id" != e.name
            }), this.$$("filters").clearAll(), this.$$("filters").parse(e.filters), this.$$("columns").clearAll(), this.$$("columns").parse(e.columns), this.$$("rows").clearAll(), this.$$("rows").parse(e.rows), this.$$("values").clearAll(), this.$$("values").parse(e.values)
        },
        setStructure: function(e) {
            this.define("structure", e), this.render()
        },
        getStructure: function() {
            var e = {
                    rows: [],
                    columns: [],
                    values: [],
                    filters: []
                },
                t = this.$$("rows");
            t.data.each(function(t) {
                e.rows.push(t.name)
            });
            var i = this.$$("columns");
            i.data.each(function(t) {
                e.columns.push(t.name)
            });
            var n = this.$$("values");
            n.data.each(function(t) {
                e.values.push(t)
            });
            var o = this.$$("filters");
            return o.data.each(function(t) {
                e.filters.push(t)
            }), e
        }
    }, webix.ui.window, webix.IdSpace)
}, function(e, t, i) {
    "use strict";

    function n(e) {
        if (e && e.__esModule) return e;
        var t = {};
        if (null != e)
            for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
        return t["default"] = e, t
    }
    var o = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
            return typeof e
        } : function(e) {
            return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e
        },
        s = i(8),
        a = n(s);
    i(12), webix.protoUI({
        name: "pivot-chart",
        version: "{{version}}",
        defaults: {
            fieldMap: {},
            rows: [],
            filterLabelAlign: "right",
            filterWidth: 300,
            filterMinWidth: 180,
            editButtonWidth: 110,
            filterLabelWidth: 100,
            chartType: "bar",
            color: "#36abee",
            chart: {},
            singleLegendItem: 1,
            palette: [
                ["#e33fc7", "#a244ea", "#476cee", "#36abee", "#58dccd", "#a7ee70"],
                ["#d3ee36", "#eed236", "#ee9336", "#ee4339", "#595959", "#b85981"],
                ["#c670b8", "#9984ce", "#b9b9e2", "#b0cdfa", "#a0e4eb", "#7faf1b"],
                ["#b4d9a4", "#f2f79a", "#ffaa7d", "#d6806f", "#939393", "#d9b0d1"],
                ["#780e3b", "#684da9", "#242464", "#205793", "#5199a4", "#065c27"],
                ["#54b15a", "#ecf125", "#c65000", "#990001", "#363636", "#800f3e"]
            ]
        },
        templates: {
            groupNameToStr: function(e, t) {
                return e + "_" + t
            },
            groupNameToObject: function(e) {
                var t = e.split("_");
                return {
                    name: t[0],
                    operation: t[1]
                }
            },
            seriesTitle: function(e, t) {
                var i = this.config.fieldMap[e.name] || this._capitalize(e.name),
                    n = webix.isArray(e.operation) ? e.operation[t] : e.operation;
                return i + " ( " + (webix.i18n.pivot[n] || n) + ")"
            }
        },
        templates_setter: function(e) {
            "object" == ("undefined" == typeof e ? "undefined" : o(e)) && webix.extend(this.templates, e)
        },
        chartMap: {
            bar: function(e) {
                return {
                    border: 0,
                    alpha: 1,
                    radius: 0,
                    color: e
                }
            },
            line: function(e) {
                return {
                    alpha: 1,
                    item: {
                        borderColor: e,
                        color: e
                    },
                    line: {
                        color: e,
                        width: 2
                    }
                }
            },
            radar: function(e) {
                return {
                    alpha: 1,
                    fill: !1,
                    disableItems: !0,
                    item: {
                        borderColor: e,
                        color: e
                    },
                    line: {
                        color: e,
                        width: 2
                    }
                }
            }
        },
        chartMap_setter: function(e) {
            "object" == ("undefined" == typeof e ? "undefined" : o(e)) && webix.extend(this.chartMap, e, !0)
        },
        $init: function(e) {
            this.data.provideApi(this, !0), e.structure || (e.structure = {}), webix.extend(e.structure, {
                groupBy: "",
                values: [],
                filters: []
            }), this.$view.className += " webix_pivot_chart", webix.extend(e, {
                editButtonWidth: this.defaults.editButtonWidth
            }), webix.extend(e, this.getUI(e)), this.$ready.push(webix.bind(function() {
                webix.delay(this.render, this)
            }, this)), this.data.attachEvent("onStoreUpdated", webix.bind(function() {
                this.$$("chart") && this.render(this, arguments)
            }, this))
        },
        getUI: function(e) {
            var t = [];
            t.push({
                id: "filters",
                hidden: !0,
                cols: []
            }), e.readonly || t.push({}, {
                id: "edit",
                view: "icon",
                type: "iconButton",
                align: "right",
                icon: "pencil-square-o",
                inputWidth: e.editButtonWidth,
                tooltip: this._applyLocale("settings"),
                click: webix.bind(this.configure, this)
            });
            var i = {
                    paddingY: 10,
                    paddingX: 5,
                    margin: 10,
                    maxHeight: 5,
                    id: "toolbar",
                    cols: t
                },
                n = {
                    id: "bodyLayout",
                    type: "line",
                    margin: 10,
                    cols: [{
                        id: "chart",
                        view: "chart"
                    }]
                };
            return {
                type: "clean",
                rows: [i, n]
            }
        },
        configure: function() {
            if (!this.pivotPopup) {
                var e = {
                    view: "webix_pivot_chart_config",
                    operations: [],
                    pivot: this.config.id
                };
                webix.extend(e, this.config.popup || {}), this.pivotPopup = webix.ui(e), this.callEvent("onPopup", [this.pivotPopup]), this.pivotPopup.attachEvent("onApply", webix.bind(function(e) {
                    this.config.chartType = this.pivotPopup.$$("chartType") ? this.pivotPopup.$$("chartType").getValue() : "bar", this.config.chart.scale = this.pivotPopup.$$("logScale").getValue() ? "logarithmic" : "linear", webix.extend(this.config.structure, e, !0), this.render()
                }, this))
            }
            var t = [];
            for (var i in this.operations) t.push({
                name: i,
                title: this._applyLocale(i)
            });
            this.pivotPopup._valueLength = this._valueLength, this.pivotPopup.define("operations", t);
            var n = webix.html.offset(this.$$("chart").getNode());
            this.pivotPopup.setPosition(n.x + 10, n.y + 10), this.pivotPopup.define("data", this.getFields()), this.pivotPopup._valueFields = this.pivotPopup.show()
        },
        render: function(e) {
            var t = this._processFilters();
            t.length ? (this.$$("filters").show(), this.$$("filters").define("cols", t), this._setFilterEvents()) : this.$$("filters").hide(), this._initFilters(), this._setChartConfig(), this._loadFilteredData()
        },
        _setChartConfig: function() {
            for (var e = this.config, t = e.structure.values, i = 0; i < t.length; i++) t[i].operation = t[i].operation || ["sum"], webix.isArray(t[i].operation) || (t[i].operation = [t[i].operation]);
            var n = this.config.chartType || "bar",
                o = this.chartMap[n],
                s = {
                    type: o && o("").type ? o("").type : n,
                    xAxis: webix.extend({
                        template: "#id#"
                    }, e.chart.xAxis || {}, !0),
                    yAxis: webix.extend({}, e.chart.yAxis || {})
                };
            webix.extend(s, e.chart), s.padding || (s.padding = {
                top: 17
            });
            var a = this._getSeries();
            s.series = a.series, s.legend = !1, (e.singleLegendItem || this._valueLength > 1) && (s.legend = a.legend), s.scheme = {
                $group: this._pivot_group,
                $sort: {
                    by: "id"
                }
            }, this.$$("chart").removeAllSeries();
            for (var r in s) this.$$("chart").define(r, s[r])
        },
        _applyLocale: function(e) {
            return webix.i18n.pivot[e] || e
        },
        _capitalize: function(e) {
            return e.charAt(0).toUpperCase() + e.slice(1)
        },
        _applyMap: function(e, t) {
            return this.config.fieldMap[e] || (t ? this._capitalize(e) : e)
        },
        _processFilters: function() {
            for (var e = this.config.structure.filters || [], t = [], i = 0; i < e.length; i++) {
                var n = e[i],
                    o = {
                        value: n.value,
                        label: this._applyMap(n.name, !0),
                        field: n.name,
                        view: n.type,
                        stringResult: !0,
                        labelAlign: this.config.filterLabelAlign,
                        labelWidth: this.config.filterLabelWidth,
                        minWidth: this.config.filterMinWidth,
                        maxWidth: this.config.filterWidth
                    };
                "select" != n.type && "multiselect" != n.type || (o.options = this._distinctValues(n.name), "multiselect" == n.type && o.options.shift()), t.push(o)
            }
            return t
        },
        _distinctValues: function(e) {
            var t = [{
                    value: "",
                    id: ""
                }],
                i = this.data.pull,
                n = {};
            for (var o in i) {
                var s = i[o][e];
                webix.isUndefined(s) || n[s] || (t.push({
                    value: s,
                    id: s
                }), n[s] = !0)
            }
            return t.sort(function(e, t) {
                var i = e.value,
                    n = t.value;
                return n ? i ? (i = i.toString().toLowerCase(), n = n.toString().toLowerCase(), i > n ? 1 : n > i ? -1 : 0) : -1 : 1
            }), t
        },
        _loadFilteredData: function() {
            this._initFilters(), this.data.silent(function() {
                this.data.filter(webix.bind(this._filterItem, this))
            }, this), this.$$("chart").data.silent(function() {
                this.$$("chart").clearAll()
            }, this), this.$$("chart").parse(this.data.getRange())
        },
        _setFilterEvents: function() {
            var e = this.$$("filters");
            e.reconstruct();
            for (var t = e.getChildViews(), i = this, n = 0; n < t.length; n++) {
                var o = t[n];
                "select" == o.name || "multiselect" == o.name || "datepicker" == o.name ? o.attachEvent("onChange", function(e) {
                    i._setFilterValue(this.config.field, e)
                }) : webix.isUndefined(o.getValue) || o.attachEvent("onTimedKeyPress", function() {
                    i._setFilterValue(this.config.field, this.getValue())
                })
            }
        },
        _setFilterValue: function(e, t) {
            for (var i = this.config.structure.filters, n = 0; n < i.length; n++)
                if (i[n].name == e) return i[n].value = t, this._loadFilteredData(), !0;
            return !1
        },
        groupNameToStr: function(e) {
            return e.name + "_" + e.operation
        },
        groupNameToObject: function(e) {
            var t = e.split("_");
            return {
                name: t[0],
                operation: t[1]
            }
        },
        _getSeries: function() {
            var e, t, i, n, o, s = {},
                a = [],
                r = this.config.structure.values;
            for (i = {
                    valign: "middle",
                    align: "right",
                    width: 140,
                    layout: "y"
                }, webix.extend(i, this.config.chart.legend || {}, !0), i.values = [], i.marker || (i.marker = {}), i.marker.type = "line" == this.config.chartType ? "item" : "s", this.series_names = [], this._valueLength = 0, e = 0; e < r.length; e++)
                for (webix.isArray(r[e].operation) || (r[e].operation = [r[e].operation]), webix.isArray(r[e].color) || (r[e].color = [r[e].color || this._getColor(this._valueLength)]), t = 0; t < r[e].operation.length; t++) {
                    n = this.templates.groupNameToStr(r[e].name, r[e].operation[t]), this.series_names.push(n), r[e].color[t] || (r[e].color[t] = this._getColor(this._valueLength));
                    var l = r[e].color[t],
                        u = this.chartMap[this.config.chartType](l) || {};
                    u.value = "#" + n + "#", u.tooltip = {
                        template: webix.bind(function(e) {
                            return e[this].toFixed(3)
                        }, n)
                    }, a.push(u), o = this.templates.seriesTitle.call(this, r[e], t), i.values.push({
                        text: o,
                        color: l
                    }), s[n] = [r[e].name, r[e].operation[t]], this._valueLength++
                }
            return this._pivot_group = {}, r.length && (this._pivot_group = webix.copy({
                by: this.config.structure.groupBy,
                map: s
            })), {
                series: a,
                legend: i
            }
        },
        _getColor: function(e) {
            var t = this.config.palette,
                i = e / t[0].length;
            i = i > t.length ? 0 : parseInt(i, 10);
            var n = e % t[0].length;
            return t[i][n]
        },
        _processLegend: function() {
            var e, t, i, n = this.config.structure.values;
            for (t = {
                    valign: "middle",
                    align: "right",
                    width: 140,
                    layout: "y"
                }, webix.extend(t, this.config.chart.legend || {}, !0), t.values = [], t.marker || (t.marker = {}), t.marker.type = "line" == this.config.chartType ? "item" : "s", e = 0; e < n.length; e++) i = this.templates.seriesTitle.call(this, n[e]), t.values.push({
                text: i,
                color: n[e].color
            });
            return t
        },
        operations: {
            sum: 1,
            count: 1,
            max: 1,
            min: 1
        },
        addGroupMethod: function(e, t) {
            this.operations[e] = 1, t && (webix.GroupMethods[e] = t)
        },
        removeGroupMethod: function(e) {
            delete this.operations[e]
        },
        groupMethods_setter: function(e) {
            for (var t in e) e.hasOwnProperty(t) && this.addGroupMethod(t, e[t])
        },
        getFields: function() {
            var e, t = [],
                i = {};
            for (e = 0; e < Math.min(this.data.count() || 5); e++) {
                var n = this.data.getItem(this.data.getIdByIndex(e));
                for (var s in n) i[s] || (t.push(s), i[s] = webix.uid())
            }
            var a = this.config.structure,
                r = {
                    fields: [],
                    groupBy: [],
                    values: [],
                    filters: []
                },
                l = "object" == o(a.groupBy) ? a.groupBy[0] : a.groupBy;
            webix.isUndefined(i[l]) || (r.groupBy.push({
                name: l,
                text: this._applyMap(l),
                id: i[l]
            }), delete i[l]);
            var u, h = {};
            for (e = 0; e < a.values.length; e++)
                if (l = a.values[e], !webix.isUndefined(i[l.name]))
                    if (u = this._applyMap(l.name), webix.isUndefined(h[l.name])) h[l.name] = r.values.length, r.values.push({
                        name: l.name,
                        text: u,
                        operation: l.operation,
                        color: l.color || [this._getColor(e)],
                        id: i[l.name]
                    });
                    else {
                        var c = r.values[h[l.name]];
                        c.operation = c.operation.concat(l.operation), c.color = c.color.concat(l.color || [this._getColor(e)])
                    }
            for (e = 0; e < (a.filters || []).length; e++) l = a.filters[e], webix.isUndefined(i[l.name]) || (u = this._applyMap(l.name), r.filters.push({
                name: l.name,
                text: u,
                type: l.type,
                value: l.value,
                id: i[l]
            }), delete i[l.name]);
            for (e = 0; e < t.length; e++) l = t[e], webix.isUndefined(i[l]) || r.fields.push({
                name: l,
                text: this._applyMap(l),
                id: i[l]
            });
            return r
        },
        _initFilters: function() {
            var e = this.config.structure.filters || [];
            a.init(e)
        },
        _filterItem: function(e) {
            var t = this.config.structure.filters || [];
            return a.filterItem(t, e)
        },
        getStructure: function() {
            return this.config.structure
        },
        getConfigWindow: function() {
            return this._config_popup
        }
    }, webix.IdSpace, webix.ui.layout, webix.DataLoader, webix.EventSystem, webix.Settings)
}, function(e, t) {
    "use strict";
    webix.protoUI({
        name: "webix_pivot_chart_config",
        $init: function(e) {
            this.$view.className += " webix_pivot_chart_popup", webix.extend(e, this.defaults), webix.extend(e, this._getUI(e)), this.$ready.push(this._afterInit)
        },
        defaults: {
            padding: 8,
            height: 500,
            width: 650,
            head: !1,
            modal: !0,
            move: !0,
            chartTypeLabelWidth: 80,
            chartTypeWidth: 250,
            cancelButtonWidth: 100,
            applyButtonWidth: 100,
            logScaleLabelWidth: 125,
            fieldsColumnWidth: 280
        },
        _getUI: function(e) {
            var t = [],
                i = webix.$$(e.pivot),
                n = i.chartMap;
            for (var o in n) t.push({
                id: o,
                value: i._applyLocale(o)
            });
            return {
                head: {
                    view: "toolbar",
                    cols: [{
                        id: "config_title",
                        view: "label",
                        label: webix.i18n.pivot.windowTitle
                    }, {
                        view: "button",
                        id: "cancel",
                        label: i._applyLocale("cancel"),
                        width: e.cancelButtonWidth
                    }, {
                        view: "button",
                        id: "apply",
                        type: "form",
                        css: "webix_pivot_apply",
                        label: i._applyLocale("apply"),
                        width: e.applyButtonWidth
                    }]
                },
                body: {
                    type: "space",
                    rows: [{
                        type: "wide",
                        cols: [{
                            width: e.fieldsColumnWidth,
                            rows: [{
                                id: "fieldsHeader",
                                css: "webix_pivot_header_fields",
                                template: "<div class='webix_pivot_fields_msg'>" + webix.i18n.pivot.windowMessage || "</div>",
                                height: 40
                            }, {
                                id: "fields",
                                view: "list",
                                type: {
                                    height: "auto"
                                },
                                drag: !0,
                                template: "<span class='webix_pivot_list_marker'></span>#text#",
                                on: {
                                    onBeforeDrop: webix.bind(this._skipValueDrag, this),
                                    onBeforeDropOut: webix.bind(this._checkValueDrag, this),
                                    onBeforeDrag: webix.bind(this._hidePopups, this)
                                }
                            }]
                        }, {
                            type: "wide",
                            rows: [{
                                rows: [{
                                    id: "filtersHeader",
                                    data: {
                                        value: "filters",
                                        icon: "filter"
                                    },
                                    template: this._popup_templates.popupIconHeaders,
                                    css: "webix_pivot_popup_title",
                                    height: 40
                                }, {
                                    id: "filters",
                                    view: "list",
                                    scroll: !0,
                                    gravity: 2,
                                    drag: !0,
                                    css: "webix_pivot_values",
                                    template: function(e) {
                                        return e.type = e.type || "select", "<div class='webix_pivot_link'>" + e.text + "<div class='webix_link_selection filter'>" + i._applyLocale(e.type) + "</div></div> "
                                    },
                                    type: {
                                        height: 35
                                    },
                                    onClick: {
                                        webix_link_selection: webix.bind(this._filterSelector, this)
                                    },
                                    on: {
                                        onBeforeDrag: webix.bind(this._hidePopups, this)
                                    }
                                }]
                            }, {
                                rows: [{
                                    id: "valuesHeader",
                                    data: {
                                        value: "values",
                                        icon: "bar-chart"
                                    },
                                    template: this._popup_templates.popupIconHeaders,
                                    css: "webix_pivot_popup_title",
                                    height: 40
                                }, {
                                    id: "values",
                                    view: "list",
                                    scroll: !0,
                                    gravity: 3,
                                    drag: !0,
                                    css: "webix_pivot_values",
                                    type: {
                                        height: "auto"
                                    },
                                    template: webix.bind(this._function_template, this),
                                    onClick: {
                                        webix_link_title: webix.bind(this._function_selector, this),
                                        webix_link_selection: webix.bind(this._function_selector, this),
                                        webix_color_selection: webix.bind(this._function_color, this),
                                        webix_pivot_minus: webix.bind(this._function_remove, this)
                                    },
                                    on: {
                                        onBeforeDrop: webix.bind(this._copyValueField, this),
                                        onBeforeDropOut: webix.bind(this._checkValueDrag, this),
                                        onBeforeDrag: webix.bind(this._hidePopups, this)
                                    }
                                }]
                            }, {
                                rows: [{
                                    id: "groupHeader",
                                    data: {
                                        value: "groupBy",
                                        icon: "sitemap"
                                    },
                                    template: this._popup_templates.popupIconHeaders,
                                    css: "webix_pivot_popup_title",
                                    height: 40
                                }, {
                                    id: "groupBy",
                                    view: "list",
                                    yCount: 1,
                                    scroll: !1,
                                    drag: !0,
                                    type: {
                                        height: 35
                                    },
                                    template: "<a class='webix_pivot_link'>#text#</a> ",
                                    on: {
                                        onBeforeDrop: webix.bind(this._changeGroupby, this),
                                        onBeforeDrag: webix.bind(this._hidePopups, this)
                                    }
                                }]
                            }]
                        }]
                    }, {
                        borderless: !0,
                        css: "webix_pivot_footer",
                        cols: [{
                            view: "checkbox",
                            id: "logScale",
                            value: i.config.chart.scale && "logarithmic" == i.config.chart.scale,
                            label: webix.i18n.pivot.logScale,
                            labelWidth: e.logScaleLabelWidth,
                            width: e.logScaleLabelWidth + 20
                        }, {}, {
                            view: "select",
                            id: "chartType",
                            value: i.config.chartType,
                            label: webix.i18n.pivot.chartType,
                            options: t,
                            labelWidth: e.chartTypeLabelWidth,
                            width: e.chartTypeWidth
                        }]
                    }]
                }
            }
        },
        _popup_templates: {
            popupHeaders: function(e) {
                return webix.i18n.pivot[e.value]
            },
            popupIconHeaders: function(e) {
                return "<span class='webix_pivot_header_icon webix_icon fa-" + e.icon + "'></span>" + webix.i18n.pivot[e.value]
            }
        },
        _hidePopups: function() {
            webix.callEvent("onClick", [])
        },
        _skipValueDrag: function(e) {
            if (e.from == this.$$("values")) {
                var t = e.source[0];
                return this.$$("values").getItem(t) && this.$$("values").remove(t), !1
            }
            return !0
        },
        _checkValueDrag: function(e) {
            if (e.to != e.from) {
                var t = e.source[0];
                e.from == this.$$("values") && e.to != this.$$("fields") ? (delete this.$$("values").getItem(t).operation, delete this.$$("values").getItem(t).color, this.$$("fields").getItem(t) && this.$$("fields").remove(t)) : e.from == this.$$("fields") && e.to != this.$$("values") && this.$$("values").getItem(t) && this.$$("values").remove(t)
            }
        },
        _copyValueField: function(e) {
            if (e.to && e.from != e.to) {
                var t = e.source,
                    i = e.from.getItem(t);
                if (e.from == this.$$("fields")) return e.to.getItem(t) ? (this._function_add({}, t), this._valueLength++) : (i = webix.copy(i), e.to.add(webix.copy(i), e.index), this._valueLength++), !1;
                this.$$("fields").getItem(t) || this.$$("fields").add(webix.copy(i)), this._increaseColorIndex = !0
            }
            return !0
        },
        _changeGroupby: function(e) {
            if (this.$$("groupBy").data.order.length) {
                var t = this.$$("groupBy").getFirstId(),
                    i = webix.copy(this.$$("groupBy").getItem(t));
                this.$$("groupBy").remove(t), this.$$("fields").add(i)
            }
            return !0
        },
        _afterInit: function() {
            this.attachEvent("onItemClick", function(e) {
                if ("button" == this.$eventSource.name) {
                    var t = this.getStructure();
                    "apply" != this.innerId(e) || t.values.length && t.groupBy ? (this.callEvent("on" + this.innerId(e), [t]), this.hide()) : webix.alert(webix.i18n.pivot.valuesNotDefined)
                }
            })
        },
        _function_template: function(e) {
            e.operation = e.operation || ["sum"], webix.isArray(e.operation) || (e.operation = [e.operation]);
            for (var t = [], i = webix.$$(this.config.pivot), n = i._applyLocale, o = 0; o < e.operation.length; o++) {
                e.color || (e.color = [i._getColor(this._valueLength)]), e.color[o] || e.color.push(i._getColor(this._valueLength));
                var s = "<div class='webix_pivot_link' webix_operation='" + o + "'>";
                s += "<div class='webix_color_selection'><div style='background-color:" + n(e.color[o]) + "'></div></div>", s += "<div class='webix_link_title'>" + e.text + "</div>", s += "<div class='webix_link_selection'>" + n(e.operation[o]) + "</div>", s += "<div class='webix_pivot_minus webix_icon fa-times'></div>", s += "</div>", t.push(s)
            }
            return this._increaseColorIndex && (this._increaseColorIndex = !1, this._valueLength++), t.join(" ")
        },
        _function_selector: function(e, t) {
            var i = {
                    view: "webix_pivot_popup",
                    autofit: !0,
                    autoheight: !0,
                    width: 150,
                    data: this.config.operations || []
                },
                n = webix.ui(i);
            n.show(e), n.attachEvent("onHide", webix.bind(function() {
                var i = webix.html.locate(e, "webix_operation"),
                    o = n.getSelected();
                null !== o && (this.$$("values").getItem(t).operation[i] = o.name, this.$$("values").updateItem(t)), n.close()
            }, this))
        },
        _function_color: function(e, t) {
            var i = {
                view: "colorboard",
                borderless: !0
            };
            webix.$$(this.config.pivot).config.colorboard ? webix.extend(i, webix.$$(this.config.pivot).config.colorboard) : webix.extend(i, {
                width: 150,
                height: 150,
                palette: webix.$$(this.config.pivot).config.palette
            });
            var n = webix.ui({
                view: "popup",
                id: "colorsPopup",
                body: i
            });
            return n.show(e), n.getBody().attachEvent("onSelect", function() {
                n.hide()
            }), n.attachEvent("onHide", webix.bind(function() {
                var i = webix.html.locate(e, "webix_operation"),
                    o = n.getBody().getValue();
                o && (this.$$("values").getItem(t).color[i] = o, this.$$("values").updateItem(t)), n.close()
            }, this)), !1
        },
        _function_add: function(e, t) {
            var i = this.$$("values").getItem(t);
            i.operation.push("sum");
            var n = webix.$$(this.config.pivot);
            n.config.palette;
            i.color.push(n._getColor(this._valueLength)), this.$$("values").updateItem(t), webix.delay(function() {
                for (var e = i.operation.length - 1, n = this.$$("values").getItemNode(t).childNodes, o = null, s = 0; s < n.length; s++)
                    if (o = n[s], o.getAttribute) {
                        var a = o.getAttribute("webix_operation");
                        if (!webix.isUndefined(a) && a == e) break
                    }
                null !== o && this._function_selector(o, t)
            }, this)
        },
        _function_remove: function(e, t) {
            var i = webix.html.locate(e, "webix_operation"),
                n = this.$$("values").getItem(t);
            return n.operation.length > 1 ? (n.operation.splice(i, 1), this.$$("values").updateItem(t)) : this.$$("values").remove(t), !1
        },
        _filterSelector: function(e, t) {
            var i = webix.$$(this.config.pivot)._applyLocale,
                n = {
                    view: "webix_pivot_popup",
                    autofit: !0,
                    height: 150,
                    width: 150,
                    data: [{
                        name: "datepicker",
                        title: i("date")
                    }, {
                        name: "multiselect",
                        title: i("multiselect")
                    }, {
                        name: "select",
                        title: i("select")
                    }, {
                        name: "text",
                        title: i("text")
                    }]
                },
                o = webix.ui(n);
            o.show(e), o.attachEvent("onHide", webix.bind(function() {
                var e = o.getSelected();
                if (null !== e) {
                    var i = this.$$("filters").getItem(t);
                    i.type = e.name, this.$$("filters").updateItem(t)
                }
                o.close()
            }, this))
        },
        data_setter: function(e) {
            this.$$("fields").clearAll(), this.$$("fields").parse(e.fields), this.$$("fields").filter(function(e) {
                return "id" != e.name
            }), this.$$("filters").clearAll(), this.$$("filters").parse(e.filters), this.$$("groupBy").clearAll(), this.$$("groupBy").parse(e.groupBy), this.$$("values").clearAll(), this.$$("values").parse(e.values)
        },
        getStructure: function() {
            var e = {
                    groupBy: "",
                    values: [],
                    filters: []
                },
                t = this.$$("groupBy");
            t.count() && (e.groupBy = t.getItem(t.getFirstId()).name);
            var i, n = this.$$("values");
            n.data.each(webix.bind(function(t) {
                for (var n = 0; n < t.operation.length; n++) i = webix.copy(t), webix.extend(i, {
                    operation: t.operation[n],
                    color: t.color[n] || webix.$$(this.config.pivot).config.color
                }, !0), e.values.push(i)
            }, this));
            var o = this.$$("filters");
            return o.data.each(function(t) {
                e.filters.push(t)
            }), e
        }
    }, webix.ui.window, webix.IdSpace)
}]);