{"version":3,"sources":["webpack:///../../../../../src/.internal/plugins/overLapBuster/OverlapBuster.ts","webpack:///./plugins/overlapBuster.js"],"names":["OverlapBuster_OverlapBuster","_super","OverlapBuster","_this","call","this","revealRatio","collapseDelay","tolerance","d3forceSimulation","src","_shiftedTargets","Dictionary","_disposers","push","Disposer","_targets","List","targets","events","on","ev","newValue","handleHover","handleOut","isTemplate","once","register","Object","tslib_es6","prototype","init","defineProperty","mainTarget","target","_centerTarget","cancelCollapse","hasKey","uid","collapseCurrent","nodes_1","_nodes","each","hitTest","x","pixelX","y","pixelY","radius","Math","max","measuredWidth","measuredHeight","ox","oy","setKey","originalX","dx","originalY","dy","stopAnimation","force","d","utils_Array","node","_collapseTimeout","setTimeout","isInTransition","animation","animations","pop","kill","stop","animate","property","to","defaultState","transitionDuration","undefined","clear","dispose","indexOf","sprite","invalid","validate","ax1","ay1","ax2","ay2","bx1","by1","bx2","by2","Plugin","Registry","registeredClasses","window","am4plugins_overlapBuster","overlapBuster_namespaceObject"],"mappings":";;;;;;;;;;;;;;;;;;;iRAuEAA,EAAA,SAAAC,GAwEC,SAAAC,IAAA,IAAAC,EAECF,EAAAG,KAAAC,OAAOA,YAhDDF,EAAAG,YAAsB,GAQtBH,EAAAI,cAAwB,IAexBJ,EAAAK,UAAoB,EA4B1BL,EAAKM,kBAAoBC,EAAA,IAGzBP,EAAKQ,gBAAkB,IAAIC,EAAA,EAC3BT,EAAKU,WAAWC,KAAK,IAAIC,EAAA,EAAS,WAAM,OAAAZ,EAAKQ,mBAG7CR,EAAKa,SAAW,IAAIC,EAAA,EACpBd,EAAKU,WAAWC,KAAK,IAAIC,EAAA,EAAS,WAAM,OAAAZ,EAAKe,WAG7Cf,EAAKa,SAASG,OAAOC,GAAG,WAAY,SAACC,GAGpClB,EAAKU,WAAWC,KAAK,IAAIC,EAAA,GACxBM,EAAGC,SAASH,OAAOC,GAAG,OAAQjB,EAAKoB,YAAapB,GAChDkB,EAAGC,SAASH,OAAOC,GAAG,MA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AiB/C,KAAKG,UAEzCiF,EAAMP,EAAOrC,OACb6C,EAAMR,EAAOnC,OACb4C,EAAMF,EAAMP,EAAO/B,cAAgB9C,KAAKG,UACxCoF,EAAMF,EAAMR,EAAO9B,eAAiB/C,KAAKG,UAE7C,QAASiF,EAAMF,GAAOI,EAAMN,GAAOK,EAAMF,GAAOI,EAAMN,IAIzDpF,EA5TA,CAAmC2F,EAAA,GAoUnCC,EAAA,EAASC,kBAAiC,cAAI/F,EC1Y9CgG,OAAAC,yBAAkCC","file":"./plugins/overlapBuster.js","sourcesContent":["/**\r\n * Plugin which enables automatically exploding overlapping elements.\r\n */\r\n\r\n/**\r\n * ============================================================================\r\n * IMPORTS\r\n * ============================================================================\r\n * @hidden\r\n */\r\nimport { Plugin } from \"../../core/utils/Plugin\";\r\nimport { List } from \"../../core/utils/List\";\r\nimport * as $array from \"../../core/utils/Array\";\r\n//import * as $math from \"../../core/utils/Math\";\r\nimport * as d3force from \"d3-force\";\r\nimport { Dictionary } from \"../../core/utils/Dictionary\";\r\nimport { Disposer, MultiDisposer, IDisposer } from \"../../core/utils/Disposer\";\r\nimport { Sprite } from \"../../core/Sprite\";\r\nimport { Optional } from \"../../core/utils/Type\";\r\nimport { ISpriteEvents, AMEvent } from \"../../core/SpriteEvents\";\r\nimport { registry } from \"../../core/Registry\";\r\n\r\n\r\n/**\r\n * ============================================================================\r\n * REQUISITES\r\n * ============================================================================\r\n * @hidden\r\n */\r\n\r\n/**\r\n * @ignore\r\n */\r\nexport interface IOverlapBusterTarget {\r\n\ttarget: Sprite,\r\n\toriginalX: number,\r\n\toriginalY: number\r\n}\r\n\r\n\r\n/**\r\n * ============================================================================\r\n * MAIN CLASS\r\n * ============================================================================\r\n * @hidden\r\n */\r\n\r\n/**\r\n * A plugin which automatically groups [[PercenSeries]] slices that are smaller\r\n * than certain percent into one \"Other\" slice.\r\n *\r\n * By pushing an instance of [[Annnotation]] into `plugin` list of\r\n * any [[Chart]], it automatically applies the functionality.\r\n *\r\n * Example:\r\n *\r\n * ```TypeScript\r\n * let overlap = chart.plugins.push(new am4plugins_overlapBuster.OverlapBuster());\r\n * overlap.targets.push(bullet);\r\n * ```\r\n * ```JavaScript\r\n * let overlap = chart.plugins.push(new am4plugins_overlapBuster.OverlapBuster());\r\n * overlap.targets.push(bullet);\r\n * ```\r\n * ```JSON\r\n * // this plugin does not support JSON config\r\n * ```\r\n *\r\n * @since 4.6.2\r\n * @see {@link https://www.amcharts.com/docs/v4/tutorials/plugin-overlap-buster/} for more information and usage instructions\r\n */\r\nexport class OverlapBuster extends Plugin {\r\n\r\n\t/**\r\n\t * Overlap check targets.\r\n\t */\r\n\tprivate _targets: List;\r\n\r\n\t/**\r\n\t * List of elements that have been misplaced temporarily.\r\n\t */\r\n\tprivate _shiftedTargets: Dictionary;\r\n\r\n\t/**\r\n\t * An object which is current center of the exploded cluster.\r\n\t */\r\n\tprivate _centerTarget: Optional;\r\n\r\n\t/**\r\n\t * How much of the obstructed object should be arevealed approximately.\r\n\t *\r\n\t * The number is relative (0-1). With `0` meaning the objstructed objects\r\n\t * won't be moved at all, `0.5` (default) will make at least half of the\r\n\t * object show up, and `1` to reveal object whole.\r\n\t * \r\n\t * @default 0.7\r\n\t */\r\n\tpublic revealRatio: number = 0.7;\r\n\r\n\t/**\r\n\t * A delay in milliseconds to postpone collapse of expanded items once\r\n\t * they are unhovered.\r\n\t *\r\n\t * @default 500\r\n\t */\r\n\tpublic collapseDelay: number = 500;\r\n\r\n\t/**\r\n\t * How big an area to check for overlapping elements should be checked in\r\n\t * relation to hovered items size.\r\n\t *\r\n\t * `1` (one) means it will affect only elements that are at least partially\r\n\t * overlapping with the target element.\r\n\t *\r\n\t * `2` (two) will check area twice as big.\r\n\t *\r\n\t * Etc.\r\n\t *\r\n\t * @default 2\r\n\t */\r\n\tpublic tolerance: number = 2;\r\n\r\n\t/**\r\n\t * Timeout reference.\r\n\t */\r\n\tprivate _collapseTimeout: IDisposer;\r\n\r\n\t/**\r\n\t * A reference to the `d3.Simulation` instance for fine-grained configuration\r\n\t * of node gravitational dynamics.\r\n\t *\r\n\t * @see {@link https://github.com/d3/d3-force#simulation} For more info\r\n\t */\r\n\tpublic d3forceSimulation: d3force.Simulation<{}, d3force.SimulationLinkDatum>;\r\n\r\n\t/**\r\n\t * List of affected nodes.\r\n\t */\r\n\tprotected _nodes: any[];\r\n\r\n\t/**\r\n\t * Constructor\r\n\t */\r\n\tconstructor() {\r\n\t\t// Nothing to do here\r\n\t\tsuper();\r\n\r\n\t\t// Create simulation\r\n\t\tthis.d3forceSimulation = d3force.forceSimulation();\r\n\r\n\t\t// Init shifted targets list\r\n\t\tthis._shiftedTargets = new Dictionary();\r\n\t\tthis._disposers.push(new Disposer(() => this._shiftedTargets));\r\n\r\n\t\t// Create list\r\n\t\tthis._targets = new List();\r\n\t\tthis._disposers.push(new Disposer(() => this.targets));\r\n\r\n\t\t// Events\r\n\t\tthis._targets.events.on(\"inserted\", (ev) => {\r\n\r\n\t\t\t// Set up hover events\r\n\t\t\tthis._disposers.push(new MultiDisposer([\r\n\t\t\t\tev.newValue.events.on(\"over\", this.handleHover, this),\r\n\t\t\t\tev.newValue.events.on(\"out\", this.handleOut, this)\r\n\t\t\t]));\r\n\r\n\t\t\t// We need this in order to auto-register clones of the template\r\n\t\t\tif (ev.newValue.isTemplate) {\r\n\t\t\t\tthis._disposers.push(\r\n\t\t\t\t\tev.newValue.events.once(\"ready\", this.register, this)\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t}\r\n\r\n\t/**\r\n\t * Initializes plugin.\r\n\t */\r\n\tpublic init() {\r\n\t\tsuper.init();\r\n\t}\r\n\r\n\t/**\r\n\t * A list of objects to check for overlapping.\r\n\t *\r\n\t * If you push a list template into this, e.g. bullet from a series, all\r\n\t * elements created from that templat will automatically end up in this list.\r\n\t * \r\n\t * @return List of target objects\r\n\t */\r\n\tpublic get targets(): List {\r\n\t\treturn this._targets;\r\n\t}\r\n\r\n\t/**\r\n\t * Handles hover event on a target element.\r\n\t * \r\n\t * @param ev Event\r\n\t */\r\n\tprivate handleHover(ev: AMEvent[\"over\"]): void {\r\n\t\tlet mainTarget = ev.target;\r\n\r\n\r\n\t\t// Collapse currently exploded items\r\n\t\tif (this._centerTarget) {\r\n\r\n\t\t\tif (this._centerTarget === mainTarget) {\r\n\t\t\t\t// Same item. Do nothing.\r\n\t\t\t\tthis.cancelCollapse();\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tif (this._shiftedTargets.hasKey(mainTarget.uid)) {\r\n\t\t\t\t// Currently expanded item.\r\n\t\t\t\t// Clear collapse timeout which probably is already ticking after\r\n\t\t\t\t// hovering out of the previous center.\r\n\t\t\t\tthis.cancelCollapse();\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// Some totally different cluster was hovered.\r\n\t\t\t// Initiate immediate collapse of currently exploded cluster.\r\n\t\t\tthis.collapseCurrent();\r\n\r\n\t\t}\r\n\r\n\t\t// Set up simulation\r\n\t\t//let w = $math.max(50, this.target.innerWidth);\r\n\t\t//let h = $math.max(50, this.target.innerHeight);\r\n\t\tlet d3forceSimulation = this.d3forceSimulation;\r\n\t\tif (d3forceSimulation) {\r\n\t\t\t// Assemble ojects\r\n\t\t\tlet nodes: any[] = [];\r\n\t\t\tthis._nodes = nodes;\r\n\t\t\tthis._targets.each((target) => {\r\n\t\t\t\tif (this.hitTest(mainTarget, target)) {\r\n\t\t\t\t\tlet x = target.pixelX;\r\n\t\t\t\t\tlet y = target.pixelY;\r\n\r\n\t\t\t\t\tnodes.push({\r\n\t\t\t\t\t\tradius: Math.max(target.measuredWidth, target.measuredHeight) / 2 * this.revealRatio,\r\n\t\t\t\t\t\ttarget: target,\r\n\t\t\t\t\t\tx: x,\r\n\t\t\t\t\t\ty: y,\r\n\t\t\t\t\t\tox: x,\r\n\t\t\t\t\t\toy: y\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\t// Log shifted\r\n\t\t\t\t\tthis._shiftedTargets.setKey(target.uid, {\r\n\t\t\t\t\t\ttarget: target,\r\n\t\t\t\t\t\toriginalX: target.dx,\r\n\t\t\t\t\t\toriginalY: target.dy\r\n\t\t\t\t\t});\r\n\t\t\t\t\tthis.stopAnimation(target);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tthis.d3forceSimulation = d3force.forceSimulation(nodes)\r\n\t\t\t\t.force('collision', d3force.forceCollide().radius(function(d) {\r\n\t\t\t\t\treturn (d).radius;\r\n\t\t\t\t}))\r\n\t\t\t\t.on(\"tick\", () => {\r\n\t\t\t\t\t$array.each(nodes, (node) => {\r\n\t\t\t\t\t\t// node.target.dx = node.target.pixelX - node.x;\r\n\t\t\t\t\t\t// node.target.dy = node.target.pixelY - node.y;\r\n\t\t\t\t\t\tnode.target.dx = node.x - node.ox;\r\n\t\t\t\t\t\tnode.target.dy = node.y - node.oy;\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t}\r\n\r\n\t\t// Set center\r\n\t\tthis._centerTarget = mainTarget;\r\n\r\n\t}\r\n\r\n\t/**\r\n\t * Handles out event on a target element.\r\n\t * \r\n\t * @param ev Event\r\n\t */\r\n\tprivate handleOut(ev: AMEvent[\"out\"]): void {\r\n\r\n\t\t// Dispose old timeout if necessary\r\n\t\tthis.cancelCollapse();\r\n\r\n\t\t// Delay collapse\r\n\t\tthis._collapseTimeout = this.target.setTimeout(() => {\r\n\t\t\tthis.collapseCurrent();\r\n\t\t}, this.collapseDelay + 10);\r\n\r\n\t}\r\n\r\n\t/**\r\n\t * Stops object's animations.\r\n\t * @param target Target\r\n\t */\r\n\tprivate stopAnimation(target: Sprite): void {\r\n\t\tif (target.isInTransition()) {\r\n\t\t\tlet animation = target.animations.pop();\r\n\t\t\twhile(animation) {\r\n\t\t\t\tanimation.kill();\r\n\t\t\t\tanimation = target.animations.pop();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Collapses currently expanded cluster of objects.\r\n\t */\r\n\tprivate collapseCurrent(): void {\r\n\t\t// Stop all directed force simulations\r\n\t\tthis.d3forceSimulation.force(\"collision\", null);\r\n\t\tthis.d3forceSimulation.stop();\r\n\r\n\t\t// Animate elements back to their original positions\r\n\t\t$array.each(this._nodes, (node) => {\r\n\t\t\tnode.target.animate(\r\n\t\t\t\t[\r\n\t\t\t\t\t{ property: \"dx\", to: 0 },\r\n\t\t\t\t\t{ property: \"dy\", to: 0 }\r\n\t\t\t\t],\r\n\t\t\t\tthis.target.defaultState.transitionDuration\r\n\t\t\t);\r\n\t\t});\r\n\r\n\t\t// Reset center\r\n\t\tthis._centerTarget = undefined;\r\n\r\n\t\t// Clear the list\r\n\t\tthis._shiftedTargets.clear();\r\n\t}\r\n\r\n\t/**\r\n\t * Cancels the collapse timeout.\r\n\t */\r\n\tprivate cancelCollapse(): void {\r\n\t\tif (this._collapseTimeout) {\r\n\t\t\tthis._collapseTimeout.dispose();\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Registers new element.\r\n\t * \r\n\t * @param ev Event\r\n\t */\r\n\tprivate register(ev: AMEvent[\"ready\"]): void {\r\n\t\tif (this._targets.indexOf(ev.target) == -1) {\r\n\t\t\tthis._targets.push(ev.target);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the this element has any of its parts overlapping with another\r\n\t * element.\r\n\t *\r\n\t * @todo Description (review)\r\n\t * @param sprite Second element to test again\r\n\t * @return Overlapping?\r\n\t */\r\n\t\tpublic hitTest(target: Sprite, sprite: Sprite): boolean {\r\n\t\t\t// validate, otherwise we will not know measuredWidth and measuredHeight\r\n\t\t\tif (target.invalid) {\r\n\t\t\t\ttarget.validate();\r\n\t\t\t}\r\n\t\t\tif (target.invalid) {\r\n\t\t\t\ttarget.validate();\r\n\t\t\t}\r\n\r\n\t\t\tlet ax1 = target.pixelX;\r\n\t\t\tlet ay1 = target.pixelY;\r\n\t\t\tlet ax2 = ax1 + target.measuredWidth * this.tolerance;\r\n\t\t\tlet ay2 = ay1 + target.measuredHeight * this.tolerance;\r\n\r\n\t\t\tlet bx1 = sprite.pixelX;\r\n\t\t\tlet by1 = sprite.pixelY;\r\n\t\t\tlet bx2 = bx1 + sprite.measuredWidth * this.tolerance;\r\n\t\t\tlet by2 = by1 + sprite.measuredHeight * this.tolerance;\r\n\r\n\t\t\treturn !(bx1 > ax2 || bx2 < ax1 || by1 > ay2 || by2 < ay1);\r\n\t\t}\r\n\r\n\r\n}\r\n\r\n/**\r\n * Register class in system, so that it can be instantiated using its name from\r\n * anywhere.\r\n *\r\n * @ignore\r\n */\r\nregistry.registeredClasses[\"OverlapBuster\"] = OverlapBuster;\r\n\n\n\n// WEBPACK FOOTER //\n// ../../../../../src/.internal/plugins/overLapBuster/OverlapBuster.ts","import * as m from \"../../es2015/plugins/overlapBuster\";\nwindow.am4plugins_overlapBuster = m;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./plugins/overlapBuster.js\n// module id = null\n// module chunks = "],"sourceRoot":""}