From 607fb54a616e5d25b89bfe4460f1e8c82370d330 Mon Sep 17 00:00:00 2001 From: XD-DENG Date: Sat, 23 Jul 2016 16:04:57 +0800 Subject: [PATCH] Use compressed version of word cloud extension in order to minimise the size of JS library file --- inst/echarts.js | 3535 +---------------------------------------------- 1 file changed, 1 insertion(+), 3534 deletions(-) diff --git a/inst/echarts.js b/inst/echarts.js index 45b37f7..f38e472 100644 --- a/inst/echarts.js +++ b/inst/echarts.js @@ -35,3537 +35,4 @@ i.handleLabels=[],i.handleLabelPoints=[],this._createHandle(l,0,r,c,o,s),this._c axisLine:{show:!0,lineStyle:{width:2,type:"solid"}},axisTick:{show:!0,length:6,lineStyle:{width:2}},axisLabel:{show:!0,interval:"auto"},splitLine:{show:!0,lineStyle:{type:"dashed",opacity:.2}}};a.merge(s.prototype,i(51)),o("single",s,n,l),t.exports=s},function(t,e,i){function n(t,e,i){this.dimension="x",this.dimensions=["x"],this._axis=null,this._rect,this._init(t,e,i),this._model=t}var r=i(375),o=i(22),a=i(13);n.prototype={type:"singleAxis",constructor:n,_init:function(t,e,i){var n=this.dimension,a=new r(n,o.createScaleByModel(t),[0,0],t.get("type"),t.get("position")),s="category"===a.type;a.onBand=s&&t.get("boundaryGap"),a.inverse=t.get("inverse"),a.orient=t.get("orient"),t.axis=a,a.model=t,this._axis=a},update:function(t,e){this._updateAxisFromSeries(t)},_updateAxisFromSeries:function(t){t.eachSeries(function(t){var e=t.getData(),i=this.dimension;this._axis.scale.unionExtent(e.getDataExtent(t.coordDimToDataDim(i))),o.niceScaleExtent(this._axis,this._axis.model)},this)},resize:function(t,e){this._rect=a.getLayoutRect({left:t.get("left"),top:t.get("top"),right:t.get("right"),bottom:t.get("bottom"),width:t.get("width"),height:t.get("height")},{width:e.getWidth(),height:e.getHeight()}),this._adjustAxis()},getRect:function(){return this._rect},_adjustAxis:function(){var t=this._rect,e=this._axis,i=e.isHorizontal(),n=i?[0,t.width]:[0,t.height],r=e.reverse?1:0;e.setExtent(n[r],n[1-r]),this._updateAxisTransform(e,i?t.x:t.y)},_updateAxisTransform:function(t,e){var i=t.getExtent(),n=i[0]+i[1],r=t.isHorizontal();t.toGlobalCoord=r?function(t){return t+e}:function(t){return n-t+e},t.toLocalCoord=r?function(t){return t-e}:function(t){return n-t+e}},getAxis:function(){return this._axis},getBaseAxis:function(){return this._axis},containPoint:function(t){var e=this.getRect(),i=this.getAxis(),n=i.orient;return"horizontal"===n?i.contain(i.toLocalCoord(t[0]))&&t[1]>=e.y&&t[1]<=e.y+e.height:i.contain(i.toLocalCoord(t[1]))&&t[0]>=e.y&&t[0]<=e.y+e.height},pointToData:function(t){var e=this.getAxis();return[e.coordToData(e.toLocalCoord(t["horizontal"===e.orient?0:1]))]},dataToPoint:function(t){var e=this.getAxis(),i=this.getRect(),n=[],r="horizontal"===e.orient?0:1;return n[r]=e.toGlobalCoord(e.dataToCoord(+t)),n[1-r]=0===r?i.y+i.height/2:i.x+i.width/2,n}},t.exports=n},function(t,e,i){var n=i(1),r=i(42),o=i(22),a=function(t,e,i,n,o){r.call(this,t,e,i),this.type=n||"value",this.position=o||"bottom",this.orient=null,this._labelInterval=null};a.prototype={constructor:a,model:null,isHorizontal:function(){var t=this.position;return"top"===t||"bottom"===t},getLabelInterval:function(){var t=this._labelInterval;if(!t){var e=this.model,i=e.getModel("axisLabel"),r=i.get("interval");if("category"!==this.type||"auto"!==r)return t=this._labelInterval="auto"===r?0:r;t=this._labelInterval=o.getAxisLabelInterval(n.map(this.scale.getTicks(),this.dataToCoord,this),e.getFormattedLabels(),i.getModel("textStyle").getFont(),this.isHorizontal())}return t},toGlobalCoord:null,toLocalCoord:null},n.inherits(a,r),t.exports=a},function(t,e,i){function n(t,e){var i=[];return t.eachComponent("singleAxis",function(n,o){var a=new r(n,t,e);a.name="single_"+o,a.resize(n,e),n.coordinateSystem=a,i.push(a)}),t.eachSeries(function(e){if("singleAxis"===e.get("coordinateSystem")){var i=e.get("singleAxisIndex")||0,n=t.getComponent("singleAxis",i);e.coordinateSystem=n.coordinateSystem}}),i}var r=i(374);i(23).register("single",{create:n,dimensions:r.prototype.dimensions})},function(t,e,i){"use strict";function n(t,e){this.id=null==t?"":t,this.inEdges=[],this.outEdges=[],this.edges=[],this.hostGraph,this.dataIndex=null==e?-1:e}function r(t,e,i){this.node1=t,this.node2=e,this.dataIndex=null==i?-1:i}var o=i(1),a=function(t){this._directed=t||!1,this.nodes=[],this.edges=[],this._nodesMap={},this._edgesMap={},this.data,this.edgeData},s=a.prototype;s.type="graph",s.isDirected=function(){return this._directed},s.addNode=function(t,e){t=t||""+e;var i=this._nodesMap;if(!i[t]){var r=new n(t,e);return r.hostGraph=this,this.nodes.push(r),i[t]=r,r}},s.getNodeByIndex=function(t){var e=this.data.getRawIndex(t);return this.nodes[e]},s.getNodeById=function(t){return this._nodesMap[t]},s.addEdge=function(t,e,i){var o=this._nodesMap,a=this._edgesMap;if("number"==typeof t&&(t=this.nodes[t]),"number"==typeof e&&(e=this.nodes[e]),t instanceof n||(t=o[t]),e instanceof n||(e=o[e]),t&&e){var s=t.id+"-"+e.id;if(!a[s]){var l=new r(t,e,i);return l.hostGraph=this,this._directed&&(t.outEdges.push(l),e.inEdges.push(l)),t.edges.push(l),t!==e&&e.edges.push(l),this.edges.push(l),a[s]=l,l}}},s.getEdgeByIndex=function(t){var e=this.edgeData.getRawIndex(t);return this.edges[e]},s.getEdge=function(t,e){t instanceof n&&(t=t.id),e instanceof n&&(e=e.id);var i=this._edgesMap;return this._directed?i[t+"-"+e]:i[t+"-"+e]||i[e+"-"+t]},s.eachNode=function(t,e){for(var i=this.nodes,n=i.length,r=0;n>r;r++)i[r].dataIndex>=0&&t.call(e,i[r],r)},s.eachEdge=function(t,e){for(var i=this.edges,n=i.length,r=0;n>r;r++)i[r].dataIndex>=0&&i[r].node1.dataIndex>=0&&i[r].node2.dataIndex>=0&&t.call(e,i[r],r)},s.breadthFirstTraverse=function(t,e,i,r){if(e instanceof n||(e=this._nodesMap[e]),e){for(var o="out"===i?"outEdges":"in"===i?"inEdges":"edges",a=0;ar;r++)i[r].dataIndex=-1;for(var r=0,o=t.count();o>r;r++)i[t.getRawIndex(r)].dataIndex=r;e.filterSelf(function(t){var i=n[e.getRawIndex(t)];return i.node1.dataIndex>=0&&i.node2.dataIndex>=0});for(var r=0,o=n.length;o>r;r++)n[r].dataIndex=-1;for(var r=0,o=e.count();o>r;r++)n[e.getRawIndex(r)].dataIndex=r},s.clone=function(){for(var t=new a(this._directed),e=this.nodes,i=this.edges,n=0;n=0&&this[t][e].setItemVisual(this.dataIndex,i,n)},getVisual:function(i,n){return this[t][e].getItemVisual(this.dataIndex,i,n)},setLayout:function(i,n){this.dataIndex>=0&&this[t][e].setItemLayout(this.dataIndex,i,n)},getLayout:function(){return this[t][e].getItemLayout(this.dataIndex)},getGraphicEl:function(){return this[t][e].getItemGraphicEl(this.dataIndex)},getRawIndex:function(){return this[t][e].getRawIndex(this.dataIndex)}}};o.mixin(n,l("hostGraph","data")),o.mixin(r,l("hostGraph","edgeData")),a.Node=n,a.Edge=r,t.exports=a},function(t,e,i){function n(t,e){this.root,this.data,this._nodes=[],this.hostModel=t,this.levelModels=o.map(e||[],function(e){return new a(e,t,t.ecModel)})}function r(t,e){var i=e.children;t.parentNode!==e&&(i.push(t),t.parentNode=e)}var o=i(1),a=i(8),s=i(14),l=i(239),u=i(30),h=function(t,e){this.name=t||"",this.depth=0,this.height=0,this.parentNode=null,this.dataIndex=-1,this.children=[],this.viewChildren=[],this.hostTree=e};h.prototype={constructor:h,isRemoved:function(){return this.dataIndex<0},eachNode:function(t,e,i){"function"==typeof t&&(i=e,e=t,t=null),t=t||{},o.isString(t)&&(t={order:t});var n,r=t.order||"preorder",a=this[t.attr||"children"];"preorder"===r&&(n=e.call(i,this));for(var s=0;!n&&se&&(e=n.height)}this.height=e+1},getNodeById:function(t){if(this.getId()===t)return this;for(var e=0,i=this.children,n=i.length;n>e;e++){var r=i[e].getNodeById(t);if(r)return r}},contains:function(t){if(t===this)return!0;for(var e=0,i=this.children,n=i.length;n>e;e++){var r=i[e].contains(t);if(r)return r}},getAncestors:function(t){for(var e=[],i=t?this:this.parentNode;i;)e.push(i),i=i.parentNode;return e.reverse(),e},getValue:function(t){var e=this.hostTree.data;return e.get(e.getDimension(t||"value"),this.dataIndex)},setLayout:function(t,e){this.dataIndex>=0&&this.hostTree.data.setItemLayout(this.dataIndex,t,e)},getLayout:function(){return this.hostTree.data.getItemLayout(this.dataIndex)},getModel:function(t){if(!(this.dataIndex<0)){var e=this.hostTree,i=e.data.getItemModel(this.dataIndex),n=this.getLevelModel();return i.getModel(t,(n||e.hostModel).getModel(t))}},getLevelModel:function(){return(this.hostTree.levelModels||[])[this.depth]},setVisual:function(t,e){this.dataIndex>=0&&this.hostTree.data.setItemVisual(this.dataIndex,t,e)},getVisual:function(t,e){return this.hostTree.data.getItemVisual(this.dataIndex,t,e)},getRawIndex:function(){return this.hostTree.data.getRawIndex(this.dataIndex)},getId:function(){return this.hostTree.data.getId(this.dataIndex)}},n.prototype={constructor:n,type:"tree",eachNode:function(t,e,i){this.root.eachNode(t,e,i)},getNodeByDataIndex:function(t){var e=this.data.getRawIndex(t);return this._nodes[e]},getNodeByName:function(t){return this.root.getNodeByName(t)},update:function(){for(var t=this.data,e=this._nodes,i=0,n=e.length;n>i;i++)e[i].dataIndex=-1;for(var i=0,n=t.count();n>i;i++)e[t.getRawIndex(i)].dataIndex=i},clearLayouts:function(){this.data.clearItemLayouts()}},n.createTree=function(t,e,i){function o(t,e){c.push(t);var i=new h(t.name,a);e?r(i,e):a.root=i,a._nodes.push(i);var n=t.children;if(n)for(var s=0;so;o++){var s=e[o];s.el.animateTo(s.target,s.time,s.delay,s.easing,n)}return this}}}var r=i(1);t.exports={createWrap:n}},function(t,e,i){function n(){function t(e,n){if(n>=i.length)return e;for(var o=-1,a=e.length,s=i[n++],l={},u={};++o=i.length)return t;var a=[],s=n[o++];return r.each(t,function(t,i){a.push({key:i,values:e(t,o)})}),s?a.sort(function(t,e){return s(t.key,e.key)}):a}var i=[],n=[];return{key:function(t){return i.push(t),this},sortKeys:function(t){return n[i.length-1]=t,this},entries:function(i){return e(t(i,0),0)}}}var r=i(1);t.exports=n},function(t,e,i){var n=i(1),r={get:function(t,e,i){var r=n.clone((o[t]||{})[e]);return i&&n.isArray(r)?r[r.length-1]:r}},o={color:{active:["#006edd","#e0ffff"],inactive:["rgba(0,0,0,0)"]},colorHue:{active:[0,360],inactive:[0,0]},colorSaturation:{active:[.3,1],inactive:[0,0]},colorLightness:{active:[.9,.5],inactive:[0,0]},colorAlpha:{active:[.3,1],inactive:[0,0]},opacity:{active:[.3,1],inactive:[0,0]},symbol:{active:["circle","roundRect","diamond"],inactive:["none"]},symbolSize:{active:[10,50],inactive:[0,0]}};t.exports=r}])}); - -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(require("echarts")); - else if(typeof define === 'function' && define.amd) - define(["echarts"], factory); - else if(typeof exports === 'object') - exports["echarts-wordcloud"] = factory(require("echarts")); - else - root["echarts-wordcloud"] = factory(root["echarts"]); -})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = __webpack_require__(1); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - var echarts = __webpack_require__(2); - var layoutUtil = __webpack_require__(3); - - __webpack_require__(11); - __webpack_require__(13); - - var wordCloudLayoutHelper = __webpack_require__(14); - - if (!wordCloudLayoutHelper.isSupported) { - throw new Error('Sorry your browser not support wordCloud'); - } - - // https://github.com/timdream/wordcloud2.js/blob/c236bee60436e048949f9becc4f0f67bd832dc5c/index.js#L233 - function updateCanvasMask(maskCanvas) { - var ctx = maskCanvas.getContext('2d'); - var imageData = ctx.getImageData( - 0, 0, maskCanvas.width, maskCanvas.height); - var newImageData = ctx.createImageData(imageData); - - for (var i = 0; i < imageData.data.length; i += 4) { - var tone = imageData.data[i] + - imageData.data[i + 1] + - imageData.data[i + 2]; - var alpha = imageData.data[i + 3]; - - if (alpha < 128 || tone > 128 * 3) { - // Area not to draw - newImageData.data[i] = 0; - newImageData.data[i + 1] = 0; - newImageData.data[i + 2] = 0; - newImageData.data[i + 3] = 0; - } - else { - // Area to draw - // The color must be same with backgroundColor - newImageData.data[i] = 255; - newImageData.data[i + 1] = 255; - newImageData.data[i + 2] = 255; - newImageData.data[i + 3] = 255; - } - } - - ctx.putImageData(newImageData, 0, 0); - } - - echarts.registerLayout(function (ecModel, api) { - ecModel.eachSeriesByType('wordCloud', function (seriesModel) { - var gridRect = layoutUtil.getLayoutRect( - seriesModel.getBoxLayoutParams(), { - width: api.getWidth(), - height: api.getHeight() - } - ); - var data = seriesModel.getData(); - - var canvas = document.createElement('canvas'); - canvas.width = gridRect.width; - canvas.height = gridRect.height; - - var ctx = canvas.getContext('2d'); - var maskImage = seriesModel.get('maskImage'); - if (maskImage) { - try { - ctx.drawImage(maskImage, 0, 0, canvas.width, canvas.height); - updateCanvasMask(canvas); - } - catch (e) { - console.error('Invalid mask image'); - console.error(e.toString()); - } - } - - var sizeRange = seriesModel.get('sizeRange'); - var rotationRange = seriesModel.get('rotationRange'); - var valueExtent = data.getDataExtent('value'); - - var DEGREE_TO_RAD = Math.PI / 180; - var gridSize = seriesModel.get('gridSize'); - wordCloudLayoutHelper(canvas, { - list: data.mapArray('value', function (value, idx) { - var itemModel = data.getItemModel(idx); - return [ - data.getName(idx), - itemModel.get('textStyle.normal.textSize', true) - || echarts.number.linearMap(value, valueExtent, sizeRange), - idx - ]; - }).sort(function (a, b) { - // Sort from large to small in case there is no more room for more words - return b[1] - a[1]; - }), - fontFamily: seriesModel.get('textStyle.normal.fontFamily') - || seriesModel.get('textStyle.emphasis.fontFamily') - || ecModel.get('textStyle.fontFamily'), - fontWeight: seriesModel.get('textStyle.normal.fontWeight') - || seriesModel.get('textStyle.emphasis.fontWeight') - || ecModel.get('textStyle.fontWeight'), - gridSize: gridSize, - - ellipticity: gridRect.height / gridRect.width, - - minRotation: rotationRange[0] * DEGREE_TO_RAD, - maxRotation: rotationRange[1] * DEGREE_TO_RAD, - - clearCanvas: !maskImage, - - rotateRatio: 1, - - rotationStep: seriesModel.get('rotationStep') * DEGREE_TO_RAD, - - drawOutOfBound: false, - - shuffle: false, - - shape: seriesModel.get('shape') - }); - - canvas.addEventListener('wordclouddrawn', function (e) { - var item = e.detail.item; - if (e.detail.drawn && seriesModel.layoutInstance.ondraw) { - e.detail.drawn.gx += gridRect.x / gridSize; - e.detail.drawn.gy += gridRect.y / gridSize; - seriesModel.layoutInstance.ondraw( - item[0], item[1], item[2], e.detail.drawn - ); - } - }); - - seriesModel.layoutInstance = { - ondraw: null - }; - }); - }); - - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - module.exports = __WEBPACK_EXTERNAL_MODULE_2__; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - // Layout helpers for each component positioning - - - var zrUtil = __webpack_require__(4); - var BoundingRect = __webpack_require__(6); - var numberUtil = __webpack_require__(9); - var formatUtil = __webpack_require__(10); - var parsePercent = numberUtil.parsePercent; - var each = zrUtil.each; - - var layout = {}; - - var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height']; - - function boxLayout(orient, group, gap, maxWidth, maxHeight) { - var x = 0; - var y = 0; - if (maxWidth == null) { - maxWidth = Infinity; - } - if (maxHeight == null) { - maxHeight = Infinity; - } - var currentLineMaxSize = 0; - group.eachChild(function (child, idx) { - var position = child.position; - var rect = child.getBoundingRect(); - var nextChild = group.childAt(idx + 1); - var nextChildRect = nextChild && nextChild.getBoundingRect(); - var nextX; - var nextY; - if (orient === 'horizontal') { - var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0); - nextX = x + moveX; - // Wrap when width exceeds maxWidth or meet a `newline` group - if (nextX > maxWidth || child.newline) { - x = 0; - nextX = moveX; - y += currentLineMaxSize + gap; - currentLineMaxSize = rect.height; - } - else { - currentLineMaxSize = Math.max(currentLineMaxSize, rect.height); - } - } - else { - var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0); - nextY = y + moveY; - // Wrap when width exceeds maxHeight or meet a `newline` group - if (nextY > maxHeight || child.newline) { - x += currentLineMaxSize + gap; - y = 0; - nextY = moveY; - currentLineMaxSize = rect.width; - } - else { - currentLineMaxSize = Math.max(currentLineMaxSize, rect.width); - } - } - - if (child.newline) { - return; - } - - position[0] = x; - position[1] = y; - - orient === 'horizontal' - ? (x = nextX + gap) - : (y = nextY + gap); - }); - } - - /** - * VBox or HBox layouting - * @param {string} orient - * @param {module:zrender/container/Group} group - * @param {number} gap - * @param {number} [width=Infinity] - * @param {number} [height=Infinity] - */ - layout.box = boxLayout; - - /** - * VBox layouting - * @param {module:zrender/container/Group} group - * @param {number} gap - * @param {number} [width=Infinity] - * @param {number} [height=Infinity] - */ - layout.vbox = zrUtil.curry(boxLayout, 'vertical'); - - /** - * HBox layouting - * @param {module:zrender/container/Group} group - * @param {number} gap - * @param {number} [width=Infinity] - * @param {number} [height=Infinity] - */ - layout.hbox = zrUtil.curry(boxLayout, 'horizontal'); - - /** - * If x or x2 is not specified or 'center' 'left' 'right', - * the width would be as long as possible. - * If y or y2 is not specified or 'middle' 'top' 'bottom', - * the height would be as long as possible. - * - * @param {Object} positionInfo - * @param {number|string} [positionInfo.x] - * @param {number|string} [positionInfo.y] - * @param {number|string} [positionInfo.x2] - * @param {number|string} [positionInfo.y2] - * @param {Object} containerRect - * @param {string|number} margin - * @return {Object} {width, height} - */ - layout.getAvailableSize = function (positionInfo, containerRect, margin) { - var containerWidth = containerRect.width; - var containerHeight = containerRect.height; - - var x = parsePercent(positionInfo.x, containerWidth); - var y = parsePercent(positionInfo.y, containerHeight); - var x2 = parsePercent(positionInfo.x2, containerWidth); - var y2 = parsePercent(positionInfo.y2, containerHeight); - - (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0); - (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth); - (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0); - (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight); - - margin = formatUtil.normalizeCssArray(margin || 0); - - return { - width: Math.max(x2 - x - margin[1] - margin[3], 0), - height: Math.max(y2 - y - margin[0] - margin[2], 0) - }; - }; - - /** - * Parse position info. - * - * @param {Object} positionInfo - * @param {number|string} [positionInfo.left] - * @param {number|string} [positionInfo.top] - * @param {number|string} [positionInfo.right] - * @param {number|string} [positionInfo.bottom] - * @param {number|string} [positionInfo.width] - * @param {number|string} [positionInfo.height] - * @param {number|string} [positionInfo.aspect] Aspect is width / height - * @param {Object} containerRect - * @param {string|number} [margin] - * - * @return {module:zrender/core/BoundingRect} - */ - layout.getLayoutRect = function ( - positionInfo, containerRect, margin - ) { - margin = formatUtil.normalizeCssArray(margin || 0); - - var containerWidth = containerRect.width; - var containerHeight = containerRect.height; - - var left = parsePercent(positionInfo.left, containerWidth); - var top = parsePercent(positionInfo.top, containerHeight); - var right = parsePercent(positionInfo.right, containerWidth); - var bottom = parsePercent(positionInfo.bottom, containerHeight); - var width = parsePercent(positionInfo.width, containerWidth); - var height = parsePercent(positionInfo.height, containerHeight); - - var verticalMargin = margin[2] + margin[0]; - var horizontalMargin = margin[1] + margin[3]; - var aspect = positionInfo.aspect; - - // If width is not specified, calculate width from left and right - if (isNaN(width)) { - width = containerWidth - right - horizontalMargin - left; - } - if (isNaN(height)) { - height = containerHeight - bottom - verticalMargin - top; - } - - // If width and height are not given - // 1. Graph should not exceeds the container - // 2. Aspect must be keeped - // 3. Graph should take the space as more as possible - if (isNaN(width) && isNaN(height)) { - if (aspect > containerWidth / containerHeight) { - width = containerWidth * 0.8; - } - else { - height = containerHeight * 0.8; - } - } - - if (aspect != null) { - // Calculate width or height with given aspect - if (isNaN(width)) { - width = aspect * height; - } - if (isNaN(height)) { - height = width / aspect; - } - } - - // If left is not specified, calculate left from right and width - if (isNaN(left)) { - left = containerWidth - right - width - horizontalMargin; - } - if (isNaN(top)) { - top = containerHeight - bottom - height - verticalMargin; - } - - // Align left and top - switch (positionInfo.left || positionInfo.right) { - case 'center': - left = containerWidth / 2 - width / 2 - margin[3]; - break; - case 'right': - left = containerWidth - width - horizontalMargin; - break; - } - switch (positionInfo.top || positionInfo.bottom) { - case 'middle': - case 'center': - top = containerHeight / 2 - height / 2 - margin[0]; - break; - case 'bottom': - top = containerHeight - height - verticalMargin; - break; - } - // If something is wrong and left, top, width, height are calculated as NaN - left = left || 0; - top = top || 0; - if (isNaN(width)) { - // Width may be NaN if only one value is given except width - width = containerWidth - left - (right || 0); - } - if (isNaN(height)) { - // Height may be NaN if only one value is given except height - height = containerHeight - top - (bottom || 0); - } - - var rect = new BoundingRect(left + margin[3], top + margin[0], width, height); - rect.margin = margin; - return rect; - }; - - /** - * Position group of component in viewport - * Group position is specified by either - * {left, top}, {right, bottom} - * If all properties exists, right and bottom will be igonred. - * - * @param {module:zrender/container/Group} group - * @param {Object} positionInfo - * @param {number|string} [positionInfo.left] - * @param {number|string} [positionInfo.top] - * @param {number|string} [positionInfo.right] - * @param {number|string} [positionInfo.bottom] - * @param {Object} containerRect - * @param {string|number} margin - */ - layout.positionGroup = function ( - group, positionInfo, containerRect, margin - ) { - var groupRect = group.getBoundingRect(); - - positionInfo = zrUtil.extend(zrUtil.clone(positionInfo), { - width: groupRect.width, - height: groupRect.height - }); - - positionInfo = layout.getLayoutRect( - positionInfo, containerRect, margin - ); - - group.position = [ - positionInfo.x - groupRect.x, - positionInfo.y - groupRect.y - ]; - }; - - /** - * Consider Case: - * When defulat option has {left: 0, width: 100}, and we set {right: 0} - * through setOption or media query, using normal zrUtil.merge will cause - * {right: 0} does not take effect. - * - * @example - * ComponentModel.extend({ - * init: function () { - * ... - * var inputPositionParams = layout.getLayoutParams(option); - * this.mergeOption(inputPositionParams); - * }, - * mergeOption: function (newOption) { - * newOption && zrUtil.merge(thisOption, newOption, true); - * layout.mergeLayoutParam(thisOption, newOption); - * } - * }); - * - * @param {Object} targetOption - * @param {Object} newOption - * @param {Object|string} [opt] - * @param {boolean} [opt.ignoreSize=false] Some component must has width and height. - */ - layout.mergeLayoutParam = function (targetOption, newOption, opt) { - !zrUtil.isObject(opt) && (opt = {}); - var hNames = ['width', 'left', 'right']; // Order by priority. - var vNames = ['height', 'top', 'bottom']; // Order by priority. - var hResult = merge(hNames); - var vResult = merge(vNames); - - copy(hNames, targetOption, hResult); - copy(vNames, targetOption, vResult); - - function merge(names) { - var newParams = {}; - var newValueCount = 0; - var merged = {}; - var mergedValueCount = 0; - var enoughParamNumber = opt.ignoreSize ? 1 : 2; - - each(names, function (name) { - merged[name] = targetOption[name]; - }); - each(names, function (name) { - // Consider case: newOption.width is null, which is - // set by user for removing width setting. - hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]); - hasValue(newParams, name) && newValueCount++; - hasValue(merged, name) && mergedValueCount++; - }); - - // Case: newOption: {width: ..., right: ...}, - // or targetOption: {right: ...} and newOption: {width: ...}, - // There is no conflict when merged only has params count - // little than enoughParamNumber. - if (mergedValueCount === enoughParamNumber || !newValueCount) { - return merged; - } - // Case: newOption: {width: ..., right: ...}, - // Than we can make sure user only want those two, and ignore - // all origin params in targetOption. - else if (newValueCount >= enoughParamNumber) { - return newParams; - } - else { - // Chose another param from targetOption by priority. - // When 'ignoreSize', enoughParamNumber is 1 and those will not happen. - for (var i = 0; i < names.length; i++) { - var name = names[i]; - if (!hasProp(newParams, name) && hasProp(targetOption, name)) { - newParams[name] = targetOption[name]; - break; - } - } - return newParams; - } - } - - function hasProp(obj, name) { - return obj.hasOwnProperty(name); - } - - function hasValue(obj, name) { - return obj[name] != null && obj[name] !== 'auto'; - } - - function copy(names, target, source) { - each(names, function (name) { - target[name] = source[name]; - }); - } - }; - - /** - * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object. - * @param {Object} source - * @return {Object} Result contains those props. - */ - layout.getLayoutParams = function (source) { - return layout.copyLayoutParams({}, source); - }; - - /** - * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object. - * @param {Object} source - * @return {Object} Result contains those props. - */ - layout.copyLayoutParams = function (target, source) { - source && target && each(LOCATION_PARAMS, function (name) { - source.hasOwnProperty(name) && (target[name] = source[name]); - }); - return target; - }; - - module.exports = layout; - - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - /** - * @module zrender/core/util - */ - - var Gradient = __webpack_require__(5); - // 用于处理merge时无法遍历Date等对象的问题 - var BUILTIN_OBJECT = { - '[object Function]': 1, - '[object RegExp]': 1, - '[object Date]': 1, - '[object Error]': 1, - '[object CanvasGradient]': 1 - }; - - var objToString = Object.prototype.toString; - - var arrayProto = Array.prototype; - var nativeForEach = arrayProto.forEach; - var nativeFilter = arrayProto.filter; - var nativeSlice = arrayProto.slice; - var nativeMap = arrayProto.map; - var nativeReduce = arrayProto.reduce; - - /** - * @param {*} source - * @return {*} 拷贝后的新对象 - */ - function clone(source) { - if (typeof source == 'object' && source !== null) { - var result = source; - if (source instanceof Array) { - result = []; - for (var i = 0, len = source.length; i < len; i++) { - result[i] = clone(source[i]); - } - } - else if ( - !isBuildInObject(source) - // 是否为 dom 对象 - && !isDom(source) - ) { - result = {}; - for (var key in source) { - if (source.hasOwnProperty(key)) { - result[key] = clone(source[key]); - } - } - } - - return result; - } - - return source; - } - - /** - * @memberOf module:zrender/core/util - * @param {*} target - * @param {*} source - * @param {boolean} [overwrite=false] - */ - function merge(target, source, overwrite) { - // We should escapse that source is string - // and enter for ... in ... - if (!isObject(source) || !isObject(target)) { - return overwrite ? clone(source) : target; - } - - for (var key in source) { - if (source.hasOwnProperty(key)) { - var targetProp = target[key]; - var sourceProp = source[key]; - - if (isObject(sourceProp) - && isObject(targetProp) - && !isArray(sourceProp) - && !isArray(targetProp) - && !isDom(sourceProp) - && !isDom(targetProp) - && !isBuildInObject(sourceProp) - && !isBuildInObject(targetProp) - ) { - // 如果需要递归覆盖,就递归调用merge - merge(targetProp, sourceProp, overwrite); - } - else if (overwrite || !(key in target)) { - // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况 - // NOTE,在 target[key] 不存在的时候也是直接覆盖 - target[key] = clone(source[key], true); - } - } - } - - return target; - } - - /** - * @param {Array} targetAndSources The first item is target, and the rests are source. - * @param {boolean} [overwrite=false] - * @return {*} target - */ - function mergeAll(targetAndSources, overwrite) { - var result = targetAndSources[0]; - for (var i = 1, len = targetAndSources.length; i < len; i++) { - result = merge(result, targetAndSources[i], overwrite); - } - return result; - } - - /** - * @param {*} target - * @param {*} source - * @memberOf module:zrender/core/util - */ - function extend(target, source) { - for (var key in source) { - if (source.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - return target; - } - - /** - * @param {*} target - * @param {*} source - * @param {boolen} [overlay=false] - * @memberOf module:zrender/core/util - */ - function defaults(target, source, overlay) { - for (var key in source) { - if (source.hasOwnProperty(key) - && (overlay ? source[key] != null : target[key] == null) - ) { - target[key] = source[key]; - } - } - return target; - } - - function createCanvas() { - return document.createElement('canvas'); - } - // FIXME - var _ctx; - function getContext() { - if (!_ctx) { - // Use util.createCanvas instead of createCanvas - // because createCanvas may be overwritten in different environment - _ctx = util.createCanvas().getContext('2d'); - } - return _ctx; - } - - /** - * 查询数组中元素的index - * @memberOf module:zrender/core/util - */ - function indexOf(array, value) { - if (array) { - if (array.indexOf) { - return array.indexOf(value); - } - for (var i = 0, len = array.length; i < len; i++) { - if (array[i] === value) { - return i; - } - } - } - return -1; - } - - /** - * 构造类继承关系 - * - * @memberOf module:zrender/core/util - * @param {Function} clazz 源类 - * @param {Function} baseClazz 基类 - */ - function inherits(clazz, baseClazz) { - var clazzPrototype = clazz.prototype; - function F() {} - F.prototype = baseClazz.prototype; - clazz.prototype = new F(); - - for (var prop in clazzPrototype) { - clazz.prototype[prop] = clazzPrototype[prop]; - } - clazz.prototype.constructor = clazz; - clazz.superClass = baseClazz; - } - - /** - * @memberOf module:zrender/core/util - * @param {Object|Function} target - * @param {Object|Function} sorce - * @param {boolean} overlay - */ - function mixin(target, source, overlay) { - target = 'prototype' in target ? target.prototype : target; - source = 'prototype' in source ? source.prototype : source; - - defaults(target, source, overlay); - } - - /** - * @param {Array|TypedArray} data - */ - function isArrayLike(data) { - if (! data) { - return; - } - if (typeof data == 'string') { - return false; - } - return typeof data.length == 'number'; - } - - /** - * 数组或对象遍历 - * @memberOf module:zrender/core/util - * @param {Object|Array} obj - * @param {Function} cb - * @param {*} [context] - */ - function each(obj, cb, context) { - if (!(obj && cb)) { - return; - } - if (obj.forEach && obj.forEach === nativeForEach) { - obj.forEach(cb, context); - } - else if (obj.length === +obj.length) { - for (var i = 0, len = obj.length; i < len; i++) { - cb.call(context, obj[i], i, obj); - } - } - else { - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - cb.call(context, obj[key], key, obj); - } - } - } - } - - /** - * 数组映射 - * @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} - */ - function reduce(obj, cb, memo, context) { - if (!(obj && cb)) { - return; - } - if (obj.reduce && obj.reduce === nativeReduce) { - return obj.reduce(cb, memo, context); - } - else { - for (var i = 0, len = obj.length; i < len; i++) { - memo = cb.call(context, memo, obj[i], i, obj); - } - return memo; - } - } - - /** - * 数组过滤 - * @memberOf module:zrender/core/util - * @param {Array} obj - * @param {Function} cb - * @param {*} [context] - * @return {Array} - */ - function filter(obj, cb, context) { - if (!(obj && cb)) { - return; - } - if (obj.filter && obj.filter === nativeFilter) { - return obj.filter(cb, context); - } - else { - var result = []; - for (var i = 0, len = obj.length; i < len; i++) { - if (cb.call(context, obj[i], i, obj)) { - result.push(obj[i]); - } - } - return result; - } - } - - /** - * 数组项查找 - * @memberOf module:zrender/core/util - * @param {Array} obj - * @param {Function} cb - * @param {*} [context] - * @return {Array} - */ - function find(obj, cb, context) { - if (!(obj && cb)) { - return; - } - for (var i = 0, len = obj.length; i < len; i++) { - if (cb.call(context, obj[i], i, obj)) { - return obj[i]; - } - } - } - - /** - * @memberOf module:zrender/core/util - * @param {Function} func - * @param {*} context - * @return {Function} - */ - function bind(func, context) { - var args = nativeSlice.call(arguments, 2); - return function () { - return func.apply(context, args.concat(nativeSlice.call(arguments))); - }; - } - - /** - * @memberOf module:zrender/core/util - * @param {Function} func - * @return {Function} - */ - function curry(func) { - var args = nativeSlice.call(arguments, 1); - return function () { - return func.apply(this, args.concat(nativeSlice.call(arguments))); - }; - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isArray(value) { - return objToString.call(value) === '[object Array]'; - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isFunction(value) { - return typeof value === 'function'; - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isString(value) { - return objToString.call(value) === '[object String]'; - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isObject(value) { - // Avoid a V8 JIT bug in Chrome 19-20. - // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. - var type = typeof value; - return type === 'function' || (!!value && type == 'object'); - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isBuildInObject(value) { - return !!BUILTIN_OBJECT[objToString.call(value)] - || (value instanceof Gradient); - } - - /** - * @memberOf module:zrender/core/util - * @param {*} value - * @return {boolean} - */ - function isDom(value) { - return value && value.nodeType === 1 - && typeof(value.nodeName) == 'string'; - } - - /** - * If value1 is not null, then return value1, otherwise judget rest of values. - * @memberOf module:zrender/core/util - * @return {*} Final value - */ - function retrieve(values) { - for (var i = 0, len = arguments.length; i < len; i++) { - if (arguments[i] != null) { - return arguments[i]; - } - } - } - - /** - * @memberOf module:zrender/core/util - * @param {Array} arr - * @param {number} startIndex - * @param {number} endIndex - * @return {Array} - */ - function slice() { - return Function.call.apply(nativeSlice, arguments); - } - - /** - * @memberOf module:zrender/core/util - * @param {boolean} condition - * @param {string} message - */ - function assert(condition, message) { - if (!condition) { - throw new Error(message); - } - } - - var util = { - inherits: inherits, - mixin: mixin, - clone: clone, - merge: merge, - mergeAll: mergeAll, - extend: extend, - defaults: defaults, - getContext: getContext, - createCanvas: createCanvas, - indexOf: indexOf, - slice: slice, - find: find, - isArrayLike: isArrayLike, - each: each, - map: map, - reduce: reduce, - filter: filter, - bind: bind, - curry: curry, - isArray: isArray, - isString: isString, - isObject: isObject, - isFunction: isFunction, - isBuildInObject: isBuildInObject, - isDom: isDom, - retrieve: retrieve, - assert: assert, - noop: function () {} - }; - module.exports = util; - - - -/***/ }, -/* 5 */ -/***/ function(module, exports) { - - - - /** - * @param {Array.} colorStops - */ - var Gradient = function (colorStops) { - - this.colorStops = colorStops || []; - }; - - Gradient.prototype = { - - constructor: Gradient, - - addColorStop: function (offset, color) { - this.colorStops.push({ - - offset: offset, - - color: color - }); - } - }; - - module.exports = Gradient; - - -/***/ }, -/* 6 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - /** - * @module echarts/core/BoundingRect - */ - - - var vec2 = __webpack_require__(7); - var matrix = __webpack_require__(8); - - var v2ApplyTransform = vec2.applyTransform; - var mathMin = Math.min; - var mathAbs = Math.abs; - var mathMax = Math.max; - /** - * @alias module:echarts/core/BoundingRect - */ - function BoundingRect(x, y, width, height) { - /** - * @type {number} - */ - this.x = x; - /** - * @type {number} - */ - this.y = y; - /** - * @type {number} - */ - this.width = width; - /** - * @type {number} - */ - this.height = height; - } - - BoundingRect.prototype = { - - constructor: BoundingRect, - - /** - * @param {module:echarts/core/BoundingRect} other - */ - union: function (other) { - var x = mathMin(other.x, this.x); - var y = mathMin(other.y, this.y); - - this.width = mathMax( - other.x + other.width, - this.x + this.width - ) - x; - this.height = mathMax( - other.y + other.height, - this.y + this.height - ) - y; - this.x = x; - this.y = y; - }, - - /** - * @param {Array.} m - * @methods - */ - applyTransform: (function () { - var min = []; - var max = []; - return function (m) { - // In case usage like this - // el.getBoundingRect().applyTransform(el.transform) - // And element has no transform - if (!m) { - return; - } - min[0] = this.x; - min[1] = this.y; - max[0] = this.x + this.width; - max[1] = this.y + this.height; - - v2ApplyTransform(min, min, m); - v2ApplyTransform(max, max, m); - - this.x = mathMin(min[0], max[0]); - this.y = mathMin(min[1], max[1]); - this.width = mathAbs(max[0] - min[0]); - this.height = mathAbs(max[1] - min[1]); - }; - })(), - - /** - * Calculate matrix of transforming from self to target rect - * @param {module:zrender/core/BoundingRect} b - * @return {Array.} - */ - calculateTransform: function (b) { - var a = this; - var sx = b.width / a.width; - var sy = b.height / a.height; - - var m = matrix.create(); - - // 矩阵右乘 - matrix.translate(m, m, [-a.x, -a.y]); - matrix.scale(m, m, [sx, sy]); - matrix.translate(m, m, [b.x, b.y]); - - return m; - }, - - /** - * @param {(module:echarts/core/BoundingRect|Object)} b - * @return {boolean} - */ - intersect: function (b) { - var a = this; - var ax0 = a.x; - var ax1 = a.x + a.width; - var ay0 = a.y; - var ay1 = a.y + a.height; - - var bx0 = b.x; - var bx1 = b.x + b.width; - var by0 = b.y; - var by1 = b.y + b.height; - - return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0); - }, - - contain: function (x, y) { - var rect = this; - return x >= rect.x - && x <= (rect.x + rect.width) - && y >= rect.y - && y <= (rect.y + rect.height); - }, - - /** - * @return {module:echarts/core/BoundingRect} - */ - clone: function () { - return new BoundingRect(this.x, this.y, this.width, this.height); - }, - - /** - * Copy from another rect - */ - copy: function (other) { - this.x = other.x; - this.y = other.y; - this.width = other.width; - this.height = other.height; - } - }; - - module.exports = BoundingRect; - - -/***/ }, -/* 7 */ -/***/ function(module, exports) { - - - var ArrayCtor = typeof Float32Array === 'undefined' - ? Array - : Float32Array; - - /** - * @typedef {Float32Array|Array.} Vector2 - */ - /** - * 二维向量类 - * @exports zrender/tool/vector - */ - var vector = { - /** - * 创建一个向量 - * @param {number} [x=0] - * @param {number} [y=0] - * @return {Vector2} - */ - create: function (x, y) { - var out = new ArrayCtor(2); - out[0] = x || 0; - out[1] = y || 0; - return out; - }, - - /** - * 复制向量数据 - * @param {Vector2} out - * @param {Vector2} v - * @return {Vector2} - */ - copy: function (out, v) { - out[0] = v[0]; - out[1] = v[1]; - return out; - }, - - /** - * 克隆一个向量 - * @param {Vector2} v - * @return {Vector2} - */ - clone: function (v) { - var out = new ArrayCtor(2); - out[0] = v[0]; - out[1] = v[1]; - return out; - }, - - /** - * 设置向量的两个项 - * @param {Vector2} out - * @param {number} a - * @param {number} b - * @return {Vector2} 结果 - */ - set: function (out, a, b) { - out[0] = a; - out[1] = b; - return out; - }, - - /** - * 向量相加 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - add: function (out, v1, v2) { - out[0] = v1[0] + v2[0]; - out[1] = v1[1] + v2[1]; - return out; - }, - - /** - * 向量缩放后相加 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - * @param {number} a - */ - scaleAndAdd: function (out, v1, v2, a) { - out[0] = v1[0] + v2[0] * a; - out[1] = v1[1] + v2[1] * a; - return out; - }, - - /** - * 向量相减 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - sub: function (out, v1, v2) { - out[0] = v1[0] - v2[0]; - out[1] = v1[1] - v2[1]; - return out; - }, - - /** - * 向量长度 - * @param {Vector2} v - * @return {number} - */ - len: function (v) { - return Math.sqrt(this.lenSquare(v)); - }, - - /** - * 向量长度平方 - * @param {Vector2} v - * @return {number} - */ - lenSquare: function (v) { - return v[0] * v[0] + v[1] * v[1]; - }, - - /** - * 向量乘法 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - mul: function (out, v1, v2) { - out[0] = v1[0] * v2[0]; - out[1] = v1[1] * v2[1]; - return out; - }, - - /** - * 向量除法 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - div: function (out, v1, v2) { - out[0] = v1[0] / v2[0]; - out[1] = v1[1] / v2[1]; - return out; - }, - - /** - * 向量点乘 - * @param {Vector2} v1 - * @param {Vector2} v2 - * @return {number} - */ - dot: function (v1, v2) { - return v1[0] * v2[0] + v1[1] * v2[1]; - }, - - /** - * 向量缩放 - * @param {Vector2} out - * @param {Vector2} v - * @param {number} s - */ - scale: function (out, v, s) { - out[0] = v[0] * s; - out[1] = v[1] * s; - return out; - }, - - /** - * 向量归一化 - * @param {Vector2} out - * @param {Vector2} v - */ - normalize: function (out, v) { - var d = vector.len(v); - if (d === 0) { - out[0] = 0; - out[1] = 0; - } - else { - out[0] = v[0] / d; - out[1] = v[1] / d; - } - return out; - }, - - /** - * 计算向量间距离 - * @param {Vector2} v1 - * @param {Vector2} v2 - * @return {number} - */ - distance: function (v1, v2) { - return Math.sqrt( - (v1[0] - v2[0]) * (v1[0] - v2[0]) - + (v1[1] - v2[1]) * (v1[1] - v2[1]) - ); - }, - - /** - * 向量距离平方 - * @param {Vector2} v1 - * @param {Vector2} v2 - * @return {number} - */ - distanceSquare: function (v1, v2) { - return (v1[0] - v2[0]) * (v1[0] - v2[0]) - + (v1[1] - v2[1]) * (v1[1] - v2[1]); - }, - - /** - * 求负向量 - * @param {Vector2} out - * @param {Vector2} v - */ - negate: function (out, v) { - out[0] = -v[0]; - out[1] = -v[1]; - return out; - }, - - /** - * 插值两个点 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - * @param {number} t - */ - lerp: function (out, v1, v2, t) { - out[0] = v1[0] + t * (v2[0] - v1[0]); - out[1] = v1[1] + t * (v2[1] - v1[1]); - return out; - }, - - /** - * 矩阵左乘向量 - * @param {Vector2} out - * @param {Vector2} v - * @param {Vector2} m - */ - applyTransform: function (out, v, m) { - var x = v[0]; - var y = v[1]; - out[0] = m[0] * x + m[2] * y + m[4]; - out[1] = m[1] * x + m[3] * y + m[5]; - return out; - }, - /** - * 求两个向量最小值 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - min: function (out, v1, v2) { - out[0] = Math.min(v1[0], v2[0]); - out[1] = Math.min(v1[1], v2[1]); - return out; - }, - /** - * 求两个向量最大值 - * @param {Vector2} out - * @param {Vector2} v1 - * @param {Vector2} v2 - */ - max: function (out, v1, v2) { - out[0] = Math.max(v1[0], v2[0]); - out[1] = Math.max(v1[1], v2[1]); - return out; - } - }; - - vector.length = vector.len; - vector.lengthSquare = vector.lenSquare; - vector.dist = vector.distance; - vector.distSquare = vector.distanceSquare; - - module.exports = vector; - - - -/***/ }, -/* 8 */ -/***/ function(module, exports) { - - - var ArrayCtor = typeof Float32Array === 'undefined' - ? Array - : Float32Array; - /** - * 3x2矩阵操作类 - * @exports zrender/tool/matrix - */ - var matrix = { - /** - * 创建一个单位矩阵 - * @return {Float32Array|Array.} - */ - create : function() { - var out = new ArrayCtor(6); - matrix.identity(out); - - return out; - }, - /** - * 设置矩阵为单位矩阵 - * @param {Float32Array|Array.} out - */ - identity : function(out) { - out[0] = 1; - out[1] = 0; - out[2] = 0; - out[3] = 1; - out[4] = 0; - out[5] = 0; - return out; - }, - /** - * 复制矩阵 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} m - */ - copy: function(out, m) { - out[0] = m[0]; - out[1] = m[1]; - out[2] = m[2]; - out[3] = m[3]; - out[4] = m[4]; - out[5] = m[5]; - return out; - }, - /** - * 矩阵相乘 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} m1 - * @param {Float32Array|Array.} m2 - */ - mul : function (out, m1, m2) { - // Consider matrix.mul(m, m2, m); - // where out is the same as m2. - // So use temp variable to escape error. - var out0 = m1[0] * m2[0] + m1[2] * m2[1]; - var out1 = m1[1] * m2[0] + m1[3] * m2[1]; - var out2 = m1[0] * m2[2] + m1[2] * m2[3]; - var out3 = m1[1] * m2[2] + m1[3] * m2[3]; - var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4]; - var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5]; - out[0] = out0; - out[1] = out1; - out[2] = out2; - out[3] = out3; - out[4] = out4; - out[5] = out5; - return out; - }, - /** - * 平移变换 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} a - * @param {Float32Array|Array.} v - */ - translate : function(out, a, v) { - out[0] = a[0]; - out[1] = a[1]; - out[2] = a[2]; - out[3] = a[3]; - out[4] = a[4] + v[0]; - out[5] = a[5] + v[1]; - return out; - }, - /** - * 旋转变换 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} a - * @param {number} rad - */ - rotate : function(out, a, rad) { - var aa = a[0]; - var ac = a[2]; - var atx = a[4]; - var ab = a[1]; - var ad = a[3]; - var aty = a[5]; - var st = Math.sin(rad); - var ct = Math.cos(rad); - - out[0] = aa * ct + ab * st; - out[1] = -aa * st + ab * ct; - out[2] = ac * ct + ad * st; - out[3] = -ac * st + ct * ad; - out[4] = ct * atx + st * aty; - out[5] = ct * aty - st * atx; - return out; - }, - /** - * 缩放变换 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} a - * @param {Float32Array|Array.} v - */ - scale : function(out, a, v) { - var vx = v[0]; - var vy = v[1]; - out[0] = a[0] * vx; - out[1] = a[1] * vy; - out[2] = a[2] * vx; - out[3] = a[3] * vy; - out[4] = a[4] * vx; - out[5] = a[5] * vy; - return out; - }, - /** - * 求逆矩阵 - * @param {Float32Array|Array.} out - * @param {Float32Array|Array.} a - */ - invert : function(out, a) { - - var aa = a[0]; - var ac = a[2]; - var atx = a[4]; - var ab = a[1]; - var ad = a[3]; - var aty = a[5]; - - var det = aa * ad - ab * ac; - if (!det) { - return null; - } - det = 1.0 / det; - - out[0] = ad * det; - out[1] = -ab * det; - out[2] = -ac * det; - out[3] = aa * det; - out[4] = (ac * aty - ad * atx) * det; - out[5] = (ab * atx - aa * aty) * det; - return out; - } - }; - - module.exports = matrix; - - - -/***/ }, -/* 9 */ -/***/ function(module, exports) { - - /** - * 数值处理模块 - * @module echarts/util/number - */ - - - - var number = {}; - - var RADIAN_EPSILON = 1e-4; - - function _trim(str) { - return str.replace(/^\s+/, '').replace(/\s+$/, ''); - } - - /** - * Linear mapping a value from domain to range - * @memberOf module:echarts/util/number - * @param {(number|Array.)} val - * @param {Array.} domain Domain extent domain[0] can be bigger than domain[1] - * @param {Array.} range Range extent range[0] can be bigger than range[1] - * @param {boolean} clamp - * @return {(number|Array.} - */ - number.linearMap = function (val, domain, range, clamp) { - var subDomain = domain[1] - domain[0]; - var subRange = range[1] - range[0]; - - if (subDomain === 0) { - return subRange === 0 - ? range[0] - : (range[0] + range[1]) / 2; - } - - // Avoid accuracy problem in edge, such as - // 146.39 - 62.83 === 83.55999999999999. - // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError - // It is a little verbose for efficiency considering this method - // is a hotspot. - if (clamp) { - if (subDomain > 0) { - if (val <= domain[0]) { - return range[0]; - } - else if (val >= domain[1]) { - return range[1]; - } - } - else { - if (val >= domain[0]) { - return range[0]; - } - else if (val <= domain[1]) { - return range[1]; - } - } - } - else { - if (val === domain[0]) { - return range[0]; - } - if (val === domain[1]) { - return range[1]; - } - } - - return (val - domain[0]) / subDomain * subRange + range[0]; - }; - - /** - * 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} - */ - number.parsePercent = function(percent, all) { - switch (percent) { - case 'center': - case 'middle': - percent = '50%'; - break; - case 'left': - case 'top': - percent = '0%'; - break; - case 'right': - case 'bottom': - percent = '100%'; - break; - } - if (typeof percent === 'string') { - if (_trim(percent).match(/%$/)) { - return parseFloat(percent) / 100 * all; - } - - return parseFloat(percent); - } - - return percent == null ? NaN : +percent; - }; - - /** - * Fix rounding error of float numbers - * @param {number} x - * @return {number} - */ - number.round = function (x) { - // PENDING - return +(+x).toFixed(10); - }; - - number.asc = function (arr) { - arr.sort(function (a, b) { - return a - b; - }); - return arr; - }; - - /** - * Get precision - * @param {number} val - */ - number.getPrecision = function (val) { - if (isNaN(val)) { - return 0; - } - // It is much faster than methods converting number to string as follows - // var tmp = val.toString(); - // return tmp.length - 1 - tmp.indexOf('.'); - // especially when precision is low - var e = 1; - var count = 0; - while (Math.round(val * e) / e !== val) { - e *= 10; - count++; - } - return count; - }; - - /** - * @param {Array.} dataExtent - * @param {Array.} pixelExtent - * @return {number} precision - */ - number.getPixelPrecision = function (dataExtent, pixelExtent) { - var log = Math.log; - var LN10 = Math.LN10; - var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10); - var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); - return Math.max( - -dataQuantity + sizeQuantity, - 0 - ); - }; - - // Number.MAX_SAFE_INTEGER, ie do not support. - number.MAX_SAFE_INTEGER = 9007199254740991; - - /** - * To 0 - 2 * PI, considering negative radian. - * @param {number} radian - * @return {number} - */ - number.remRadian = function (radian) { - var pi2 = Math.PI * 2; - return (radian % pi2 + pi2) % pi2; - }; - - /** - * @param {type} radian - * @return {boolean} - */ - number.isRadianAroundZero = function (val) { - return val > -RADIAN_EPSILON && val < RADIAN_EPSILON; - }; - - /** - * @param {string|Date|number} value - * @return {number} timestamp - */ - number.parseDate = function (value) { - return value instanceof Date - ? value - : new Date( - typeof value === 'string' - ? value.replace(/-/g, '/') - : Math.round(value) - ); - }; - - /** - * Quantity of a number. e.g. 0.1, 1, 10, 100 - * @param {number} val - * @return {number} - */ - number.quantity = function (val) { - return Math.pow(10, Math.floor(Math.log(val) / Math.LN10)); - }; - - // "Nice Numbers for Graph Labels" of Graphic Gems - /** - * 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. - * @param {number} val - * @param {boolean} round - * @return {number} - */ - number.nice = function (val, round) { - var exp10 = number.quantity(val); - var f = val / exp10; // between 1 and 10 - var nf; - if (round) { - if (f < 1.5) { nf = 1; } - else if (f < 2.5) { nf = 2; } - else if (f < 4) { nf = 3; } - else if (f < 7) { nf = 5; } - else { nf = 10; } - } - else { - if (f < 1) { nf = 1; } - else if (f < 2) { nf = 2; } - else if (f < 3) { nf = 3; } - else if (f < 5) { nf = 5; } - else { nf = 10; } - } - return nf * exp10; - }; - - module.exports = number; - - -/***/ }, -/* 10 */ -/***/ function(module, exports, __webpack_require__) { - - - - var zrUtil = __webpack_require__(4); - var numberUtil = __webpack_require__(9); - - /** - * 每三位默认加,格式化 - * @type {string|number} x - */ - function addCommas(x) { - if (isNaN(x)) { - return '-'; - } - x = (x + '').split('.'); - return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,') - + (x.length > 1 ? ('.' + x[1]) : ''); - } - - /** - * @param {string} str - * @return {string} str - */ - function toCamelCase(str) { - return str.toLowerCase().replace(/-(.)/g, function(match, group1) { - return group1.toUpperCase(); - }); - } - - /** - * 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.} val - */ - function normalizeCssArray(val) { - var len = val.length; - if (typeof (val) === 'number') { - return [val, val, val, val]; - } - else if (len === 2) { - // vertical | horizontal - return [val[0], val[1], val[0], val[1]]; - } - else if (len === 3) { - // top | horizontal | bottom - return [val[0], val[1], val[2], val[1]]; - } - return val; - } - - function encodeHTML(source) { - return String(source) - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); - } - - var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; - - function wrapVar(varName, seriesIdx) { - return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}'; - } - /** - * Template formatter - * @param {string} tpl - * @param {Array.|Object} paramsList - * @return {string} - */ - function formatTpl(tpl, paramsList) { - if (!zrUtil.isArray(paramsList)) { - paramsList = [paramsList]; - } - var seriesLen = paramsList.length; - if (!seriesLen) { - return ''; - } - - var $vars = paramsList[0].$vars; - for (var i = 0; i < $vars.length; i++) { - var alias = TPL_VAR_ALIAS[i]; - tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0)); - } - for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) { - for (var k = 0; k < $vars.length; k++) { - tpl = tpl.replace( - wrapVar(TPL_VAR_ALIAS[k], seriesIdx), - paramsList[seriesIdx][$vars[k]] - ); - } - } - - return tpl; - } - - /** - * ISO Date format - * @param {string} tpl - * @param {number} value - * @inner - */ - function formatTime(tpl, value) { - if (tpl === 'week' - || tpl === 'month' - || tpl === 'quarter' - || tpl === 'half-year' - || tpl === 'year' - ) { - tpl = 'MM-dd\nyyyy'; - } - - var date = numberUtil.parseDate(value); - var y = date.getFullYear(); - var M = date.getMonth() + 1; - var d = date.getDate(); - var h = date.getHours(); - var m = date.getMinutes(); - var s = date.getSeconds(); - - tpl = tpl.replace('MM', s2d(M)) - .toLowerCase() - .replace('yyyy', y) - .replace('yy', y % 100) - .replace('dd', s2d(d)) - .replace('d', d) - .replace('hh', s2d(h)) - .replace('h', h) - .replace('mm', s2d(m)) - .replace('m', m) - .replace('ss', s2d(s)) - .replace('s', s); - - return tpl; - } - - /** - * @param {string} str - * @return {string} - * @inner - */ - function s2d(str) { - return str < 10 ? ('0' + str) : str; - } - - module.exports = { - - normalizeCssArray: normalizeCssArray, - - addCommas: addCommas, - - toCamelCase: toCamelCase, - - encodeHTML: encodeHTML, - - formatTpl: formatTpl, - - formatTime: formatTime - }; - - -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { - - var completeDimensions = __webpack_require__(12); - var echarts = __webpack_require__(2); - - echarts.extendSeriesModel({ - - type: 'series.wordCloud', - - visualColorAccessPath: 'textStyle.normal.color', - - optionUpdated: function () { - var option = this.option; - option.gridSize = Math.max(Math.floor(option.gridSize), 4); - }, - - getInitialData: function (option, ecModel) { - var dimensions = completeDimensions(['value'], option.data); - var list = new echarts.List(dimensions, this); - list.initData(option.data); - return list; - }, - - // Most of options are from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md - defaultOption: { - - maskImage: null, - - // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' - shape: 'circle', - - left: 'center', - - top: 'center', - - width: '70%', - - height: '80%', - - sizeRange: [12, 60], - - rotationRange: [-90, 90], - - rotationStep: 45, - - gridSize: 8, - - textStyle: { - normal: { - fontWeight: 'normal' - } - } - } - }); - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - /** - * Complete dimensions by data (guess dimension). - */ - - - var zrUtil = __webpack_require__(4); - - /** - * Complete the dimensions array guessed from the data structure. - * @param {Array.} dimensions Necessary dimensions, like ['x', 'y'] - * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]] - * @param {Array.} defaultNames Default names to fill not necessary dimensions, like ['value'] - * @param {string} extraPrefix Prefix of name when filling the left dimensions. - * @return {Array.} - */ - function completeDimensions(dimensions, data, defaultNames, extraPrefix) { - if (!data) { - return dimensions; - } - - var value0 = retrieveValue(data[0]); - var dimSize = zrUtil.isArray(value0) && value0.length || 1; - - defaultNames = defaultNames || []; - extraPrefix = extraPrefix || 'extra'; - for (var i = 0; i < dimSize; i++) { - if (!dimensions[i]) { - var name = defaultNames[i] || (extraPrefix + (i - defaultNames.length)); - dimensions[i] = guessOrdinal(data, i) - ? {type: 'ordinal', name: name} - : name; - } - } - - return dimensions; - } - - // The rule should not be complex, otherwise user might not - // be able to known where the data is wrong. - function guessOrdinal(data, dimIndex) { - for (var i = 0, len = data.length; i < len; i++) { - var value = retrieveValue(data[i]); - - if (!zrUtil.isArray(value)) { - return false; - } - - var value = value[dimIndex]; - if (value != null && isFinite(value)) { - return false; - } - else if (zrUtil.isString(value) && value !== '-') { - return true; - } - } - return false; - } - - function retrieveValue(o) { - return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o; - } - - module.exports = completeDimensions; - - - -/***/ }, -/* 13 */ -/***/ function(module, exports, __webpack_require__) { - - var echarts = __webpack_require__(2); - - function getShallow(model, path) { - return model && model.getShallow(path); - } - - echarts.extendChartView({ - - type: 'wordCloud', - - render: function (seriesModel, ecModel, api) { - var group = this.group; - group.removeAll(); - - var data = seriesModel.getData(); - - var gridSize = seriesModel.get('gridSize'); - - seriesModel.layoutInstance.ondraw = function (text, size, dataIdx, drawn) { - var itemModel = data.getItemModel(dataIdx); - var textStyleModel = itemModel.getModel('textStyle.normal'); - var emphasisTextStyleModel = itemModel.getModel('textStyle.emphasis'); - - var getFont = function (model, otherModel) { - var ecModel = model.ecModel; - var gTextStyleModel = ecModel && ecModel.getModel('textStyle'); - return ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'].map(function (name, idx) { - if (idx !== 2) { - return model.getShallow(name) - || otherModel.getShallow(name) - || getShallow(gTextStyleModel, name); - } - else { - return ( - model.getShallow(name, true) - || Math.round( - model === textStyleModel - ? size : (otherModel.getShallow(name, true) || size) - ) - ) + 'px'; - } - }).join(' '); - }; - var text = new echarts.graphic.Text({ - style: { - x: drawn.info.fillTextOffsetX, - y: drawn.info.fillTextOffsetY + size * 0.5, - text: text, - textBaseline: 'middle', - font: getFont(textStyleModel, emphasisTextStyleModel) - }, - scale: [1 / drawn.info.mu, 1 / drawn.info.mu], - position: [ - (drawn.gx + drawn.info.gw / 2) * gridSize, - (drawn.gy + drawn.info.gh / 2) * gridSize - ], - rotation: drawn.rot - }); - - text.setStyle(textStyleModel.getItemStyle()); - text.setStyle({ - fill: data.getItemVisual(dataIdx, 'color') - }); - - group.add(text); - - data.setItemGraphicEl(dataIdx, text); - echarts.graphic.setHoverStyle( - text, echarts.util.extend( - emphasisTextStyleModel.getItemStyle(), - { - font: getFont(emphasisTextStyleModel, textStyleModel) - } - ) - ); - }; - } - }); - -/***/ }, -/* 14 */ -/***/ function(module, exports, __webpack_require__) { - - var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - * wordcloud2.js - * http://timdream.org/wordcloud2.js/ - * - * Copyright 2011 - 2013 Tim Chien - * Released under the MIT license - */ - - 'use strict'; - - // setImmediate - if (!window.setImmediate) { - window.setImmediate = (function setupSetImmediate() { - return window.msSetImmediate || - window.webkitSetImmediate || - window.mozSetImmediate || - window.oSetImmediate || - (function setupSetZeroTimeout() { - if (!window.postMessage || !window.addEventListener) { - return null; - } - - var callbacks = [undefined]; - var message = 'zero-timeout-message'; - - // Like setTimeout, but only takes a function argument. There's - // no time argument (always zero) and no arguments (you have to - // use a closure). - var setZeroTimeout = function setZeroTimeout(callback) { - var id = callbacks.length; - callbacks.push(callback); - window.postMessage(message + id.toString(36), '*'); - - return id; - }; - - window.addEventListener('message', function setZeroTimeoutMessage(evt) { - // Skipping checking event source, retarded IE confused this window - // object with another in the presence of iframe - if (typeof evt.data !== 'string' || - evt.data.substr(0, message.length) !== message/* || - evt.source !== window */) { - return; - } - - evt.stopImmediatePropagation(); - - var id = parseInt(evt.data.substr(message.length), 36); - if (!callbacks[id]) { - return; - } - - callbacks[id](); - callbacks[id] = undefined; - }, true); - - /* specify clearImmediate() here since we need the scope */ - window.clearImmediate = function clearZeroTimeout(id) { - if (!callbacks[id]) { - return; - } - - callbacks[id] = undefined; - }; - - return setZeroTimeout; - })() || - // fallback - function setImmediateFallback(fn) { - window.setTimeout(fn, 0); - }; - })(); - } - - if (!window.clearImmediate) { - window.clearImmediate = (function setupClearImmediate() { - return window.msClearImmediate || - window.webkitClearImmediate || - window.mozClearImmediate || - window.oClearImmediate || - // "clearZeroTimeout" is implement on the previous block || - // fallback - function clearImmediateFallback(timer) { - window.clearTimeout(timer); - }; - })(); - } - - (function(global) { - - // Check if WordCloud can run on this browser - var isSupported = (function isSupported() { - var canvas = document.createElement('canvas'); - if (!canvas || !canvas.getContext) { - return false; - } - - var ctx = canvas.getContext('2d'); - if (!ctx.getImageData) { - return false; - } - if (!ctx.fillText) { - return false; - } - - if (!Array.prototype.some) { - return false; - } - if (!Array.prototype.push) { - return false; - } - - return true; - }()); - - // Find out if the browser impose minium font size by - // drawing small texts on a canvas and measure it's width. - var minFontSize = (function getMinFontSize() { - if (!isSupported) { - return; - } - - var ctx = document.createElement('canvas').getContext('2d'); - - // start from 20 - var size = 20; - - // two sizes to measure - var hanWidth, mWidth; - - while (size) { - ctx.font = size.toString(10) + 'px sans-serif'; - if ((ctx.measureText('\uFF37').width === hanWidth) && - (ctx.measureText('m').width) === mWidth) { - return (size + 1); - } - - hanWidth = ctx.measureText('\uFF37').width; - mWidth = ctx.measureText('m').width; - - size--; - } - - return 0; - })(); - - // Based on http://jsfromhell.com/array/shuffle - var shuffleArray = function shuffleArray(arr) { - for (var j, x, i = arr.length; i; - j = Math.floor(Math.random() * i), - x = arr[--i], arr[i] = arr[j], - arr[j] = x) {} - return arr; - }; - - var WordCloud = function WordCloud(elements, options) { - if (!isSupported) { - return; - } - - if (!Array.isArray(elements)) { - elements = [elements]; - } - - elements.forEach(function(el, i) { - if (typeof el === 'string') { - elements[i] = document.getElementById(el); - if (!elements[i]) { - throw 'The element id specified is not found.'; - } - } else if (!el.tagName && !el.appendChild) { - throw 'You must pass valid HTML elements, or ID of the element.'; - } - }); - - /* Default values to be overwritten by options object */ - var settings = { - list: [], - fontFamily: '"Trebuchet MS", "Heiti TC", "微軟正黑體", ' + - '"Arial Unicode MS", "Droid Fallback Sans", sans-serif', - fontWeight: 'normal', - color: 'random-dark', - minSize: 0, // 0 to disable - weightFactor: 1, - clearCanvas: true, - backgroundColor: '#fff', // opaque white = rgba(255, 255, 255, 1) - - gridSize: 8, - drawOutOfBound: false, - origin: null, - - drawMask: false, - maskColor: 'rgba(255,0,0,0.3)', - maskGapWidth: 0.3, - - wait: 0, - abortThreshold: 0, // disabled - abort: function noop() {}, - - minRotation: - Math.PI / 2, - maxRotation: Math.PI / 2, - rotationStep: 0.1, - - shuffle: true, - rotateRatio: 0.1, - - shape: 'circle', - ellipticity: 0.65, - - classes: null, - - hover: null, - click: null - }; - - if (options) { - for (var key in options) { - if (key in settings) { - settings[key] = options[key]; - } - } - } - - /* Convert weightFactor into a function */ - if (typeof settings.weightFactor !== 'function') { - var factor = settings.weightFactor; - settings.weightFactor = function weightFactor(pt) { - return pt * factor; //in px - }; - } - - /* Convert shape into a function */ - if (typeof settings.shape !== 'function') { - switch (settings.shape) { - case 'circle': - /* falls through */ - default: - // 'circle' is the default and a shortcut in the code loop. - settings.shape = 'circle'; - break; - - case 'cardioid': - settings.shape = function shapeCardioid(theta) { - return 1 - Math.sin(theta); - }; - break; - - /* - To work out an X-gon, one has to calculate "m", - where 1/(cos(2*PI/X)+m*sin(2*PI/X)) = 1/(cos(0)+m*sin(0)) - http://www.wolframalpha.com/input/?i=1%2F%28cos%282*PI%2FX%29%2Bm*sin%28 - 2*PI%2FX%29%29+%3D+1%2F%28cos%280%29%2Bm*sin%280%29%29 - Copy the solution into polar equation r = 1/(cos(t') + m*sin(t')) - where t' equals to mod(t, 2PI/X); - */ - - case 'diamond': - case 'square': - // http://www.wolframalpha.com/input/?i=plot+r+%3D+1%2F%28cos%28mod+ - // %28t%2C+PI%2F2%29%29%2Bsin%28mod+%28t%2C+PI%2F2%29%29%29%2C+t+%3D - // +0+..+2*PI - settings.shape = function shapeSquare(theta) { - var thetaPrime = theta % (2 * Math.PI / 4); - return 1 / (Math.cos(thetaPrime) + Math.sin(thetaPrime)); - }; - break; - - case 'triangle-forward': - // http://www.wolframalpha.com/input/?i=plot+r+%3D+1%2F%28cos%28mod+ - // %28t%2C+2*PI%2F3%29%29%2Bsqrt%283%29sin%28mod+%28t%2C+2*PI%2F3%29 - // %29%29%2C+t+%3D+0+..+2*PI - settings.shape = function shapeTriangle(theta) { - var thetaPrime = theta % (2 * Math.PI / 3); - return 1 / (Math.cos(thetaPrime) + - Math.sqrt(3) * Math.sin(thetaPrime)); - }; - break; - - case 'triangle': - case 'triangle-upright': - settings.shape = function shapeTriangle(theta) { - var thetaPrime = (theta + Math.PI * 3 / 2) % (2 * Math.PI / 3); - return 1 / (Math.cos(thetaPrime) + - Math.sqrt(3) * Math.sin(thetaPrime)); - }; - break; - - case 'pentagon': - settings.shape = function shapePentagon(theta) { - var thetaPrime = (theta + 0.955) % (2 * Math.PI / 5); - return 1 / (Math.cos(thetaPrime) + - 0.726543 * Math.sin(thetaPrime)); - }; - break; - - case 'star': - settings.shape = function shapeStar(theta) { - var thetaPrime = (theta + 0.955) % (2 * Math.PI / 10); - if ((theta + 0.955) % (2 * Math.PI / 5) - (2 * Math.PI / 10) >= 0) { - return 1 / (Math.cos((2 * Math.PI / 10) - thetaPrime) + - 3.07768 * Math.sin((2 * Math.PI / 10) - thetaPrime)); - } else { - return 1 / (Math.cos(thetaPrime) + - 3.07768 * Math.sin(thetaPrime)); - } - }; - break; - } - } - - /* Make sure gridSize is a whole number and is not smaller than 4px */ - settings.gridSize = Math.max(Math.floor(settings.gridSize), 4); - - /* shorthand */ - var g = settings.gridSize; - var maskRectWidth = g - settings.maskGapWidth; - - /* normalize rotation settings */ - var rotationRange = Math.abs(settings.maxRotation - settings.minRotation); - var minRotation = Math.min(settings.maxRotation, settings.minRotation); - var rotationStep = settings.rotationStep; - - /* information/object available to all functions, set when start() */ - var grid, // 2d array containing filling information - ngx, ngy, // width and height of the grid - center, // position of the center of the cloud - maxRadius; - - /* timestamp for measuring each putWord() action */ - var escapeTime; - - /* function for getting the color of the text */ - var getTextColor; - function random_hsl_color(min, max) { - return 'hsl(' + - (Math.random() * 360).toFixed() + ',' + - (Math.random() * 30 + 70).toFixed() + '%,' + - (Math.random() * (max - min) + min).toFixed() + '%)'; - } - switch (settings.color) { - case 'random-dark': - getTextColor = function getRandomDarkColor() { - return random_hsl_color(10, 50); - }; - break; - - case 'random-light': - getTextColor = function getRandomLightColor() { - return random_hsl_color(50, 90); - }; - break; - - default: - if (typeof settings.color === 'function') { - getTextColor = settings.color; - } - break; - } - - /* function for getting the classes of the text */ - var getTextClasses = null; - if (typeof settings.classes === 'function') { - getTextClasses = settings.classes; - } - - /* Interactive */ - var interactive = false; - var infoGrid = []; - var hovered; - - var getInfoGridFromMouseTouchEvent = - function getInfoGridFromMouseTouchEvent(evt) { - var canvas = evt.currentTarget; - var rect = canvas.getBoundingClientRect(); - var clientX; - var clientY; - /** Detect if touches are available */ - if (evt.touches) { - clientX = evt.touches[0].clientX; - clientY = evt.touches[0].clientY; - } else { - clientX = evt.clientX; - clientY = evt.clientY; - } - var eventX = clientX - rect.left; - var eventY = clientY - rect.top; - - var x = Math.floor(eventX * ((canvas.width / rect.width) || 1) / g); - var y = Math.floor(eventY * ((canvas.height / rect.height) || 1) / g); - - return infoGrid[x][y]; - }; - - var wordcloudhover = function wordcloudhover(evt) { - var info = getInfoGridFromMouseTouchEvent(evt); - - if (hovered === info) { - return; - } - - hovered = info; - if (!info) { - settings.hover(undefined, undefined, evt); - - return; - } - - settings.hover(info.item, info.dimension, evt); - - }; - - var wordcloudclick = function wordcloudclick(evt) { - var info = getInfoGridFromMouseTouchEvent(evt); - if (!info) { - return; - } - - settings.click(info.item, info.dimension, evt); - evt.preventDefault(); - }; - - /* Get points on the grid for a given radius away from the center */ - var pointsAtRadius = []; - var getPointsAtRadius = function getPointsAtRadius(radius) { - if (pointsAtRadius[radius]) { - return pointsAtRadius[radius]; - } - - // Look for these number of points on each radius - var T = radius * 8; - - // Getting all the points at this radius - var t = T; - var points = []; - - if (radius === 0) { - points.push([center[0], center[1], 0]); - } - - while (t--) { - // distort the radius to put the cloud in shape - var rx = 1; - if (settings.shape !== 'circle') { - rx = settings.shape(t / T * 2 * Math.PI); // 0 to 1 - } - - // Push [x, y, t]; t is used solely for getTextColor() - points.push([ - center[0] + radius * rx * Math.cos(-t / T * 2 * Math.PI), - center[1] + radius * rx * Math.sin(-t / T * 2 * Math.PI) * - settings.ellipticity, - t / T * 2 * Math.PI]); - } - - pointsAtRadius[radius] = points; - return points; - }; - - /* Return true if we had spent too much time */ - var exceedTime = function exceedTime() { - return ((settings.abortThreshold > 0) && - ((new Date()).getTime() - escapeTime > settings.abortThreshold)); - }; - - /* Get the deg of rotation according to settings, and luck. */ - var getRotateDeg = function getRotateDeg() { - if (settings.rotateRatio === 0) { - return 0; - } - - if (Math.random() > settings.rotateRatio) { - return 0; - } - - if (rotationRange === 0) { - return minRotation; - } - - return minRotation + Math.round(Math.random() * rotationRange / rotationStep) * rotationStep; - }; - - var getTextInfo = function getTextInfo(word, weight, rotateDeg) { - // calculate the acutal font size - // fontSize === 0 means weightFactor function wants the text skipped, - // and size < minSize means we cannot draw the text. - var debug = false; - var fontSize = settings.weightFactor(weight); - if (fontSize <= settings.minSize) { - return false; - } - - // Scale factor here is to make sure fillText is not limited by - // the minium font size set by browser. - // It will always be 1 or 2n. - var mu = 1; - if (fontSize < minFontSize) { - mu = (function calculateScaleFactor() { - var mu = 2; - while (mu * fontSize < minFontSize) { - mu += 2; - } - return mu; - })(); - } - - var fcanvas = document.createElement('canvas'); - var fctx = fcanvas.getContext('2d', { willReadFrequently: true }); - - fctx.font = settings.fontWeight + ' ' + - (fontSize * mu).toString(10) + 'px ' + settings.fontFamily; - - // Estimate the dimension of the text with measureText(). - var fw = fctx.measureText(word).width / mu; - var fh = Math.max(fontSize * mu, - fctx.measureText('m').width, - fctx.measureText('\uFF37').width) / mu; - - // Create a boundary box that is larger than our estimates, - // so text don't get cut of (it sill might) - var boxWidth = fw + fh * 2; - var boxHeight = fh * 3; - var fgw = Math.ceil(boxWidth / g); - var fgh = Math.ceil(boxHeight / g); - boxWidth = fgw * g; - boxHeight = fgh * g; - - // Calculate the proper offsets to make the text centered at - // the preferred position. - - // This is simply half of the width. - var fillTextOffsetX = - fw / 2; - // Instead of moving the box to the exact middle of the preferred - // position, for Y-offset we move 0.4 instead, so Latin alphabets look - // vertical centered. - var fillTextOffsetY = - fh * 0.4; - - // Calculate the actual dimension of the canvas, considering the rotation. - var cgh = Math.ceil((boxWidth * Math.abs(Math.sin(rotateDeg)) + - boxHeight * Math.abs(Math.cos(rotateDeg))) / g); - var cgw = Math.ceil((boxWidth * Math.abs(Math.cos(rotateDeg)) + - boxHeight * Math.abs(Math.sin(rotateDeg))) / g); - var width = cgw * g; - var height = cgh * g; - - fcanvas.setAttribute('width', width); - fcanvas.setAttribute('height', height); - - if (debug) { - // Attach fcanvas to the DOM - document.body.appendChild(fcanvas); - // Save it's state so that we could restore and draw the grid correctly. - fctx.save(); - } - - // Scale the canvas with |mu|. - fctx.scale(1 / mu, 1 / mu); - fctx.translate(width * mu / 2, height * mu / 2); - fctx.rotate(- rotateDeg); - - // Once the width/height is set, ctx info will be reset. - // Set it again here. - fctx.font = settings.fontWeight + ' ' + - (fontSize * mu).toString(10) + 'px ' + settings.fontFamily; - - // Fill the text into the fcanvas. - // XXX: We cannot because textBaseline = 'top' here because - // Firefox and Chrome uses different default line-height for canvas. - // Please read https://bugzil.la/737852#c6. - // Here, we use textBaseline = 'middle' and draw the text at exactly - // 0.5 * fontSize lower. - fctx.fillStyle = '#000'; - fctx.textBaseline = 'middle'; - fctx.fillText(word, fillTextOffsetX * mu, - (fillTextOffsetY + fontSize * 0.5) * mu); - - // Get the pixels of the text - var imageData = fctx.getImageData(0, 0, width, height).data; - - if (exceedTime()) { - return false; - } - - if (debug) { - // Draw the box of the original estimation - fctx.strokeRect(fillTextOffsetX * mu, - fillTextOffsetY, fw * mu, fh * mu); - fctx.restore(); - } - - // Read the pixels and save the information to the occupied array - var occupied = []; - var gx = cgw, gy, x, y; - var bounds = [cgh / 2, cgw / 2, cgh / 2, cgw / 2]; - while (gx--) { - gy = cgh; - while (gy--) { - y = g; - singleGridLoop: { - while (y--) { - x = g; - while (x--) { - if (imageData[((gy * g + y) * width + - (gx * g + x)) * 4 + 3]) { - occupied.push([gx, gy]); - - if (gx < bounds[3]) { - bounds[3] = gx; - } - if (gx > bounds[1]) { - bounds[1] = gx; - } - if (gy < bounds[0]) { - bounds[0] = gy; - } - if (gy > bounds[2]) { - bounds[2] = gy; - } - - if (debug) { - fctx.fillStyle = 'rgba(255, 0, 0, 0.5)'; - fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5); - } - break singleGridLoop; - } - } - } - if (debug) { - fctx.fillStyle = 'rgba(0, 0, 255, 0.5)'; - fctx.fillRect(gx * g, gy * g, g - 0.5, g - 0.5); - } - } - } - } - - if (debug) { - fctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; - fctx.fillRect(bounds[3] * g, - bounds[0] * g, - (bounds[1] - bounds[3] + 1) * g, - (bounds[2] - bounds[0] + 1) * g); - } - - // Return information needed to create the text on the real canvas - return { - mu: mu, - occupied: occupied, - bounds: bounds, - gw: cgw, - gh: cgh, - fillTextOffsetX: fillTextOffsetX, - fillTextOffsetY: fillTextOffsetY, - fillTextWidth: fw, - fillTextHeight: fh, - fontSize: fontSize - }; - }; - - /* Determine if there is room available in the given dimension */ - var canFitText = function canFitText(gx, gy, gw, gh, occupied) { - // Go through the occupied points, - // return false if the space is not available. - var i = occupied.length; - while (i--) { - var px = gx + occupied[i][0]; - var py = gy + occupied[i][1]; - - if (px >= ngx || py >= ngy || px < 0 || py < 0) { - if (!settings.drawOutOfBound) { - return false; - } - continue; - } - - if (!grid[px][py]) { - return false; - } - } - return true; - }; - - /* Actually draw the text on the grid */ - var drawText = function drawText(gx, gy, info, word, weight, - distance, theta, rotateDeg, attributes) { - - var fontSize = info.fontSize; - var color; - if (getTextColor) { - color = getTextColor(word, weight, fontSize, distance, theta); - } else { - color = settings.color; - } - - var classes; - if (getTextClasses) { - classes = getTextClasses(word, weight, fontSize, distance, theta); - } else { - classes = settings.classes; - } - - var dimension; - var bounds = info.bounds; - dimension = { - x: (gx + bounds[3]) * g, - y: (gy + bounds[0]) * g, - w: (bounds[1] - bounds[3] + 1) * g, - h: (bounds[2] - bounds[0] + 1) * g - }; - - elements.forEach(function(el) { - if (el.getContext) { - var ctx = el.getContext('2d'); - var mu = info.mu; - - // Save the current state before messing it - ctx.save(); - ctx.scale(1 / mu, 1 / mu); - - ctx.font = settings.fontWeight + ' ' + - (fontSize * mu).toString(10) + 'px ' + settings.fontFamily; - ctx.fillStyle = color; - - // Translate the canvas position to the origin coordinate of where - // the text should be put. - ctx.translate((gx + info.gw / 2) * g * mu, - (gy + info.gh / 2) * g * mu); - - if (rotateDeg !== 0) { - ctx.rotate(- rotateDeg); - } - - // Finally, fill the text. - - // XXX: We cannot because textBaseline = 'top' here because - // Firefox and Chrome uses different default line-height for canvas. - // Please read https://bugzil.la/737852#c6. - // Here, we use textBaseline = 'middle' and draw the text at exactly - // 0.5 * fontSize lower. - ctx.textBaseline = 'middle'; - ctx.fillText(word, info.fillTextOffsetX * mu, - (info.fillTextOffsetY + fontSize * 0.5) * mu); - - // The below box is always matches how s are positioned - /* ctx.strokeRect(info.fillTextOffsetX, info.fillTextOffsetY, - info.fillTextWidth, info.fillTextHeight); */ - - // Restore the state. - ctx.restore(); - } else { - // drawText on DIV element - var span = document.createElement('span'); - var transformRule = ''; - transformRule = 'rotate(' + (- rotateDeg / Math.PI * 180) + 'deg) '; - if (info.mu !== 1) { - transformRule += - 'translateX(-' + (info.fillTextWidth / 4) + 'px) ' + - 'scale(' + (1 / info.mu) + ')'; - } - var styleRules = { - 'position': 'absolute', - 'display': 'block', - 'font': settings.fontWeight + ' ' + - (fontSize * info.mu) + 'px ' + settings.fontFamily, - 'left': ((gx + info.gw / 2) * g + info.fillTextOffsetX) + 'px', - 'top': ((gy + info.gh / 2) * g + info.fillTextOffsetY) + 'px', - 'width': info.fillTextWidth + 'px', - 'height': info.fillTextHeight + 'px', - 'lineHeight': fontSize + 'px', - 'whiteSpace': 'nowrap', - 'transform': transformRule, - 'webkitTransform': transformRule, - 'msTransform': transformRule, - 'transformOrigin': '50% 40%', - 'webkitTransformOrigin': '50% 40%', - 'msTransformOrigin': '50% 40%' - }; - if (color) { - styleRules.color = color; - } - span.textContent = word; - for (var cssProp in styleRules) { - span.style[cssProp] = styleRules[cssProp]; - } - if (attributes) { - for (var attribute in attributes) { - span.setAttribute(attribute, attributes[attribute]); - } - } - if (classes) { - span.className += classes; - } - el.appendChild(span); - } - }); - }; - - /* Help function to updateGrid */ - var fillGridAt = function fillGridAt(x, y, drawMask, dimension, item) { - if (x >= ngx || y >= ngy || x < 0 || y < 0) { - return; - } - - grid[x][y] = false; - - if (drawMask) { - var ctx = elements[0].getContext('2d'); - ctx.fillRect(x * g, y * g, maskRectWidth, maskRectWidth); - } - - if (interactive) { - infoGrid[x][y] = { item: item, dimension: dimension }; - } - }; - - /* Update the filling information of the given space with occupied points. - Draw the mask on the canvas if necessary. */ - var updateGrid = function updateGrid(gx, gy, gw, gh, info, item) { - var occupied = info.occupied; - var drawMask = settings.drawMask; - var ctx; - if (drawMask) { - ctx = elements[0].getContext('2d'); - ctx.save(); - ctx.fillStyle = settings.maskColor; - } - - var dimension; - if (interactive) { - var bounds = info.bounds; - dimension = { - x: (gx + bounds[3]) * g, - y: (gy + bounds[0]) * g, - w: (bounds[1] - bounds[3] + 1) * g, - h: (bounds[2] - bounds[0] + 1) * g - }; - } - - var i = occupied.length; - while (i--) { - var px = gx + occupied[i][0]; - var py = gy + occupied[i][1]; - - if (px >= ngx || py >= ngy || px < 0 || py < 0) { - continue; - } - - fillGridAt(px, py, drawMask, dimension, item); - } - - if (drawMask) { - ctx.restore(); - } - }; - - /* putWord() processes each item on the list, - calculate it's size and determine it's position, and actually - put it on the canvas. */ - var putWord = function putWord(item) { - var word, weight, attributes; - if (Array.isArray(item)) { - word = item[0]; - weight = item[1]; - } else { - word = item.word; - weight = item.weight; - attributes = item.attributes; - } - var rotateDeg = getRotateDeg(); - - // get info needed to put the text onto the canvas - var info = getTextInfo(word, weight, rotateDeg); - - // not getting the info means we shouldn't be drawing this one. - if (!info) { - return false; - } - - if (exceedTime()) { - return false; - } - - // If drawOutOfBound is set to false, - // skip the loop if we have already know the bounding box of - // word is larger than the canvas. - if (!settings.drawOutOfBound) { - var bounds = info.bounds; - if ((bounds[1] - bounds[3] + 1) > ngx || - (bounds[2] - bounds[0] + 1) > ngy) { - return false; - } - } - - // Determine the position to put the text by - // start looking for the nearest points - var r = maxRadius + 1; - - var tryToPutWordAtPoint = function(gxy) { - var gx = Math.floor(gxy[0] - info.gw / 2); - var gy = Math.floor(gxy[1] - info.gh / 2); - var gw = info.gw; - var gh = info.gh; - - // If we cannot fit the text at this position, return false - // and go to the next position. - if (!canFitText(gx, gy, gw, gh, info.occupied)) { - return false; - } - - // Actually put the text on the canvas - drawText(gx, gy, info, word, weight, - (maxRadius - r), gxy[2], rotateDeg, attributes); - - // Mark the spaces on the grid as filled - updateGrid(gx, gy, gw, gh, info, item); - - return { - gx: gx, - gy: gy, - rot: rotateDeg, - info: info - }; - }; - - while (r--) { - var points = getPointsAtRadius(maxRadius - r); - - if (settings.shuffle) { - points = [].concat(points); - shuffleArray(points); - } - - // Try to fit the words by looking at each point. - // array.some() will stop and return true - // when putWordAtPoint() returns true. - for (var i = 0; i < points.length; i++) { - var res = tryToPutWordAtPoint(points[i]); - if (res) { - return res; - } - } - - // var drawn = points.some(tryToPutWordAtPoint); - // if (drawn) { - // // leave putWord() and return true - // return true; - // } - } - // we tried all distances but text won't fit, return null - return null; - }; - - /* Send DOM event to all elements. Will stop sending event and return - if the previous one is canceled (for cancelable events). */ - var sendEvent = function sendEvent(type, cancelable, detail) { - if (cancelable) { - return !elements.some(function(el) { - var evt = document.createEvent('CustomEvent'); - evt.initCustomEvent(type, true, cancelable, detail || {}); - return !el.dispatchEvent(evt); - }, this); - } else { - elements.forEach(function(el) { - var evt = document.createEvent('CustomEvent'); - evt.initCustomEvent(type, true, cancelable, detail || {}); - el.dispatchEvent(evt); - }, this); - } - }; - - /* Start drawing on a canvas */ - var start = function start() { - // For dimensions, clearCanvas etc., - // we only care about the first element. - var canvas = elements[0]; - - if (canvas.getContext) { - ngx = Math.ceil(canvas.width / g); - ngy = Math.ceil(canvas.height / g); - } else { - var rect = canvas.getBoundingClientRect(); - ngx = Math.ceil(rect.width / g); - ngy = Math.ceil(rect.height / g); - } - - // Sending a wordcloudstart event which cause the previous loop to stop. - // Do nothing if the event is canceled. - if (!sendEvent('wordcloudstart', true)) { - return; - } - - // Determine the center of the word cloud - center = (settings.origin) ? - [settings.origin[0]/g, settings.origin[1]/g] : - [ngx / 2, ngy / 2]; - - // Maxium radius to look for space - maxRadius = Math.floor(Math.sqrt(ngx * ngx + ngy * ngy)); - - /* Clear the canvas only if the clearCanvas is set, - if not, update the grid to the current canvas state */ - grid = []; - - var gx, gy, i; - if (!canvas.getContext || settings.clearCanvas) { - elements.forEach(function(el) { - if (el.getContext) { - var ctx = el.getContext('2d'); - ctx.fillStyle = settings.backgroundColor; - ctx.clearRect(0, 0, ngx * (g + 1), ngy * (g + 1)); - ctx.fillRect(0, 0, ngx * (g + 1), ngy * (g + 1)); - } else { - el.textContent = ''; - el.style.backgroundColor = settings.backgroundColor; - el.style.position = 'relative'; - } - }); - - /* fill the grid with empty state */ - gx = ngx; - while (gx--) { - grid[gx] = []; - gy = ngy; - while (gy--) { - grid[gx][gy] = true; - } - } - } else { - /* Determine bgPixel by creating - another canvas and fill the specified background color. */ - var bctx = document.createElement('canvas').getContext('2d'); - - bctx.fillStyle = settings.backgroundColor; - bctx.fillRect(0, 0, 1, 1); - var bgPixel = bctx.getImageData(0, 0, 1, 1).data; - - /* Read back the pixels of the canvas we got to tell which part of the - canvas is empty. - (no clearCanvas only works with a canvas, not divs) */ - var imageData = - canvas.getContext('2d').getImageData(0, 0, ngx * g, ngy * g).data; - - gx = ngx; - var x, y; - while (gx--) { - grid[gx] = []; - gy = ngy; - while (gy--) { - y = g; - singleGridLoop: while (y--) { - x = g; - while (x--) { - i = 4; - while (i--) { - if (imageData[((gy * g + y) * ngx * g + - (gx * g + x)) * 4 + i] !== bgPixel[i]) { - grid[gx][gy] = false; - break singleGridLoop; - } - } - } - } - if (grid[gx][gy] !== false) { - grid[gx][gy] = true; - } - } - } - - imageData = bctx = bgPixel = undefined; - } - - // fill the infoGrid with empty state if we need it - if (settings.hover || settings.click) { - - interactive = true; - - /* fill the grid with empty state */ - gx = ngx + 1; - while (gx--) { - infoGrid[gx] = []; - } - - if (settings.hover) { - canvas.addEventListener('mousemove', wordcloudhover); - } - - if (settings.click) { - canvas.addEventListener('click', wordcloudclick); - canvas.addEventListener('touchstart', wordcloudclick); - canvas.addEventListener('touchend', function (e) { - e.preventDefault(); - }); - canvas.style.webkitTapHighlightColor = 'rgba(0, 0, 0, 0)'; - } - - canvas.addEventListener('wordcloudstart', function stopInteraction() { - canvas.removeEventListener('wordcloudstart', stopInteraction); - - canvas.removeEventListener('mousemove', wordcloudhover); - canvas.removeEventListener('click', wordcloudclick); - hovered = undefined; - }); - } - - i = 0; - var loopingFunction, stoppingFunction; - if (settings.wait !== 0) { - loopingFunction = window.setTimeout; - stoppingFunction = window.clearTimeout; - } else { - loopingFunction = window.setImmediate; - stoppingFunction = window.clearImmediate; - } - - var addEventListener = function addEventListener(type, listener) { - elements.forEach(function(el) { - el.addEventListener(type, listener); - }, this); - }; - - var removeEventListener = function removeEventListener(type, listener) { - elements.forEach(function(el) { - el.removeEventListener(type, listener); - }, this); - }; - - var anotherWordCloudStart = function anotherWordCloudStart() { - removeEventListener('wordcloudstart', anotherWordCloudStart); - stoppingFunction(timer); - }; - - addEventListener('wordcloudstart', anotherWordCloudStart); - - var timer = loopingFunction(function loop() { - if (i >= settings.list.length) { - stoppingFunction(timer); - sendEvent('wordcloudstop', false); - removeEventListener('wordcloudstart', anotherWordCloudStart); - - return; - } - escapeTime = (new Date()).getTime(); - var drawn = putWord(settings.list[i]); - var canceled = !sendEvent('wordclouddrawn', true, { - item: settings.list[i], drawn: drawn }); - if (exceedTime() || canceled) { - stoppingFunction(timer); - settings.abort(); - sendEvent('wordcloudabort', false); - sendEvent('wordcloudstop', false); - removeEventListener('wordcloudstart', anotherWordCloudStart); - return; - } - i++; - timer = loopingFunction(loop, settings.wait); - }, settings.wait); - }; - - // All set, start the drawing - start(); - }; - - WordCloud.isSupported = isSupported; - WordCloud.minFontSize = minFontSize; - - // Expose the library as an AMD module - if (true) { - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { return WordCloud; }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = WordCloud; - } else { - global.WordCloud = WordCloud; - } - - })(this); //jshint ignore:line - -/***/ } -/******/ ]) -}); -; \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("echarts")):"function"==typeof define&&define.amd?define(["echarts"],e):"object"==typeof exports?exports["echarts-wordcloud"]=e(require("echarts")):t["echarts-wordcloud"]=e(t.echarts)}(this,function(t){return function(t){function e(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(14)},function(t,e,r){function n(t){if("object"==typeof t&&null!==t){var e=t;if(t instanceof Array){e=[];for(var r=0,a=t.length;a>r;r++)e[r]=n(t[r])}else if(!I(t)&&!T(t)){e={};for(var i in t)t.hasOwnProperty(i)&&(e[i]=n(t[i]))}return e}return t}function a(t,e,r){if(!C(e)||!C(t))return r?n(e):t;for(var i in e)if(e.hasOwnProperty(i)){var o=t[i],u=e[i];!C(u)||!C(o)||M(u)||M(o)||T(u)||T(o)||I(u)||I(o)?!r&&i in t||(t[i]=n(e[i],!0)):a(o,u,r)}return t}function i(t,e){for(var r=t[0],n=1,i=t.length;i>n;n++)r=a(r,t[n],e);return r}function o(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function u(t,e,r){for(var n in e)e.hasOwnProperty(n)&&(r?null!=e[n]:null==t[n])&&(t[n]=e[n]);return t}function c(){return document.createElement("canvas")}function l(){return A||(A=W.createCanvas().getContext("2d")),A}function s(t,e){if(t){if(t.indexOf)return t.indexOf(e);for(var r=0,n=t.length;n>r;r++)if(t[r]===e)return r}return-1}function f(t,e){function r(){}var n=t.prototype;r.prototype=e.prototype,t.prototype=new r;for(var a in n)t.prototype[a]=n[a];t.prototype.constructor=t,t.superClass=e}function h(t,e,r){t="prototype"in t?t.prototype:t,e="prototype"in e?e.prototype:e,u(t,e,r)}function d(t){return t?"string"==typeof t?!1:"number"==typeof t.length:void 0}function g(t,e,r){if(t&&e)if(t.forEach&&t.forEach===z)t.forEach(e,r);else if(t.length===+t.length)for(var n=0,a=t.length;a>n;n++)e.call(r,t[n],n,t);else for(var i in t)t.hasOwnProperty(i)&&e.call(r,t[i],i,t)}function m(t,e,r){if(t&&e){if(t.map&&t.map===q)return t.map(e,r);for(var n=[],a=0,i=t.length;i>a;a++)n.push(e.call(r,t[a],a,t));return n}}function p(t,e,r,n){if(t&&e){if(t.reduce&&t.reduce===j)return t.reduce(e,r,n);for(var a=0,i=t.length;i>a;a++)r=e.call(n,r,t[a],a,t);return r}}function v(t,e,r){if(t&&e){if(t.filter&&t.filter===L)return t.filter(e,r);for(var n=[],a=0,i=t.length;i>a;a++)e.call(r,t[a],a,t)&&n.push(t[a]);return n}}function y(t,e,r){if(t&&e)for(var n=0,a=t.length;a>n;n++)if(e.call(r,t[n],n,t))return t[n]}function w(t,e){var r=D.call(arguments,2);return function(){return t.apply(e,r.concat(D.call(arguments)))}}function x(t){var e=D.call(arguments,1);return function(){return t.apply(this,e.concat(D.call(arguments)))}}function M(t){return"[object Array]"===R.call(t)}function b(t){return"function"==typeof t}function S(t){return"[object String]"===R.call(t)}function C(t){var e=typeof t;return"function"===e||!!t&&"object"==e}function I(t){return!!P[R.call(t)]||t instanceof F}function T(t){return t&&1===t.nodeType&&"string"==typeof t.nodeName}function N(t){for(var e=0,r=arguments.length;r>e;e++)if(null!=arguments[e])return arguments[e]}function E(){return Function.call.apply(D,arguments)}function k(t,e){if(!t)throw new Error(e)}var A,F=r(10),P={"[object Function]":1,"[object RegExp]":1,"[object Date]":1,"[object Error]":1,"[object CanvasGradient]":1},R=Object.prototype.toString,O=Array.prototype,z=O.forEach,L=O.filter,D=O.slice,q=O.map,j=O.reduce,W={inherits:f,mixin:h,clone:n,merge:a,mergeAll:i,extend:o,defaults:u,getContext:l,createCanvas:c,indexOf:s,slice:E,find:y,isArrayLike:d,each:g,map:m,reduce:p,filter:v,bind:w,curry:x,isArray:M,isString:S,isObject:C,isFunction:b,isBuildInObject:I,isDom:T,retrieve:N,assert:k,noop:function(){}};t.exports=W},function(e,r){e.exports=t},function(t,e){function r(t){return t.replace(/^\s+/,"").replace(/\s+$/,"")}var n={},a=1e-4;n.linearMap=function(t,e,r,n){var a=e[1]-e[0],i=r[1]-r[0];if(0===a)return 0===i?r[0]:(r[0]+r[1])/2;if(n)if(a>0){if(t<=e[0])return r[0];if(t>=e[1])return r[1]}else{if(t>=e[0])return r[0];if(t<=e[1])return r[1]}else{if(t===e[0])return r[0];if(t===e[1])return r[1]}return(t-e[0])/a*i+r[0]},n.parsePercent=function(t,e){switch(t){case"center":case"middle":t="50%";break;case"left":case"top":t="0%";break;case"right":case"bottom":t="100%"}return"string"==typeof t?r(t).match(/%$/)?parseFloat(t)/100*e:parseFloat(t):null==t?NaN:+t},n.round=function(t){return+(+t).toFixed(10)},n.asc=function(t){return t.sort(function(t,e){return t-e}),t},n.getPrecision=function(t){if(isNaN(t))return 0;for(var e=1,r=0;Math.round(t*e)/e!==t;)e*=10,r++;return r},n.getPixelPrecision=function(t,e){var r=Math.log,n=Math.LN10,a=Math.floor(r(t[1]-t[0])/n),i=Math.round(r(Math.abs(e[1]-e[0]))/n);return Math.max(-a+i,0)},n.MAX_SAFE_INTEGER=9007199254740991,n.remRadian=function(t){var e=2*Math.PI;return(t%e+e)%e},n.isRadianAroundZero=function(t){return t>-a&&a>t},n.parseDate=function(t){return t instanceof Date?t:new Date("string"==typeof t?t.replace(/-/g,"/"):Math.round(t))},n.quantity=function(t){return Math.pow(10,Math.floor(Math.log(t)/Math.LN10))},n.nice=function(t,e){var r,a=n.quantity(t),i=t/a;return r=e?1.5>i?1:2.5>i?2:4>i?3:7>i?5:10:1>i?1:2>i?2:3>i?3:5>i?5:10,r*a},t.exports=n},function(t,e,r){function n(t,e,r,n){if(!e)return t;var u=i(e[0]),c=o.isArray(u)&&u.length||1;r=r||[],n=n||"extra";for(var l=0;c>l;l++)if(!t[l]){var s=r[l]||n+(l-r.length);t[l]=a(e,l)?{type:"ordinal",name:s}:s}return t}function a(t,e){for(var r=0,n=t.length;n>r;r++){var a=i(t[r]);if(!o.isArray(a))return!1;var a=a[e];if(null!=a&&isFinite(a))return!1;if(o.isString(a)&&"-"!==a)return!0}return!1}function i(t){return o.isArray(t)?t:o.isObject(t)?t.value:t}var o=r(1);t.exports=n},function(t,e,r){function n(t){return isNaN(t)?"-":(t=(t+"").split("."),t[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,"$1,")+(t.length>1?"."+t[1]:""))}function a(t){return t.toLowerCase().replace(/-(.)/g,function(t,e){return e.toUpperCase()})}function i(t){var e=t.length;return"number"==typeof t?[t,t,t,t]:2===e?[t[0],t[1],t[0],t[1]]:3===e?[t[0],t[1],t[2],t[1]]:t}function o(t){return String(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function u(t,e){return"{"+t+(null==e?"":e)+"}"}function c(t,e){f.isArray(e)||(e=[e]);var r=e.length;if(!r)return"";for(var n=e[0].$vars,a=0;ao;o++)for(var c=0;ct?"0"+t:t}var f=r(1),h=r(3),d=["a","b","c","d","e","f","g"];t.exports={normalizeCssArray:i,addCommas:n,toCamelCase:a,encodeHTML:o,formatTpl:c,formatTime:l}},function(t,e,r){"use strict";function n(t,e,r,n,a){var i=0,o=0;null==n&&(n=1/0),null==a&&(a=1/0);var u=0;e.eachChild(function(c,l){var s,f,h=c.position,d=c.getBoundingRect(),g=e.childAt(l+1),m=g&&g.getBoundingRect();if("horizontal"===t){var p=d.width+(m?-m.x+d.x:0);s=i+p,s>n||c.newline?(i=0,s=p,o+=u+r,u=d.height):u=Math.max(u,d.height)}else{var v=d.height+(m?-m.y+d.y:0);f=o+v,f>a||c.newline?(i+=u+r,o=0,f=v,u=d.width):u=Math.max(u,d.width)}c.newline||(h[0]=i,h[1]=o,"horizontal"===t?i=s+r:o=f+r)})}var a=r(1),i=r(7),o=r(3),u=r(5),c=o.parsePercent,l=a.each,s={},f=["left","right","top","bottom","width","height"];s.box=n,s.vbox=a.curry(n,"vertical"),s.hbox=a.curry(n,"horizontal"),s.getAvailableSize=function(t,e,r){var n=e.width,a=e.height,i=c(t.x,n),o=c(t.y,a),l=c(t.x2,n),s=c(t.y2,a);return(isNaN(i)||isNaN(parseFloat(t.x)))&&(i=0),(isNaN(l)||isNaN(parseFloat(t.x2)))&&(l=n),(isNaN(o)||isNaN(parseFloat(t.y)))&&(o=0),(isNaN(s)||isNaN(parseFloat(t.y2)))&&(s=a),r=u.normalizeCssArray(r||0),{width:Math.max(l-i-r[1]-r[3],0),height:Math.max(s-o-r[0]-r[2],0)}},s.getLayoutRect=function(t,e,r){r=u.normalizeCssArray(r||0);var n=e.width,a=e.height,o=c(t.left,n),l=c(t.top,a),s=c(t.right,n),f=c(t.bottom,a),h=c(t.width,n),d=c(t.height,a),g=r[2]+r[0],m=r[1]+r[3],p=t.aspect;switch(isNaN(h)&&(h=n-s-m-o),isNaN(d)&&(d=a-f-g-l),isNaN(h)&&isNaN(d)&&(p>n/a?h=.8*n:d=.8*a),null!=p&&(isNaN(h)&&(h=p*d),isNaN(d)&&(d=h/p)),isNaN(o)&&(o=n-s-h-m),isNaN(l)&&(l=a-f-d-g),t.left||t.right){case"center":o=n/2-h/2-r[3];break;case"right":o=n-h-m}switch(t.top||t.bottom){case"middle":case"center":l=a/2-d/2-r[0];break;case"bottom":l=a-d-g}o=o||0,l=l||0,isNaN(h)&&(h=n-o-(s||0)),isNaN(d)&&(d=a-l-(f||0));var v=new i(o+r[3],l+r[0],h,d);return v.margin=r,v},s.positionGroup=function(t,e,r,n){var i=t.getBoundingRect();e=a.extend(a.clone(e),{width:i.width,height:i.height}),e=s.getLayoutRect(e,r,n),t.position=[e.x-i.x,e.y-i.y]},s.mergeLayoutParam=function(t,e,r){function n(n){var a={},u=0,c={},s=0,f=r.ignoreSize?1:2;if(l(n,function(e){c[e]=t[e]}),l(n,function(t){i(e,t)&&(a[t]=c[t]=e[t]),o(a,t)&&u++,o(c,t)&&s++}),s!==f&&u){if(u>=f)return a;for(var h=0;hn||r>u||c>i||a>l)},contain:function(t,e){var r=this;return t>=r.x&&t<=r.x+r.width&&e>=r.y&&e<=r.y+r.height},clone:function(){return new n(this.x,this.y,this.width,this.height)},copy:function(t){this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}},t.exports=n},function(t,e){var r="undefined"==typeof Float32Array?Array:Float32Array,n={create:function(){var t=new r(6);return n.identity(t),t},identity:function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},mul:function(t,e,r){var n=e[0]*r[0]+e[2]*r[1],a=e[1]*r[0]+e[3]*r[1],i=e[0]*r[2]+e[2]*r[3],o=e[1]*r[2]+e[3]*r[3],u=e[0]*r[4]+e[2]*r[5]+e[4],c=e[1]*r[4]+e[3]*r[5]+e[5];return t[0]=n,t[1]=a,t[2]=i,t[3]=o,t[4]=u,t[5]=c,t},translate:function(t,e,r){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4]+r[0],t[5]=e[5]+r[1],t},rotate:function(t,e,r){var n=e[0],a=e[2],i=e[4],o=e[1],u=e[3],c=e[5],l=Math.sin(r),s=Math.cos(r);return t[0]=n*s+o*l,t[1]=-n*l+o*s,t[2]=a*s+u*l,t[3]=-a*l+s*u,t[4]=s*i+l*c,t[5]=s*c-l*i,t},scale:function(t,e,r){var n=r[0],a=r[1];return t[0]=e[0]*n,t[1]=e[1]*a,t[2]=e[2]*n,t[3]=e[3]*a,t[4]=e[4]*n,t[5]=e[5]*a,t},invert:function(t,e){var r=e[0],n=e[2],a=e[4],i=e[1],o=e[3],u=e[5],c=r*o-i*n;return c?(c=1/c,t[0]=o*c,t[1]=-i*c,t[2]=-n*c,t[3]=r*c,t[4]=(n*u-o*a)*c,t[5]=(i*a-r*u)*c,t):null}};t.exports=n},function(t,e){var r="undefined"==typeof Float32Array?Array:Float32Array,n={create:function(t,e){var n=new r(2);return n[0]=t||0,n[1]=e||0,n},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t},clone:function(t){var e=new r(2);return e[0]=t[0],e[1]=t[1],e},set:function(t,e,r){return t[0]=e,t[1]=r,t},add:function(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t},scaleAndAdd:function(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t},sub:function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t},len:function(t){return Math.sqrt(this.lenSquare(t))},lenSquare:function(t){return t[0]*t[0]+t[1]*t[1]},mul:function(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t},div:function(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t},dot:function(t,e){return t[0]*e[0]+t[1]*e[1]},scale:function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t},normalize:function(t,e){var r=n.len(e);return 0===r?(t[0]=0,t[1]=0):(t[0]=e[0]/r,t[1]=e[1]/r),t},distance:function(t,e){return Math.sqrt((t[0]-e[0])*(t[0]-e[0])+(t[1]-e[1])*(t[1]-e[1]))},distanceSquare:function(t,e){return(t[0]-e[0])*(t[0]-e[0])+(t[1]-e[1])*(t[1]-e[1])},negate:function(t,e){return t[0]=-e[0],t[1]=-e[1],t},lerp:function(t,e,r,n){return t[0]=e[0]+n*(r[0]-e[0]),t[1]=e[1]+n*(r[1]-e[1]),t},applyTransform:function(t,e,r){var n=e[0],a=e[1];return t[0]=r[0]*n+r[2]*a+r[4],t[1]=r[1]*n+r[3]*a+r[5],t},min:function(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t},max:function(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t}};n.length=n.len,n.lengthSquare=n.lenSquare,n.dist=n.distance,n.distSquare=n.distanceSquare,t.exports=n},function(t,e){var r=function(t){this.colorStops=t||[]};r.prototype={constructor:r,addColorStop:function(t,e){this.colorStops.push({offset:t,color:e})}},t.exports=r},function(t,e,r){var n=r(4),a=r(2);a.extendSeriesModel({type:"series.wordCloud",visualColorAccessPath:"textStyle.normal.color",optionUpdated:function(){var t=this.option;t.gridSize=Math.max(Math.floor(t.gridSize),4)},getInitialData:function(t,e){var r=n(["value"],t.data),i=new a.List(r,this);return i.initData(t.data),i},defaultOption:{maskImage:null,shape:"circle",left:"center",top:"center",width:"70%",height:"80%",sizeRange:[12,60],rotationRange:[-90,90],rotationStep:45,gridSize:8,textStyle:{normal:{fontWeight:"normal"}}}})},function(t,e,r){function n(t,e){return t&&t.getShallow(e)}var a=r(2);a.extendChartView({type:"wordCloud",render:function(t,e,r){var i=this.group;i.removeAll();var o=t.getData(),u=t.get("gridSize");t.layoutInstance.ondraw=function(t,e,r,c){var l=o.getItemModel(r),s=l.getModel("textStyle.normal"),f=l.getModel("textStyle.emphasis"),h=function(t,r){var a=t.ecModel,i=a&&a.getModel("textStyle");return["fontStyle","fontWeight","fontSize","fontFamily"].map(function(a,o){return 2!==o?t.getShallow(a)||r.getShallow(a)||n(i,a):(t.getShallow(a,!0)||Math.round(t===s?e:r.getShallow(a,!0)||e))+"px"}).join(" ")},t=new a.graphic.Text({style:{x:c.info.fillTextOffsetX,y:c.info.fillTextOffsetY+.5*e,text:t,textBaseline:"middle",font:h(s,f)},scale:[1/c.info.mu,1/c.info.mu],position:[(c.gx+c.info.gw/2)*u,(c.gy+c.info.gh/2)*u],rotation:c.rot});t.setStyle(s.getItemStyle()),t.setStyle({fill:o.getItemVisual(r,"color")}),i.add(t),o.setItemGraphicEl(r,t),a.graphic.setHoverStyle(t,a.util.extend(f.getItemStyle(),{font:h(f,s)}))}}})},function(t,e,r){var n,a;window.setImmediate||(window.setImmediate=function(){return window.msSetImmediate||window.webkitSetImmediate||window.mozSetImmediate||window.oSetImmediate||function(){if(!window.postMessage||!window.addEventListener)return null;var t=[void 0],e="zero-timeout-message",r=function(r){var n=t.length;return t.push(r),window.postMessage(e+n.toString(36),"*"),n};return window.addEventListener("message",function(r){if("string"==typeof r.data&&r.data.substr(0,e.length)===e){r.stopImmediatePropagation();var n=parseInt(r.data.substr(e.length),36);t[n]&&(t[n](),t[n]=void 0)}},!0),window.clearImmediate=function(e){t[e]&&(t[e]=void 0)},r}()||function(t){window.setTimeout(t,0)}}()),window.clearImmediate||(window.clearImmediate=function(){return window.msClearImmediate||window.webkitClearImmediate||window.mozClearImmediate||window.oClearImmediate||function(t){window.clearTimeout(t)}}()),function(r){var i=function(){var t=document.createElement("canvas");if(!t||!t.getContext)return!1;var e=t.getContext("2d");return e.getImageData&&e.fillText&&Array.prototype.some&&Array.prototype.push?!0:!1}(),o=function(){if(i){for(var t,e,r=document.createElement("canvas").getContext("2d"),n=20;n;){if(r.font=n.toString(10)+"px sans-serif",r.measureText("W").width===t&&r.measureText("m").width===e)return n+1;t=r.measureText("W").width,e=r.measureText("m").width,n--}return 0}}(),u=function(t){for(var e,r,n=t.length;n;e=Math.floor(Math.random()*n),r=t[--n],t[n]=t[e],t[e]=r);return t},c=function(t,e){function r(t,e){return"hsl("+(360*Math.random()).toFixed()+","+(30*Math.random()+70).toFixed()+"%,"+(Math.random()*(e-t)+t).toFixed()+"%)"}if(i){Array.isArray(t)||(t=[t]),t.forEach(function(e,r){if("string"==typeof e){if(t[r]=document.getElementById(e),!t[r])throw"The element id specified is not found."}else if(!e.tagName&&!e.appendChild)throw"You must pass valid HTML elements, or ID of the element."});var n={list:[],fontFamily:'"Trebuchet MS", "Heiti TC", "微軟正黑體", "Arial Unicode MS", "Droid Fallback Sans", sans-serif',fontWeight:"normal",color:"random-dark",minSize:0,weightFactor:1,clearCanvas:!0,backgroundColor:"#fff",gridSize:8,drawOutOfBound:!1,origin:null,drawMask:!1,maskColor:"rgba(255,0,0,0.3)",maskGapWidth:.3,wait:0,abortThreshold:0,abort:function(){},minRotation:-Math.PI/2,maxRotation:Math.PI/2,rotationStep:.1,shuffle:!0,rotateRatio:.1,shape:"circle",ellipticity:.65,classes:null,hover:null,click:null};if(e)for(var a in e)a in n&&(n[a]=e[a]);if("function"!=typeof n.weightFactor){var c=n.weightFactor;n.weightFactor=function(t){return t*c}}if("function"!=typeof n.shape)switch(n.shape){case"circle":default:n.shape="circle";break;case"cardioid":n.shape=function(t){return 1-Math.sin(t)};break;case"diamond":case"square":n.shape=function(t){var e=t%(2*Math.PI/4);return 1/(Math.cos(e)+Math.sin(e))};break;case"triangle-forward":n.shape=function(t){var e=t%(2*Math.PI/3);return 1/(Math.cos(e)+Math.sqrt(3)*Math.sin(e))};break;case"triangle":case"triangle-upright":n.shape=function(t){var e=(t+3*Math.PI/2)%(2*Math.PI/3);return 1/(Math.cos(e)+Math.sqrt(3)*Math.sin(e))};break;case"pentagon":n.shape=function(t){var e=(t+.955)%(2*Math.PI/5);return 1/(Math.cos(e)+.726543*Math.sin(e))};break;case"star":n.shape=function(t){var e=(t+.955)%(2*Math.PI/10);return(t+.955)%(2*Math.PI/5)-2*Math.PI/10>=0?1/(Math.cos(2*Math.PI/10-e)+3.07768*Math.sin(2*Math.PI/10-e)):1/(Math.cos(e)+3.07768*Math.sin(e))}}n.gridSize=Math.max(Math.floor(n.gridSize),4);var l,s,f,h,d,g,m,p=n.gridSize,v=p-n.maskGapWidth,y=Math.abs(n.maxRotation-n.minRotation),w=Math.min(n.maxRotation,n.minRotation),x=n.rotationStep;switch(n.color){case"random-dark":m=function(){return r(10,50)};break;case"random-light":m=function(){return r(50,90)};break;default:"function"==typeof n.color&&(m=n.color)}var M=null;"function"==typeof n.classes&&(M=n.classes);var b,S=!1,C=[],I=function(t){var e,r,n=t.currentTarget,a=n.getBoundingClientRect();t.touches?(e=t.touches[0].clientX,r=t.touches[0].clientY):(e=t.clientX,r=t.clientY);var i=e-a.left,o=r-a.top,u=Math.floor(i*(n.width/a.width||1)/p),c=Math.floor(o*(n.height/a.height||1)/p);return C[u][c]},T=function(t){var e=I(t);if(b!==e)return b=e,e?void n.hover(e.item,e.dimension,t):void n.hover(void 0,void 0,t)},N=function(t){var e=I(t);e&&(n.click(e.item,e.dimension,t),t.preventDefault())},E=[],k=function(t){if(E[t])return E[t];var e=8*t,r=e,a=[];for(0===t&&a.push([h[0],h[1],0]);r--;){var i=1;"circle"!==n.shape&&(i=n.shape(r/e*2*Math.PI)),a.push([h[0]+t*i*Math.cos(-r/e*2*Math.PI),h[1]+t*i*Math.sin(-r/e*2*Math.PI)*n.ellipticity,r/e*2*Math.PI])}return E[t]=a,a},A=function(){return n.abortThreshold>0&&(new Date).getTime()-g>n.abortThreshold},F=function(){return 0===n.rotateRatio?0:Math.random()>n.rotateRatio?0:0===y?w:w+Math.round(Math.random()*y/x)*x},P=function(t,e,r){var a=!1,i=n.weightFactor(e);if(i<=n.minSize)return!1;var u=1;o>i&&(u=function(){for(var t=2;o>t*i;)t+=2;return t}());var c=document.createElement("canvas"),l=c.getContext("2d",{willReadFrequently:!0});l.font=n.fontWeight+" "+(i*u).toString(10)+"px "+n.fontFamily;var s=l.measureText(t).width/u,f=Math.max(i*u,l.measureText("m").width,l.measureText("W").width)/u,h=s+2*f,d=3*f,g=Math.ceil(h/p),m=Math.ceil(d/p);h=g*p,d=m*p;var v=-s/2,y=.4*-f,w=Math.ceil((h*Math.abs(Math.sin(r))+d*Math.abs(Math.cos(r)))/p),x=Math.ceil((h*Math.abs(Math.cos(r))+d*Math.abs(Math.sin(r)))/p),M=x*p,b=w*p;c.setAttribute("width",M),c.setAttribute("height",b),a&&(document.body.appendChild(c),l.save()),l.scale(1/u,1/u),l.translate(M*u/2,b*u/2),l.rotate(-r),l.font=n.fontWeight+" "+(i*u).toString(10)+"px "+n.fontFamily,l.fillStyle="#000",l.textBaseline="middle",l.fillText(t,v*u,(y+.5*i)*u);var S=l.getImageData(0,0,M,b).data;if(A())return!1;a&&(l.strokeRect(v*u,y,s*u,f*u),l.restore());for(var C,I,T,N=[],E=x,k=[w/2,x/2,w/2,x/2];E--;)for(C=w;C--;){T=p;t:{for(;T--;)for(I=p;I--;)if(S[4*((C*p+T)*M+(E*p+I))+3]){N.push([E,C]),Ek[1]&&(k[1]=E),Ck[2]&&(k[2]=C),a&&(l.fillStyle="rgba(255, 0, 0, 0.5)",l.fillRect(E*p,C*p,p-.5,p-.5));break t}a&&(l.fillStyle="rgba(0, 0, 255, 0.5)",l.fillRect(E*p,C*p,p-.5,p-.5))}}return a&&(l.fillStyle="rgba(0, 255, 0, 0.5)",l.fillRect(k[3]*p,k[0]*p,(k[1]-k[3]+1)*p,(k[2]-k[0]+1)*p)),{mu:u,occupied:N,bounds:k,gw:x,gh:w,fillTextOffsetX:v,fillTextOffsetY:y,fillTextWidth:s,fillTextHeight:f,fontSize:i}},R=function(t,e,r,a,i){for(var o=i.length;o--;){var u=t+i[o][0],c=e+i[o][1];if(u>=s||c>=f||0>u||0>c){if(!n.drawOutOfBound)return!1}else if(!l[u][c])return!1}return!0},O=function(e,r,a,i,o,u,c,l,s){var f,h=a.fontSize;f=m?m(i,o,h,u,c):n.color;var d;d=M?M(i,o,h,u,c):n.classes;var g,v=a.bounds;g={x:(e+v[3])*p,y:(r+v[0])*p,w:(v[1]-v[3]+1)*p,h:(v[2]-v[0]+1)*p},t.forEach(function(t){if(t.getContext){var o=t.getContext("2d"),u=a.mu;o.save(),o.scale(1/u,1/u),o.font=n.fontWeight+" "+(h*u).toString(10)+"px "+n.fontFamily,o.fillStyle=f,o.translate((e+a.gw/2)*p*u,(r+a.gh/2)*p*u),0!==l&&o.rotate(-l),o.textBaseline="middle",o.fillText(i,a.fillTextOffsetX*u,(a.fillTextOffsetY+.5*h)*u),o.restore()}else{var c=document.createElement("span"),g="";g="rotate("+-l/Math.PI*180+"deg) ",1!==a.mu&&(g+="translateX(-"+a.fillTextWidth/4+"px) scale("+1/a.mu+")");var m={position:"absolute",display:"block",font:n.fontWeight+" "+h*a.mu+"px "+n.fontFamily,left:(e+a.gw/2)*p+a.fillTextOffsetX+"px",top:(r+a.gh/2)*p+a.fillTextOffsetY+"px",width:a.fillTextWidth+"px",height:a.fillTextHeight+"px",lineHeight:h+"px",whiteSpace:"nowrap",transform:g,webkitTransform:g,msTransform:g,transformOrigin:"50% 40%",webkitTransformOrigin:"50% 40%",msTransformOrigin:"50% 40%"};f&&(m.color=f),c.textContent=i;for(var v in m)c.style[v]=m[v];if(s)for(var y in s)c.setAttribute(y,s[y]);d&&(c.className+=d),t.appendChild(c)}})},z=function(e,r,n,a,i){if(!(e>=s||r>=f||0>e||0>r)){if(l[e][r]=!1,n){var o=t[0].getContext("2d");o.fillRect(e*p,r*p,v,v)}S&&(C[e][r]={item:i,dimension:a})}},L=function(e,r,a,i,o,u){var c,l=o.occupied,h=n.drawMask;h&&(c=t[0].getContext("2d"),c.save(),c.fillStyle=n.maskColor);var d;if(S){var g=o.bounds;d={x:(e+g[3])*p,y:(r+g[0])*p,w:(g[1]-g[3]+1)*p,h:(g[2]-g[0]+1)*p}}for(var m=l.length;m--;){var v=e+l[m][0],y=r+l[m][1];v>=s||y>=f||0>v||0>y||z(v,y,h,d,u)}h&&c.restore()},D=function(t){var e,r,a;Array.isArray(t)?(e=t[0],r=t[1]):(e=t.word,r=t.weight,a=t.attributes);var i=F(),o=P(e,r,i);if(!o)return!1;if(A())return!1;if(!n.drawOutOfBound){var c=o.bounds;if(c[1]-c[3]+1>s||c[2]-c[0]+1>f)return!1}for(var l=d+1,h=function(n){var u=Math.floor(n[0]-o.gw/2),c=Math.floor(n[1]-o.gh/2),s=o.gw,f=o.gh;return R(u,c,s,f,o.occupied)?(O(u,c,o,e,r,d-l,n[2],i,a),L(u,c,s,f,o,t),{gx:u,gy:c,rot:i,info:o}):!1};l--;){var g=k(d-l);n.shuffle&&(g=[].concat(g),u(g));for(var m=0;m=n.list.length)return x(k),q("wordcloudstop",!1),void I("wordcloudstart",E);g=(new Date).getTime();var t=D(n.list[o]),e=!q("wordclouddrawn",!0,{item:n.list[o],drawn:t});return A()||e?(x(k),n.abort(),q("wordcloudabort",!1),q("wordcloudstop",!1),void I("wordcloudstart",E)):(o++,void(k=w(R,n.wait)))},n.wait)}};j()}};c.isSupported=i,c.minFontSize=o,n=[],a=function(){return c}.apply(e,n),!(void 0!==a&&(t.exports=a))}(this)},function(t,e,r){function n(t){for(var e=t.getContext("2d"),r=e.getImageData(0,0,t.width,t.height),n=e.createImageData(r),a=0;ao||i>384?(n.data[a]=0,n.data[a+1]=0,n.data[a+2]=0,n.data[a+3]=0):(n.data[a]=255,n.data[a+1]=255,n.data[a+2]=255,n.data[a+3]=255)}e.putImageData(n,0,0)}var a=r(2),i=r(6);r(11),r(12);var o=r(13);if(!o.isSupported)throw new Error("Sorry your browser not support wordCloud");a.registerLayout(function(t,e){t.eachSeriesByType("wordCloud",function(r){var u=i.getLayoutRect(r.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),c=r.getData(),l=document.createElement("canvas");l.width=u.width,l.height=u.height;var s=l.getContext("2d"),f=r.get("maskImage");if(f)try{s.drawImage(f,0,0,l.width,l.height),n(l)}catch(h){console.error("Invalid mask image"),console.error(h.toString())}var d=r.get("sizeRange"),g=r.get("rotationRange"),m=c.getDataExtent("value"),p=Math.PI/180,v=r.get("gridSize");o(l,{list:c.mapArray("value",function(t,e){var r=c.getItemModel(e);return[c.getName(e),r.get("textStyle.normal.textSize",!0)||a.number.linearMap(t,m,d),e]}).sort(function(t,e){return e[1]-t[1]}),fontFamily:r.get("textStyle.normal.fontFamily")||r.get("textStyle.emphasis.fontFamily")||t.get("textStyle.fontFamily"),fontWeight:r.get("textStyle.normal.fontWeight")||r.get("textStyle.emphasis.fontWeight")||t.get("textStyle.fontWeight"),gridSize:v,ellipticity:u.height/u.width,minRotation:g[0]*p,maxRotation:g[1]*p,clearCanvas:!f,rotateRatio:1,rotationStep:r.get("rotationStep")*p,drawOutOfBound:!1,shuffle:!1,shape:r.get("shape")}),l.addEventListener("wordclouddrawn",function(t){var e=t.detail.item;t.detail.drawn&&r.layoutInstance.ondraw&&(t.detail.drawn.gx+=u.x/v,t.detail.drawn.gy+=u.y/v,r.layoutInstance.ondraw(e[0],e[1],e[2],t.detail.drawn))}),r.layoutInstance={ondraw:null}})})}])}); \ No newline at end of file