vap-visual
Advanced tools
Comparing version 0.0.7 to 0.0.8
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDrawer = exports.LegendDrawer = void 0; | ||
var _ = require("lodash"); | ||
var _Drawer_1 = require("./Types/_Drawer"); | ||
@@ -11,3 +12,7 @@ Object.defineProperty(exports, "LegendDrawer", { enumerable: true, get: function () { return _Drawer_1.LegendDrawer; } }); | ||
var NoneLegend_1 = require("./Types/NoneLegend"); | ||
var NONE = new NoneLegend_1.default(null, null, null, null, null, 0); | ||
exports.getDrawer = function (container, mode, visual, onChange, labelFormat, valueFormat, duration) { | ||
if (mode == 'none' || !_.has(visual, 'legend') || visual.legend.postion == 'n') { | ||
return NONE; | ||
} | ||
switch (mode) { | ||
@@ -23,4 +28,4 @@ case 'label': | ||
default: | ||
return new NoneLegend_1.default(container, visual, onChange, labelFormat, valueFormat, duration); | ||
return NONE; | ||
} | ||
}; |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (legend == null || legend == undefined) { | ||
return legend; | ||
return { postion: 'n' }; | ||
} | ||
@@ -67,4 +67,7 @@ if (legend.postion == 'n') { | ||
this.lastLoad = null; | ||
if (visual == null) { | ||
return; | ||
} | ||
this.config = getSupport(visual.legend); | ||
if (this.config == null || this.config == undefined) { | ||
if (this.config == null || this.config == undefined || this.config.postion == 'n') { | ||
return; | ||
@@ -71,0 +74,0 @@ } |
import { LegendDrawer } from './_Drawer'; | ||
import { Layout } from '../../../interface'; | ||
export default class extends LegendDrawer { | ||
draw(): void; | ||
resize(layout: any): any; | ||
resize(ui: Layout): Layout; | ||
setData(data: any[]): any[]; | ||
} |
@@ -22,9 +22,11 @@ "use strict"; | ||
} | ||
default_1.prototype.draw = function () { | ||
default_1.prototype.resize = function (ui) { | ||
return ui; | ||
}; | ||
default_1.prototype.resize = function (layout) { | ||
return layout; | ||
default_1.prototype.setData = function (data) { | ||
return data; | ||
}; | ||
; | ||
return default_1; | ||
}(_Drawer_1.LegendDrawer)); | ||
exports.default = default_1; |
@@ -100,5 +100,2 @@ "use strict"; | ||
this.update(this.DATA); | ||
// if (this.__legendMode != 'none' && this.legendDrawer != null) { | ||
// this.legendDrawer.draw(); | ||
// } | ||
}; | ||
@@ -105,0 +102,0 @@ /** |
{ | ||
"name": "vap-visual", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "vap-visual - A Visual FrameWork base on d3 & lodash", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,292 +0,263 @@ | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var d3 = require("d3"); | ||
var _ = require("lodash"); | ||
var util_1 = require("../util"); | ||
var ToolTip_1 = require("../_Common/ToolTip"); | ||
var default_1 = /** @class */ (function () { | ||
function default_1(selector, conf) { | ||
var _this = this; | ||
this.id = "_l_" + Math.ceil(_.random(9999999)); | ||
// 事件 | ||
this.Events = new Map(); | ||
// 初始化参数 | ||
this.CONFIG = null; | ||
this._loaded = false; | ||
// 内部扩展属性, 可通过 overwrite 方式重新默认 | ||
this.__ClassName = ''; | ||
this.__Grid = null; | ||
// SVG 上层容器 | ||
this.WIDTH = 0; | ||
this.HEIGHT = 0; | ||
this.CONTAINER = null; | ||
// SVG Self | ||
this.SVG = null; | ||
// SVG / DEF | ||
this.DEFS = null; | ||
// SVG / G.ROOT | ||
this.ROOT = null; | ||
// SVG / G.AXISES - > xAxis ,yAxis | ||
this.AXIX = null; | ||
// SVG / G.LEGEND | ||
this.LEGEND = null; | ||
// SVG / G.MARKED | ||
this.MARK = null; | ||
// SVG / G.TOP | ||
this.EXT_TOP = null; | ||
// SVG / G.BOTTOM | ||
this.EXT_BOTTOM = null; | ||
// MAX_COUNT | ||
this.MAXCOUNT = util_1.default.getDefault().maxcount; | ||
this.DURATION = util_1.default.getDefault().duration; | ||
// FORMART LABEL / VALUE | ||
this.FormatLabel = function (v, o) { return v; }; | ||
this.FormatValue = util_1.default.buildFormat('number'); | ||
// Layout and Cache Data | ||
this.LAYOUT = { x: 0, y: 0, w: 0, h: 0 }; | ||
this.LAYOUT_LEGEND = { x: 0, y: 0, w: 0, h: 0 }; | ||
this.checkedField = []; | ||
this.selectedItem = null; | ||
this.ORGIN_DATA = []; | ||
this.SORT_DATA = []; | ||
this.DATA = []; | ||
this.CONFIG = conf; | ||
// Fix bug from constructor syntax delay | ||
window.setTimeout(function () { | ||
var GLOBAL = util_1.default.getDefault(); | ||
_this.__ClassName = "" + GLOBAL.prefix + _this.__ClassName + " " + (GLOBAL.className ? GLOBAL.className : ''); | ||
_this.__Grid = _.merge({}, GLOBAL.grid, _this.__Grid); | ||
_this.initSVG(selector); | ||
if (_.has(_this.CONFIG, 'data') && _this.CONFIG.data != null) { | ||
var data = _.concat([], _this.CONFIG.data); | ||
_.unset(_this.CONFIG, 'data'); | ||
_this.setData(data); | ||
} | ||
}, 2); | ||
window.addEventListener('resize', function () { | ||
if (_this._needResize()) { | ||
_this.drawGraphAndLegend(); | ||
} | ||
}); | ||
} | ||
// 打包:重置 checkedField 重新layout 重新update ,重绘legend | ||
default_1.prototype.drawGraphAndLegend = function () { | ||
this.layout(this.DATA); | ||
this.update(this.DATA); | ||
}; | ||
/** | ||
* 当 Legend 被重新选中时 | ||
*/ | ||
default_1.prototype.onLegendSelected = function (checkFields) { | ||
this.checkedField = checkFields.map(function (item) { return item.field; }); | ||
this.DATA = _.concat([], this.SORT_DATA); | ||
this.drawGraphAndLegend(); | ||
}; | ||
default_1.prototype._tip = function (data, idx) { | ||
var _this = this; | ||
if (_.isString(this.CONFIG.valueField)) { | ||
ToolTip_1.default.show("<div class=\"_tip _tip-" + idx + "\">\n <h2><i></i><span>" + this.FormatLabel(data[this.CONFIG.labelField], data) + "</span></h2>\n <p class=\"_item\"><span class=\"_label\">" + (this.CONFIG.valueLabel || '') + " : </span><span class=\"_value\">" + this.FormatValue(data[this.CONFIG.valueField]) + "</span></p>\n </div>"); | ||
} | ||
else { | ||
var html_1 = []; | ||
html_1.push("<h2><span>" + this.FormatLabel(data[this.CONFIG.labelField], data) + "</span></h2>"); | ||
this.CONFIG.valueField.map(function (field, i) { | ||
html_1.push("<p class=\"_item " + (idx == i ? 'current' : '') + "\"><span class=\"_label\">" + _this.CONFIG.valueLabel[i] + " : </span><span class=\"_number _value\">" + _this.FormatValue(data[field]) + "</span></p>"); | ||
}); | ||
html_1.push("<p class=\"_item _item_sum\"><span class=\"_label\">\u5171\u8BA1 : </span><span class=\"_number _value\">" + this.FormatValue(data.__total) + "</span></p>"); | ||
ToolTip_1.default.show(html_1.join('')); | ||
} | ||
}; | ||
// 提示 | ||
default_1.prototype.tip = function (enter, path) { | ||
if (path === void 0) { path = ''; } | ||
if (this.CONFIG.tip === null) { | ||
return; | ||
} | ||
var self = this; | ||
enter.on('mouseover', function (d, i) { | ||
var data = path ? _.get(d, path) : d; | ||
var index = i; | ||
if (_.isArray(self.CONFIG.valueField)) { | ||
index = parseInt(d3.select(this.parentNode).attr('series')); | ||
} | ||
if (_.has(this.CONFIG, 'tip')) { | ||
var result = self.CONFIG.tip(data, index); | ||
ToolTip_1.default.show(result); | ||
} | ||
else { | ||
self._tip(data, index); | ||
} | ||
}); | ||
enter.on('mouseout', function () { return ToolTip_1.default.hide(); }); | ||
}; | ||
// 通用方法 :点击事件 | ||
default_1.prototype.click = function (enter, path) { | ||
if (path === void 0) { path = ''; } | ||
if (!_.has(this.CONFIG, 'onClick')) { | ||
return; | ||
} | ||
var self = this; | ||
enter.on('click', function (d, i) { | ||
// idx: 计算选中 extra: 额外 返回 | ||
var _a = __read([i, i], 2), idx = _a[0], extra = _a[1]; | ||
var data = path ? _.get(d, path) : d; | ||
var isGroup = _.isArray(self.CONFIG.valueField); | ||
var clazz = isGroup ? '_group' : '_item'; | ||
// console.log(data) | ||
if (isGroup) { | ||
idx = data._idx; | ||
extra = data._field; | ||
} | ||
if (self.CONFIG.clickSelect) { | ||
self.ROOT.selectAll('g.' + clazz).classed(clazz + '_selected', false); | ||
if (data[self.CONFIG.labelField] == self.selectedItem) { | ||
self.selectedItem = null; | ||
self.CONFIG.onClick(null); | ||
} | ||
else { | ||
self.ROOT.selectAll('g.' + clazz + '_' + idx).classed(clazz + '_selected', true); | ||
self.selectedItem = data[self.CONFIG.labelField]; | ||
self.CONFIG.onClick(data, extra); | ||
} | ||
} | ||
else { | ||
self.CONFIG.onClick(data, extra); | ||
} | ||
}); | ||
}; | ||
// 初始化画布 | ||
default_1.prototype.initSVG = function (selector) { | ||
if (this._loaded) { | ||
return; | ||
} | ||
if (selector) { | ||
this.CONTAINER = d3.select(selector); | ||
} | ||
this.CONTAINER.empty(); | ||
var size = this.CONTAINER.size(); | ||
if (size == 0) { | ||
console.error("Selector does not match any elements \uFF1A %c " + selector + " ", 'color:red;background:yellow;'); | ||
return; | ||
} | ||
else if (size > 1) { | ||
console.error("Selector matched too many elements \uFF1A %c " + selector, 'color:red;background:yellow;'); | ||
return; | ||
} | ||
this.CONTAINER.classed('_visual', true).classed(this.__ClassName, true); | ||
if (_.has(this.CONFIG, 'className')) | ||
this.CONTAINER.classed(this.CONFIG.className, true).classed(this.__ClassName, true); | ||
if (_.has(this.CONFIG, 'maxCount') && _.isNumber(this.CONFIG.maxCount)) | ||
this.MAXCOUNT = this.CONFIG.maxCount; | ||
if (_.has(this.CONFIG, 'duration') && _.isNumber(this.CONFIG.duration)) | ||
this.DURATION = this.CONFIG.duration; | ||
if (_.has(this.CONFIG, 'valueFormat')) | ||
this.FormatValue = util_1.default.buildFormat(this.CONFIG.valueFormat); | ||
if (_.has(this.CONFIG, 'labelFormat')) | ||
this.FormatLabel = this.CONFIG.labelFormat; | ||
this.SVG = this.CONTAINER.append('svg'); | ||
this.DEFS = this.SVG.append('defs'); | ||
this.EXT_TOP = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_ext_top _root_clickable' : '_ext_top'); | ||
this.ROOT = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_root _root_clickable' : '_root'); | ||
this.AXIX = this.SVG.append('g').attr('class', '_axis'); | ||
this.LEGEND = this.SVG.append('g').attr('class', '_legend ' + (_.has(this.CONFIG.legend, 'mode') ? ' _legend_' + this.CONFIG.legend.mode : '_legend_simple')); | ||
this.MARK = this.SVG.append('g').attr('class', '_mark'); | ||
this.EXT_BOTTOM = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_ext_bottom _root_clickable' : '_ext_bottom'); | ||
if (this.CONFIG.defs) { | ||
this.DEFS.html(this.CONFIG.defs); | ||
} | ||
else if (this.CONFIG.fillStyle) { | ||
util_1.default.def(this.DEFS, this.CONFIG.fillStyle); | ||
} | ||
this._needResize(true); | ||
this.SVG.attr('width', this.WIDTH).attr('height', this.HEIGHT); | ||
this.init(); | ||
this._loaded = true; | ||
}; | ||
// 判断是否需要 Resize (可传 force 强㓡 resize) | ||
default_1.prototype._needResize = function (force) { | ||
if (force === void 0) { force = false; } | ||
var rootNode = this.CONTAINER.node(); | ||
var width = Math.floor(rootNode.offsetWidth); | ||
var height = Math.floor(rootNode.offsetHeight); | ||
if (force || this.WIDTH != width || this.HEIGHT != height) { | ||
this.WIDTH = width; | ||
this.HEIGHT = height; | ||
var grid = Object.assign({}, this.__Grid, this.CONFIG.grid); | ||
this.LAYOUT = { x: grid.left, y: grid.top, w: this.WIDTH - grid.left - grid.right, h: this.HEIGHT - grid.top - grid.bottom, }; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
default_1.prototype.itemClass = function (d, i) { | ||
return "_item _item_" + i + " " + (this.CONFIG.fillStyle ? ('_item_fill_style _item_fill_' + this.CONFIG.fillStyle) : ''); | ||
}; | ||
/** | ||
* If you register a event on it , the call function would be processed. | ||
*/ | ||
default_1.prototype.on = function (type, call) { | ||
this.Events.set(type, call); | ||
}; | ||
/** | ||
* Bind data to chart | ||
*/ | ||
default_1.prototype.setData = function (data) { | ||
var _this = this; | ||
if (this.SVG == null) { | ||
// FIX BUGS FOR CONTRUCT SYNTAX | ||
return this._loaded || window.setTimeout(function () { return _this.setData(data); }, 33); | ||
} | ||
this.ORGIN_DATA = _.concat([], data); | ||
this.SORT_DATA = this.sort(this.ORGIN_DATA); | ||
this.DATA = _.concat([], this.SORT_DATA); | ||
this.drawGraphAndLegend(); | ||
}; | ||
/** | ||
* Reset Options For this chart | ||
*/ | ||
default_1.prototype.setOption = function (conf) { | ||
this.CONFIG = _.merge({}, this.CONFIG, conf); | ||
if (this.SVG) { | ||
this.SVG.remove(); | ||
this._loaded = false; | ||
} | ||
this.initSVG(); | ||
if (this.ORGIN_DATA) { | ||
this.SORT_DATA = this.sort(this.ORGIN_DATA); | ||
this.DATA = _.concat([], this.SORT_DATA); | ||
this.drawGraphAndLegend(); | ||
} | ||
}; | ||
/** | ||
* sort 方法通常需要完成 | ||
* 1. 排序 | ||
* 2. 定义自身需要的变量 | ||
* 3. 转换数据为需要 update 的格式 并返回 | ||
* */ | ||
default_1.prototype.sort = function (arr) { return arr; }; | ||
/** | ||
* layout 方法通常需要完成 | ||
* 1. 设置 Axis 坐标轴 | ||
* 2. 设置 Scale | ||
* 3. 定义自身需要的变量 | ||
* */ | ||
default_1.prototype.layout = function (arr) { }; | ||
return default_1; | ||
}()); | ||
exports.default = default_1; | ||
// import * as d3 from 'd3'; | ||
// import * as _ from 'lodash'; | ||
// import { GeoOpts } from './interface'; | ||
// import { VISUAL_EVENT, Layout } from '../interface'; | ||
// import Utils from '../util'; | ||
// import ToolTip from '../_Common/ToolTip'; | ||
// export default abstract class <T extends GeoOpts> { | ||
// protected id = `_l_${Math.ceil(_.random(9999999))}` | ||
// // 事件 | ||
// protected Events: Map<VISUAL_EVENT, Function> = new Map(); | ||
// // 初始化参数 | ||
// protected CONFIG: T = null; | ||
// private _loaded = false; | ||
// // 内部扩展属性, 可通过 overwrite 方式重新默认 | ||
// protected __ClassName = ''; | ||
// // SVG 上层容器 | ||
// protected WIDTH = 0; | ||
// protected HEIGHT = 0; | ||
// protected CONTAINER: d3.Selection<any, any, any, any> = null; | ||
// // SVG Self | ||
// protected SVG: d3.Selection<any, any, any, any> = null; | ||
// // SVG / DEF | ||
// protected DEFS: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.ROOT | ||
// protected ROOT: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.AXISES - > xAxis ,yAxis | ||
// protected AXIX: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.LEGEND | ||
// protected LEGEND: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.MARKED | ||
// protected MARK: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.TOP | ||
// protected EXT_TOP: d3.Selection<any, any, any, any> = null; | ||
// // SVG / G.BOTTOM | ||
// protected EXT_BOTTOM: d3.Selection<any, any, any, any> = null; | ||
// // MAX_COUNT | ||
// protected MAXCOUNT = Utils.getDefault().maxcount; | ||
// protected DURATION = Utils.getDefault().duration; | ||
// // FORMART LABEL / VALUE | ||
// protected FormatLabel = (v, o?) => v; | ||
// protected FormatValue = Utils.buildFormat('number'); | ||
// // Layout and Cache Data | ||
// protected LAYOUT: Layout = { x: 0, y: 0, w: 0, h: 0 }; | ||
// protected selectedItem: string | number = null; | ||
// private ORGIN_DATA = []; | ||
// private SORT_DATA = []; | ||
// private DATA = []; | ||
// constructor(selector: string, conf: T) { | ||
// this.CONFIG = conf; | ||
// // Fix bug from constructor syntax delay | ||
// window.setTimeout(() => { | ||
// let GLOBAL = Utils.getDefault(); | ||
// this.__ClassName = `${GLOBAL.prefix}${this.__ClassName} ${GLOBAL.className ? GLOBAL.className : ''}` | ||
// this.__Grid = _.merge({}, GLOBAL.grid, this.__Grid); | ||
// this.initSVG(selector); | ||
// if (_.has(this.CONFIG, 'data') && this.CONFIG.data != null) { | ||
// let data = _.concat([], this.CONFIG.data) | ||
// _.unset(this.CONFIG, 'data'); | ||
// this.setData(data); | ||
// } | ||
// }, 2); | ||
// window.addEventListener('resize', () => { | ||
// if (this._needResize()) { | ||
// this.drawGraphAndLegend(); | ||
// } | ||
// }) | ||
// } | ||
// // 打包:重置 checkedField 重新layout 重新update ,重绘legend | ||
// private drawGraphAndLegend() { | ||
// this.layout(this.DATA); | ||
// this.update(this.DATA); | ||
// } | ||
// /** | ||
// * 当 Legend 被重新选中时 | ||
// */ | ||
// protected onLegendSelected(checkFields) { | ||
// this.checkedField = checkFields.map(item => item.field); | ||
// this.DATA = _.concat([], this.SORT_DATA); | ||
// this.drawGraphAndLegend(); | ||
// } | ||
// protected _tip(data, idx) { | ||
// if (_.isString(this.CONFIG.valueField)) { | ||
// ToolTip.show(`<div class="_tip _tip-${idx}"> | ||
// <h2><i></i><span>${this.FormatLabel(data[this.CONFIG.labelField], data)}</span></h2> | ||
// <p class="_item"><span class="_label">${this.CONFIG.valueLabel || ''} : </span><span class="_value">${this.FormatValue(data[this.CONFIG.valueField])}</span></p> | ||
// </div>`); | ||
// } else { | ||
// let html = [] | ||
// html.push(`<h2><span>${this.FormatLabel(data[this.CONFIG.labelField], data)}</span></h2>`); | ||
// this.CONFIG.valueField.map((field, i) => { | ||
// html.push(`<p class="_item ${idx == i ? 'current' : ''}"><span class="_label">${this.CONFIG.valueLabel[i]} : </span><span class="_number _value">${this.FormatValue(data[field])}</span></p>`); | ||
// }) | ||
// html.push(`<p class="_item _item_sum"><span class="_label">共计 : </span><span class="_number _value">${this.FormatValue(data.__total)}</span></p>`); | ||
// ToolTip.show(html.join('')); | ||
// } | ||
// } | ||
// // 提示 | ||
// protected tip(enter: d3.Selection<any, any, any, any>, path = '') { | ||
// if (this.CONFIG.tip === null) { | ||
// return; | ||
// } | ||
// var self = this; | ||
// enter.on('mouseover', function (d: any, i) { | ||
// var data = path ? _.get(d, path) : d; | ||
// var index = i; | ||
// if (_.isArray(self.CONFIG.valueField)) { | ||
// index = parseInt(d3.select(this.parentNode).attr('series')); | ||
// } | ||
// if (_.has(this.CONFIG, 'tip')) { | ||
// let result = self.CONFIG.tip(data, index); | ||
// ToolTip.show(result); | ||
// } else { | ||
// self._tip(data, index); | ||
// } | ||
// }); | ||
// enter.on('mouseout', () => ToolTip.hide()); | ||
// } | ||
// // 通用方法 :点击事件 | ||
// protected click(enter: d3.Selection<any, any, any, any>, path = '') { | ||
// if (!_.has(this.CONFIG, 'onClick')) { | ||
// return; | ||
// } | ||
// var self = this; | ||
// enter.on('click', function (d: any, i) { | ||
// // idx: 计算选中 extra: 额外 返回 | ||
// let [idx, extra] = [i, i]; | ||
// var data = path ? _.get(d, path) : d; | ||
// let isGroup = _.isArray(self.CONFIG.valueField); | ||
// let clazz = isGroup ? '_group' : '_item'; | ||
// // console.log(data) | ||
// if (isGroup) { | ||
// idx = data._idx; | ||
// extra = data._field; | ||
// } | ||
// if (self.CONFIG.clickSelect) { | ||
// self.ROOT.selectAll('g.' + clazz).classed(clazz + '_selected', false); | ||
// if (data[self.CONFIG.labelField] == self.selectedItem) { | ||
// self.selectedItem = null; | ||
// self.CONFIG.onClick(null) | ||
// } else { | ||
// self.ROOT.selectAll('g.' + clazz + '_' + idx).classed(clazz + '_selected', true); | ||
// self.selectedItem = data[self.CONFIG.labelField]; | ||
// self.CONFIG.onClick(data, extra) | ||
// } | ||
// } else { | ||
// self.CONFIG.onClick(data, extra) | ||
// } | ||
// }); | ||
// } | ||
// // 初始化画布 | ||
// private initSVG(selector?: string) { | ||
// if (this._loaded) { | ||
// return; | ||
// } | ||
// if (selector) { | ||
// this.CONTAINER = d3.select(selector); | ||
// } | ||
// this.CONTAINER.empty(); | ||
// let size = this.CONTAINER.size(); | ||
// if (size == 0) { | ||
// console.error(`Selector does not match any elements : %c ${selector} `, 'color:red;background:yellow;') | ||
// return; | ||
// } else if (size > 1) { | ||
// console.error(`Selector matched too many elements : %c ${selector}`, 'color:red;background:yellow;') | ||
// return; | ||
// } | ||
// this.CONTAINER.classed('_visual', true).classed(this.__ClassName, true); | ||
// if (_.has(this.CONFIG, 'className')) this.CONTAINER.classed(this.CONFIG.className, true).classed(this.__ClassName, true); | ||
// if (_.has(this.CONFIG, 'maxCount') && _.isNumber(this.CONFIG.maxCount)) this.MAXCOUNT = this.CONFIG.maxCount; | ||
// if (_.has(this.CONFIG, 'duration') && _.isNumber(this.CONFIG.duration)) this.DURATION = this.CONFIG.duration; | ||
// if (_.has(this.CONFIG, 'valueFormat')) this.FormatValue = Utils.buildFormat(this.CONFIG.valueFormat); | ||
// if (_.has(this.CONFIG, 'labelFormat')) this.FormatLabel = this.CONFIG.labelFormat; | ||
// this.SVG = this.CONTAINER.append('svg'); | ||
// this.DEFS = this.SVG.append('defs'); | ||
// this.EXT_TOP = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_ext_top _root_clickable' : '_ext_top'); | ||
// this.ROOT = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_root _root_clickable' : '_root'); | ||
// this.AXIX = this.SVG.append('g').attr('class', '_axis'); | ||
// this.LEGEND = this.SVG.append('g').attr('class', '_legend ' + (_.has(this.CONFIG.legend, 'mode') ? ' _legend_' + this.CONFIG.legend.mode : '_legend_simple')); | ||
// this.MARK = this.SVG.append('g').attr('class', '_mark'); | ||
// this.EXT_BOTTOM = this.SVG.append('g').attr('class', this.CONFIG.onClick ? '_ext_bottom _root_clickable' : '_ext_bottom'); | ||
// if (this.CONFIG.defs) { | ||
// this.DEFS.html(this.CONFIG.defs); | ||
// } else if (this.CONFIG.fillStyle) { | ||
// Utils.def(this.DEFS, this.CONFIG.fillStyle); | ||
// } | ||
// this._needResize(true); | ||
// this.SVG.attr('width', this.WIDTH).attr('height', this.HEIGHT); | ||
// this.init(); | ||
// this._loaded = true; | ||
// } | ||
// // 判断是否需要 Resize (可传 force 强㓡 resize) | ||
// private _needResize(force = false) { | ||
// let rootNode = this.CONTAINER.node(); | ||
// let width = Math.floor(rootNode.offsetWidth); | ||
// let height = Math.floor(rootNode.offsetHeight); | ||
// if (force || this.WIDTH != width || this.HEIGHT != height) { | ||
// this.WIDTH = width; | ||
// this.HEIGHT = height; | ||
// var grid = Object.assign({}, this.__Grid, this.CONFIG.grid); | ||
// this.LAYOUT = { x: grid.left, y: grid.top, w: this.WIDTH - grid.left - grid.right, h: this.HEIGHT - grid.top - grid.bottom, }; | ||
// return true; | ||
// } | ||
// return false; | ||
// } | ||
// protected itemClass(d, i) { | ||
// return `_item _item_${i} ${this.CONFIG.fillStyle ? ('_item_fill_style _item_fill_' + this.CONFIG.fillStyle) : ''}` | ||
// } | ||
// /** | ||
// * If you register a event on it , the call function would be processed. | ||
// */ | ||
// on(type: VISUAL_EVENT, call: Function) { | ||
// this.Events.set(type, call); | ||
// } | ||
// /** | ||
// * Bind data to chart | ||
// */ | ||
// setData(data: any[]) { | ||
// if (this.SVG == null) { | ||
// // FIX BUGS FOR CONTRUCT SYNTAX | ||
// return this._loaded || window.setTimeout(() => this.setData(data), 33) | ||
// } | ||
// this.ORGIN_DATA = _.concat([], data); | ||
// this.SORT_DATA = this.sort(this.ORGIN_DATA); | ||
// this.DATA = _.concat([], this.SORT_DATA); | ||
// this.drawGraphAndLegend(); | ||
// } | ||
// /** | ||
// * Reset Options For this chart | ||
// */ | ||
// setOption(conf: T) { | ||
// this.CONFIG = _.merge({}, this.CONFIG, conf); | ||
// if (this.SVG) { | ||
// this.SVG.remove(); | ||
// this._loaded = false; | ||
// } | ||
// this.initSVG(); | ||
// if (this.ORGIN_DATA) { | ||
// this.SORT_DATA = this.sort(this.ORGIN_DATA); | ||
// this.DATA = _.concat([], this.SORT_DATA); | ||
// this.drawGraphAndLegend(); | ||
// } | ||
// } | ||
// /** | ||
// * init 暂时强制实现 | ||
// */ | ||
// protected abstract init(); | ||
// /** | ||
// * sort 方法通常需要完成 | ||
// * 1. 排序 | ||
// * 2. 定义自身需要的变量 | ||
// * 3. 转换数据为需要 update 的格式 并返回 | ||
// * */ | ||
// protected sort(arr: any[]): any[] { return arr; } | ||
// /** | ||
// * layout 方法通常需要完成 | ||
// * 1. 设置 Axis 坐标轴 | ||
// * 2. 设置 Scale | ||
// * 3. 定义自身需要的变量 | ||
// * */ | ||
// protected layout(arr: any[]): void { } | ||
// // update must implement | ||
// protected abstract update(arr: any[]) | ||
// } |
400308
9627