From 71d5390ddd65df2c3e5e8c3268e99f4b4fce1fcd Mon Sep 17 00:00:00 2001 From: jiahui Date: Fri, 19 Aug 2016 15:24:50 +0800 Subject: [PATCH 1/2] add some options for convenient --- README.md | 9 + dist/echarts-wordcloud.js | 456 ++++++++++++++++++++++++++++------ dist/echarts-wordcloud.min.js | 2 +- example/wordCloud.html | 6 +- src/WordCloudSeries.js | 39 ++- src/WordCloudView.js | 7 +- src/wordCloud.js | 37 ++- 7 files changed, 461 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 0c9fa1f..cebb403 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ chart.setOption({ maskImage: maskImage, + ellipticity :1, + // Folllowing left/top/width/height/right/bottom are used for positioning the word cloud // Default to be put in the center and has 75% x 80% size. @@ -63,15 +65,22 @@ chart.setOption({ right: null, bottom: null, + //Origin of the “cloud” in [x, y] . x y can be percentage or value in px + origin:['50%','50%'], + // Text size range which the value in data will be mapped to. // Default to have minimum 12px and maximum 60px size. sizeRange: [12, 60], + //Mapping text value to size by using formular y = a^p + b. p refer to sizeMapPower + sizeMapPower: 1 , + // Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45 rotationRange: [-90, 90], rotationStep: 45, + rotateRatio:1, // size of the grid in pixels for marking the availability of the canvas // the larger the grid size, the bigger the gap between words. diff --git a/dist/echarts-wordcloud.js b/dist/echarts-wordcloud.js index 606d953..e0c09a0 100644 --- a/dist/echarts-wordcloud.js +++ b/dist/echarts-wordcloud.js @@ -105,6 +105,24 @@ return /******/ (function(modules) { // webpackBootstrap ctx.putImageData(newImageData, 0, 0); } + /** + * Mapping a value from domain to range using the function y=ax^p+b (p means power) + * @param {number} val + * @param {Array.} domain Domain extent domain[1] is bigger than domain[0] + * @param {Array.} range Range extent range[1] is bigger than range[0] + * @param {number} power + * @return {(number|Array.} + */ + function valueMap(val, domain, range, power) { + if(range[1] > range[0]){ + var a = (range[1] - range[0]) / (Math.pow(domain[1],power)-Math.pow(domain[0],power)); + var b = range[1] - a * Math.pow(domain[1],power); + return Math.ceil(a*Math.pow(val,power)+b); + }else{ + return range[0]; + } + }; + echarts.registerLayout(function (ecModel, api) { ecModel.eachSeriesByType('wordCloud', function (seriesModel) { var gridRect = layoutUtil.getLayoutRect( @@ -135,16 +153,23 @@ return /******/ (function(modules) { // webpackBootstrap var sizeRange = seriesModel.get('sizeRange'); var rotationRange = seriesModel.get('rotationRange'); var valueExtent = data.getDataExtent('value'); + var sizeMapPower = seriesModel.get('sizeMapPower'); var DEGREE_TO_RAD = Math.PI / 180; var gridSize = seriesModel.get('gridSize'); + + //Fix origin(if precentage) + var origin = seriesModel.get('origin'); + var x = /^\d+%$/.test(origin[0]) ? gridRect.width * parseInt(origin[0],10) / 100 : origin[0]; + var y = /^\d+%$/.test(origin[1]) ? gridRect.height * parseInt(origin[1],10) / 100 : origin[1]; + 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), + || valueMap(value, valueExtent, sizeRange,sizeMapPower), idx ]; }).sort(function (a, b) { @@ -159,22 +184,24 @@ return /******/ (function(modules) { // webpackBootstrap || ecModel.get('textStyle.fontWeight'), gridSize: gridSize, - ellipticity: gridRect.height / gridRect.width, + ellipticity: seriesModel.get('ellipticity'), minRotation: rotationRange[0] * DEGREE_TO_RAD, maxRotation: rotationRange[1] * DEGREE_TO_RAD, clearCanvas: !maskImage, - rotateRatio: 1, + rotateRatio: seriesModel.get('rotateRatio'), rotationStep: seriesModel.get('rotationStep') * DEGREE_TO_RAD, drawOutOfBound: false, - shuffle: false, + shuffle: seriesModel.get('shuffle'), - shape: seriesModel.get('shape') + shape: seriesModel.get('shape'), + + origin : [x,y] }); canvas.addEventListener('wordclouddrawn', function (e) { @@ -210,9 +237,9 @@ return /******/ (function(modules) { // webpackBootstrap var zrUtil = __webpack_require__(4); - var BoundingRect = __webpack_require__(6); - var numberUtil = __webpack_require__(9); - var formatUtil = __webpack_require__(10); + var BoundingRect = __webpack_require__(5); + var numberUtil = __webpack_require__(8); + var formatUtil = __webpack_require__(9); var parsePercent = numberUtil.parsePercent; var each = zrUtil.each; @@ -482,10 +509,10 @@ return /******/ (function(modules) { // webpackBootstrap positionInfo, containerRect, margin ); - group.position = [ + group.attr('position', [ positionInfo.x - groupRect.x, positionInfo.y - groupRect.y - ]; + ]); }; /** @@ -608,20 +635,23 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, /* 4 */ -/***/ function(module, exports, __webpack_require__) { +/***/ function(module, exports) { /** * @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 + '[object CanvasGradient]': 1, + '[object CanvasPattern]': 1, + // In node-canvas Image can be Canvas.Image + '[object Image]': 1 }; var objToString = Object.prototype.toString; @@ -1018,8 +1048,7 @@ return /******/ (function(modules) { // webpackBootstrap * @return {boolean} */ function isBuildInObject(value) { - return !!BUILTIN_OBJECT[objToString.call(value)] - || (value instanceof Gradient); + return !!BUILTIN_OBJECT[objToString.call(value)]; } /** @@ -1103,37 +1132,6 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, /* 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'; @@ -1142,8 +1140,8 @@ return /******/ (function(modules) { // webpackBootstrap */ - var vec2 = __webpack_require__(7); - var matrix = __webpack_require__(8); + var vec2 = __webpack_require__(6); + var matrix = __webpack_require__(7); var v2ApplyTransform = vec2.applyTransform; var mathMin = Math.min; @@ -1292,7 +1290,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 7 */ +/* 6 */ /***/ function(module, exports) { @@ -1316,8 +1314,14 @@ return /******/ (function(modules) { // webpackBootstrap */ create: function (x, y) { var out = new ArrayCtor(2); - out[0] = x || 0; - out[1] = y || 0; + if (x == null) { + x = 0; + } + if (y == null) { + y = 0; + } + out[0] = x; + out[1] = y; return out; }, @@ -1572,7 +1576,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 8 */ +/* 7 */ /***/ function(module, exports) { @@ -1736,7 +1740,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 9 */ +/* 8 */ /***/ function(module, exports) { /** @@ -1864,6 +1868,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {number} val */ number.getPrecision = function (val) { + val = +val; if (isNaN(val)) { return 0; } @@ -1926,7 +1931,8 @@ return /******/ (function(modules) { // webpackBootstrap ? value : new Date( typeof value === 'string' - ? value.replace(/-/g, '/') + // FIXME Date.parse('1970-01-01') is UTC, Date.parse('1970/01/01') is local + ? (new Date(value.replace(/-/g, '/')) - new Date('1970/01/01')) : Math.round(value) ); }; @@ -1973,13 +1979,14 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }, -/* 10 */ +/* 9 */ /***/ function(module, exports, __webpack_require__) { var zrUtil = __webpack_require__(4); - var numberUtil = __webpack_require__(9); + var numberUtil = __webpack_require__(8); + var textContain = __webpack_require__(10); /** * 每三位默认加,格式化 @@ -2057,7 +2064,7 @@ return /******/ (function(modules) { // webpackBootstrap return ''; } - var $vars = paramsList[0].$vars; + 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)); @@ -2135,10 +2142,293 @@ return /******/ (function(modules) { // webpackBootstrap formatTpl: formatTpl, - formatTime: formatTime + formatTime: formatTime, + + truncateText: textContain.truncateText }; +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + + + var textWidthCache = {}; + var textWidthCacheCounter = 0; + var TEXT_CACHE_MAX = 5000; + + var util = __webpack_require__(4); + var BoundingRect = __webpack_require__(5); + var retrieve = util.retrieve; + + function getTextWidth(text, textFont) { + var key = text + ':' + textFont; + if (textWidthCache[key]) { + return textWidthCache[key]; + } + + var textLines = (text + '').split('\n'); + var width = 0; + + for (var i = 0, l = textLines.length; i < l; i++) { + // measureText 可以被覆盖以兼容不支持 Canvas 的环境 + width = Math.max(textContain.measureText(textLines[i], textFont).width, width); + } + + if (textWidthCacheCounter > TEXT_CACHE_MAX) { + textWidthCacheCounter = 0; + textWidthCache = {}; + } + textWidthCacheCounter++; + textWidthCache[key] = width; + + return width; + } + + function getTextRect(text, textFont, textAlign, textBaseline) { + var textLineLen = ((text || '') + '').split('\n').length; + + var width = getTextWidth(text, textFont); + // FIXME 高度计算比较粗暴 + var lineHeight = getTextWidth('国', textFont); + var height = textLineLen * lineHeight; + + var rect = new BoundingRect(0, 0, width, height); + // Text has a special line height property + rect.lineHeight = lineHeight; + + switch (textBaseline) { + case 'bottom': + case 'alphabetic': + rect.y -= lineHeight; + break; + case 'middle': + rect.y -= lineHeight / 2; + break; + // case 'hanging': + // case 'top': + } + + // FIXME Right to left language + switch (textAlign) { + case 'end': + case 'right': + rect.x -= rect.width; + break; + case 'center': + rect.x -= rect.width / 2; + break; + // case 'start': + // case 'left': + } + + return rect; + } + + function adjustTextPositionOnRect(textPosition, rect, textRect, distance) { + + var x = rect.x; + var y = rect.y; + + var height = rect.height; + var width = rect.width; + + var textHeight = textRect.height; + + var halfHeight = height / 2 - textHeight / 2; + + var textAlign = 'left'; + + switch (textPosition) { + case 'left': + x -= distance; + y += halfHeight; + textAlign = 'right'; + break; + case 'right': + x += distance + width; + y += halfHeight; + textAlign = 'left'; + break; + case 'top': + x += width / 2; + y -= distance + textHeight; + textAlign = 'center'; + break; + case 'bottom': + x += width / 2; + y += height + distance; + textAlign = 'center'; + break; + case 'inside': + x += width / 2; + y += halfHeight; + textAlign = 'center'; + break; + case 'insideLeft': + x += distance; + y += halfHeight; + textAlign = 'left'; + break; + case 'insideRight': + x += width - distance; + y += halfHeight; + textAlign = 'right'; + break; + case 'insideTop': + x += width / 2; + y += distance; + textAlign = 'center'; + break; + case 'insideBottom': + x += width / 2; + y += height - textHeight - distance; + textAlign = 'center'; + break; + case 'insideTopLeft': + x += distance; + y += distance; + textAlign = 'left'; + break; + case 'insideTopRight': + x += width - distance; + y += distance; + textAlign = 'right'; + break; + case 'insideBottomLeft': + x += distance; + y += height - textHeight - distance; + break; + case 'insideBottomRight': + x += width - distance; + y += height - textHeight - distance; + textAlign = 'right'; + break; + } + + return { + x: x, + y: y, + textAlign: textAlign, + textBaseline: 'top' + }; + } + + /** + * Show ellipsis if overflow. + * + * @param {string} text + * @param {string} containerWidth + * @param {string} textFont + * @param {number} [ellipsis='...'] + * @param {Object} [options] + * @param {number} [options.maxIterations=3] + * @param {number} [options.minChar=0] If truncate result are less + * then minChar, ellipsis will not show, which is + * better for user hint in some cases. + * @param {number} [options.placeholder=''] When all truncated, use the placeholder. + * @return {string} + */ + function truncateText(text, containerWidth, textFont, ellipsis, options) { + if (!containerWidth) { + return ''; + } + + options = options || {}; + + ellipsis = retrieve(ellipsis, '...'); + var maxIterations = retrieve(options.maxIterations, 2); + var minChar = retrieve(options.minChar, 0); + // FIXME + // Other languages? + var cnCharWidth = getTextWidth('国', textFont); + // FIXME + // Consider proportional font? + var ascCharWidth = getTextWidth('a', textFont); + var placeholder = retrieve(options.placeholder, ''); + + // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'. + // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'. + var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap. + for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) { + contentWidth -= ascCharWidth; + } + + var ellipsisWidth = getTextWidth(ellipsis); + if (ellipsisWidth > contentWidth) { + ellipsis = ''; + ellipsisWidth = 0; + } + + contentWidth = containerWidth - ellipsisWidth; + + var textLines = (text + '').split('\n'); + + for (var i = 0, len = textLines.length; i < len; i++) { + var textLine = textLines[i]; + var lineWidth = getTextWidth(textLine, textFont); + + if (lineWidth <= containerWidth) { + continue; + } + + for (var j = 0;; j++) { + if (lineWidth <= contentWidth || j >= maxIterations) { + textLine += ellipsis; + break; + } + + var subLength = j === 0 + ? estimateLength(textLine, contentWidth, ascCharWidth, cnCharWidth) + : lineWidth > 0 + ? Math.floor(textLine.length * contentWidth / lineWidth) + : 0; + + textLine = textLine.substr(0, subLength); + lineWidth = getTextWidth(textLine, textFont); + } + + if (textLine === '') { + textLine = placeholder; + } + + textLines[i] = textLine; + } + + return textLines.join('\n'); + } + + function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) { + var width = 0; + var i = 0; + for (var len = text.length; i < len && width < contentWidth; i++) { + var charCode = text.charCodeAt(i); + width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth; + } + return i; + } + + var textContain = { + + getWidth: getTextWidth, + + getBoundingRect: getTextRect, + + adjustTextPositionOnRect: adjustTextPositionOnRect, + + truncateText: truncateText, + + measureText: function (text, textFont) { + var ctx = util.getContext(); + ctx.font = textFont || '12px sans-serif'; + return ctx.measureText(text); + } + }; + + module.exports = textContain; + + /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { @@ -2164,31 +2454,46 @@ return /******/ (function(modules) { // webpackBootstrap return list; }, - // Most of options are from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md + defaultOption: { - maskImage: null, + //Options below are from from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md - // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' - shape: 'circle', + shape: 'circle', // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' - left: 'center', + maskImage: null, // with image loaded - top: 'center', + origin:['50%','50%'], //Origin of the “cloud” in [x, y] . x y can be percentage or value in px - width: '70%', + sizeRange: [12, 60], //Text size range - height: '80%', + rotationRange: [-90, 90], - sizeRange: [12, 60], + rotationStep: 45, - rotationRange: [-90, 90], + shuffle:false, - rotationStep: 45, + rotateRatio:1, gridSize: 8, - textStyle: { + ellipticity :1, + + //Options below are added for convenient + + sizeMapPower: 1 , //Mapping text value to size by using formular y = a^p + b. p refer to sizeMapPower + + //Options below are from http://echarts.baidu.com/option.html + + left: 'center', + + top: 'center', + + width: '100%', + + height: '100%', + + textStyle: { normal: { fontWeight: 'normal' } @@ -2239,7 +2544,7 @@ return /******/ (function(modules) { // webpackBootstrap // The rule should not be complex, otherwise user might not // be able to known where the data is wrong. - function guessOrdinal(data, dimIndex) { + var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) { for (var i = 0, len = data.length; i < len; i++) { var value = retrieveValue(data[i]); @@ -2256,7 +2561,7 @@ return /******/ (function(modules) { // webpackBootstrap } } return false; - } + }; function retrieveValue(o) { return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o; @@ -2330,11 +2635,16 @@ return /******/ (function(modules) { // webpackBootstrap }); text.setStyle(textStyleModel.getItemStyle()); + text.setStyle({ fill: data.getItemVisual(dataIdx, 'color') }); - group.add(text); + try{ + group.add(text); + }catch(err){ + window.console && console.log(err); + } data.setItemGraphicEl(dataIdx, text); echarts.graphic.setHoverStyle( diff --git a/dist/echarts-wordcloud.min.js b/dist/echarts-wordcloud.min.js index 9eb416d..5bd9228 100644 --- a/dist/echarts-wordcloud.min.js +++ b/dist/echarts-wordcloud.min.js @@ -1 +1 @@ -!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 +!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){function r(t){if("object"==typeof t&&null!==t){var e=t;if(t instanceof Array){e=[];for(var n=0,a=t.length;n0){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(t=+t,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&&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,r){function n(t,e,r,n){if(!e)return t;var u=a(e[0]),c=i.isArray(u)&&u.length||1;r=r||[],n=n||"extra";for(var l=0;l1?"."+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;an||c.newline?(i=0,s=m,o+=u+r,u=d.height):u=Math.max(u,d.height)}else{var v=d.height+(p?-p.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(4),o=r(3),u=r(6),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],p=r[1]+r[3],m=t.aspect;switch(isNaN(h)&&(h=n-s-p-o),isNaN(d)&&(d=a-f-g-l),isNaN(h)&&isNaN(d)&&(m>n/a?h=.8*n:d=.8*a),null!=m&&(isNaN(h)&&(h=m*d),isNaN(d)&&(d=h/m)),isNaN(o)&&(o=n-s-h-p),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-p}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.attr("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;hs&&(l=0,c={}),l++,c[r]=a,a}function a(t,e,r,a){var i=((t||"")+"").split("\n").length,o=n(t,e),u=n("国",e),c=i*u,l=new h(0,0,o,c);switch(l.lineHeight=u,a){case"bottom":case"alphabetic":l.y-=u;break;case"middle":l.y-=u/2}switch(r){case"end":case"right":l.x-=l.width;break;case"center":l.x-=l.width/2}return l}function i(t,e,r,n){var a=e.x,i=e.y,o=e.height,u=e.width,c=r.height,l=o/2-c/2,s="left";switch(t){case"left":a-=n,i+=l,s="right";break;case"right":a+=n+u,i+=l,s="left";break;case"top":a+=u/2,i-=n+c,s="center";break;case"bottom":a+=u/2,i+=o+n,s="center";break;case"inside":a+=u/2,i+=l,s="center";break;case"insideLeft":a+=n,i+=l,s="left";break;case"insideRight":a+=u-n,i+=l,s="right";break;case"insideTop":a+=u/2,i+=n,s="center";break;case"insideBottom":a+=u/2,i+=o-c-n,s="center";break;case"insideTopLeft":a+=n,i+=n,s="left";break;case"insideTopRight":a+=u-n,i+=n,s="right";break;case"insideBottomLeft":a+=n,i+=o-c-n;break;case"insideBottomRight":a+=u-n,i+=o-c-n,s="right"}return{x:a,y:i,textAlign:s,textBaseline:"top"}}function o(t,e,r,a,i){if(!e)return"";i=i||{},a=d(a,"...");for(var o=d(i.maxIterations,2),c=d(i.minChar,0),l=n("国",r),s=n("a",r),f=d(i.placeholder,""),h=e=Math.max(0,e-1),g=0;g=s;g++)h-=s;var p=n(a);p>h&&(a="",p=0),h=e-p;for(var m=(t+"").split("\n"),g=0,v=m.length;g=o){w+=a;break}var M=0===x?u(w,h,s,l):y>0?Math.floor(w.length*h/y):0;w=w.substr(0,M),y=n(w,r)}""===w&&(w=f),m[g]=w}}return m.join("\n")}function u(t,e,r,n){for(var a=0,i=0,o=t.length;i=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,p,m=n.gridSize,v=m-n.maskGapWidth,w=Math.abs(n.maxRotation-n.minRotation),y=Math.min(n.maxRotation,n.minRotation),x=n.rotationStep;switch(n.color){case"random-dark":p=function(){return r(10,50)};break;case"random-light":p=function(){return r(50,90)};break;default:"function"==typeof n.color&&(p=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)/m),c=Math.floor(o*(n.height/a.height||1)/m);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)},k=function(t){var e=I(t);e&&(n.click(e.item,e.dimension,t),t.preventDefault())},N=[],E=function(t){if(N[t])return N[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 N[t]=a,a},R=function(){return n.abortThreshold>0&&(new Date).getTime()-g>n.abortThreshold},P=function(){return 0===n.rotateRatio?0:Math.random()>n.rotateRatio?0:0===w?y:y+Math.round(Math.random()*w/x)*x},A=function(t,e,r){var a=!1,i=n.weightFactor(e);if(i<=n.minSize)return!1;var u=1;iE[1]&&(E[1]=N),CE[2]&&(E[2]=C),a&&(l.fillStyle="rgba(255, 0, 0, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5));break t}a&&(l.fillStyle="rgba(0, 0, 255, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5))}}return a&&(l.fillStyle="rgba(0, 255, 0, 0.5)",l.fillRect(E[3]*m,E[0]*m,(E[1]-E[3]+1)*m,(E[2]-E[0]+1)*m)),{mu:u,occupied:k,bounds:E,gw:x,gh:y,fillTextOffsetX:v,fillTextOffsetY:w,fillTextWidth:s,fillTextHeight:f,fontSize:i}},F=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||u<0||c<0){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=p?p(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])*m,y:(r+v[0])*m,w:(v[1]-v[3]+1)*m,h:(v[2]-v[0]+1)*m},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)*m*u,(r+a.gh/2)*m*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 p={position:"absolute",display:"block",font:n.fontWeight+" "+h*a.mu+"px "+n.fontFamily,left:(e+a.gw/2)*m+a.fillTextOffsetX+"px",top:(r+a.gh/2)*m+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&&(p.color=f),c.textContent=i;for(var v in p)c.style[v]=p[v];if(s)for(var w in s)c.setAttribute(w,s[w]);d&&(c.className+=d),t.appendChild(c)}})},z=function(e,r,n,a,i){if(!(e>=s||r>=f||e<0||r<0)){if(l[e][r]=!1,n){var o=t[0].getContext("2d");o.fillRect(e*m,r*m,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])*m,y:(r+g[0])*m,w:(g[1]-g[3]+1)*m,h:(g[2]-g[0]+1)*m}}for(var p=l.length;p--;){var v=e+l[p][0],w=r+l[p][1];v>=s||w>=f||v<0||w<0||z(v,w,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=P(),o=A(e,r,i);if(!o)return!1;if(R())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!!F(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})};l--;){var g=E(d-l);n.shuffle&&(g=[].concat(g),u(g));for(var p=0;p=n.list.length)return x(E),j("wordcloudstop",!1),void I("wordcloudstart",N);g=(new Date).getTime();var t=D(n.list[o]),e=!j("wordclouddrawn",!0,{item:n.list[o],drawn:t});return R()||e?(x(E),n.abort(),j("wordcloudabort",!1),j("wordcloudstop",!1),void I("wordcloudstart",N)):(o++,void(E=y(F,n.wait)))},n.wait)}};B()}};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;a384?(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)}function a(t,e,r,n){if(r[1]>r[0]){var a=(r[1]-r[0])/(Math.pow(e[1],n)-Math.pow(e[0],n)),i=r[1]-a*Math.pow(e[1],n);return Math.ceil(a*Math.pow(t,n)+i)}return r[0]}var i=r(2),o=r(7);r(11),r(12);var u=r(13);if(!u.isSupported)throw new Error("Sorry your browser not support wordCloud");i.registerLayout(function(t,e){t.eachSeriesByType("wordCloud",function(r){var i=o.getLayoutRect(r.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),c=r.getData(),l=document.createElement("canvas");l.width=i.width,l.height=i.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"),p=c.getDataExtent("value"),m=r.get("sizeMapPower"),v=Math.PI/180,w=r.get("gridSize"),y=r.get("origin"),x=/^\d+%$/.test(y[0])?i.width*parseInt(y[0],10)/100:y[0],M=/^\d+%$/.test(y[1])?i.height*parseInt(y[1],10)/100:y[1];u(l,{list:c.mapArray("value",function(t,e){var r=c.getItemModel(e);return[c.getName(e),r.get("textStyle.normal.textSize",!0)||a(t,p,d,m),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:w,ellipticity:r.get("ellipticity"),minRotation:g[0]*v,maxRotation:g[1]*v,clearCanvas:!f,rotateRatio:r.get("rotateRatio"),rotationStep:r.get("rotationStep")*v,drawOutOfBound:!1,shuffle:r.get("shuffle"),shape:r.get("shape"),origin:[x,M]}),l.addEventListener("wordclouddrawn",function(t){var e=t.detail.item;t.detail.drawn&&r.layoutInstance.ondraw&&(t.detail.drawn.gx+=i.x/w,t.detail.drawn.gy+=i.y/w,r.layoutInstance.ondraw(e[0],e[1],e[2],t.detail.drawn))}),r.layoutInstance={ondraw:null}})})}])}); \ No newline at end of file diff --git a/example/wordCloud.html b/example/wordCloud.html index a9a2713..780dd40 100644 --- a/example/wordCloud.html +++ b/example/wordCloud.html @@ -24,11 +24,11 @@ sizeRange: [12, 50], rotationRange: [-90, 90], shape: 'pentagon', - width: 600, - height: 400, + sizeMapPower:0.5, + origin:['50%','50%'], textStyle: { normal: { - color: function () { + color: function (params) { return 'rgb(' + [ Math.round(Math.random() * 160), Math.round(Math.random() * 160), diff --git a/src/WordCloudSeries.js b/src/WordCloudSeries.js index ced194d..845b19d 100644 --- a/src/WordCloudSeries.js +++ b/src/WordCloudSeries.js @@ -19,31 +19,46 @@ echarts.extendSeriesModel({ return list; }, - // Most of options are from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md + defaultOption: { - maskImage: null, + //Options below are from from https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md - // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' - shape: 'circle', + shape: 'circle', // Shape can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' - left: 'center', + maskImage: null, // with image loaded - top: 'center', + origin:['50%','50%'], //Origin of the “cloud” in [x, y] . x y can be percentage or value in px - width: '70%', + sizeRange: [12, 60], //Text size range - height: '80%', + rotationRange: [-90, 90], - sizeRange: [12, 60], + rotationStep: 45, - rotationRange: [-90, 90], + shuffle:false, - rotationStep: 45, + rotateRatio:1, gridSize: 8, - textStyle: { + ellipticity :1, + + //Options below are added for convenient + + sizeMapPower: 1 , //Mapping text value to size by using formular y = a^p + b. p refer to sizeMapPower + + //Options below are from http://echarts.baidu.com/option.html + + left: 'center', + + top: 'center', + + width: '100%', + + height: '100%', + + textStyle: { normal: { fontWeight: 'normal' } diff --git a/src/WordCloudView.js b/src/WordCloudView.js index 0f3e780..26558a6 100644 --- a/src/WordCloudView.js +++ b/src/WordCloudView.js @@ -58,11 +58,16 @@ echarts.extendChartView({ }); text.setStyle(textStyleModel.getItemStyle()); + text.setStyle({ fill: data.getItemVisual(dataIdx, 'color') }); - group.add(text); + try{ + group.add(text); + }catch(err){ + window.console && console.log(err); + } data.setItemGraphicEl(dataIdx, text); echarts.graphic.setHoverStyle( diff --git a/src/wordCloud.js b/src/wordCloud.js index 6741b3a..5b4e8a4 100644 --- a/src/wordCloud.js +++ b/src/wordCloud.js @@ -43,6 +43,24 @@ function updateCanvasMask(maskCanvas) { ctx.putImageData(newImageData, 0, 0); } +/** + * Mapping a value from domain to range using the function y=ax^p+b (p means power) + * @param {number} val + * @param {Array.} domain Domain extent domain[1] is bigger than domain[0] + * @param {Array.} range Range extent range[1] is bigger than range[0] + * @param {number} power + * @return {(number|Array.} + */ +function valueMap(val, domain, range, power) { + if(range[1] > range[0]){ + var a = (range[1] - range[0]) / (Math.pow(domain[1],power)-Math.pow(domain[0],power)); + var b = range[1] - a * Math.pow(domain[1],power); + return Math.ceil(a*Math.pow(val,power)+b); + }else{ + return range[0]; + } +}; + echarts.registerLayout(function (ecModel, api) { ecModel.eachSeriesByType('wordCloud', function (seriesModel) { var gridRect = layoutUtil.getLayoutRect( @@ -73,16 +91,23 @@ echarts.registerLayout(function (ecModel, api) { var sizeRange = seriesModel.get('sizeRange'); var rotationRange = seriesModel.get('rotationRange'); var valueExtent = data.getDataExtent('value'); + var sizeMapPower = seriesModel.get('sizeMapPower'); var DEGREE_TO_RAD = Math.PI / 180; var gridSize = seriesModel.get('gridSize'); + + //Fix origin(if precentage) + var origin = seriesModel.get('origin'); + var x = /^\d+%$/.test(origin[0]) ? gridRect.width * parseInt(origin[0],10) / 100 : origin[0]; + var y = /^\d+%$/.test(origin[1]) ? gridRect.height * parseInt(origin[1],10) / 100 : origin[1]; + 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), + || valueMap(value, valueExtent, sizeRange,sizeMapPower), idx ]; }).sort(function (a, b) { @@ -97,22 +122,24 @@ echarts.registerLayout(function (ecModel, api) { || ecModel.get('textStyle.fontWeight'), gridSize: gridSize, - ellipticity: gridRect.height / gridRect.width, + ellipticity: seriesModel.get('ellipticity'), minRotation: rotationRange[0] * DEGREE_TO_RAD, maxRotation: rotationRange[1] * DEGREE_TO_RAD, clearCanvas: !maskImage, - rotateRatio: 1, + rotateRatio: seriesModel.get('rotateRatio'), rotationStep: seriesModel.get('rotationStep') * DEGREE_TO_RAD, drawOutOfBound: false, - shuffle: false, + shuffle: seriesModel.get('shuffle'), + + shape: seriesModel.get('shape'), - shape: seriesModel.get('shape') + origin : [x,y] }); canvas.addEventListener('wordclouddrawn', function (e) { From f2bb0ac3d71baa405bed724a73c3d4bbfcc11ea1 Mon Sep 17 00:00:00 2001 From: jiahui Date: Tue, 23 Aug 2016 16:40:57 +0800 Subject: [PATCH 2/2] bugfix --- dist/echarts-wordcloud.js | 2 +- dist/echarts-wordcloud.min.js | 2 +- src/wordCloud.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/echarts-wordcloud.js b/dist/echarts-wordcloud.js index e0c09a0..3fdf424 100644 --- a/dist/echarts-wordcloud.js +++ b/dist/echarts-wordcloud.js @@ -114,7 +114,7 @@ return /******/ (function(modules) { // webpackBootstrap * @return {(number|Array.} */ function valueMap(val, domain, range, power) { - if(range[1] > range[0]){ + if(domain[1] > domain[0]){ var a = (range[1] - range[0]) / (Math.pow(domain[1],power)-Math.pow(domain[0],power)); var b = range[1] - a * Math.pow(domain[1],power); return Math.ceil(a*Math.pow(val,power)+b); diff --git a/dist/echarts-wordcloud.min.js b/dist/echarts-wordcloud.min.js index 5bd9228..e03e8ec 100644 --- a/dist/echarts-wordcloud.min.js +++ b/dist/echarts-wordcloud.min.js @@ -1 +1 @@ -!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){function r(t){if("object"==typeof t&&null!==t){var e=t;if(t instanceof Array){e=[];for(var n=0,a=t.length;n0){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(t=+t,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&&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,r){function n(t,e,r,n){if(!e)return t;var u=a(e[0]),c=i.isArray(u)&&u.length||1;r=r||[],n=n||"extra";for(var l=0;l1?"."+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;an||c.newline?(i=0,s=m,o+=u+r,u=d.height):u=Math.max(u,d.height)}else{var v=d.height+(p?-p.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(4),o=r(3),u=r(6),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],p=r[1]+r[3],m=t.aspect;switch(isNaN(h)&&(h=n-s-p-o),isNaN(d)&&(d=a-f-g-l),isNaN(h)&&isNaN(d)&&(m>n/a?h=.8*n:d=.8*a),null!=m&&(isNaN(h)&&(h=m*d),isNaN(d)&&(d=h/m)),isNaN(o)&&(o=n-s-h-p),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-p}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.attr("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;hs&&(l=0,c={}),l++,c[r]=a,a}function a(t,e,r,a){var i=((t||"")+"").split("\n").length,o=n(t,e),u=n("国",e),c=i*u,l=new h(0,0,o,c);switch(l.lineHeight=u,a){case"bottom":case"alphabetic":l.y-=u;break;case"middle":l.y-=u/2}switch(r){case"end":case"right":l.x-=l.width;break;case"center":l.x-=l.width/2}return l}function i(t,e,r,n){var a=e.x,i=e.y,o=e.height,u=e.width,c=r.height,l=o/2-c/2,s="left";switch(t){case"left":a-=n,i+=l,s="right";break;case"right":a+=n+u,i+=l,s="left";break;case"top":a+=u/2,i-=n+c,s="center";break;case"bottom":a+=u/2,i+=o+n,s="center";break;case"inside":a+=u/2,i+=l,s="center";break;case"insideLeft":a+=n,i+=l,s="left";break;case"insideRight":a+=u-n,i+=l,s="right";break;case"insideTop":a+=u/2,i+=n,s="center";break;case"insideBottom":a+=u/2,i+=o-c-n,s="center";break;case"insideTopLeft":a+=n,i+=n,s="left";break;case"insideTopRight":a+=u-n,i+=n,s="right";break;case"insideBottomLeft":a+=n,i+=o-c-n;break;case"insideBottomRight":a+=u-n,i+=o-c-n,s="right"}return{x:a,y:i,textAlign:s,textBaseline:"top"}}function o(t,e,r,a,i){if(!e)return"";i=i||{},a=d(a,"...");for(var o=d(i.maxIterations,2),c=d(i.minChar,0),l=n("国",r),s=n("a",r),f=d(i.placeholder,""),h=e=Math.max(0,e-1),g=0;g=s;g++)h-=s;var p=n(a);p>h&&(a="",p=0),h=e-p;for(var m=(t+"").split("\n"),g=0,v=m.length;g=o){w+=a;break}var M=0===x?u(w,h,s,l):y>0?Math.floor(w.length*h/y):0;w=w.substr(0,M),y=n(w,r)}""===w&&(w=f),m[g]=w}}return m.join("\n")}function u(t,e,r,n){for(var a=0,i=0,o=t.length;i=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,p,m=n.gridSize,v=m-n.maskGapWidth,w=Math.abs(n.maxRotation-n.minRotation),y=Math.min(n.maxRotation,n.minRotation),x=n.rotationStep;switch(n.color){case"random-dark":p=function(){return r(10,50)};break;case"random-light":p=function(){return r(50,90)};break;default:"function"==typeof n.color&&(p=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)/m),c=Math.floor(o*(n.height/a.height||1)/m);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)},k=function(t){var e=I(t);e&&(n.click(e.item,e.dimension,t),t.preventDefault())},N=[],E=function(t){if(N[t])return N[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 N[t]=a,a},R=function(){return n.abortThreshold>0&&(new Date).getTime()-g>n.abortThreshold},P=function(){return 0===n.rotateRatio?0:Math.random()>n.rotateRatio?0:0===w?y:y+Math.round(Math.random()*w/x)*x},A=function(t,e,r){var a=!1,i=n.weightFactor(e);if(i<=n.minSize)return!1;var u=1;iE[1]&&(E[1]=N),CE[2]&&(E[2]=C),a&&(l.fillStyle="rgba(255, 0, 0, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5));break t}a&&(l.fillStyle="rgba(0, 0, 255, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5))}}return a&&(l.fillStyle="rgba(0, 255, 0, 0.5)",l.fillRect(E[3]*m,E[0]*m,(E[1]-E[3]+1)*m,(E[2]-E[0]+1)*m)),{mu:u,occupied:k,bounds:E,gw:x,gh:y,fillTextOffsetX:v,fillTextOffsetY:w,fillTextWidth:s,fillTextHeight:f,fontSize:i}},F=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||u<0||c<0){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=p?p(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])*m,y:(r+v[0])*m,w:(v[1]-v[3]+1)*m,h:(v[2]-v[0]+1)*m},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)*m*u,(r+a.gh/2)*m*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 p={position:"absolute",display:"block",font:n.fontWeight+" "+h*a.mu+"px "+n.fontFamily,left:(e+a.gw/2)*m+a.fillTextOffsetX+"px",top:(r+a.gh/2)*m+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&&(p.color=f),c.textContent=i;for(var v in p)c.style[v]=p[v];if(s)for(var w in s)c.setAttribute(w,s[w]);d&&(c.className+=d),t.appendChild(c)}})},z=function(e,r,n,a,i){if(!(e>=s||r>=f||e<0||r<0)){if(l[e][r]=!1,n){var o=t[0].getContext("2d");o.fillRect(e*m,r*m,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])*m,y:(r+g[0])*m,w:(g[1]-g[3]+1)*m,h:(g[2]-g[0]+1)*m}}for(var p=l.length;p--;){var v=e+l[p][0],w=r+l[p][1];v>=s||w>=f||v<0||w<0||z(v,w,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=P(),o=A(e,r,i);if(!o)return!1;if(R())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!!F(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})};l--;){var g=E(d-l);n.shuffle&&(g=[].concat(g),u(g));for(var p=0;p=n.list.length)return x(E),j("wordcloudstop",!1),void I("wordcloudstart",N);g=(new Date).getTime();var t=D(n.list[o]),e=!j("wordclouddrawn",!0,{item:n.list[o],drawn:t});return R()||e?(x(E),n.abort(),j("wordcloudabort",!1),j("wordcloudstop",!1),void I("wordcloudstart",N)):(o++,void(E=y(F,n.wait)))},n.wait)}};B()}};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;a384?(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)}function a(t,e,r,n){if(r[1]>r[0]){var a=(r[1]-r[0])/(Math.pow(e[1],n)-Math.pow(e[0],n)),i=r[1]-a*Math.pow(e[1],n);return Math.ceil(a*Math.pow(t,n)+i)}return r[0]}var i=r(2),o=r(7);r(11),r(12);var u=r(13);if(!u.isSupported)throw new Error("Sorry your browser not support wordCloud");i.registerLayout(function(t,e){t.eachSeriesByType("wordCloud",function(r){var i=o.getLayoutRect(r.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),c=r.getData(),l=document.createElement("canvas");l.width=i.width,l.height=i.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"),p=c.getDataExtent("value"),m=r.get("sizeMapPower"),v=Math.PI/180,w=r.get("gridSize"),y=r.get("origin"),x=/^\d+%$/.test(y[0])?i.width*parseInt(y[0],10)/100:y[0],M=/^\d+%$/.test(y[1])?i.height*parseInt(y[1],10)/100:y[1];u(l,{list:c.mapArray("value",function(t,e){var r=c.getItemModel(e);return[c.getName(e),r.get("textStyle.normal.textSize",!0)||a(t,p,d,m),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:w,ellipticity:r.get("ellipticity"),minRotation:g[0]*v,maxRotation:g[1]*v,clearCanvas:!f,rotateRatio:r.get("rotateRatio"),rotationStep:r.get("rotationStep")*v,drawOutOfBound:!1,shuffle:r.get("shuffle"),shape:r.get("shape"),origin:[x,M]}),l.addEventListener("wordclouddrawn",function(t){var e=t.detail.item;t.detail.drawn&&r.layoutInstance.ondraw&&(t.detail.drawn.gx+=i.x/w,t.detail.drawn.gy+=i.y/w,r.layoutInstance.ondraw(e[0],e[1],e[2],t.detail.drawn))}),r.layoutInstance={ondraw:null}})})}])}); \ 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){function r(t){if("object"==typeof t&&null!==t){var e=t;if(t instanceof Array){e=[];for(var n=0,a=t.length;n0){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(t=+t,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&&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,r){function n(t,e,r,n){if(!e)return t;var u=a(e[0]),c=i.isArray(u)&&u.length||1;r=r||[],n=n||"extra";for(var l=0;l1?"."+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;an||c.newline?(i=0,s=m,o+=u+r,u=d.height):u=Math.max(u,d.height)}else{var v=d.height+(p?-p.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(4),o=r(3),u=r(6),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],p=r[1]+r[3],m=t.aspect;switch(isNaN(h)&&(h=n-s-p-o),isNaN(d)&&(d=a-f-g-l),isNaN(h)&&isNaN(d)&&(m>n/a?h=.8*n:d=.8*a),null!=m&&(isNaN(h)&&(h=m*d),isNaN(d)&&(d=h/m)),isNaN(o)&&(o=n-s-h-p),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-p}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.attr("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;hs&&(l=0,c={}),l++,c[r]=a,a}function a(t,e,r,a){var i=((t||"")+"").split("\n").length,o=n(t,e),u=n("国",e),c=i*u,l=new h(0,0,o,c);switch(l.lineHeight=u,a){case"bottom":case"alphabetic":l.y-=u;break;case"middle":l.y-=u/2}switch(r){case"end":case"right":l.x-=l.width;break;case"center":l.x-=l.width/2}return l}function i(t,e,r,n){var a=e.x,i=e.y,o=e.height,u=e.width,c=r.height,l=o/2-c/2,s="left";switch(t){case"left":a-=n,i+=l,s="right";break;case"right":a+=n+u,i+=l,s="left";break;case"top":a+=u/2,i-=n+c,s="center";break;case"bottom":a+=u/2,i+=o+n,s="center";break;case"inside":a+=u/2,i+=l,s="center";break;case"insideLeft":a+=n,i+=l,s="left";break;case"insideRight":a+=u-n,i+=l,s="right";break;case"insideTop":a+=u/2,i+=n,s="center";break;case"insideBottom":a+=u/2,i+=o-c-n,s="center";break;case"insideTopLeft":a+=n,i+=n,s="left";break;case"insideTopRight":a+=u-n,i+=n,s="right";break;case"insideBottomLeft":a+=n,i+=o-c-n;break;case"insideBottomRight":a+=u-n,i+=o-c-n,s="right"}return{x:a,y:i,textAlign:s,textBaseline:"top"}}function o(t,e,r,a,i){if(!e)return"";i=i||{},a=d(a,"...");for(var o=d(i.maxIterations,2),c=d(i.minChar,0),l=n("国",r),s=n("a",r),f=d(i.placeholder,""),h=e=Math.max(0,e-1),g=0;g=s;g++)h-=s;var p=n(a);p>h&&(a="",p=0),h=e-p;for(var m=(t+"").split("\n"),g=0,v=m.length;g=o){w+=a;break}var M=0===x?u(w,h,s,l):y>0?Math.floor(w.length*h/y):0;w=w.substr(0,M),y=n(w,r)}""===w&&(w=f),m[g]=w}}return m.join("\n")}function u(t,e,r,n){for(var a=0,i=0,o=t.length;i=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,p,m=n.gridSize,v=m-n.maskGapWidth,w=Math.abs(n.maxRotation-n.minRotation),y=Math.min(n.maxRotation,n.minRotation),x=n.rotationStep;switch(n.color){case"random-dark":p=function(){return r(10,50)};break;case"random-light":p=function(){return r(50,90)};break;default:"function"==typeof n.color&&(p=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)/m),c=Math.floor(o*(n.height/a.height||1)/m);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)},k=function(t){var e=I(t);e&&(n.click(e.item,e.dimension,t),t.preventDefault())},N=[],E=function(t){if(N[t])return N[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 N[t]=a,a},R=function(){return n.abortThreshold>0&&(new Date).getTime()-g>n.abortThreshold},P=function(){return 0===n.rotateRatio?0:Math.random()>n.rotateRatio?0:0===w?y:y+Math.round(Math.random()*w/x)*x},A=function(t,e,r){var a=!1,i=n.weightFactor(e);if(i<=n.minSize)return!1;var u=1;iE[1]&&(E[1]=N),CE[2]&&(E[2]=C),a&&(l.fillStyle="rgba(255, 0, 0, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5));break t}a&&(l.fillStyle="rgba(0, 0, 255, 0.5)",l.fillRect(N*m,C*m,m-.5,m-.5))}}return a&&(l.fillStyle="rgba(0, 255, 0, 0.5)",l.fillRect(E[3]*m,E[0]*m,(E[1]-E[3]+1)*m,(E[2]-E[0]+1)*m)),{mu:u,occupied:k,bounds:E,gw:x,gh:y,fillTextOffsetX:v,fillTextOffsetY:w,fillTextWidth:s,fillTextHeight:f,fontSize:i}},F=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||u<0||c<0){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=p?p(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])*m,y:(r+v[0])*m,w:(v[1]-v[3]+1)*m,h:(v[2]-v[0]+1)*m},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)*m*u,(r+a.gh/2)*m*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 p={position:"absolute",display:"block",font:n.fontWeight+" "+h*a.mu+"px "+n.fontFamily,left:(e+a.gw/2)*m+a.fillTextOffsetX+"px",top:(r+a.gh/2)*m+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&&(p.color=f),c.textContent=i;for(var v in p)c.style[v]=p[v];if(s)for(var w in s)c.setAttribute(w,s[w]);d&&(c.className+=d),t.appendChild(c)}})},z=function(e,r,n,a,i){if(!(e>=s||r>=f||e<0||r<0)){if(l[e][r]=!1,n){var o=t[0].getContext("2d");o.fillRect(e*m,r*m,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])*m,y:(r+g[0])*m,w:(g[1]-g[3]+1)*m,h:(g[2]-g[0]+1)*m}}for(var p=l.length;p--;){var v=e+l[p][0],w=r+l[p][1];v>=s||w>=f||v<0||w<0||z(v,w,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=P(),o=A(e,r,i);if(!o)return!1;if(R())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!!F(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})};l--;){var g=E(d-l);n.shuffle&&(g=[].concat(g),u(g));for(var p=0;p=n.list.length)return x(E),j("wordcloudstop",!1),void I("wordcloudstart",N);g=(new Date).getTime();var t=D(n.list[o]),e=!j("wordclouddrawn",!0,{item:n.list[o],drawn:t});return R()||e?(x(E),n.abort(),j("wordcloudabort",!1),j("wordcloudstop",!1),void I("wordcloudstart",N)):(o++,void(E=y(F,n.wait)))},n.wait)}};B()}};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;a384?(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)}function a(t,e,r,n){if(e[1]>e[0]){var a=(r[1]-r[0])/(Math.pow(e[1],n)-Math.pow(e[0],n)),i=r[1]-a*Math.pow(e[1],n);return Math.ceil(a*Math.pow(t,n)+i)}return r[0]}var i=r(2),o=r(7);r(11),r(12);var u=r(13);if(!u.isSupported)throw new Error("Sorry your browser not support wordCloud");i.registerLayout(function(t,e){t.eachSeriesByType("wordCloud",function(r){var i=o.getLayoutRect(r.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),c=r.getData(),l=document.createElement("canvas");l.width=i.width,l.height=i.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"),p=c.getDataExtent("value"),m=r.get("sizeMapPower"),v=Math.PI/180,w=r.get("gridSize"),y=r.get("origin"),x=/^\d+%$/.test(y[0])?i.width*parseInt(y[0],10)/100:y[0],M=/^\d+%$/.test(y[1])?i.height*parseInt(y[1],10)/100:y[1];u(l,{list:c.mapArray("value",function(t,e){var r=c.getItemModel(e);return[c.getName(e),r.get("textStyle.normal.textSize",!0)||a(t,p,d,m),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:w,ellipticity:r.get("ellipticity"),minRotation:g[0]*v,maxRotation:g[1]*v,clearCanvas:!f,rotateRatio:r.get("rotateRatio"),rotationStep:r.get("rotationStep")*v,drawOutOfBound:!1,shuffle:r.get("shuffle"),shape:r.get("shape"),origin:[x,M]}),l.addEventListener("wordclouddrawn",function(t){var e=t.detail.item;t.detail.drawn&&r.layoutInstance.ondraw&&(t.detail.drawn.gx+=i.x/w,t.detail.drawn.gy+=i.y/w,r.layoutInstance.ondraw(e[0],e[1],e[2],t.detail.drawn))}),r.layoutInstance={ondraw:null}})})}])}); \ No newline at end of file diff --git a/src/wordCloud.js b/src/wordCloud.js index 5b4e8a4..18a1d86 100644 --- a/src/wordCloud.js +++ b/src/wordCloud.js @@ -52,7 +52,7 @@ function updateCanvasMask(maskCanvas) { * @return {(number|Array.} */ function valueMap(val, domain, range, power) { - if(range[1] > range[0]){ + if(domain[1] > domain[0]){ var a = (range[1] - range[0]) / (Math.pow(domain[1],power)-Math.pow(domain[0],power)); var b = range[1] - a * Math.pow(domain[1],power); return Math.ceil(a*Math.pow(val,power)+b);