v3.0.6
This commit is contained in:
@@ -0,0 +1,418 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('echarts')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'echarts'], factory) :
|
||||
(factory((global.bmap = {}),global.echarts));
|
||||
}(this, (function (exports,echarts) { 'use strict';
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/* global BMap */
|
||||
|
||||
function BMapCoordSys(bmap, api) {
|
||||
this._bmap = bmap;
|
||||
this.dimensions = ['lng', 'lat'];
|
||||
this._mapOffset = [0, 0];
|
||||
|
||||
this._api = api;
|
||||
|
||||
this._projection = new BMap.MercatorProjection();
|
||||
}
|
||||
|
||||
BMapCoordSys.prototype.dimensions = ['lng', 'lat'];
|
||||
|
||||
BMapCoordSys.prototype.setZoom = function (zoom) {
|
||||
this._zoom = zoom;
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.setCenter = function (center) {
|
||||
this._center = this._projection.lngLatToPoint(new BMap.Point(center[0], center[1]));
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.setMapOffset = function (mapOffset) {
|
||||
this._mapOffset = mapOffset;
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.getBMap = function () {
|
||||
return this._bmap;
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.dataToPoint = function (data) {
|
||||
var point = new BMap.Point(data[0], data[1]);
|
||||
// TODO mercator projection is toooooooo slow
|
||||
// var mercatorPoint = this._projection.lngLatToPoint(point);
|
||||
|
||||
// var width = this._api.getZr().getWidth();
|
||||
// var height = this._api.getZr().getHeight();
|
||||
// var divider = Math.pow(2, 18 - 10);
|
||||
// return [
|
||||
// Math.round((mercatorPoint.x - this._center.x) / divider + width / 2),
|
||||
// Math.round((this._center.y - mercatorPoint.y) / divider + height / 2)
|
||||
// ];
|
||||
var px = this._bmap.pointToOverlayPixel(point);
|
||||
var mapOffset = this._mapOffset;
|
||||
return [px.x - mapOffset[0], px.y - mapOffset[1]];
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.pointToData = function (pt) {
|
||||
var mapOffset = this._mapOffset;
|
||||
var pt = this._bmap.overlayPixelToPoint({
|
||||
x: pt[0] + mapOffset[0],
|
||||
y: pt[1] + mapOffset[1]
|
||||
});
|
||||
return [pt.lng, pt.lat];
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.getViewRect = function () {
|
||||
var api = this._api;
|
||||
return new echarts.graphic.BoundingRect(0, 0, api.getWidth(), api.getHeight());
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.getRoamTransform = function () {
|
||||
return echarts.matrix.create();
|
||||
};
|
||||
|
||||
BMapCoordSys.prototype.prepareCustoms = function (data) {
|
||||
var rect = this.getViewRect();
|
||||
return {
|
||||
coordSys: {
|
||||
// The name exposed to user is always 'cartesian2d' but not 'grid'.
|
||||
type: 'bmap',
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height
|
||||
},
|
||||
api: {
|
||||
coord: echarts.util.bind(this.dataToPoint, this),
|
||||
size: echarts.util.bind(dataToCoordSize, this)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function dataToCoordSize(dataSize, dataItem) {
|
||||
dataItem = dataItem || [0, 0];
|
||||
return echarts.util.map([0, 1], function (dimIdx) {
|
||||
var val = dataItem[dimIdx];
|
||||
var halfSize = dataSize[dimIdx] / 2;
|
||||
var p1 = [];
|
||||
var p2 = [];
|
||||
p1[dimIdx] = val - halfSize;
|
||||
p2[dimIdx] = val + halfSize;
|
||||
p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
|
||||
return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
|
||||
}, this);
|
||||
}
|
||||
|
||||
var Overlay;
|
||||
|
||||
// For deciding which dimensions to use when creating list data
|
||||
BMapCoordSys.dimensions = BMapCoordSys.prototype.dimensions;
|
||||
|
||||
function createOverlayCtor() {
|
||||
function Overlay(root) {
|
||||
this._root = root;
|
||||
}
|
||||
|
||||
Overlay.prototype = new BMap.Overlay();
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param {BMap.Map} map
|
||||
* @override
|
||||
*/
|
||||
Overlay.prototype.initialize = function (map) {
|
||||
map.getPanes().labelPane.appendChild(this._root);
|
||||
return this._root;
|
||||
};
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Overlay.prototype.draw = function () {};
|
||||
|
||||
return Overlay;
|
||||
}
|
||||
|
||||
BMapCoordSys.create = function (ecModel, api) {
|
||||
var bmapCoordSys;
|
||||
var root = api.getDom();
|
||||
|
||||
// TODO Dispose
|
||||
ecModel.eachComponent('bmap', function (bmapModel) {
|
||||
var painter = api.getZr().painter;
|
||||
var viewportRoot = painter.getViewportRoot();
|
||||
if (typeof BMap === 'undefined') {
|
||||
throw new Error('BMap api is not loaded');
|
||||
}
|
||||
Overlay = Overlay || createOverlayCtor();
|
||||
if (bmapCoordSys) {
|
||||
throw new Error('Only one bmap component can exist');
|
||||
}
|
||||
if (!bmapModel.__bmap) {
|
||||
// Not support IE8
|
||||
var bmapRoot = root.querySelector('.ec-extension-bmap');
|
||||
if (bmapRoot) {
|
||||
// Reset viewport left and top, which will be changed
|
||||
// in moving handler in BMapView
|
||||
viewportRoot.style.left = '0px';
|
||||
viewportRoot.style.top = '0px';
|
||||
root.removeChild(bmapRoot);
|
||||
}
|
||||
bmapRoot = document.createElement('div');
|
||||
bmapRoot.style.cssText = 'width:100%;height:100%';
|
||||
// Not support IE8
|
||||
bmapRoot.classList.add('ec-extension-bmap');
|
||||
root.appendChild(bmapRoot);
|
||||
var bmap = bmapModel.__bmap = new BMap.Map(bmapRoot);
|
||||
|
||||
var overlay = new Overlay(viewportRoot);
|
||||
bmap.addOverlay(overlay);
|
||||
|
||||
// Override
|
||||
painter.getViewportRootOffset = function () {
|
||||
return {offsetLeft: 0, offsetTop: 0};
|
||||
};
|
||||
}
|
||||
var bmap = bmapModel.__bmap;
|
||||
|
||||
// Set bmap options
|
||||
// centerAndZoom before layout and render
|
||||
var center = bmapModel.get('center');
|
||||
var zoom = bmapModel.get('zoom');
|
||||
if (center && zoom) {
|
||||
var pt = new BMap.Point(center[0], center[1]);
|
||||
bmap.centerAndZoom(pt, zoom);
|
||||
}
|
||||
|
||||
bmapCoordSys = new BMapCoordSys(bmap, api);
|
||||
bmapCoordSys.setMapOffset(bmapModel.__mapOffset || [0, 0]);
|
||||
bmapCoordSys.setZoom(zoom);
|
||||
bmapCoordSys.setCenter(center);
|
||||
|
||||
bmapModel.coordinateSystem = bmapCoordSys;
|
||||
});
|
||||
|
||||
ecModel.eachSeries(function (seriesModel) {
|
||||
if (seriesModel.get('coordinateSystem') === 'bmap') {
|
||||
seriesModel.coordinateSystem = bmapCoordSys;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
function v2Equal(a, b) {
|
||||
return a && b && a[0] === b[0] && a[1] === b[1];
|
||||
}
|
||||
|
||||
echarts.extendComponentModel({
|
||||
type: 'bmap',
|
||||
|
||||
getBMap: function () {
|
||||
// __bmap is injected when creating BMapCoordSys
|
||||
return this.__bmap;
|
||||
},
|
||||
|
||||
setCenterAndZoom: function (center, zoom) {
|
||||
this.option.center = center;
|
||||
this.option.zoom = zoom;
|
||||
},
|
||||
|
||||
centerOrZoomChanged: function (center, zoom) {
|
||||
var option = this.option;
|
||||
return !(v2Equal(center, option.center) && zoom === option.zoom);
|
||||
},
|
||||
|
||||
defaultOption: {
|
||||
|
||||
center: [104.114129, 37.550339],
|
||||
|
||||
zoom: 5,
|
||||
|
||||
mapStyle: {},
|
||||
|
||||
roam: false
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
echarts.extendComponentView({
|
||||
type: 'bmap',
|
||||
|
||||
render: function (bMapModel, ecModel, api) {
|
||||
var rendering = true;
|
||||
|
||||
var bmap = bMapModel.getBMap();
|
||||
var viewportRoot = api.getZr().painter.getViewportRoot();
|
||||
var coordSys = bMapModel.coordinateSystem;
|
||||
var moveHandler = function (type, target) {
|
||||
if (rendering) {
|
||||
return;
|
||||
}
|
||||
var offsetEl = viewportRoot.parentNode.parentNode.parentNode;
|
||||
var mapOffset = [
|
||||
-parseInt(offsetEl.style.left, 10) || 0,
|
||||
-parseInt(offsetEl.style.top, 10) || 0
|
||||
];
|
||||
viewportRoot.style.left = mapOffset[0] + 'px';
|
||||
viewportRoot.style.top = mapOffset[1] + 'px';
|
||||
|
||||
coordSys.setMapOffset(mapOffset);
|
||||
bMapModel.__mapOffset = mapOffset;
|
||||
|
||||
api.dispatchAction({
|
||||
type: 'bmapRoam'
|
||||
});
|
||||
};
|
||||
|
||||
function zoomEndHandler() {
|
||||
if (rendering) {
|
||||
return;
|
||||
}
|
||||
api.dispatchAction({
|
||||
type: 'bmapRoam'
|
||||
});
|
||||
}
|
||||
|
||||
bmap.removeEventListener('moving', this._oldMoveHandler);
|
||||
// FIXME
|
||||
// Moveend may be triggered by centerAndZoom method when creating coordSys next time
|
||||
// bmap.removeEventListener('moveend', this._oldMoveHandler);
|
||||
bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
|
||||
bmap.addEventListener('moving', moveHandler);
|
||||
// bmap.addEventListener('moveend', moveHandler);
|
||||
bmap.addEventListener('zoomend', zoomEndHandler);
|
||||
|
||||
this._oldMoveHandler = moveHandler;
|
||||
this._oldZoomEndHandler = zoomEndHandler;
|
||||
|
||||
var roam = bMapModel.get('roam');
|
||||
if (roam && roam !== 'scale') {
|
||||
bmap.enableDragging();
|
||||
}
|
||||
else {
|
||||
bmap.disableDragging();
|
||||
}
|
||||
if (roam && roam !== 'move') {
|
||||
bmap.enableScrollWheelZoom();
|
||||
bmap.enableDoubleClickZoom();
|
||||
bmap.enablePinchToZoom();
|
||||
}
|
||||
else {
|
||||
bmap.disableScrollWheelZoom();
|
||||
bmap.disableDoubleClickZoom();
|
||||
bmap.disablePinchToZoom();
|
||||
}
|
||||
|
||||
var originalStyle = bMapModel.__mapStyle;
|
||||
|
||||
var newMapStyle = bMapModel.get('mapStyle') || {};
|
||||
// FIXME, Not use JSON methods
|
||||
var mapStyleStr = JSON.stringify(newMapStyle);
|
||||
if (JSON.stringify(originalStyle) !== mapStyleStr) {
|
||||
// FIXME May have blank tile when dragging if setMapStyle
|
||||
if (Object.keys(newMapStyle).length) {
|
||||
bmap.setMapStyle(newMapStyle);
|
||||
}
|
||||
bMapModel.__mapStyle = JSON.parse(mapStyleStr);
|
||||
}
|
||||
|
||||
rendering = false;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* BMap component extension
|
||||
*/
|
||||
|
||||
echarts.registerCoordinateSystem('bmap', BMapCoordSys);
|
||||
|
||||
// Action
|
||||
echarts.registerAction({
|
||||
type: 'bmapRoam',
|
||||
event: 'bmapRoam',
|
||||
update: 'updateLayout'
|
||||
}, function (payload, ecModel) {
|
||||
ecModel.eachComponent('bmap', function (bMapModel) {
|
||||
var bmap = bMapModel.getBMap();
|
||||
var center = bmap.getCenter();
|
||||
bMapModel.setCenterAndZoom([center.lng, center.lat], bmap.getZoom());
|
||||
});
|
||||
});
|
||||
|
||||
var version = '1.0.0';
|
||||
|
||||
exports.version = version;
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=bmap.js.map
|
||||
File diff suppressed because one or more lines are too long
22
source/vue/xzs-admin/public/admin/components/echarts/extension/bmap.min.js
vendored
Normal file
22
source/vue/xzs-admin/public/admin/components/echarts/extension/bmap.min.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("echarts")):"function"==typeof define&&define.amd?define(["exports","echarts"],e):e(t.bmap={},t.echarts)}(this,function(t,e){"use strict";function o(t,e){this._bmap=t,this.dimensions=["lng","lat"],this._mapOffset=[0,0],this._api=e,this._projection=new BMap.MercatorProjection}function n(t,o){return o=o||[0,0],e.util.map([0,1],function(e){var n=o[e],i=t[e]/2,a=[],r=[];return a[e]=n-i,r[e]=n+i,a[1-e]=r[1-e]=o[1-e],Math.abs(this.dataToPoint(a)[e]-this.dataToPoint(r)[e])},this)}function i(){function t(t){this._root=t}return t.prototype=new BMap.Overlay,t.prototype.initialize=function(t){return t.getPanes().labelPane.appendChild(this._root),this._root},t.prototype.draw=function(){},t}function a(t,e){return t&&e&&t[0]===e[0]&&t[1]===e[1]}o.prototype.dimensions=["lng","lat"],o.prototype.setZoom=function(t){this._zoom=t},o.prototype.setCenter=function(t){this._center=this._projection.lngLatToPoint(new BMap.Point(t[0],t[1]))},o.prototype.setMapOffset=function(t){this._mapOffset=t},o.prototype.getBMap=function(){return this._bmap},o.prototype.dataToPoint=function(t){var e=new BMap.Point(t[0],t[1]),o=this._bmap.pointToOverlayPixel(e),n=this._mapOffset;return[o.x-n[0],o.y-n[1]]},o.prototype.pointToData=function(t){var e=this._mapOffset;return[(t=this._bmap.overlayPixelToPoint({x:t[0]+e[0],y:t[1]+e[1]})).lng,t.lat]},o.prototype.getViewRect=function(){var t=this._api;return new e.graphic.BoundingRect(0,0,t.getWidth(),t.getHeight())},o.prototype.getRoamTransform=function(){return e.matrix.create()},o.prototype.prepareCustoms=function(t){var o=this.getViewRect();return{coordSys:{type:"bmap",x:o.x,y:o.y,width:o.width,height:o.height},api:{coord:e.util.bind(this.dataToPoint,this),size:e.util.bind(n,this)}}};var r;o.dimensions=o.prototype.dimensions,o.create=function(t,e){var n,a=e.getDom();t.eachComponent("bmap",function(t){var p=e.getZr().painter,s=p.getViewportRoot();if("undefined"==typeof BMap)throw new Error("BMap api is not loaded");if(r=r||i(),n)throw new Error("Only one bmap component can exist");if(!t.__bmap){var m=a.querySelector(".ec-extension-bmap");m&&(s.style.left="0px",s.style.top="0px",a.removeChild(m)),(m=document.createElement("div")).style.cssText="width:100%;height:100%",m.classList.add("ec-extension-bmap"),a.appendChild(m);var c=t.__bmap=new BMap.Map(m),d=new r(s);c.addOverlay(d),p.getViewportRootOffset=function(){return{offsetLeft:0,offsetTop:0}}}var c=t.__bmap,f=t.get("center"),l=t.get("zoom");if(f&&l){var h=new BMap.Point(f[0],f[1]);c.centerAndZoom(h,l)}(n=new o(c,e)).setMapOffset(t.__mapOffset||[0,0]),n.setZoom(l),n.setCenter(f),t.coordinateSystem=n}),t.eachSeries(function(t){"bmap"===t.get("coordinateSystem")&&(t.coordinateSystem=n)})},e.extendComponentModel({type:"bmap",getBMap:function(){return this.__bmap},setCenterAndZoom:function(t,e){this.option.center=t,this.option.zoom=e},centerOrZoomChanged:function(t,e){var o=this.option;return!(a(t,o.center)&&e===o.zoom)},defaultOption:{center:[104.114129,37.550339],zoom:5,mapStyle:{},roam:!1}}),e.extendComponentView({type:"bmap",render:function(t,e,o){function n(){i||o.dispatchAction({type:"bmapRoam"})}var i=!0,a=t.getBMap(),r=o.getZr().painter.getViewportRoot(),p=t.coordinateSystem,s=function(e,n){if(!i){var a=r.parentNode.parentNode.parentNode,s=[-parseInt(a.style.left,10)||0,-parseInt(a.style.top,10)||0];r.style.left=s[0]+"px",r.style.top=s[1]+"px",p.setMapOffset(s),t.__mapOffset=s,o.dispatchAction({type:"bmapRoam"})}};a.removeEventListener("moving",this._oldMoveHandler),a.removeEventListener("zoomend",this._oldZoomEndHandler),a.addEventListener("moving",s),a.addEventListener("zoomend",n),this._oldMoveHandler=s,this._oldZoomEndHandler=n;var m=t.get("roam");m&&"scale"!==m?a.enableDragging():a.disableDragging(),m&&"move"!==m?(a.enableScrollWheelZoom(),a.enableDoubleClickZoom(),a.enablePinchToZoom()):(a.disableScrollWheelZoom(),a.disableDoubleClickZoom(),a.disablePinchToZoom());var c=t.__mapStyle,d=t.get("mapStyle")||{},f=JSON.stringify(d);JSON.stringify(c)!==f&&(Object.keys(d).length&&a.setMapStyle(d),t.__mapStyle=JSON.parse(f)),i=!1}}),e.registerCoordinateSystem("bmap",o),e.registerAction({type:"bmapRoam",event:"bmapRoam",update:"updateLayout"},function(t,e){e.eachComponent("bmap",function(t){var e=t.getBMap(),o=e.getCenter();t.setCenterAndZoom([o.lng,o.lat],e.getZoom())})});t.version="1.0.0"});
|
||||
@@ -0,0 +1,851 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('echarts')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'echarts'], factory) :
|
||||
(factory((global.dataTool = {}),global.echarts));
|
||||
}(this, (function (exports,echarts) { 'use strict';
|
||||
|
||||
/**
|
||||
* @module zrender/core/util
|
||||
*/
|
||||
|
||||
// 用于处理merge时无法遍历Date等对象的问题
|
||||
var arrayProto = Array.prototype;
|
||||
var nativeMap = arrayProto.map;
|
||||
|
||||
|
||||
/**
|
||||
* Those data types can be cloned:
|
||||
* Plain object, Array, TypedArray, number, string, null, undefined.
|
||||
* Those data types will be assgined using the orginal data:
|
||||
* BUILTIN_OBJECT
|
||||
* Instance of user defined class will be cloned to a plain object, without
|
||||
* properties in prototype.
|
||||
* Other data types is not supported (not sure what will happen).
|
||||
*
|
||||
* Caution: do not support clone Date, for performance consideration.
|
||||
* (There might be a large number of date in `series.data`).
|
||||
* So date should not be modified in and out of echarts.
|
||||
*
|
||||
* @param {*} source
|
||||
* @return {*} new
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} target
|
||||
* @param {*} source
|
||||
* @param {boolean} [overwrite=false]
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array} targetAndSources The first item is target, and the rests are source.
|
||||
* @param {boolean} [overwrite=false]
|
||||
* @return {*} target
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} target
|
||||
* @param {*} source
|
||||
* @memberOf module:zrender/core/util
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} target
|
||||
* @param {*} source
|
||||
* @param {boolean} [overlay=false]
|
||||
* @memberOf module:zrender/core/util
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询数组中元素的index
|
||||
* @memberOf module:zrender/core/util
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 构造类继承关系
|
||||
*
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Function} clazz 源类
|
||||
* @param {Function} baseClazz 基类
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Object|Function} target
|
||||
* @param {Object|Function} sorce
|
||||
* @param {boolean} overlay
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Consider typed array.
|
||||
* @param {Array|TypedArray} data
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 数组或对象遍历
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Object|Array} obj
|
||||
* @param {Function} cb
|
||||
* @param {*} [context]
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 数组映射
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Array} obj
|
||||
* @param {Function} cb
|
||||
* @param {*} [context]
|
||||
* @return {Array}
|
||||
*/
|
||||
function map(obj, cb, context) {
|
||||
if (!(obj && cb)) {
|
||||
return;
|
||||
}
|
||||
if (obj.map && obj.map === nativeMap) {
|
||||
return obj.map(cb, context);
|
||||
}
|
||||
else {
|
||||
var result = [];
|
||||
for (var i = 0, len = obj.length; i < len; i++) {
|
||||
result.push(cb.call(context, obj[i], i, obj));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Array} obj
|
||||
* @param {Function} cb
|
||||
* @param {Object} [memo]
|
||||
* @param {*} [context]
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 数组过滤
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Array} obj
|
||||
* @param {Function} cb
|
||||
* @param {*} [context]
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 数组项查找
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Array} obj
|
||||
* @param {Function} cb
|
||||
* @param {*} [context]
|
||||
* @return {*}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Function} func
|
||||
* @param {*} context
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Function} func
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Whether is exactly NaN. Notice isNaN('a') returns true.
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* If value1 is not null, then return value1, otherwise judget rest of values.
|
||||
* Low performance.
|
||||
* @memberOf module:zrender/core/util
|
||||
* @return {*} Final value
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {Array} arr
|
||||
* @param {number} startIndex
|
||||
* @param {number} endIndex
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Normalize css liked array configuration
|
||||
* e.g.
|
||||
* 3 => [3, 3, 3, 3]
|
||||
* [4, 2] => [4, 2, 4, 2]
|
||||
* [4, 3, 2] => [4, 3, 2, 3]
|
||||
* @param {number|Array.<number>} val
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {boolean} condition
|
||||
* @param {string} message
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf module:zrender/core/util
|
||||
* @param {string} str string to be trimed
|
||||
* @return {string} trimed string
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Set an object as primitive to be ignored traversing children in clone or merge
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// GEXF File Parser
|
||||
// http://gexf.net/1.2draft/gexf-12draft-primer.pdf
|
||||
|
||||
function parse(xml) {
|
||||
var doc;
|
||||
if (typeof xml === 'string') {
|
||||
var parser = new DOMParser();
|
||||
doc = parser.parseFromString(xml, 'text/xml');
|
||||
}
|
||||
else {
|
||||
doc = xml;
|
||||
}
|
||||
if (!doc || doc.getElementsByTagName('parsererror').length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var gexfRoot = getChildByTagName(doc, 'gexf');
|
||||
|
||||
if (!gexfRoot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var graphRoot = getChildByTagName(gexfRoot, 'graph');
|
||||
|
||||
var attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes'));
|
||||
var attributesMap = {};
|
||||
for (var i = 0; i < attributes.length; i++) {
|
||||
attributesMap[attributes[i].id] = attributes[i];
|
||||
}
|
||||
|
||||
return {
|
||||
nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap),
|
||||
links: parseEdges(getChildByTagName(graphRoot, 'edges'))
|
||||
};
|
||||
}
|
||||
|
||||
function parseAttributes(parent) {
|
||||
return parent ? map(getChildrenByTagName(parent, 'attribute'), function (attribDom) {
|
||||
return {
|
||||
id: getAttr(attribDom, 'id'),
|
||||
title: getAttr(attribDom, 'title'),
|
||||
type: getAttr(attribDom, 'type')
|
||||
};
|
||||
}) : [];
|
||||
}
|
||||
|
||||
function parseNodes(parent, attributesMap) {
|
||||
return parent ? map(getChildrenByTagName(parent, 'node'), function (nodeDom) {
|
||||
|
||||
var id = getAttr(nodeDom, 'id');
|
||||
var label = getAttr(nodeDom, 'label');
|
||||
|
||||
var node = {
|
||||
id: id,
|
||||
name: label,
|
||||
itemStyle: {
|
||||
normal: {}
|
||||
}
|
||||
};
|
||||
|
||||
var vizSizeDom = getChildByTagName(nodeDom, 'viz:size');
|
||||
var vizPosDom = getChildByTagName(nodeDom, 'viz:position');
|
||||
var vizColorDom = getChildByTagName(nodeDom, 'viz:color');
|
||||
// var vizShapeDom = getChildByTagName(nodeDom, 'viz:shape');
|
||||
|
||||
var attvaluesDom = getChildByTagName(nodeDom, 'attvalues');
|
||||
|
||||
if (vizSizeDom) {
|
||||
node.symbolSize = parseFloat(getAttr(vizSizeDom, 'value'));
|
||||
}
|
||||
if (vizPosDom) {
|
||||
node.x = parseFloat(getAttr(vizPosDom, 'x'));
|
||||
node.y = parseFloat(getAttr(vizPosDom, 'y'));
|
||||
// z
|
||||
}
|
||||
if (vizColorDom) {
|
||||
node.itemStyle.normal.color = 'rgb(' +[
|
||||
getAttr(vizColorDom, 'r') | 0,
|
||||
getAttr(vizColorDom, 'g') | 0,
|
||||
getAttr(vizColorDom, 'b') | 0
|
||||
].join(',') + ')';
|
||||
}
|
||||
// if (vizShapeDom) {
|
||||
// node.shape = getAttr(vizShapeDom, 'shape');
|
||||
// }
|
||||
if (attvaluesDom) {
|
||||
var attvalueDomList = getChildrenByTagName(attvaluesDom, 'attvalue');
|
||||
|
||||
node.attributes = {};
|
||||
|
||||
for (var j = 0; j < attvalueDomList.length; j++) {
|
||||
var attvalueDom = attvalueDomList[j];
|
||||
var attId = getAttr(attvalueDom, 'for');
|
||||
var attValue = getAttr(attvalueDom, 'value');
|
||||
var attribute = attributesMap[attId];
|
||||
|
||||
if (attribute) {
|
||||
switch (attribute.type) {
|
||||
case 'integer':
|
||||
case 'long':
|
||||
attValue = parseInt(attValue, 10);
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
attValue = parseFloat(attValue);
|
||||
break;
|
||||
case 'boolean':
|
||||
attValue = attValue.toLowerCase() == 'true';
|
||||
break;
|
||||
default:
|
||||
}
|
||||
node.attributes[attId] = attValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}) : [];
|
||||
}
|
||||
|
||||
function parseEdges(parent) {
|
||||
return parent ? map(getChildrenByTagName(parent, 'edge'), function (edgeDom) {
|
||||
var id = getAttr(edgeDom, 'id');
|
||||
var label = getAttr(edgeDom, 'label');
|
||||
|
||||
var sourceId = getAttr(edgeDom, 'source');
|
||||
var targetId = getAttr(edgeDom, 'target');
|
||||
|
||||
var edge = {
|
||||
id: id,
|
||||
name: label,
|
||||
source: sourceId,
|
||||
target: targetId,
|
||||
lineStyle: {
|
||||
normal: {}
|
||||
}
|
||||
};
|
||||
|
||||
var lineStyle = edge.lineStyle.normal;
|
||||
|
||||
var vizThicknessDom = getChildByTagName(edgeDom, 'viz:thickness');
|
||||
var vizColorDom = getChildByTagName(edgeDom, 'viz:color');
|
||||
// var vizShapeDom = getChildByTagName(edgeDom, 'viz:shape');
|
||||
|
||||
if (vizThicknessDom) {
|
||||
lineStyle.width = parseFloat(vizThicknessDom.getAttribute('value'));
|
||||
}
|
||||
if (vizColorDom) {
|
||||
lineStyle.color = 'rgb(' + [
|
||||
getAttr(vizColorDom, 'r') | 0,
|
||||
getAttr(vizColorDom, 'g') | 0,
|
||||
getAttr(vizColorDom, 'b') | 0
|
||||
].join(',') + ')';
|
||||
}
|
||||
// if (vizShapeDom) {
|
||||
// edge.shape = vizShapeDom.getAttribute('shape');
|
||||
// }
|
||||
|
||||
return edge;
|
||||
}) : [];
|
||||
}
|
||||
|
||||
function getAttr(el, attrName) {
|
||||
return el.getAttribute(attrName);
|
||||
}
|
||||
|
||||
function getChildByTagName (parent, tagName) {
|
||||
var node = parent.firstChild;
|
||||
|
||||
while (node) {
|
||||
if (
|
||||
node.nodeType != 1 ||
|
||||
node.nodeName.toLowerCase() != tagName.toLowerCase()
|
||||
) {
|
||||
node = node.nextSibling;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getChildrenByTagName (parent, tagName) {
|
||||
var node = parent.firstChild;
|
||||
var children = [];
|
||||
while (node) {
|
||||
if (node.nodeName.toLowerCase() == tagName.toLowerCase()) {
|
||||
children.push(node);
|
||||
}
|
||||
node = node.nextSibling;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
var gexf = (Object.freeze || Object)({
|
||||
parse: parse
|
||||
});
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* A third-party license is embeded for some of the code in this file:
|
||||
* The method "quantile" was copied from "d3.js".
|
||||
* (See more details in the comment of the method below.)
|
||||
* The use of the source code of this file is also subject to the terms
|
||||
* and consitions of the license of "d3.js" (BSD-3Clause, see
|
||||
* </licenses/LICENSE-d3>).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Linear mapping a value from domain to range
|
||||
* @memberOf module:echarts/util/number
|
||||
* @param {(number|Array.<number>)} val
|
||||
* @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
|
||||
* @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
|
||||
* @param {boolean} clamp
|
||||
* @return {(number|Array.<number>}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Convert a percent string to absolute number.
|
||||
* Returns NaN if percent is not a valid string or number
|
||||
* @memberOf module:echarts/util/number
|
||||
* @param {string|number} percent
|
||||
* @param {number} all
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* (1) Fix rounding error of float numbers.
|
||||
* (2) Support return string to avoid scientific notation like '3.5e-7'.
|
||||
*
|
||||
* @param {number} x
|
||||
* @param {number} [precision]
|
||||
* @param {boolean} [returnStr]
|
||||
* @return {number|string}
|
||||
*/
|
||||
|
||||
|
||||
function asc(arr) {
|
||||
arr.sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get precision
|
||||
* @param {number} val
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|number} val
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Minimal dicernible data precisioin according to a single pixel.
|
||||
*
|
||||
* @param {Array.<number>} dataExtent
|
||||
* @param {Array.<number>} pixelExtent
|
||||
* @return {number} precision
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Get a data of given precision, assuring the sum of percentages
|
||||
* in valueList is 1.
|
||||
* The largest remainer method is used.
|
||||
* https://en.wikipedia.org/wiki/Largest_remainder_method
|
||||
*
|
||||
* @param {Array.<number>} valueList a list of all data
|
||||
* @param {number} idx index of the data to be processed in valueList
|
||||
* @param {number} precision integer number showing digits of precision
|
||||
* @return {number} percent ranging from 0 to 100
|
||||
*/
|
||||
|
||||
|
||||
// Number.MAX_SAFE_INTEGER, ie do not support.
|
||||
|
||||
|
||||
/**
|
||||
* To 0 - 2 * PI, considering negative radian.
|
||||
* @param {number} radian
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {type} radian
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
/* eslint-enable */
|
||||
|
||||
/**
|
||||
* @param {string|Date|number} value These values can be accepted:
|
||||
* + An instance of Date, represent a time in its own time zone.
|
||||
* + Or string in a subset of ISO 8601, only including:
|
||||
* + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
|
||||
* + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
|
||||
* + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
|
||||
* all of which will be treated as local time if time zone is not specified
|
||||
* (see <https://momentjs.com/>).
|
||||
* + Or other string format, including (all of which will be treated as loacal time):
|
||||
* '2012', '2012-3-1', '2012/3/1', '2012/03/01',
|
||||
* '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
|
||||
* + a timestamp, which represent a time in UTC.
|
||||
* @return {Date} date
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Quantity of a number. e.g. 0.1, 1, 10, 100
|
||||
*
|
||||
* @param {number} val
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* find a “nice” number approximately equal to x. Round the number if round = true,
|
||||
* take ceiling if round = false. The primary observation is that the “nicest”
|
||||
* numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
|
||||
*
|
||||
* See "Nice Numbers for Graph Labels" of Graphic Gems.
|
||||
*
|
||||
* @param {number} val Non-negative value.
|
||||
* @param {boolean} round
|
||||
* @return {number}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This code was copied from "d3.js"
|
||||
* <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
|
||||
* See the license statement at the head of this file.
|
||||
* @param {Array.<number>} ascArr
|
||||
*/
|
||||
function quantile(ascArr, p) {
|
||||
var H = (ascArr.length - 1) * p + 1;
|
||||
var h = Math.floor(H);
|
||||
var v = +ascArr[h - 1];
|
||||
var e = H - h;
|
||||
return e ? v + e * (ascArr[h] - v) : v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order intervals asc, and split them when overlap.
|
||||
* expect(numberUtil.reformIntervals([
|
||||
* {interval: [18, 62], close: [1, 1]},
|
||||
* {interval: [-Infinity, -70], close: [0, 0]},
|
||||
* {interval: [-70, -26], close: [1, 1]},
|
||||
* {interval: [-26, 18], close: [1, 1]},
|
||||
* {interval: [62, 150], close: [1, 1]},
|
||||
* {interval: [106, 150], close: [1, 1]},
|
||||
* {interval: [150, Infinity], close: [0, 0]}
|
||||
* ])).toEqual([
|
||||
* {interval: [-Infinity, -70], close: [0, 0]},
|
||||
* {interval: [-70, -26], close: [1, 1]},
|
||||
* {interval: [-26, 18], close: [0, 1]},
|
||||
* {interval: [18, 62], close: [0, 1]},
|
||||
* {interval: [62, 150], close: [0, 1]},
|
||||
* {interval: [150, Infinity], close: [0, 0]}
|
||||
* ]);
|
||||
* @param {Array.<Object>} list, where `close` mean open or close
|
||||
* of the interval, and Infinity can be used.
|
||||
* @return {Array.<Object>} The origin list, which has been reformed.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* parseFloat NaNs numeric-cast false positives (null|true|false|"")
|
||||
* ...but misinterprets leading-number strings, particularly hex literals ("0x...")
|
||||
* subtraction forces infinities to NaN
|
||||
*
|
||||
* @param {*} v
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* See:
|
||||
* <https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
|
||||
* <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
|
||||
*
|
||||
* Helper method for preparing data.
|
||||
*
|
||||
* @param {Array.<number>} rawData like
|
||||
* [
|
||||
* [12,232,443], (raw data set for the first box)
|
||||
* [3843,5545,1232], (raw datat set for the second box)
|
||||
* ...
|
||||
* ]
|
||||
* @param {Object} [opt]
|
||||
*
|
||||
* @param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
|
||||
* default 1.5, means Q1 - 1.5 * (Q3 - Q1).
|
||||
* If 'none'/0 passed, min bound will not be used.
|
||||
* @param {(number|string)} [opt.layout='horizontal']
|
||||
* Box plot layout, can be 'horizontal' or 'vertical'
|
||||
* @return {Object} {
|
||||
* boxData: Array.<Array.<number>>
|
||||
* outliers: Array.<Array.<number>>
|
||||
* axisData: Array.<string>
|
||||
* }
|
||||
*/
|
||||
var prepareBoxplotData = function (rawData, opt) {
|
||||
opt = opt || [];
|
||||
var boxData = [];
|
||||
var outliers = [];
|
||||
var axisData = [];
|
||||
var boundIQR = opt.boundIQR;
|
||||
var useExtreme = boundIQR === 'none' || boundIQR === 0;
|
||||
|
||||
for (var i = 0; i < rawData.length; i++) {
|
||||
axisData.push(i + '');
|
||||
var ascList = asc(rawData[i].slice());
|
||||
|
||||
var Q1 = quantile(ascList, 0.25);
|
||||
var Q2 = quantile(ascList, 0.5);
|
||||
var Q3 = quantile(ascList, 0.75);
|
||||
var min = ascList[0];
|
||||
var max = ascList[ascList.length - 1];
|
||||
|
||||
var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
|
||||
|
||||
var low = useExtreme
|
||||
? min
|
||||
: Math.max(min, Q1 - bound);
|
||||
var high = useExtreme
|
||||
? max
|
||||
: Math.min(max, Q3 + bound);
|
||||
|
||||
boxData.push([low, Q1, Q2, Q3, high]);
|
||||
|
||||
for (var j = 0; j < ascList.length; j++) {
|
||||
var dataItem = ascList[j];
|
||||
if (dataItem < low || dataItem > high) {
|
||||
var outlier = [i, dataItem];
|
||||
opt.layout === 'vertical' && outlier.reverse();
|
||||
outliers.push(outlier);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
boxData: boxData,
|
||||
outliers: outliers,
|
||||
axisData: axisData
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var version = '1.0.0';
|
||||
|
||||
// For backward compatibility, where the namespace `dataTool` will
|
||||
// be mounted on `echarts` is the extension `dataTool` is imported.
|
||||
// But the old version of echarts do not have `dataTool` namespace,
|
||||
// so check it before mounting.
|
||||
if (echarts.dataTool) {
|
||||
echarts.dataTool.version = version;
|
||||
echarts.dataTool.gexf = gexf;
|
||||
echarts.dataTool.prepareBoxplotData = prepareBoxplotData;
|
||||
}
|
||||
|
||||
exports.version = version;
|
||||
exports.gexf = gexf;
|
||||
exports.prepareBoxplotData = prepareBoxplotData;
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=dataTool.js.map
|
||||
File diff suppressed because one or more lines are too long
22
source/vue/xzs-admin/public/admin/components/echarts/extension/dataTool.min.js
vendored
Normal file
22
source/vue/xzs-admin/public/admin/components/echarts/extension/dataTool.min.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("echarts")):"function"==typeof define&&define.amd?define(["exports","echarts"],t):t(e.dataTool={},e.echarts)}(this,function(e,t){"use strict";function r(e,t,r){if(e&&t){if(e.map&&e.map===c)return e.map(t,r);for(var a=[],n=0,o=e.length;n<o;n++)a.push(t.call(r,e[n],n,e));return a}}function a(e){return e?r(u(e,"attribute"),function(e){return{id:i(e,"id"),title:i(e,"title"),type:i(e,"type")}}):[]}function n(e,t){return e?r(u(e,"node"),function(e){var r={id:i(e,"id"),name:i(e,"label"),itemStyle:{normal:{}}},a=l(e,"viz:size"),n=l(e,"viz:position"),o=l(e,"viz:color"),s=l(e,"attvalues");if(a&&(r.symbolSize=parseFloat(i(a,"value"))),n&&(r.x=parseFloat(i(n,"x")),r.y=parseFloat(i(n,"y"))),o&&(r.itemStyle.normal.color="rgb("+[0|i(o,"r"),0|i(o,"g"),0|i(o,"b")].join(",")+")"),s){var f=u(s,"attvalue");r.attributes={};for(var c=0;c<f.length;c++){var p=f[c],d=i(p,"for"),v=i(p,"value"),g=t[d];if(g){switch(g.type){case"integer":case"long":v=parseInt(v,10);break;case"float":case"double":v=parseFloat(v);break;case"boolean":v="true"==v.toLowerCase()}r.attributes[d]=v}}}return r}):[]}function o(e){return e?r(u(e,"edge"),function(e){var t={id:i(e,"id"),name:i(e,"label"),source:i(e,"source"),target:i(e,"target"),lineStyle:{normal:{}}},r=t.lineStyle.normal,a=l(e,"viz:thickness"),n=l(e,"viz:color");return a&&(r.width=parseFloat(a.getAttribute("value"))),n&&(r.color="rgb("+[0|i(n,"r"),0|i(n,"g"),0|i(n,"b")].join(",")+")"),t}):[]}function i(e,t){return e.getAttribute(t)}function l(e,t){for(var r=e.firstChild;r;){if(1==r.nodeType&&r.nodeName.toLowerCase()==t.toLowerCase())return r;r=r.nextSibling}return null}function u(e,t){for(var r=e.firstChild,a=[];r;)r.nodeName.toLowerCase()==t.toLowerCase()&&a.push(r),r=r.nextSibling;return a}function s(e){return e.sort(function(e,t){return e-t}),e}function f(e,t){var r=(e.length-1)*t+1,a=Math.floor(r),n=+e[a-1],o=r-a;return o?n+o*(e[a]-n):n}var c=Array.prototype.map,p=(Object.freeze||Object)({parse:function(e){var t;if(!(t="string"==typeof e?(new DOMParser).parseFromString(e,"text/xml"):e)||t.getElementsByTagName("parsererror").length)return null;var r=l(t,"gexf");if(!r)return null;for(var i=l(r,"graph"),u=a(l(i,"attributes")),s={},f=0;f<u.length;f++)s[u[f].id]=u[f];return{nodes:n(l(i,"nodes"),s),links:o(l(i,"edges"))}}}),d=function(e,t){for(var r=[],a=[],n=[],o=(t=t||[]).boundIQR,i="none"===o||0===o,l=0;l<e.length;l++){n.push(l+"");var u=s(e[l].slice()),c=f(u,.25),p=f(u,.5),d=f(u,.75),v=u[0],g=u[u.length-1],h=(null==o?1.5:o)*(d-c),b=i?v:Math.max(v,c-h),m=i?g:Math.min(g,d+h);r.push([b,c,p,d,m]);for(var y=0;y<u.length;y++){var x=u[y];if(x<b||x>m){var w=[l,x];"vertical"===t.layout&&w.reverse(),a.push(w)}}}return{boxData:r,outliers:a,axisData:n}};t.dataTool&&(t.dataTool.version="1.0.0",t.dataTool.gexf=p,t.dataTool.prepareBoxplotData=d),e.version="1.0.0",e.gexf=p,e.prepareBoxplotData=d});
|
||||
Reference in New Issue
Block a user