wordcloud.src.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. /**
  2. * @license Highcharts JS v8.2.2 (2020-10-22)
  3. *
  4. * (c) 2016-2019 Highsoft AS
  5. * Authors: Jon Arild Nygard
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. 'use strict';
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. factory['default'] = factory;
  13. module.exports = factory;
  14. } else if (typeof define === 'function' && define.amd) {
  15. define('highcharts/modules/wordcloud', ['highcharts'], function (Highcharts) {
  16. factory(Highcharts);
  17. factory.Highcharts = Highcharts;
  18. return factory;
  19. });
  20. } else {
  21. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  22. }
  23. }(function (Highcharts) {
  24. var _modules = Highcharts ? Highcharts._modules : {};
  25. function _registerModule(obj, path, args, fn) {
  26. if (!obj.hasOwnProperty(path)) {
  27. obj[path] = fn.apply(null, args);
  28. }
  29. }
  30. _registerModule(_modules, 'Mixins/DrawPoint.js', [], function () {
  31. /* *
  32. *
  33. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  34. *
  35. * */
  36. var isFn = function (x) {
  37. return typeof x === 'function';
  38. };
  39. /* eslint-disable no-invalid-this, valid-jsdoc */
  40. /**
  41. * Handles the drawing of a component.
  42. * Can be used for any type of component that reserves the graphic property, and
  43. * provides a shouldDraw on its context.
  44. *
  45. * @private
  46. * @function draw
  47. * @param {DrawPointParams} params
  48. * Parameters.
  49. *
  50. * @todo add type checking.
  51. * @todo export this function to enable usage
  52. */
  53. var draw = function draw(params) {
  54. var _a;
  55. var component = this,
  56. graphic = component.graphic,
  57. animatableAttribs = params.animatableAttribs,
  58. onComplete = params.onComplete,
  59. css = params.css,
  60. renderer = params.renderer,
  61. animation = (_a = component.series) === null || _a === void 0 ? void 0 : _a.options.animation;
  62. if (component.shouldDraw()) {
  63. if (!graphic) {
  64. component.graphic = graphic =
  65. renderer[params.shapeType](params.shapeArgs)
  66. .add(params.group);
  67. }
  68. graphic
  69. .css(css)
  70. .attr(params.attribs)
  71. .animate(animatableAttribs, params.isNew ? false : animation, onComplete);
  72. }
  73. else if (graphic) {
  74. var destroy = function () {
  75. component.graphic = graphic = graphic.destroy();
  76. if (isFn(onComplete)) {
  77. onComplete();
  78. }
  79. };
  80. // animate only runs complete callback if something was animated.
  81. if (Object.keys(animatableAttribs).length) {
  82. graphic.animate(animatableAttribs, void 0, function () {
  83. destroy();
  84. });
  85. }
  86. else {
  87. destroy();
  88. }
  89. }
  90. };
  91. /**
  92. * An extended version of draw customized for points.
  93. * It calls additional methods that is expected when rendering a point.
  94. * @private
  95. * @param {Highcharts.Dictionary<any>} params Parameters
  96. */
  97. var drawPoint = function drawPoint(params) {
  98. var point = this,
  99. attribs = params.attribs = params.attribs || {};
  100. // Assigning class in dot notation does go well in IE8
  101. // eslint-disable-next-line dot-notation
  102. attribs['class'] = point.getClassName();
  103. // Call draw to render component
  104. draw.call(point, params);
  105. };
  106. var drawPointModule = {
  107. draw: draw,
  108. drawPoint: drawPoint,
  109. isFn: isFn
  110. };
  111. return drawPointModule;
  112. });
  113. _registerModule(_modules, 'Mixins/Polygon.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  114. /* *
  115. *
  116. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  117. *
  118. * */
  119. /**
  120. * @private
  121. * @interface Highcharts.PolygonPointObject
  122. */ /**
  123. * @name Highcharts.PolygonPointObject#0
  124. * @type {number}
  125. */ /**
  126. * @name Highcharts.PolygonPointObject#1
  127. * @type {number}
  128. */
  129. /**
  130. * @private
  131. * @interface Highcharts.PolygonObject
  132. * @extends Array<Highcharts.PolygonPointObject>
  133. */ /**
  134. * @name Highcharts.PolygonObject#axes
  135. * @type {Array<PolygonPointObject>}
  136. */
  137. var find = U.find,
  138. isArray = U.isArray,
  139. isNumber = U.isNumber;
  140. var deg2rad = H.deg2rad;
  141. /* eslint-disable no-invalid-this, valid-jsdoc */
  142. /**
  143. * Alternative solution to correctFloat.
  144. * E.g Highcharts.correctFloat(123, 2) returns 120, when it should be 123.
  145. *
  146. * @private
  147. * @function correctFloat
  148. * @param {number} number
  149. * @param {number} [precision]
  150. * @return {number}
  151. */
  152. var correctFloat = function (number,
  153. precision) {
  154. var p = isNumber(precision) ? precision : 14,
  155. magnitude = Math.pow(10,
  156. p);
  157. return Math.round(number * magnitude) / magnitude;
  158. };
  159. /**
  160. * Calculates the normals to a line between two points.
  161. *
  162. * @private
  163. * @function getNormals
  164. * @param {Highcharts.PolygonPointObject} p1
  165. * Start point for the line. Array of x and y value.
  166. * @param {Highcharts.PolygonPointObject} p2
  167. * End point for the line. Array of x and y value.
  168. * @return {Highcharts.PolygonObject}
  169. * Returns the two normals in an array.
  170. */
  171. var getNormals = function getNormal(p1,
  172. p2) {
  173. var dx = p2[0] - p1[0], // x2 - x1
  174. dy = p2[1] - p1[1]; // y2 - y1
  175. return [
  176. [-dy,
  177. dx],
  178. [dy, -dx]
  179. ];
  180. };
  181. /**
  182. * Calculates the dot product of two coordinates. The result is a scalar value.
  183. *
  184. * @private
  185. * @function dotProduct
  186. * @param {Highcharts.PolygonPointObject} a
  187. * The x and y coordinates of the first point.
  188. *
  189. * @param {Highcharts.PolygonPointObject} b
  190. * The x and y coordinates of the second point.
  191. *
  192. * @return {number}
  193. * Returns the dot product of a and b.
  194. */
  195. var dotProduct = function dotProduct(a,
  196. b) {
  197. var ax = a[0],
  198. ay = a[1],
  199. bx = b[0],
  200. by = b[1];
  201. return ax * bx + ay * by;
  202. };
  203. /**
  204. * Projects a polygon onto a coordinate.
  205. *
  206. * @private
  207. * @function project
  208. * @param {Highcharts.PolygonObject} polygon
  209. * Array of points in a polygon.
  210. * @param {Highcharts.PolygonPointObject} target
  211. * The coordinate of pr
  212. * @return {Highcharts.RangeObject}
  213. */
  214. var project = function project(polygon,
  215. target) {
  216. var products = polygon.map(function (point) {
  217. return dotProduct(point,
  218. target);
  219. });
  220. return {
  221. min: Math.min.apply(this, products),
  222. max: Math.max.apply(this, products)
  223. };
  224. };
  225. /**
  226. * Rotates a point clockwise around the origin.
  227. *
  228. * @private
  229. * @function rotate2DToOrigin
  230. * @param {Highcharts.PolygonPointObject} point
  231. * The x and y coordinates for the point.
  232. * @param {number} angle
  233. * The angle of rotation.
  234. * @return {Highcharts.PolygonPointObject}
  235. * The x and y coordinate for the rotated point.
  236. */
  237. var rotate2DToOrigin = function (point,
  238. angle) {
  239. var x = point[0],
  240. y = point[1],
  241. rad = deg2rad * -angle,
  242. cosAngle = Math.cos(rad),
  243. sinAngle = Math.sin(rad);
  244. return [
  245. correctFloat(x * cosAngle - y * sinAngle),
  246. correctFloat(x * sinAngle + y * cosAngle)
  247. ];
  248. };
  249. /**
  250. * Rotate a point clockwise around another point.
  251. *
  252. * @private
  253. * @function rotate2DToPoint
  254. * @param {Highcharts.PolygonPointObject} point
  255. * The x and y coordinates for the point.
  256. * @param {Highcharts.PolygonPointObject} origin
  257. * The point to rotate around.
  258. * @param {number} angle
  259. * The angle of rotation.
  260. * @return {Highcharts.PolygonPointObject}
  261. * The x and y coordinate for the rotated point.
  262. */
  263. var rotate2DToPoint = function (point,
  264. origin,
  265. angle) {
  266. var x = point[0] - origin[0],
  267. y = point[1] - origin[1],
  268. rotated = rotate2DToOrigin([x,
  269. y],
  270. angle);
  271. return [
  272. rotated[0] + origin[0],
  273. rotated[1] + origin[1]
  274. ];
  275. };
  276. /**
  277. * @private
  278. */
  279. var isAxesEqual = function (axis1,
  280. axis2) {
  281. return (axis1[0] === axis2[0] &&
  282. axis1[1] === axis2[1]);
  283. };
  284. /**
  285. * @private
  286. */
  287. var getAxesFromPolygon = function (polygon) {
  288. var points,
  289. axes = polygon.axes;
  290. if (!isArray(axes)) {
  291. axes = [];
  292. points = points = polygon.concat([polygon[0]]);
  293. points.reduce(function findAxis(p1, p2) {
  294. var normals = getNormals(p1,
  295. p2),
  296. axis = normals[0]; // Use the left normal as axis.
  297. // Check that the axis is unique.
  298. if (!find(axes,
  299. function (existing) {
  300. return isAxesEqual(existing,
  301. axis);
  302. })) {
  303. axes.push(axis);
  304. }
  305. // Return p2 to be used as p1 in next iteration.
  306. return p2;
  307. });
  308. polygon.axes = axes;
  309. }
  310. return axes;
  311. };
  312. /**
  313. * @private
  314. */
  315. var getAxes = function (polygon1,
  316. polygon2) {
  317. // Get the axis from both polygons.
  318. var axes1 = getAxesFromPolygon(polygon1),
  319. axes2 = getAxesFromPolygon(polygon2);
  320. return axes1.concat(axes2);
  321. };
  322. /**
  323. * @private
  324. */
  325. var getPolygon = function (x,
  326. y,
  327. width,
  328. height,
  329. rotation) {
  330. var origin = [x,
  331. y],
  332. left = x - (width / 2),
  333. right = x + (width / 2),
  334. top = y - (height / 2),
  335. bottom = y + (height / 2),
  336. polygon = [
  337. [left,
  338. top],
  339. [right,
  340. top],
  341. [right,
  342. bottom],
  343. [left,
  344. bottom]
  345. ];
  346. return polygon.map(function (point) {
  347. return rotate2DToPoint(point, origin, -rotation);
  348. });
  349. };
  350. /**
  351. * @private
  352. */
  353. var getBoundingBoxFromPolygon = function (points) {
  354. return points.reduce(function (obj,
  355. point) {
  356. var x = point[0],
  357. y = point[1];
  358. obj.left = Math.min(x, obj.left);
  359. obj.right = Math.max(x, obj.right);
  360. obj.bottom = Math.max(y, obj.bottom);
  361. obj.top = Math.min(y, obj.top);
  362. return obj;
  363. }, {
  364. left: Number.MAX_VALUE,
  365. right: -Number.MAX_VALUE,
  366. bottom: -Number.MAX_VALUE,
  367. top: Number.MAX_VALUE
  368. });
  369. };
  370. /**
  371. * @private
  372. */
  373. var isPolygonsOverlappingOnAxis = function (axis,
  374. polygon1,
  375. polygon2) {
  376. var projection1 = project(polygon1,
  377. axis),
  378. projection2 = project(polygon2,
  379. axis),
  380. isOverlapping = !(projection2.min > projection1.max ||
  381. projection2.max < projection1.min);
  382. return !isOverlapping;
  383. };
  384. /**
  385. * Checks wether two convex polygons are colliding by using the Separating Axis
  386. * Theorem.
  387. *
  388. * @private
  389. * @function isPolygonsColliding
  390. * @param {Highcharts.PolygonObject} polygon1
  391. * First polygon.
  392. *
  393. * @param {Highcharts.PolygonObject} polygon2
  394. * Second polygon.
  395. *
  396. * @return {boolean}
  397. * Returns true if they are colliding, otherwise false.
  398. */
  399. var isPolygonsColliding = function isPolygonsColliding(polygon1,
  400. polygon2) {
  401. var axes = getAxes(polygon1,
  402. polygon2),
  403. overlappingOnAllAxes = !find(axes,
  404. function (axis) {
  405. return isPolygonsOverlappingOnAxis(axis,
  406. polygon1,
  407. polygon2);
  408. });
  409. return overlappingOnAllAxes;
  410. };
  411. /**
  412. * @private
  413. */
  414. var movePolygon = function (deltaX,
  415. deltaY,
  416. polygon) {
  417. return polygon.map(function (point) {
  418. return [
  419. point[0] + deltaX,
  420. point[1] + deltaY
  421. ];
  422. });
  423. };
  424. var collision = {
  425. getBoundingBoxFromPolygon: getBoundingBoxFromPolygon,
  426. getPolygon: getPolygon,
  427. isPolygonsColliding: isPolygonsColliding,
  428. movePolygon: movePolygon,
  429. rotate2DToOrigin: rotate2DToOrigin,
  430. rotate2DToPoint: rotate2DToPoint
  431. };
  432. return collision;
  433. });
  434. _registerModule(_modules, 'Series/WordcloudSeries.js', [_modules['Core/Series/Series.js'], _modules['Mixins/DrawPoint.js'], _modules['Core/Globals.js'], _modules['Mixins/Polygon.js'], _modules['Core/Utilities.js']], function (BaseSeries, DrawPointMixin, H, PolygonMixin, U) {
  435. /* *
  436. *
  437. * Experimental Highcharts module which enables visualization of a word cloud.
  438. *
  439. * (c) 2016-2020 Highsoft AS
  440. * Authors: Jon Arild Nygard
  441. *
  442. * License: www.highcharts.com/license
  443. *
  444. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  445. * */
  446. var drawPoint = DrawPointMixin.drawPoint;
  447. var noop = H.noop;
  448. var getBoundingBoxFromPolygon = PolygonMixin.getBoundingBoxFromPolygon,
  449. getPolygon = PolygonMixin.getPolygon,
  450. isPolygonsColliding = PolygonMixin.isPolygonsColliding,
  451. movePolygon = PolygonMixin.movePolygon,
  452. rotate2DToOrigin = PolygonMixin.rotate2DToOrigin,
  453. rotate2DToPoint = PolygonMixin.rotate2DToPoint;
  454. var extend = U.extend,
  455. find = U.find,
  456. isArray = U.isArray,
  457. isNumber = U.isNumber,
  458. isObject = U.isObject,
  459. merge = U.merge;
  460. var Series = H.Series;
  461. /**
  462. * Detects if there is a collision between two rectangles.
  463. *
  464. * @private
  465. * @function isRectanglesIntersecting
  466. *
  467. * @param {Highcharts.PolygonBoxObject} r1
  468. * First rectangle.
  469. *
  470. * @param {Highcharts.PolygonBoxObject} r2
  471. * Second rectangle.
  472. *
  473. * @return {boolean}
  474. * Returns true if the rectangles overlap.
  475. */
  476. function isRectanglesIntersecting(r1, r2) {
  477. return !(r2.left > r1.right ||
  478. r2.right < r1.left ||
  479. r2.top > r1.bottom ||
  480. r2.bottom < r1.top);
  481. }
  482. /**
  483. * Detects if a word collides with any previously placed words.
  484. *
  485. * @private
  486. * @function intersectsAnyWord
  487. *
  488. * @param {Highcharts.Point} point
  489. * Point which the word is connected to.
  490. *
  491. * @param {Array<Highcharts.Point>} points
  492. * Previously placed points to check against.
  493. *
  494. * @return {boolean}
  495. * Returns true if there is collision.
  496. */
  497. function intersectsAnyWord(point, points) {
  498. var intersects = false,
  499. rect = point.rect,
  500. polygon = point.polygon,
  501. lastCollidedWith = point.lastCollidedWith,
  502. isIntersecting = function (p) {
  503. var result = isRectanglesIntersecting(rect,
  504. p.rect);
  505. if (result &&
  506. (point.rotation % 90 || p.rotation % 90)) {
  507. result = isPolygonsColliding(polygon, p.polygon);
  508. }
  509. return result;
  510. };
  511. // If the point has already intersected a different point, chances are they
  512. // are still intersecting. So as an enhancement we check this first.
  513. if (lastCollidedWith) {
  514. intersects = isIntersecting(lastCollidedWith);
  515. // If they no longer intersects, remove the cache from the point.
  516. if (!intersects) {
  517. delete point.lastCollidedWith;
  518. }
  519. }
  520. // If not already found, then check if we can find a point that is
  521. // intersecting.
  522. if (!intersects) {
  523. intersects = !!find(points, function (p) {
  524. var result = isIntersecting(p);
  525. if (result) {
  526. point.lastCollidedWith = p;
  527. }
  528. return result;
  529. });
  530. }
  531. return intersects;
  532. }
  533. /**
  534. * Gives a set of cordinates for an Archimedian Spiral.
  535. *
  536. * @private
  537. * @function archimedeanSpiral
  538. *
  539. * @param {number} attempt
  540. * How far along the spiral we have traversed.
  541. *
  542. * @param {Highcharts.WordcloudSpiralParamsObject} [params]
  543. * Additional parameters.
  544. *
  545. * @return {boolean|Highcharts.PositionObject}
  546. * Resulting coordinates, x and y. False if the word should be dropped from the
  547. * visualization.
  548. */
  549. function archimedeanSpiral(attempt, params) {
  550. var field = params.field,
  551. result = false,
  552. maxDelta = (field.width * field.width) + (field.height * field.height),
  553. t = attempt * 0.8; // 0.2 * 4 = 0.8. Enlarging the spiral.
  554. // Emergency brake. TODO make spiralling logic more foolproof.
  555. if (attempt <= 10000) {
  556. result = {
  557. x: t * Math.cos(t),
  558. y: t * Math.sin(t)
  559. };
  560. if (!(Math.min(Math.abs(result.x), Math.abs(result.y)) < maxDelta)) {
  561. result = false;
  562. }
  563. }
  564. return result;
  565. }
  566. /**
  567. * Gives a set of cordinates for an rectangular spiral.
  568. *
  569. * @private
  570. * @function squareSpiral
  571. *
  572. * @param {number} attempt
  573. * How far along the spiral we have traversed.
  574. *
  575. * @param {Highcharts.WordcloudSpiralParamsObject} [params]
  576. * Additional parameters.
  577. *
  578. * @return {boolean|Highcharts.PositionObject}
  579. * Resulting coordinates, x and y. False if the word should be dropped from the
  580. * visualization.
  581. */
  582. function squareSpiral(attempt, params) {
  583. var a = attempt * 4,
  584. k = Math.ceil((Math.sqrt(a) - 1) / 2),
  585. t = 2 * k + 1,
  586. m = Math.pow(t, 2),
  587. isBoolean = function (x) {
  588. return typeof x === 'boolean';
  589. }, result = false;
  590. t -= 1;
  591. if (attempt <= 10000) {
  592. if (isBoolean(result) && a >= m - t) {
  593. result = {
  594. x: k - (m - a),
  595. y: -k
  596. };
  597. }
  598. m -= t;
  599. if (isBoolean(result) && a >= m - t) {
  600. result = {
  601. x: -k,
  602. y: -k + (m - a)
  603. };
  604. }
  605. m -= t;
  606. if (isBoolean(result)) {
  607. if (a >= m - t) {
  608. result = {
  609. x: -k + (m - a),
  610. y: k
  611. };
  612. }
  613. else {
  614. result = {
  615. x: k,
  616. y: k - (m - a - t)
  617. };
  618. }
  619. }
  620. result.x *= 5;
  621. result.y *= 5;
  622. }
  623. return result;
  624. }
  625. /**
  626. * Gives a set of cordinates for an rectangular spiral.
  627. *
  628. * @private
  629. * @function rectangularSpiral
  630. *
  631. * @param {number} attempt
  632. * How far along the spiral we have traversed.
  633. *
  634. * @param {Highcharts.WordcloudSpiralParamsObject} [params]
  635. * Additional parameters.
  636. *
  637. * @return {boolean|Higcharts.PositionObject}
  638. * Resulting coordinates, x and y. False if the word should be dropped from the
  639. * visualization.
  640. */
  641. function rectangularSpiral(attempt, params) {
  642. var result = squareSpiral(attempt,
  643. params),
  644. field = params.field;
  645. if (result) {
  646. result.x *= field.ratioX;
  647. result.y *= field.ratioY;
  648. }
  649. return result;
  650. }
  651. /**
  652. * @private
  653. * @function getRandomPosition
  654. *
  655. * @param {number} size
  656. * Random factor.
  657. *
  658. * @return {number}
  659. * Random position.
  660. */
  661. function getRandomPosition(size) {
  662. return Math.round((size * (Math.random() + 0.5)) / 2);
  663. }
  664. /**
  665. * Calculates the proper scale to fit the cloud inside the plotting area.
  666. *
  667. * @private
  668. * @function getScale
  669. *
  670. * @param {number} targetWidth
  671. * Width of target area.
  672. *
  673. * @param {number} targetHeight
  674. * Height of target area.
  675. *
  676. * @param {object} field
  677. * The playing field.
  678. *
  679. * @param {Highcharts.Series} series
  680. * Series object.
  681. *
  682. * @return {number}
  683. * Returns the value to scale the playing field up to the size of the target
  684. * area.
  685. */
  686. function getScale(targetWidth, targetHeight, field) {
  687. var height = Math.max(Math.abs(field.top),
  688. Math.abs(field.bottom)) * 2,
  689. width = Math.max(Math.abs(field.left),
  690. Math.abs(field.right)) * 2,
  691. scaleX = width > 0 ? 1 / width * targetWidth : 1,
  692. scaleY = height > 0 ? 1 / height * targetHeight : 1;
  693. return Math.min(scaleX, scaleY);
  694. }
  695. /**
  696. * Calculates what is called the playing field. The field is the area which all
  697. * the words are allowed to be positioned within. The area is proportioned to
  698. * match the target aspect ratio.
  699. *
  700. * @private
  701. * @function getPlayingField
  702. *
  703. * @param {number} targetWidth
  704. * Width of the target area.
  705. *
  706. * @param {number} targetHeight
  707. * Height of the target area.
  708. *
  709. * @param {Array<Highcharts.Point>} data
  710. * Array of points.
  711. *
  712. * @param {object} data.dimensions
  713. * The height and width of the word.
  714. *
  715. * @return {object}
  716. * The width and height of the playing field.
  717. */
  718. function getPlayingField(targetWidth, targetHeight, data) {
  719. var info = data.reduce(function (obj,
  720. point) {
  721. var dimensions = point.dimensions,
  722. x = Math.max(dimensions.width,
  723. dimensions.height);
  724. // Find largest height.
  725. obj.maxHeight = Math.max(obj.maxHeight, dimensions.height);
  726. // Find largest width.
  727. obj.maxWidth = Math.max(obj.maxWidth, dimensions.width);
  728. // Sum up the total maximum area of all the words.
  729. obj.area += x * x;
  730. return obj;
  731. }, {
  732. maxHeight: 0,
  733. maxWidth: 0,
  734. area: 0
  735. }),
  736. /**
  737. * Use largest width, largest height, or root of total area to give size
  738. * to the playing field.
  739. */
  740. x = Math.max(info.maxHeight, // Have enough space for the tallest word
  741. info.maxWidth, // Have enough space for the broadest word
  742. // Adjust 15% to account for close packing of words
  743. Math.sqrt(info.area) * 0.85), ratioX = targetWidth > targetHeight ? targetWidth / targetHeight : 1, ratioY = targetHeight > targetWidth ? targetHeight / targetWidth : 1;
  744. return {
  745. width: x * ratioX,
  746. height: x * ratioY,
  747. ratioX: ratioX,
  748. ratioY: ratioY
  749. };
  750. }
  751. /**
  752. * Calculates a number of degrees to rotate, based upon a number of orientations
  753. * within a range from-to.
  754. *
  755. * @private
  756. * @function getRotation
  757. *
  758. * @param {number} [orientations]
  759. * Number of orientations.
  760. *
  761. * @param {number} [index]
  762. * Index of point, used to decide orientation.
  763. *
  764. * @param {number} [from]
  765. * The smallest degree of rotation.
  766. *
  767. * @param {number} [to]
  768. * The largest degree of rotation.
  769. *
  770. * @return {boolean|number}
  771. * Returns the resulting rotation for the word. Returns false if invalid input
  772. * parameters.
  773. */
  774. function getRotation(orientations, index, from, to) {
  775. var result = false, // Default to false
  776. range,
  777. intervals,
  778. orientation;
  779. // Check if we have valid input parameters.
  780. if (isNumber(orientations) &&
  781. isNumber(index) &&
  782. isNumber(from) &&
  783. isNumber(to) &&
  784. orientations > 0 &&
  785. index > -1 &&
  786. to > from) {
  787. range = to - from;
  788. intervals = range / (orientations - 1 || 1);
  789. orientation = index % orientations;
  790. result = from + (orientation * intervals);
  791. }
  792. return result;
  793. }
  794. /**
  795. * Calculates the spiral positions and store them in scope for quick access.
  796. *
  797. * @private
  798. * @function getSpiral
  799. *
  800. * @param {Function} fn
  801. * The spiral function.
  802. *
  803. * @param {object} params
  804. * Additional parameters for the spiral.
  805. *
  806. * @return {Function}
  807. * Function with access to spiral positions.
  808. */
  809. function getSpiral(fn, params) {
  810. var length = 10000,
  811. i,
  812. arr = [];
  813. for (i = 1; i < length; i++) {
  814. arr.push(fn(i, params)); // @todo unnecessary amount of precaclulation
  815. }
  816. return function (attempt) {
  817. return attempt <= length ? arr[attempt - 1] : false;
  818. };
  819. }
  820. /**
  821. * Detects if a word is placed outside the playing field.
  822. *
  823. * @private
  824. * @function outsidePlayingField
  825. *
  826. * @param {Highcharts.PolygonBoxObject} rect
  827. * The word box.
  828. *
  829. * @param {Highcharts.WordcloudFieldObject} field
  830. * The width and height of the playing field.
  831. *
  832. * @return {boolean}
  833. * Returns true if the word is placed outside the field.
  834. */
  835. function outsidePlayingField(rect, field) {
  836. var playingField = {
  837. left: -(field.width / 2),
  838. right: field.width / 2,
  839. top: -(field.height / 2),
  840. bottom: field.height / 2
  841. };
  842. return !(playingField.left < rect.left &&
  843. playingField.right > rect.right &&
  844. playingField.top < rect.top &&
  845. playingField.bottom > rect.bottom);
  846. }
  847. /**
  848. * Check if a point intersects with previously placed words, or if it goes
  849. * outside the field boundaries. If a collision, then try to adjusts the
  850. * position.
  851. *
  852. * @private
  853. * @function intersectionTesting
  854. *
  855. * @param {Highcharts.Point} point
  856. * Point to test for intersections.
  857. *
  858. * @param {Highcharts.WordcloudTestOptionsObject} options
  859. * Options object.
  860. *
  861. * @return {boolean|Highcharts.PositionObject}
  862. * Returns an object with how much to correct the positions. Returns false if
  863. * the word should not be placed at all.
  864. */
  865. function intersectionTesting(point, options) {
  866. var placed = options.placed,
  867. field = options.field,
  868. rectangle = options.rectangle,
  869. polygon = options.polygon,
  870. spiral = options.spiral,
  871. attempt = 1,
  872. delta = {
  873. x: 0,
  874. y: 0
  875. },
  876. // Make a copy to update values during intersection testing.
  877. rect = point.rect = extend({},
  878. rectangle);
  879. point.polygon = polygon;
  880. point.rotation = options.rotation;
  881. /* while w intersects any previously placed words:
  882. do {
  883. move w a little bit along a spiral path
  884. } while any part of w is outside the playing field and
  885. the spiral radius is still smallish */
  886. while (delta !== false &&
  887. (intersectsAnyWord(point, placed) ||
  888. outsidePlayingField(rect, field))) {
  889. delta = spiral(attempt);
  890. if (isObject(delta)) {
  891. // Update the DOMRect with new positions.
  892. rect.left = rectangle.left + delta.x;
  893. rect.right = rectangle.right + delta.x;
  894. rect.top = rectangle.top + delta.y;
  895. rect.bottom = rectangle.bottom + delta.y;
  896. point.polygon = movePolygon(delta.x, delta.y, polygon);
  897. }
  898. attempt++;
  899. }
  900. return delta;
  901. }
  902. /**
  903. * Extends the playing field to have enough space to fit a given word.
  904. *
  905. * @private
  906. * @function extendPlayingField
  907. *
  908. * @param {Highcharts.WordcloudFieldObject} field
  909. * The width, height and ratios of a playing field.
  910. *
  911. * @param {Highcharts.PolygonBoxObject} rectangle
  912. * The bounding box of the word to add space for.
  913. *
  914. * @return {Highcharts.WordcloudFieldObject}
  915. * Returns the extended playing field with updated height and width.
  916. */
  917. function extendPlayingField(field, rectangle) {
  918. var height,
  919. width,
  920. ratioX,
  921. ratioY,
  922. x,
  923. extendWidth,
  924. extendHeight,
  925. result;
  926. if (isObject(field) && isObject(rectangle)) {
  927. height = (rectangle.bottom - rectangle.top);
  928. width = (rectangle.right - rectangle.left);
  929. ratioX = field.ratioX;
  930. ratioY = field.ratioY;
  931. // Use the same variable to extend both the height and width.
  932. x = ((width * ratioX) > (height * ratioY)) ? width : height;
  933. // Multiply variable with ratios to preserve aspect ratio.
  934. extendWidth = x * ratioX;
  935. extendHeight = x * ratioY;
  936. // Calculate the size of the new field after adding space for the word.
  937. result = merge(field, {
  938. // Add space on the left and right.
  939. width: field.width + (extendWidth * 2),
  940. // Add space on the top and bottom.
  941. height: field.height + (extendHeight * 2)
  942. });
  943. }
  944. else {
  945. result = field;
  946. }
  947. // Return the new extended field.
  948. return result;
  949. }
  950. /**
  951. * If a rectangle is outside a give field, then the boundaries of the field is
  952. * adjusted accordingly. Modifies the field object which is passed as the first
  953. * parameter.
  954. *
  955. * @private
  956. * @function updateFieldBoundaries
  957. *
  958. * @param {Highcharts.WordcloudFieldObject} field
  959. * The bounding box of a playing field.
  960. *
  961. * @param {Highcharts.PolygonBoxObject} rectangle
  962. * The bounding box for a placed point.
  963. *
  964. * @return {Highcharts.WordcloudFieldObject}
  965. * Returns a modified field object.
  966. */
  967. function updateFieldBoundaries(field, rectangle) {
  968. // @todo improve type checking.
  969. if (!isNumber(field.left) || field.left > rectangle.left) {
  970. field.left = rectangle.left;
  971. }
  972. if (!isNumber(field.right) || field.right < rectangle.right) {
  973. field.right = rectangle.right;
  974. }
  975. if (!isNumber(field.top) || field.top > rectangle.top) {
  976. field.top = rectangle.top;
  977. }
  978. if (!isNumber(field.bottom) || field.bottom < rectangle.bottom) {
  979. field.bottom = rectangle.bottom;
  980. }
  981. return field;
  982. }
  983. /**
  984. * A word cloud is a visualization of a set of words, where the size and
  985. * placement of a word is determined by how it is weighted.
  986. *
  987. * @sample highcharts/demo/wordcloud
  988. * Word Cloud chart
  989. *
  990. * @extends plotOptions.column
  991. * @excluding allAreas, boostThreshold, clip, colorAxis, compare,
  992. * compareBase, crisp, cropTreshold, dataGrouping, dataLabels,
  993. * depth, dragDrop, edgeColor, findNearestPointBy,
  994. * getExtremesFromAll, grouping, groupPadding, groupZPadding,
  995. * joinBy, maxPointWidth, minPointLength, navigatorOptions,
  996. * negativeColor, pointInterval, pointIntervalUnit, pointPadding,
  997. * pointPlacement, pointRange, pointStart, pointWidth, pointStart,
  998. * pointWidth, shadow, showCheckbox, showInNavigator,
  999. * softThreshold, stacking, threshold, zoneAxis, zones,
  1000. * dataSorting, boostBlending
  1001. * @product highcharts
  1002. * @since 6.0.0
  1003. * @requires modules/wordcloud
  1004. * @optionparent plotOptions.wordcloud
  1005. */
  1006. var wordCloudOptions = {
  1007. /**
  1008. * If there is no space for a word on the playing field, then this option
  1009. * will allow the playing field to be extended to fit the word. If false
  1010. * then the word will be dropped from the visualization.
  1011. *
  1012. * NB! This option is currently not decided to be published in the API, and
  1013. * is therefore marked as private.
  1014. *
  1015. * @private
  1016. */
  1017. allowExtendPlayingField: true,
  1018. animation: {
  1019. /** @internal */
  1020. duration: 500
  1021. },
  1022. borderWidth: 0,
  1023. clip: false,
  1024. colorByPoint: true,
  1025. /**
  1026. * A threshold determining the minimum font size that can be applied to a
  1027. * word.
  1028. */
  1029. minFontSize: 1,
  1030. /**
  1031. * The word with the largest weight will have a font size equal to this
  1032. * value. The font size of a word is the ratio between its weight and the
  1033. * largest occuring weight, multiplied with the value of maxFontSize.
  1034. */
  1035. maxFontSize: 25,
  1036. /**
  1037. * This option decides which algorithm is used for placement, and rotation
  1038. * of a word. The choice of algorith is therefore a crucial part of the
  1039. * resulting layout of the wordcloud. It is possible for users to add their
  1040. * own custom placement strategies for use in word cloud. Read more about it
  1041. * in our
  1042. * [documentation](https://www.highcharts.com/docs/chart-and-series-types/word-cloud-series#custom-placement-strategies)
  1043. *
  1044. * @validvalue: ["center", "random"]
  1045. */
  1046. placementStrategy: 'center',
  1047. /**
  1048. * Rotation options for the words in the wordcloud.
  1049. *
  1050. * @sample highcharts/plotoptions/wordcloud-rotation
  1051. * Word cloud with rotation
  1052. */
  1053. rotation: {
  1054. /**
  1055. * The smallest degree of rotation for a word.
  1056. */
  1057. from: 0,
  1058. /**
  1059. * The number of possible orientations for a word, within the range of
  1060. * `rotation.from` and `rotation.to`. Must be a number larger than 0.
  1061. */
  1062. orientations: 2,
  1063. /**
  1064. * The largest degree of rotation for a word.
  1065. */
  1066. to: 90
  1067. },
  1068. showInLegend: false,
  1069. /**
  1070. * Spiral used for placing a word after the initial position experienced a
  1071. * collision with either another word or the borders.
  1072. * It is possible for users to add their own custom spiralling algorithms
  1073. * for use in word cloud. Read more about it in our
  1074. * [documentation](https://www.highcharts.com/docs/chart-and-series-types/word-cloud-series#custom-spiralling-algorithm)
  1075. *
  1076. * @validvalue: ["archimedean", "rectangular", "square"]
  1077. */
  1078. spiral: 'rectangular',
  1079. /**
  1080. * CSS styles for the words.
  1081. *
  1082. * @type {Highcharts.CSSObject}
  1083. * @default {"fontFamily":"sans-serif", "fontWeight": "900"}
  1084. */
  1085. style: {
  1086. /** @ignore-option */
  1087. fontFamily: 'sans-serif',
  1088. /** @ignore-option */
  1089. fontWeight: '900',
  1090. /** @ignore-option */
  1091. whiteSpace: 'nowrap'
  1092. },
  1093. tooltip: {
  1094. followPointer: true,
  1095. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.weight}</b><br/>'
  1096. }
  1097. };
  1098. // Properties of the WordCloud series.
  1099. var wordCloudSeries = {
  1100. animate: Series.prototype.animate,
  1101. animateDrilldown: noop,
  1102. animateDrillupFrom: noop,
  1103. setClip: noop,
  1104. bindAxes: function () {
  1105. var wordcloudAxis = {
  1106. endOnTick: false,
  1107. gridLineWidth: 0,
  1108. lineWidth: 0,
  1109. maxPadding: 0,
  1110. startOnTick: false,
  1111. title: null,
  1112. tickPositions: []
  1113. };
  1114. Series.prototype.bindAxes.call(this);
  1115. extend(this.yAxis.options, wordcloudAxis);
  1116. extend(this.xAxis.options, wordcloudAxis);
  1117. },
  1118. pointAttribs: function (point, state) {
  1119. var attribs = H.seriesTypes.column.prototype
  1120. .pointAttribs.call(this,
  1121. point,
  1122. state);
  1123. delete attribs.stroke;
  1124. delete attribs['stroke-width'];
  1125. return attribs;
  1126. },
  1127. /**
  1128. * Calculates the fontSize of a word based on its weight.
  1129. *
  1130. * @private
  1131. * @function Highcharts.Series#deriveFontSize
  1132. *
  1133. * @param {number} [relativeWeight=0]
  1134. * The weight of the word, on a scale 0-1.
  1135. *
  1136. * @param {number} [maxFontSize=1]
  1137. * The maximum font size of a word.
  1138. *
  1139. * @param {number} [minFontSize=1]
  1140. * The minimum font size of a word.
  1141. *
  1142. * @return {number}
  1143. * Returns the resulting fontSize of a word. If minFontSize is larger then
  1144. * maxFontSize the result will equal minFontSize.
  1145. */
  1146. deriveFontSize: function deriveFontSize(relativeWeight, maxFontSize, minFontSize) {
  1147. var weight = isNumber(relativeWeight) ? relativeWeight : 0,
  1148. max = isNumber(maxFontSize) ? maxFontSize : 1,
  1149. min = isNumber(minFontSize) ? minFontSize : 1;
  1150. return Math.floor(Math.max(min, weight * max));
  1151. },
  1152. drawPoints: function () {
  1153. var series = this,
  1154. hasRendered = series.hasRendered,
  1155. xAxis = series.xAxis,
  1156. yAxis = series.yAxis,
  1157. chart = series.chart,
  1158. group = series.group,
  1159. options = series.options,
  1160. animation = options.animation,
  1161. allowExtendPlayingField = options.allowExtendPlayingField,
  1162. renderer = chart.renderer,
  1163. testElement = renderer.text().add(group),
  1164. placed = [],
  1165. placementStrategy = series.placementStrategy[options.placementStrategy],
  1166. spiral,
  1167. rotation = options.rotation,
  1168. scale,
  1169. weights = series.points.map(function (p) {
  1170. return p.weight;
  1171. }), maxWeight = Math.max.apply(null, weights),
  1172. // concat() prevents from sorting the original array.
  1173. data = series.points.concat().sort(function (a, b) {
  1174. return b.weight - a.weight; // Sort descending
  1175. }), field;
  1176. // Reset the scale before finding the dimensions (#11993).
  1177. // SVGGRaphicsElement.getBBox() (used in SVGElement.getBBox(boolean))
  1178. // returns slightly different values for the same element depending on
  1179. // whether it is rendered in a group which has already defined scale
  1180. // (e.g. 6) or in the group without a scale (scale = 1).
  1181. series.group.attr({
  1182. scaleX: 1,
  1183. scaleY: 1
  1184. });
  1185. // Get the dimensions for each word.
  1186. // Used in calculating the playing field.
  1187. data.forEach(function (point) {
  1188. var relativeWeight = 1 / maxWeight * point.weight,
  1189. fontSize = series.deriveFontSize(relativeWeight,
  1190. options.maxFontSize,
  1191. options.minFontSize),
  1192. css = extend({
  1193. fontSize: fontSize + 'px'
  1194. },
  1195. options.style),
  1196. bBox;
  1197. testElement.css(css).attr({
  1198. x: 0,
  1199. y: 0,
  1200. text: point.name
  1201. });
  1202. bBox = testElement.getBBox(true);
  1203. point.dimensions = {
  1204. height: bBox.height,
  1205. width: bBox.width
  1206. };
  1207. });
  1208. // Calculate the playing field.
  1209. field = getPlayingField(xAxis.len, yAxis.len, data);
  1210. spiral = getSpiral(series.spirals[options.spiral], {
  1211. field: field
  1212. });
  1213. // Draw all the points.
  1214. data.forEach(function (point) {
  1215. var relativeWeight = 1 / maxWeight * point.weight,
  1216. fontSize = series.deriveFontSize(relativeWeight,
  1217. options.maxFontSize,
  1218. options.minFontSize),
  1219. css = extend({
  1220. fontSize: fontSize + 'px'
  1221. },
  1222. options.style),
  1223. placement = placementStrategy(point, {
  1224. data: data,
  1225. field: field,
  1226. placed: placed,
  1227. rotation: rotation
  1228. }),
  1229. attr = extend(series.pointAttribs(point, (point.selected && 'select')), {
  1230. align: 'center',
  1231. 'alignment-baseline': 'middle',
  1232. x: placement.x,
  1233. y: placement.y,
  1234. text: point.name,
  1235. rotation: placement.rotation
  1236. }),
  1237. polygon = getPolygon(placement.x,
  1238. placement.y,
  1239. point.dimensions.width,
  1240. point.dimensions.height,
  1241. placement.rotation),
  1242. rectangle = getBoundingBoxFromPolygon(polygon),
  1243. delta = intersectionTesting(point, {
  1244. rectangle: rectangle,
  1245. polygon: polygon,
  1246. field: field,
  1247. placed: placed,
  1248. spiral: spiral,
  1249. rotation: placement.rotation
  1250. }),
  1251. animate;
  1252. // If there is no space for the word, extend the playing field.
  1253. if (!delta && allowExtendPlayingField) {
  1254. // Extend the playing field to fit the word.
  1255. field = extendPlayingField(field, rectangle);
  1256. // Run intersection testing one more time to place the word.
  1257. delta = intersectionTesting(point, {
  1258. rectangle: rectangle,
  1259. polygon: polygon,
  1260. field: field,
  1261. placed: placed,
  1262. spiral: spiral,
  1263. rotation: placement.rotation
  1264. });
  1265. }
  1266. // Check if point was placed, if so delete it, otherwise place it on
  1267. // the correct positions.
  1268. if (isObject(delta)) {
  1269. attr.x += delta.x;
  1270. attr.y += delta.y;
  1271. rectangle.left += delta.x;
  1272. rectangle.right += delta.x;
  1273. rectangle.top += delta.y;
  1274. rectangle.bottom += delta.y;
  1275. field = updateFieldBoundaries(field, rectangle);
  1276. placed.push(point);
  1277. point.isNull = false;
  1278. }
  1279. else {
  1280. point.isNull = true;
  1281. }
  1282. if (animation) {
  1283. // Animate to new positions
  1284. animate = {
  1285. x: attr.x,
  1286. y: attr.y
  1287. };
  1288. // Animate from center of chart
  1289. if (!hasRendered) {
  1290. attr.x = 0;
  1291. attr.y = 0;
  1292. // or animate from previous position
  1293. }
  1294. else {
  1295. delete attr.x;
  1296. delete attr.y;
  1297. }
  1298. }
  1299. point.draw({
  1300. animatableAttribs: animate,
  1301. attribs: attr,
  1302. css: css,
  1303. group: group,
  1304. renderer: renderer,
  1305. shapeArgs: void 0,
  1306. shapeType: 'text'
  1307. });
  1308. });
  1309. // Destroy the element after use.
  1310. testElement = testElement.destroy();
  1311. // Scale the series group to fit within the plotArea.
  1312. scale = getScale(xAxis.len, yAxis.len, field);
  1313. series.group.attr({
  1314. scaleX: scale,
  1315. scaleY: scale
  1316. });
  1317. },
  1318. hasData: function () {
  1319. var series = this;
  1320. return (isObject(series) &&
  1321. series.visible === true &&
  1322. isArray(series.points) &&
  1323. series.points.length > 0);
  1324. },
  1325. // Strategies used for deciding rotation and initial position of a word. To
  1326. // implement a custom strategy, have a look at the function random for
  1327. // example.
  1328. placementStrategy: {
  1329. random: function (point, options) {
  1330. var field = options.field,
  1331. r = options.rotation;
  1332. return {
  1333. x: getRandomPosition(field.width) - (field.width / 2),
  1334. y: getRandomPosition(field.height) - (field.height / 2),
  1335. rotation: getRotation(r.orientations, point.index, r.from, r.to)
  1336. };
  1337. },
  1338. center: function (point, options) {
  1339. var r = options.rotation;
  1340. return {
  1341. x: 0,
  1342. y: 0,
  1343. rotation: getRotation(r.orientations, point.index, r.from, r.to)
  1344. };
  1345. }
  1346. },
  1347. pointArrayMap: ['weight'],
  1348. // Spirals used for placing a word after the initial position experienced a
  1349. // collision with either another word or the borders. To implement a custom
  1350. // spiral, look at the function archimedeanSpiral for example.
  1351. spirals: {
  1352. 'archimedean': archimedeanSpiral,
  1353. 'rectangular': rectangularSpiral,
  1354. 'square': squareSpiral
  1355. },
  1356. utils: {
  1357. extendPlayingField: extendPlayingField,
  1358. getRotation: getRotation,
  1359. isPolygonsColliding: isPolygonsColliding,
  1360. rotate2DToOrigin: rotate2DToOrigin,
  1361. rotate2DToPoint: rotate2DToPoint
  1362. },
  1363. getPlotBox: function () {
  1364. var series = this, chart = series.chart, inverted = chart.inverted,
  1365. // Swap axes for inverted (#2339)
  1366. xAxis = series[(inverted ? 'yAxis' : 'xAxis')], yAxis = series[(inverted ? 'xAxis' : 'yAxis')], width = xAxis ? xAxis.len : chart.plotWidth, height = yAxis ? yAxis.len : chart.plotHeight, x = xAxis ? xAxis.left : chart.plotLeft, y = yAxis ? yAxis.top : chart.plotTop;
  1367. return {
  1368. translateX: x + (width / 2),
  1369. translateY: y + (height / 2),
  1370. scaleX: 1,
  1371. scaleY: 1
  1372. };
  1373. }
  1374. };
  1375. // Properties of the Sunburst series.
  1376. var wordCloudPoint = {
  1377. draw: drawPoint,
  1378. shouldDraw: function shouldDraw() {
  1379. var point = this;
  1380. return !point.isNull;
  1381. },
  1382. isValid: function isValid() {
  1383. return true;
  1384. },
  1385. weight: 1
  1386. };
  1387. /**
  1388. * A `wordcloud` series. If the [type](#series.wordcloud.type) option is not
  1389. * specified, it is inherited from [chart.type](#chart.type).
  1390. *
  1391. * @extends series,plotOptions.wordcloud
  1392. * @exclude dataSorting, boostThreshold, boostBlending
  1393. * @product highcharts
  1394. * @requires modules/wordcloud
  1395. * @apioption series.wordcloud
  1396. */
  1397. /**
  1398. * An array of data points for the series. For the `wordcloud` series type,
  1399. * points can be given in the following ways:
  1400. *
  1401. * 1. An array of arrays with 2 values. In this case, the values correspond to
  1402. * `name,weight`.
  1403. * ```js
  1404. * data: [
  1405. * ['Lorem', 4],
  1406. * ['Ipsum', 1]
  1407. * ]
  1408. * ```
  1409. *
  1410. * 2. An array of objects with named values. The following snippet shows only a
  1411. * few settings, see the complete options set below. If the total number of
  1412. * data points exceeds the series'
  1413. * [turboThreshold](#series.arearange.turboThreshold), this option is not
  1414. * available.
  1415. * ```js
  1416. * data: [{
  1417. * name: "Lorem",
  1418. * weight: 4
  1419. * }, {
  1420. * name: "Ipsum",
  1421. * weight: 1
  1422. * }]
  1423. * ```
  1424. *
  1425. * @type {Array<Array<string,number>|*>}
  1426. * @extends series.line.data
  1427. * @excluding drilldown, marker, x, y
  1428. * @product highcharts
  1429. * @apioption series.wordcloud.data
  1430. */
  1431. /**
  1432. * The name decides the text for a word.
  1433. *
  1434. * @type {string}
  1435. * @since 6.0.0
  1436. * @product highcharts
  1437. * @apioption series.sunburst.data.name
  1438. */
  1439. /**
  1440. * The weighting of a word. The weight decides the relative size of a word
  1441. * compared to the rest of the collection.
  1442. *
  1443. * @type {number}
  1444. * @since 6.0.0
  1445. * @product highcharts
  1446. * @apioption series.sunburst.data.weight
  1447. */
  1448. ''; // detach doclets above
  1449. /**
  1450. * @private
  1451. * @class
  1452. * @name Highcharts.seriesTypes.wordcloud
  1453. *
  1454. * @augments Highcharts.Series
  1455. */
  1456. BaseSeries.seriesType('wordcloud', 'column', wordCloudOptions, wordCloudSeries, wordCloudPoint);
  1457. });
  1458. _registerModule(_modules, 'masters/modules/wordcloud.src.js', [], function () {
  1459. });
  1460. }));