1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692 |
- /**
- * @license Highcharts Gantt JS v9.1.1 (2021-06-04)
- *
- * Pathfinder
- *
- * (c) 2016-2021 Øystein Moseng
- *
- * License: www.highcharts.com/license
- */
- 'use strict';
- (function (factory) {
- if (typeof module === 'object' && module.exports) {
- factory['default'] = factory;
- module.exports = factory;
- } else if (typeof define === 'function' && define.amd) {
- define('highcharts/modules/pathfinder', ['highcharts'], function (Highcharts) {
- factory(Highcharts);
- factory.Highcharts = Highcharts;
- return factory;
- });
- } else {
- factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
- }
- }(function (Highcharts) {
- var _modules = Highcharts ? Highcharts._modules : {};
- function _registerModule(obj, path, args, fn) {
- if (!obj.hasOwnProperty(path)) {
- obj[path] = fn.apply(null, args);
- }
- }
- _registerModule(_modules, 'Extensions/ArrowSymbols.js', [_modules['Core/Renderer/SVG/SVGRenderer.js']], function (SVGRenderer) {
- /* *
- *
- * (c) 2017 Highsoft AS
- * Authors: Lars A. V. Cabrera
- *
- * License: www.highcharts.com/license
- *
- * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
- *
- * */
- var symbols = SVGRenderer.prototype.symbols;
- /* *
- *
- * Functions
- *
- * */
- /**
- * Creates an arrow symbol. Like a triangle, except not filled.
- * ```
- * o
- * o
- * o
- * o
- * o
- * o
- * o
- * ```
- *
- * @private
- * @function
- *
- * @param {number} x
- * x position of the arrow
- *
- * @param {number} y
- * y position of the arrow
- *
- * @param {number} w
- * width of the arrow
- *
- * @param {number} h
- * height of the arrow
- *
- * @return {Highcharts.SVGPathArray}
- * Path array
- */
- function arrow(x, y, w, h) {
- return [
- ['M', x, y + h / 2],
- ['L', x + w, y],
- ['L', x, y + h / 2],
- ['L', x + w, y + h]
- ];
- }
- /**
- * Creates a half-width arrow symbol. Like a triangle, except not filled.
- * ```
- * o
- * o
- * o
- * o
- * o
- * ```
- *
- * @private
- * @function
- *
- * @param {number} x
- * x position of the arrow
- *
- * @param {number} y
- * y position of the arrow
- *
- * @param {number} w
- * width of the arrow
- *
- * @param {number} h
- * height of the arrow
- *
- * @return {Highcharts.SVGPathArray}
- * Path array
- */
- function arrowHalf(x, y, w, h) {
- return arrow(x, y, w / 2, h);
- }
- /**
- * Creates a left-oriented triangle.
- * ```
- * o
- * ooooooo
- * ooooooooooooo
- * ooooooo
- * o
- * ```
- *
- * @private
- * @function
- *
- * @param {number} x
- * x position of the triangle
- *
- * @param {number} y
- * y position of the triangle
- *
- * @param {number} w
- * width of the triangle
- *
- * @param {number} h
- * height of the triangle
- *
- * @return {Highcharts.SVGPathArray}
- * Path array
- */
- function triangleLeft(x, y, w, h) {
- return [
- ['M', x + w, y],
- ['L', x, y + h / 2],
- ['L', x + w, y + h],
- ['Z']
- ];
- }
- /**
- * Creates a half-width, left-oriented triangle.
- * ```
- * o
- * oooo
- * ooooooo
- * oooo
- * o
- * ```
- *
- * @private
- * @function
- *
- * @param {number} x
- * x position of the triangle
- *
- * @param {number} y
- * y position of the triangle
- *
- * @param {number} w
- * width of the triangle
- *
- * @param {number} h
- * height of the triangle
- *
- * @return {Highcharts.SVGPathArray}
- * Path array
- */
- function triangleLeftHalf(x, y, w, h) {
- return triangleLeft(x, y, w / 2, h);
- }
- symbols.arrow = arrow;
- symbols['arrow-filled'] = triangleLeft;
- symbols['arrow-filled-half'] = triangleLeftHalf;
- symbols['arrow-half'] = arrowHalf;
- symbols['triangle-left'] = triangleLeft;
- symbols['triangle-left-half'] = triangleLeftHalf;
- /* *
- *
- * Default Export
- *
- * */
- return symbols;
- });
- _registerModule(_modules, 'Gantt/Connection.js', [_modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, D, Point, U) {
- /* *
- *
- * (c) 2016 Highsoft AS
- * Authors: Øystein Moseng, Lars A. V. Cabrera
- *
- * License: www.highcharts.com/license
- *
- * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
- *
- * */
- /**
- * The default pathfinder algorithm to use for a chart. It is possible to define
- * your own algorithms by adding them to the
- * `Highcharts.Pathfinder.prototype.algorithms`
- * object before the chart has been created.
- *
- * The default algorithms are as follows:
- *
- * `straight`: Draws a straight line between the connecting
- * points. Does not avoid other points when drawing.
- *
- * `simpleConnect`: Finds a path between the points using right angles
- * only. Takes only starting/ending points into
- * account, and will not avoid other points.
- *
- * `fastAvoid`: Finds a path between the points using right angles
- * only. Will attempt to avoid other points, but its
- * focus is performance over accuracy. Works well with
- * less dense datasets.
- *
- * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
- */
- ''; // detach doclets above
- var defaultOptions = D.defaultOptions;
- var addEvent = U.addEvent,
- defined = U.defined,
- error = U.error,
- extend = U.extend,
- merge = U.merge,
- objectEach = U.objectEach,
- pick = U.pick,
- splat = U.splat;
- var deg2rad = H.deg2rad,
- max = Math.max,
- min = Math.min;
- /*
- @todo:
- - Document how to write your own algorithms
- - Consider adding a Point.pathTo method that wraps creating a connection
- and rendering it
- */
- // Set default Pathfinder options
- extend(defaultOptions, {
- /**
- * The Pathfinder module allows you to define connections between any two
- * points, represented as lines - optionally with markers for the start
- * and/or end points. Multiple algorithms are available for calculating how
- * the connecting lines are drawn.
- *
- * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
- * charts, the connectors are used to draw dependencies between tasks.
- *
- * @see [dependency](series.gantt.data.dependency)
- *
- * @sample gantt/pathfinder/demo
- * Pathfinder connections
- *
- * @declare Highcharts.ConnectorsOptions
- * @product gantt
- * @optionparent connectors
- */
- connectors: {
- /**
- * Enable connectors for this chart. Requires Highcharts Gantt.
- *
- * @type {boolean}
- * @default true
- * @since 6.2.0
- * @apioption connectors.enabled
- */
- /**
- * Set the default dash style for this chart's connecting lines.
- *
- * @type {string}
- * @default solid
- * @since 6.2.0
- * @apioption connectors.dashStyle
- */
- /**
- * Set the default color for this chart's Pathfinder connecting lines.
- * Defaults to the color of the point being connected.
- *
- * @type {Highcharts.ColorString}
- * @since 6.2.0
- * @apioption connectors.lineColor
- */
- /**
- * Set the default pathfinder margin to use, in pixels. Some Pathfinder
- * algorithms attempt to avoid obstacles, such as other points in the
- * chart. These algorithms use this margin to determine how close lines
- * can be to an obstacle. The default is to compute this automatically
- * from the size of the obstacles in the chart.
- *
- * To draw connecting lines close to existing points, set this to a low
- * number. For more space around existing points, set this number
- * higher.
- *
- * @sample gantt/pathfinder/algorithm-margin
- * Small algorithmMargin
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.algorithmMargin
- */
- /**
- * Set the default pathfinder algorithm to use for this chart. It is
- * possible to define your own algorithms by adding them to the
- * Highcharts.Pathfinder.prototype.algorithms object before the chart
- * has been created.
- *
- * The default algorithms are as follows:
- *
- * `straight`: Draws a straight line between the connecting
- * points. Does not avoid other points when drawing.
- *
- * `simpleConnect`: Finds a path between the points using right angles
- * only. Takes only starting/ending points into
- * account, and will not avoid other points.
- *
- * `fastAvoid`: Finds a path between the points using right angles
- * only. Will attempt to avoid other points, but its
- * focus is performance over accuracy. Works well with
- * less dense datasets.
- *
- * Default value: `straight` is used as default for most series types,
- * while `simpleConnect` is used as default for Gantt series, to show
- * dependencies between points.
- *
- * @sample gantt/pathfinder/demo
- * Different types used
- *
- * @type {Highcharts.PathfinderTypeValue}
- * @default undefined
- * @since 6.2.0
- */
- type: 'straight',
- /**
- * Set the default pixel width for this chart's Pathfinder connecting
- * lines.
- *
- * @since 6.2.0
- */
- lineWidth: 1,
- /**
- * Marker options for this chart's Pathfinder connectors. Note that
- * this option is overridden by the `startMarker` and `endMarker`
- * options.
- *
- * @declare Highcharts.ConnectorsMarkerOptions
- * @since 6.2.0
- */
- marker: {
- /**
- * Set the radius of the connector markers. The default is
- * automatically computed based on the algorithmMargin setting.
- *
- * Setting marker.width and marker.height will override this
- * setting.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.radius
- */
- /**
- * Set the width of the connector markers. If not supplied, this
- * is inferred from the marker radius.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.width
- */
- /**
- * Set the height of the connector markers. If not supplied, this
- * is inferred from the marker radius.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.height
- */
- /**
- * Set the color of the connector markers. By default this is the
- * same as the connector color.
- *
- * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
- * @since 6.2.0
- * @apioption connectors.marker.color
- */
- /**
- * Set the line/border color of the connector markers. By default
- * this is the same as the marker color.
- *
- * @type {Highcharts.ColorString}
- * @since 6.2.0
- * @apioption connectors.marker.lineColor
- */
- /**
- * Enable markers for the connectors.
- */
- enabled: false,
- /**
- * Horizontal alignment of the markers relative to the points.
- *
- * @type {Highcharts.AlignValue}
- */
- align: 'center',
- /**
- * Vertical alignment of the markers relative to the points.
- *
- * @type {Highcharts.VerticalAlignValue}
- */
- verticalAlign: 'middle',
- /**
- * Whether or not to draw the markers inside the points.
- */
- inside: false,
- /**
- * Set the line/border width of the pathfinder markers.
- */
- lineWidth: 1
- },
- /**
- * Marker options specific to the start markers for this chart's
- * Pathfinder connectors. Overrides the generic marker options.
- *
- * @declare Highcharts.ConnectorsStartMarkerOptions
- * @extends connectors.marker
- * @since 6.2.0
- */
- startMarker: {
- /**
- * Set the symbol of the connector start markers.
- */
- symbol: 'diamond'
- },
- /**
- * Marker options specific to the end markers for this chart's
- * Pathfinder connectors. Overrides the generic marker options.
- *
- * @declare Highcharts.ConnectorsEndMarkerOptions
- * @extends connectors.marker
- * @since 6.2.0
- */
- endMarker: {
- /**
- * Set the symbol of the connector end markers.
- */
- symbol: 'arrow-filled'
- }
- }
- });
- /**
- * Override Pathfinder connector options for a series. Requires Highcharts Gantt
- * to be loaded.
- *
- * @declare Highcharts.SeriesConnectorsOptionsObject
- * @extends connectors
- * @since 6.2.0
- * @excluding enabled, algorithmMargin
- * @product gantt
- * @apioption plotOptions.series.connectors
- */
- /**
- * Connect to a point. This option can be either a string, referring to the ID
- * of another point, or an object, or an array of either. If the option is an
- * array, each element defines a connection.
- *
- * @sample gantt/pathfinder/demo
- * Different connection types
- *
- * @declare Highcharts.XrangePointConnectorsOptionsObject
- * @type {string|Array<string|*>|*}
- * @extends plotOptions.series.connectors
- * @since 6.2.0
- * @excluding enabled
- * @product gantt
- * @requires highcharts-gantt
- * @apioption series.xrange.data.connect
- */
- /**
- * The ID of the point to connect to.
- *
- * @type {string}
- * @since 6.2.0
- * @product gantt
- * @apioption series.xrange.data.connect.to
- */
- /**
- * Get point bounding box using plotX/plotY and shapeArgs. If using
- * graphic.getBBox() directly, the bbox will be affected by animation.
- *
- * @private
- * @function
- *
- * @param {Highcharts.Point} point
- * The point to get BB of.
- *
- * @return {Highcharts.Dictionary<number>|null}
- * Result xMax, xMin, yMax, yMin.
- */
- function getPointBB(point) {
- var shapeArgs = point.shapeArgs,
- bb;
- // Prefer using shapeArgs (columns)
- if (shapeArgs) {
- return {
- xMin: shapeArgs.x || 0,
- xMax: (shapeArgs.x || 0) + (shapeArgs.width || 0),
- yMin: shapeArgs.y || 0,
- yMax: (shapeArgs.y || 0) + (shapeArgs.height || 0)
- };
- }
- // Otherwise use plotX/plotY and bb
- bb = point.graphic && point.graphic.getBBox();
- return bb ? {
- xMin: point.plotX - bb.width / 2,
- xMax: point.plotX + bb.width / 2,
- yMin: point.plotY - bb.height / 2,
- yMax: point.plotY + bb.height / 2
- } : null;
- }
- /**
- * Calculate margin to place around obstacles for the pathfinder in pixels.
- * Returns a minimum of 1 pixel margin.
- *
- * @private
- * @function
- *
- * @param {Array<object>} obstacles
- * Obstacles to calculate margin from.
- *
- * @return {number}
- * The calculated margin in pixels. At least 1.
- */
- function calculateObstacleMargin(obstacles) {
- var len = obstacles.length,
- i = 0,
- j,
- obstacleDistance,
- distances = [],
- // Compute smallest distance between two rectangles
- distance = function (a,
- b,
- bbMargin) {
- // Count the distance even if we are slightly off
- var margin = pick(bbMargin, 10),
- yOverlap = a.yMax + margin > b.yMin - margin &&
- a.yMin - margin < b.yMax + margin,
- xOverlap = a.xMax + margin > b.xMin - margin &&
- a.xMin - margin < b.xMax + margin,
- xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
- yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
- // If the rectangles collide, try recomputing with smaller margin.
- // If they collide anyway, discard the obstacle.
- if (xOverlap && yOverlap) {
- return (margin ?
- distance(a, b, Math.floor(margin / 2)) :
- Infinity);
- }
- return min(xDistance, yDistance);
- };
- // Go over all obstacles and compare them to the others.
- for (; i < len; ++i) {
- // Compare to all obstacles ahead. We will already have compared this
- // obstacle to the ones before.
- for (j = i + 1; j < len; ++j) {
- obstacleDistance = distance(obstacles[i], obstacles[j]);
- // TODO: Magic number 80
- if (obstacleDistance < 80) { // Ignore large distances
- distances.push(obstacleDistance);
- }
- }
- }
- // Ensure we always have at least one value, even in very spaceous charts
- distances.push(80);
- return max(Math.floor(distances.sort(function (a, b) {
- return (a - b);
- })[
- // Discard first 10% of the relevant distances, and then grab
- // the smallest one.
- Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
- ), 1 // 1 is the minimum margin
- );
- }
- /* eslint-disable no-invalid-this, valid-jsdoc */
- /**
- * The Connection class. Used internally to represent a connection between two
- * points.
- *
- * @private
- * @class
- * @name Highcharts.Connection
- *
- * @param {Highcharts.Point} from
- * Connection runs from this Point.
- *
- * @param {Highcharts.Point} to
- * Connection runs to this Point.
- *
- * @param {Highcharts.ConnectorsOptions} [options]
- * Connection options.
- */
- var Connection = /** @class */ (function () {
- function Connection(from, to, options) {
- /* *
- *
- * Properties
- *
- * */
- this.chart = void 0;
- this.fromPoint = void 0;
- this.graphics = void 0;
- this.pathfinder = void 0;
- this.toPoint = void 0;
- this.init(from, to, options);
- }
- /**
- * Initialize the Connection object. Used as constructor only.
- *
- * @function Highcharts.Connection#init
- *
- * @param {Highcharts.Point} from
- * Connection runs from this Point.
- *
- * @param {Highcharts.Point} to
- * Connection runs to this Point.
- *
- * @param {Highcharts.ConnectorsOptions} [options]
- * Connection options.
- */
- Connection.prototype.init = function (from, to, options) {
- this.fromPoint = from;
- this.toPoint = to;
- this.options = options;
- this.chart = from.series.chart;
- this.pathfinder = this.chart.pathfinder;
- };
- /**
- * Add (or update) this connection's path on chart. Stores reference to the
- * created element on this.graphics.path.
- *
- * @function Highcharts.Connection#renderPath
- *
- * @param {Highcharts.SVGPathArray} path
- * Path to render, in array format. E.g. ['M', 0, 0, 'L', 10, 10]
- *
- * @param {Highcharts.SVGAttributes} [attribs]
- * SVG attributes for the path.
- *
- * @param {Partial<Highcharts.AnimationOptionsObject>} [animation]
- * Animation options for the rendering.
- */
- Connection.prototype.renderPath = function (path, attribs, animation) {
- var connection = this,
- chart = this.chart,
- styledMode = chart.styledMode,
- pathfinder = chart.pathfinder,
- animate = !chart.options.chart.forExport && animation !== false,
- pathGraphic = connection.graphics && connection.graphics.path,
- anim;
- // Add the SVG element of the pathfinder group if it doesn't exist
- if (!pathfinder.group) {
- pathfinder.group = chart.renderer.g()
- .addClass('highcharts-pathfinder-group')
- .attr({ zIndex: -1 })
- .add(chart.seriesGroup);
- }
- // Shift the group to compensate for plot area.
- // Note: Do this always (even when redrawing a path) to avoid issues
- // when updating chart in a way that changes plot metrics.
- pathfinder.group.translate(chart.plotLeft, chart.plotTop);
- // Create path if does not exist
- if (!(pathGraphic && pathGraphic.renderer)) {
- pathGraphic = chart.renderer.path()
- .add(pathfinder.group);
- if (!styledMode) {
- pathGraphic.attr({
- opacity: 0
- });
- }
- }
- // Set path attribs and animate to the new path
- pathGraphic.attr(attribs);
- anim = { d: path };
- if (!styledMode) {
- anim.opacity = 1;
- }
- pathGraphic[animate ? 'animate' : 'attr'](anim, animation);
- // Store reference on connection
- this.graphics = this.graphics || {};
- this.graphics.path = pathGraphic;
- };
- /**
- * Calculate and add marker graphics for connection to the chart. The
- * created/updated elements are stored on this.graphics.start and
- * this.graphics.end.
- *
- * @function Highcharts.Connection#addMarker
- *
- * @param {string} type
- * Marker type, either 'start' or 'end'.
- *
- * @param {Highcharts.ConnectorsMarkerOptions} options
- * All options for this marker. Not calculated or merged with other
- * options.
- *
- * @param {Highcharts.SVGPathArray} path
- * Connection path in array format. This is used to calculate the
- * rotation angle of the markers.
- */
- Connection.prototype.addMarker = function (type, options, path) {
- var connection = this,
- chart = connection.fromPoint.series.chart,
- pathfinder = chart.pathfinder,
- renderer = chart.renderer,
- point = (type === 'start' ?
- connection.fromPoint :
- connection.toPoint),
- anchor = point.getPathfinderAnchorPoint(options),
- markerVector,
- radians,
- rotation,
- box,
- width,
- height,
- pathVector,
- segment;
- if (!options.enabled) {
- return;
- }
- // Last vector before start/end of path, used to get angle
- if (type === 'start') {
- segment = path[1];
- }
- else { // 'end'
- segment = path[path.length - 2];
- }
- if (segment && segment[0] === 'M' || segment[0] === 'L') {
- pathVector = {
- x: segment[1],
- y: segment[2]
- };
- // Get angle between pathVector and anchor point and use it to
- // create marker position.
- radians = point.getRadiansToVector(pathVector, anchor);
- markerVector = point.getMarkerVector(radians, options.radius, anchor);
- // Rotation of marker is calculated from angle between pathVector
- // and markerVector.
- // (Note:
- // Used to recalculate radians between markerVector and pathVector,
- // but this should be the same as between pathVector and anchor.)
- rotation = -radians / deg2rad;
- if (options.width && options.height) {
- width = options.width;
- height = options.height;
- }
- else {
- width = height = options.radius * 2;
- }
- // Add graphics object if it does not exist
- connection.graphics = connection.graphics || {};
- box = {
- x: markerVector.x - (width / 2),
- y: markerVector.y - (height / 2),
- width: width,
- height: height,
- rotation: rotation,
- rotationOriginX: markerVector.x,
- rotationOriginY: markerVector.y
- };
- if (!connection.graphics[type]) {
- // Create new marker element
- connection.graphics[type] = renderer
- .symbol(options.symbol)
- .addClass('highcharts-point-connecting-path-' + type + '-marker')
- .attr(box)
- .add(pathfinder.group);
- if (!renderer.styledMode) {
- connection.graphics[type].attr({
- fill: options.color || connection.fromPoint.color,
- stroke: options.lineColor,
- 'stroke-width': options.lineWidth,
- opacity: 0
- })
- .animate({
- opacity: 1
- }, point.series.options.animation);
- }
- }
- else {
- connection.graphics[type].animate(box);
- }
- }
- };
- /**
- * Calculate and return connection path.
- * Note: Recalculates chart obstacles on demand if they aren't calculated.
- *
- * @function Highcharts.Connection#getPath
- *
- * @param {Highcharts.ConnectorsOptions} options
- * Connector options. Not calculated or merged with other options.
- *
- * @return {object|undefined}
- * Calculated SVG path data in array format.
- */
- Connection.prototype.getPath = function (options) {
- var pathfinder = this.pathfinder,
- chart = this.chart,
- algorithm = pathfinder.algorithms[options.type],
- chartObstacles = pathfinder.chartObstacles;
- if (typeof algorithm !== 'function') {
- error('"' + options.type + '" is not a Pathfinder algorithm.');
- return {
- path: [],
- obstacles: []
- };
- }
- // This function calculates obstacles on demand if they don't exist
- if (algorithm.requiresObstacles && !chartObstacles) {
- chartObstacles =
- pathfinder.chartObstacles =
- pathfinder.getChartObstacles(options);
- // If the algorithmMargin was computed, store the result in default
- // options.
- chart.options.connectors.algorithmMargin =
- options.algorithmMargin;
- // Cache some metrics too
- pathfinder.chartObstacleMetrics =
- pathfinder.getObstacleMetrics(chartObstacles);
- }
- // Get the SVG path
- return algorithm(
- // From
- this.fromPoint.getPathfinderAnchorPoint(options.startMarker),
- // To
- this.toPoint.getPathfinderAnchorPoint(options.endMarker), merge({
- chartObstacles: chartObstacles,
- lineObstacles: pathfinder.lineObstacles || [],
- obstacleMetrics: pathfinder.chartObstacleMetrics,
- hardBounds: {
- xMin: 0,
- xMax: chart.plotWidth,
- yMin: 0,
- yMax: chart.plotHeight
- },
- obstacleOptions: {
- margin: options.algorithmMargin
- },
- startDirectionX: pathfinder.getAlgorithmStartDirection(options.startMarker)
- }, options));
- };
- /**
- * (re)Calculate and (re)draw the connection.
- *
- * @function Highcharts.Connection#render
- */
- Connection.prototype.render = function () {
- var connection = this,
- fromPoint = connection.fromPoint,
- series = fromPoint.series,
- chart = series.chart,
- pathfinder = chart.pathfinder,
- pathResult,
- path,
- options = merge(chart.options.connectors,
- series.options.connectors,
- fromPoint.options.connectors,
- connection.options),
- attribs = {};
- // Set path attribs
- if (!chart.styledMode) {
- attribs.stroke = options.lineColor || fromPoint.color;
- attribs['stroke-width'] = options.lineWidth;
- if (options.dashStyle) {
- attribs.dashstyle = options.dashStyle;
- }
- }
- attribs['class'] = // eslint-disable-line dot-notation
- 'highcharts-point-connecting-path ' +
- 'highcharts-color-' + fromPoint.colorIndex;
- options = merge(attribs, options);
- // Set common marker options
- if (!defined(options.marker.radius)) {
- options.marker.radius = min(max(Math.ceil((options.algorithmMargin || 8) / 2) - 1, 1), 5);
- }
- // Get the path
- pathResult = connection.getPath(options);
- path = pathResult.path;
- // Always update obstacle storage with obstacles from this path.
- // We don't know if future calls will need this for their algorithm.
- if (pathResult.obstacles) {
- pathfinder.lineObstacles =
- pathfinder.lineObstacles || [];
- pathfinder.lineObstacles =
- pathfinder.lineObstacles.concat(pathResult.obstacles);
- }
- // Add the calculated path to the pathfinder group
- connection.renderPath(path, attribs, series.options.animation);
- // Render the markers
- connection.addMarker('start', merge(options.marker, options.startMarker), path);
- connection.addMarker('end', merge(options.marker, options.endMarker), path);
- };
- /**
- * Destroy connection by destroying the added graphics elements.
- *
- * @function Highcharts.Connection#destroy
- */
- Connection.prototype.destroy = function () {
- if (this.graphics) {
- objectEach(this.graphics, function (val) {
- val.destroy();
- });
- delete this.graphics;
- }
- };
- return Connection;
- }());
- // Add to Highcharts namespace
- H.Connection = Connection;
- // Add pathfinding capabilities to Points
- extend(Point.prototype, /** @lends Point.prototype */ {
- /**
- * Get coordinates of anchor point for pathfinder connection.
- *
- * @private
- * @function Highcharts.Point#getPathfinderAnchorPoint
- *
- * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
- * Connection options for position on point.
- *
- * @return {Highcharts.PositionObject}
- * An object with x/y properties for the position. Coordinates are
- * in plot values, not relative to point.
- */
- getPathfinderAnchorPoint: function (markerOptions) {
- var bb = getPointBB(this),
- x,
- y;
- switch (markerOptions.align) { // eslint-disable-line default-case
- case 'right':
- x = 'xMax';
- break;
- case 'left':
- x = 'xMin';
- }
- switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
- case 'top':
- y = 'yMin';
- break;
- case 'bottom':
- y = 'yMax';
- }
- return {
- x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
- y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
- };
- },
- /**
- * Utility to get the angle from one point to another.
- *
- * @private
- * @function Highcharts.Point#getRadiansToVector
- *
- * @param {Highcharts.PositionObject} v1
- * The first vector, as an object with x/y properties.
- *
- * @param {Highcharts.PositionObject} v2
- * The second vector, as an object with x/y properties.
- *
- * @return {number}
- * The angle in degrees
- */
- getRadiansToVector: function (v1, v2) {
- var box;
- if (!defined(v2)) {
- box = getPointBB(this);
- if (box) {
- v2 = {
- x: (box.xMin + box.xMax) / 2,
- y: (box.yMin + box.yMax) / 2
- };
- }
- }
- return Math.atan2(v2.y - v1.y, v1.x - v2.x);
- },
- /**
- * Utility to get the position of the marker, based on the path angle and
- * the marker's radius.
- *
- * @private
- * @function Highcharts.Point#getMarkerVector
- *
- * @param {number} radians
- * The angle in radians from the point center to another vector.
- *
- * @param {number} markerRadius
- * The radius of the marker, to calculate the additional distance to
- * the center of the marker.
- *
- * @param {object} anchor
- * The anchor point of the path and marker as an object with x/y
- * properties.
- *
- * @return {object}
- * The marker vector as an object with x/y properties.
- */
- getMarkerVector: function (radians, markerRadius, anchor) {
- var twoPI = Math.PI * 2.0,
- theta = radians,
- bb = getPointBB(this),
- rectWidth = bb.xMax - bb.xMin,
- rectHeight = bb.yMax - bb.yMin,
- rAtan = Math.atan2(rectHeight,
- rectWidth),
- tanTheta = 1,
- leftOrRightRegion = false,
- rectHalfWidth = rectWidth / 2.0,
- rectHalfHeight = rectHeight / 2.0,
- rectHorizontalCenter = bb.xMin + rectHalfWidth,
- rectVerticalCenter = bb.yMin + rectHalfHeight,
- edgePoint = {
- x: rectHorizontalCenter,
- y: rectVerticalCenter
- },
- xFactor = 1,
- yFactor = 1;
- while (theta < -Math.PI) {
- theta += twoPI;
- }
- while (theta > Math.PI) {
- theta -= twoPI;
- }
- tanTheta = Math.tan(theta);
- if ((theta > -rAtan) && (theta <= rAtan)) {
- // Right side
- yFactor = -1;
- leftOrRightRegion = true;
- }
- else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
- // Top side
- yFactor = -1;
- }
- else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
- // Left side
- xFactor = -1;
- leftOrRightRegion = true;
- }
- else {
- // Bottom side
- xFactor = -1;
- }
- // Correct the edgePoint according to the placement of the marker
- if (leftOrRightRegion) {
- edgePoint.x += xFactor * (rectHalfWidth);
- edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
- }
- else {
- edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
- edgePoint.y += yFactor * (rectHalfHeight);
- }
- if (anchor.x !== rectHorizontalCenter) {
- edgePoint.x = anchor.x;
- }
- if (anchor.y !== rectVerticalCenter) {
- edgePoint.y = anchor.y;
- }
- return {
- x: edgePoint.x + (markerRadius * Math.cos(theta)),
- y: edgePoint.y - (markerRadius * Math.sin(theta))
- };
- }
- });
- /**
- * Warn if using legacy options. Copy the options over. Note that this will
- * still break if using the legacy options in chart.update, addSeries etc.
- * @private
- */
- function warnLegacy(chart) {
- if (chart.options.pathfinder ||
- chart.series.reduce(function (acc, series) {
- if (series.options) {
- merge(true, (series.options.connectors = series.options.connectors ||
- {}), series.options.pathfinder);
- }
- return acc || series.options && series.options.pathfinder;
- }, false)) {
- merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
- error('WARNING: Pathfinder options have been renamed. ' +
- 'Use "chart.connectors" or "series.connectors" instead.');
- }
- }
- return Connection;
- });
- _registerModule(_modules, 'Gantt/PathfinderAlgorithms.js', [_modules['Core/Utilities.js']], function (U) {
- /* *
- *
- * (c) 2016 Highsoft AS
- * Author: Øystein Moseng
- *
- * License: www.highcharts.com/license
- *
- * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
- *
- * */
- var extend = U.extend,
- pick = U.pick;
- var min = Math.min,
- max = Math.max,
- abs = Math.abs;
- /**
- * Get index of last obstacle before xMin. Employs a type of binary search, and
- * thus requires that obstacles are sorted by xMin value.
- *
- * @private
- * @function findLastObstacleBefore
- *
- * @param {Array<object>} obstacles
- * Array of obstacles to search in.
- *
- * @param {number} xMin
- * The xMin threshold.
- *
- * @param {number} [startIx]
- * Starting index to search from. Must be within array range.
- *
- * @return {number}
- * The index of the last obstacle element before xMin.
- */
- function findLastObstacleBefore(obstacles, xMin, startIx) {
- var left = startIx || 0, // left limit
- right = obstacles.length - 1, // right limit
- min = xMin - 0.0000001, // Make sure we include all obstacles at xMin
- cursor,
- cmp;
- while (left <= right) {
- cursor = (right + left) >> 1;
- cmp = min - obstacles[cursor].xMin;
- if (cmp > 0) {
- left = cursor + 1;
- }
- else if (cmp < 0) {
- right = cursor - 1;
- }
- else {
- return cursor;
- }
- }
- return left > 0 ? left - 1 : 0;
- }
- /**
- * Test if a point lays within an obstacle.
- *
- * @private
- * @function pointWithinObstacle
- *
- * @param {object} obstacle
- * Obstacle to test.
- *
- * @param {Highcharts.Point} point
- * Point with x/y props.
- *
- * @return {boolean}
- * Whether point is within the obstacle or not.
- */
- function pointWithinObstacle(obstacle, point) {
- return (point.x <= obstacle.xMax &&
- point.x >= obstacle.xMin &&
- point.y <= obstacle.yMax &&
- point.y >= obstacle.yMin);
- }
- /**
- * Find the index of an obstacle that wraps around a point.
- * Returns -1 if not found.
- *
- * @private
- * @function findObstacleFromPoint
- *
- * @param {Array<object>} obstacles
- * Obstacles to test.
- *
- * @param {Highcharts.Point} point
- * Point with x/y props.
- *
- * @return {number}
- * Ix of the obstacle in the array, or -1 if not found.
- */
- function findObstacleFromPoint(obstacles, point) {
- var i = findLastObstacleBefore(obstacles,
- point.x + 1) + 1;
- while (i--) {
- if (obstacles[i].xMax >= point.x &&
- // optimization using lazy evaluation
- pointWithinObstacle(obstacles[i], point)) {
- return i;
- }
- }
- return -1;
- }
- /**
- * Get SVG path array from array of line segments.
- *
- * @private
- * @function pathFromSegments
- *
- * @param {Array<object>} segments
- * The segments to build the path from.
- *
- * @return {Highcharts.SVGPathArray}
- * SVG path array as accepted by the SVG Renderer.
- */
- function pathFromSegments(segments) {
- var path = [];
- if (segments.length) {
- path.push(['M', segments[0].start.x, segments[0].start.y]);
- for (var i = 0; i < segments.length; ++i) {
- path.push(['L', segments[i].end.x, segments[i].end.y]);
- }
- }
- return path;
- }
- /**
- * Limits obstacle max/mins in all directions to bounds. Modifies input
- * obstacle.
- *
- * @private
- * @function limitObstacleToBounds
- *
- * @param {object} obstacle
- * Obstacle to limit.
- *
- * @param {object} bounds
- * Bounds to use as limit.
- *
- * @return {void}
- */
- function limitObstacleToBounds(obstacle, bounds) {
- obstacle.yMin = max(obstacle.yMin, bounds.yMin);
- obstacle.yMax = min(obstacle.yMax, bounds.yMax);
- obstacle.xMin = max(obstacle.xMin, bounds.xMin);
- obstacle.xMax = min(obstacle.xMax, bounds.xMax);
- }
- /**
- * Get an SVG path from a starting coordinate to an ending coordinate.
- * Draws a straight line.
- *
- * @function Highcharts.Pathfinder.algorithms.straight
- *
- * @param {Highcharts.PositionObject} start
- * Starting coordinate, object with x/y props.
- *
- * @param {Highcharts.PositionObject} end
- * Ending coordinate, object with x/y props.
- *
- * @return {object}
- * An object with the SVG path in Array form as accepted by the SVG
- * renderer, as well as an array of new obstacles making up this
- * path.
- */
- function straight(start, end) {
- return {
- path: [
- ['M', start.x, start.y],
- ['L', end.x, end.y]
- ],
- obstacles: [{ start: start, end: end }]
- };
- }
- /**
- * Find a path from a starting coordinate to an ending coordinate, using
- * right angles only, and taking only starting/ending obstacle into
- * consideration.
- *
- * @function Highcharts.Pathfinder.algorithms.simpleConnect
- *
- * @param {Highcharts.PositionObject} start
- * Starting coordinate, object with x/y props.
- *
- * @param {Highcharts.PositionObject} end
- * Ending coordinate, object with x/y props.
- *
- * @param {object} options
- * Options for the algorithm:
- * - chartObstacles: Array of chart obstacles to avoid
- * - startDirectionX: Optional. True if starting in the X direction.
- * If not provided, the algorithm starts in the direction that is
- * the furthest between start/end.
- *
- * @return {object}
- * An object with the SVG path in Array form as accepted by the SVG
- * renderer, as well as an array of new obstacles making up this
- * path.
- */
- var simpleConnect = function (start,
- end,
- options) {
- var segments = [],
- endSegment,
- dir = pick(options.startDirectionX,
- abs(end.x - start.x) > abs(end.y - start.y)) ? 'x' : 'y',
- chartObstacles = options.chartObstacles,
- startObstacleIx = findObstacleFromPoint(chartObstacles,
- start),
- endObstacleIx = findObstacleFromPoint(chartObstacles,
- end),
- startObstacle,
- endObstacle,
- prevWaypoint,
- waypoint,
- waypoint2,
- useMax,
- endPoint;
- // eslint-disable-next-line valid-jsdoc
- /**
- * Return a clone of a point with a property set from a target object,
- * optionally with an offset
- * @private
- */
- function copyFromPoint(from, fromKey, to, toKey, offset) {
- var point = {
- x: from.x,
- y: from.y
- };
- point[fromKey] = to[toKey || fromKey] + (offset || 0);
- return point;
- }
- // eslint-disable-next-line valid-jsdoc
- /**
- * Return waypoint outside obstacle.
- * @private
- */
- function getMeOut(obstacle, point, direction) {
- var useMax = abs(point[direction] - obstacle[direction + 'Min']) >
- abs(point[direction] - obstacle[direction + 'Max']);
- return copyFromPoint(point, direction, obstacle, direction + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1);
- }
- // Pull out end point
- if (endObstacleIx > -1) {
- endObstacle = chartObstacles[endObstacleIx];
- waypoint = getMeOut(endObstacle, end, dir);
- endSegment = {
- start: waypoint,
- end: end
- };
- endPoint = waypoint;
- }
- else {
- endPoint = end;
- }
- // If an obstacle envelops the start point, add a segment to get out,
- // and around it.
- if (startObstacleIx > -1) {
- startObstacle = chartObstacles[startObstacleIx];
- waypoint = getMeOut(startObstacle, start, dir);
- segments.push({
- start: start,
- end: waypoint
- });
- // If we are going back again, switch direction to get around start
- // obstacle.
- if (
- // Going towards max from start:
- waypoint[dir] >= start[dir] ===
- // Going towards min to end:
- waypoint[dir] >= endPoint[dir]) {
- dir = dir === 'y' ? 'x' : 'y';
- useMax = start[dir] < end[dir];
- segments.push({
- start: waypoint,
- end: copyFromPoint(waypoint, dir, startObstacle, dir + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1)
- });
- // Switch direction again
- dir = dir === 'y' ? 'x' : 'y';
- }
- }
- // We are around the start obstacle. Go towards the end in one
- // direction.
- prevWaypoint = segments.length ?
- segments[segments.length - 1].end :
- start;
- waypoint = copyFromPoint(prevWaypoint, dir, endPoint);
- segments.push({
- start: prevWaypoint,
- end: waypoint
- });
- // Final run to end point in the other direction
- dir = dir === 'y' ? 'x' : 'y';
- waypoint2 = copyFromPoint(waypoint, dir, endPoint);
- segments.push({
- start: waypoint,
- end: waypoint2
- });
- // Finally add the endSegment
- segments.push(endSegment);
- return {
- path: pathFromSegments(segments),
- obstacles: segments
- };
- };
- simpleConnect.requiresObstacles = true;
- /**
- * Find a path from a starting coordinate to an ending coordinate, taking
- * obstacles into consideration. Might not always find the optimal path,
- * but is fast, and usually good enough.
- *
- * @function Highcharts.Pathfinder.algorithms.fastAvoid
- *
- * @param {Highcharts.PositionObject} start
- * Starting coordinate, object with x/y props.
- *
- * @param {Highcharts.PositionObject} end
- * Ending coordinate, object with x/y props.
- *
- * @param {object} options
- * Options for the algorithm.
- * - chartObstacles: Array of chart obstacles to avoid
- * - lineObstacles: Array of line obstacles to jump over
- * - obstacleMetrics: Object with metrics of chartObstacles cached
- * - hardBounds: Hard boundaries to not cross
- * - obstacleOptions: Options for the obstacles, including margin
- * - startDirectionX: Optional. True if starting in the X direction.
- * If not provided, the algorithm starts in the
- * direction that is the furthest between
- * start/end.
- *
- * @return {object}
- * An object with the SVG path in Array form as accepted by the SVG
- * renderer, as well as an array of new obstacles making up this
- * path.
- */
- var fastAvoid = function (start,
- end,
- options) {
- /*
- Algorithm rules/description
- - Find initial direction
- - Determine soft/hard max for each direction.
- - Move along initial direction until obstacle.
- - Change direction.
- - If hitting obstacle,
- first try to change length of previous line
- before changing direction again.
-
- Soft min/max x = start/destination x +/- widest obstacle + margin
- Soft min/max y = start/destination y +/- tallest obstacle + margin
-
- @todo:
- - Make retrospective,
- try changing prev segment to reduce
- corners
- - Fix logic for breaking out of end-points - not always picking
- the best direction currently
- - When going around the end obstacle we should not always go the
- shortest route,
- rather pick the one closer to the end point
- */
- var dirIsX = pick(options.startDirectionX,
- abs(end.x - start.x) > abs(end.y - start.y)),
- dir = dirIsX ? 'x' : 'y',
- segments,
- useMax,
- extractedEndPoint,
- endSegments = [],
- forceObstacleBreak = false, // Used in clearPathTo to keep track of
- // when to force break through an obstacle.
- // Boundaries to stay within. If beyond soft boundary, prefer to
- // change direction ASAP. If at hard max, always change immediately.
- metrics = options.obstacleMetrics,
- softMinX = min(start.x,
- end.x) - metrics.maxWidth - 10,
- softMaxX = max(start.x,
- end.x) + metrics.maxWidth + 10,
- softMinY = min(start.y,
- end.y) - metrics.maxHeight - 10,
- softMaxY = max(start.y,
- end.y) + metrics.maxHeight + 10,
- // Obstacles
- chartObstacles = options.chartObstacles,
- startObstacleIx = findLastObstacleBefore(chartObstacles,
- softMinX),
- endObstacleIx = findLastObstacleBefore(chartObstacles,
- softMaxX);
- // eslint-disable-next-line valid-jsdoc
- /**
- * How far can you go between two points before hitting an obstacle?
- * Does not work for diagonal lines (because it doesn't have to).
- * @private
- */
- function pivotPoint(fromPoint, toPoint, directionIsX) {
- var firstPoint,
- lastPoint,
- highestPoint,
- lowestPoint,
- i,
- searchDirection = fromPoint.x < toPoint.x ? 1 : -1;
- if (fromPoint.x < toPoint.x) {
- firstPoint = fromPoint;
- lastPoint = toPoint;
- }
- else {
- firstPoint = toPoint;
- lastPoint = fromPoint;
- }
- if (fromPoint.y < toPoint.y) {
- lowestPoint = fromPoint;
- highestPoint = toPoint;
- }
- else {
- lowestPoint = toPoint;
- highestPoint = fromPoint;
- }
- // Go through obstacle range in reverse if toPoint is before
- // fromPoint in the X-dimension.
- i = searchDirection < 0 ?
- // Searching backwards, start at last obstacle before last point
- min(findLastObstacleBefore(chartObstacles, lastPoint.x), chartObstacles.length - 1) :
- // Forwards. Since we're not sorted by xMax, we have to look
- // at all obstacles.
- 0;
- // Go through obstacles in this X range
- while (chartObstacles[i] && (searchDirection > 0 && chartObstacles[i].xMin <= lastPoint.x ||
- searchDirection < 0 && chartObstacles[i].xMax >= firstPoint.x)) {
- // If this obstacle is between from and to points in a straight
- // line, pivot at the intersection.
- if (chartObstacles[i].xMin <= lastPoint.x &&
- chartObstacles[i].xMax >= firstPoint.x &&
- chartObstacles[i].yMin <= highestPoint.y &&
- chartObstacles[i].yMax >= lowestPoint.y) {
- if (directionIsX) {
- return {
- y: fromPoint.y,
- x: fromPoint.x < toPoint.x ?
- chartObstacles[i].xMin - 1 :
- chartObstacles[i].xMax + 1,
- obstacle: chartObstacles[i]
- };
- }
- // else ...
- return {
- x: fromPoint.x,
- y: fromPoint.y < toPoint.y ?
- chartObstacles[i].yMin - 1 :
- chartObstacles[i].yMax + 1,
- obstacle: chartObstacles[i]
- };
- }
- i += searchDirection;
- }
- return toPoint;
- }
- /**
- * Decide in which direction to dodge or get out of an obstacle.
- * Considers desired direction, which way is shortest, soft and hard
- * bounds.
- *
- * (? Returns a string, either xMin, xMax, yMin or yMax.)
- *
- * @private
- * @function
- *
- * @param {object} obstacle
- * Obstacle to dodge/escape.
- *
- * @param {object} fromPoint
- * Point with x/y props that's dodging/escaping.
- *
- * @param {object} toPoint
- * Goal point.
- *
- * @param {boolean} dirIsX
- * Dodge in X dimension.
- *
- * @param {object} bounds
- * Hard and soft boundaries.
- *
- * @return {boolean}
- * Use max or not.
- */
- function getDodgeDirection(obstacle, fromPoint, toPoint, dirIsX, bounds) {
- var softBounds = bounds.soft, hardBounds = bounds.hard, dir = dirIsX ? 'x' : 'y', toPointMax = { x: fromPoint.x, y: fromPoint.y }, toPointMin = { x: fromPoint.x, y: fromPoint.y }, minPivot, maxPivot, maxOutOfSoftBounds = obstacle[dir + 'Max'] >=
- softBounds[dir + 'Max'], minOutOfSoftBounds = obstacle[dir + 'Min'] <=
- softBounds[dir + 'Min'], maxOutOfHardBounds = obstacle[dir + 'Max'] >=
- hardBounds[dir + 'Max'], minOutOfHardBounds = obstacle[dir + 'Min'] <=
- hardBounds[dir + 'Min'],
- // Find out if we should prefer one direction over the other if
- // we can choose freely
- minDistance = abs(obstacle[dir + 'Min'] - fromPoint[dir]), maxDistance = abs(obstacle[dir + 'Max'] - fromPoint[dir]),
- // If it's a small difference, pick the one leading towards dest
- // point. Otherwise pick the shortest distance
- useMax = abs(minDistance - maxDistance) < 10 ?
- fromPoint[dir] < toPoint[dir] :
- maxDistance < minDistance;
- // Check if we hit any obstacles trying to go around in either
- // direction.
- toPointMin[dir] = obstacle[dir + 'Min'];
- toPointMax[dir] = obstacle[dir + 'Max'];
- minPivot = pivotPoint(fromPoint, toPointMin, dirIsX)[dir] !==
- toPointMin[dir];
- maxPivot = pivotPoint(fromPoint, toPointMax, dirIsX)[dir] !==
- toPointMax[dir];
- useMax = minPivot ?
- (maxPivot ? useMax : true) :
- (maxPivot ? false : useMax);
- // useMax now contains our preferred choice, bounds not taken into
- // account. If both or neither direction is out of bounds we want to
- // use this.
- // Deal with soft bounds
- useMax = minOutOfSoftBounds ?
- (maxOutOfSoftBounds ? useMax : true) : // Out on min
- (maxOutOfSoftBounds ? false : useMax); // Not out on min
- // Deal with hard bounds
- useMax = minOutOfHardBounds ?
- (maxOutOfHardBounds ? useMax : true) : // Out on min
- (maxOutOfHardBounds ? false : useMax); // Not out on min
- return useMax;
- }
- // eslint-disable-next-line valid-jsdoc
- /**
- * Find a clear path between point.
- * @private
- */
- function clearPathTo(fromPoint, toPoint, dirIsX) {
- // Don't waste time if we've hit goal
- if (fromPoint.x === toPoint.x && fromPoint.y === toPoint.y) {
- return [];
- }
- var dir = dirIsX ? 'x' : 'y',
- pivot,
- segments,
- waypoint,
- waypointUseMax,
- envelopingObstacle,
- secondEnvelopingObstacle,
- envelopWaypoint,
- obstacleMargin = options.obstacleOptions.margin,
- bounds = {
- soft: {
- xMin: softMinX,
- xMax: softMaxX,
- yMin: softMinY,
- yMax: softMaxY
- },
- hard: options.hardBounds
- };
- // If fromPoint is inside an obstacle we have a problem. Break out
- // by just going to the outside of this obstacle. We prefer to go to
- // the nearest edge in the chosen direction.
- envelopingObstacle =
- findObstacleFromPoint(chartObstacles, fromPoint);
- if (envelopingObstacle > -1) {
- envelopingObstacle = chartObstacles[envelopingObstacle];
- waypointUseMax = getDodgeDirection(envelopingObstacle, fromPoint, toPoint, dirIsX, bounds);
- // Cut obstacle to hard bounds to make sure we stay within
- limitObstacleToBounds(envelopingObstacle, options.hardBounds);
- envelopWaypoint = dirIsX ? {
- y: fromPoint.y,
- x: envelopingObstacle[waypointUseMax ? 'xMax' : 'xMin'] +
- (waypointUseMax ? 1 : -1)
- } : {
- x: fromPoint.x,
- y: envelopingObstacle[waypointUseMax ? 'yMax' : 'yMin'] +
- (waypointUseMax ? 1 : -1)
- };
- // If we crashed into another obstacle doing this, we put the
- // waypoint between them instead
- secondEnvelopingObstacle = findObstacleFromPoint(chartObstacles, envelopWaypoint);
- if (secondEnvelopingObstacle > -1) {
- secondEnvelopingObstacle = chartObstacles[secondEnvelopingObstacle];
- // Cut obstacle to hard bounds
- limitObstacleToBounds(secondEnvelopingObstacle, options.hardBounds);
- // Modify waypoint to lay between obstacles
- envelopWaypoint[dir] = waypointUseMax ? max(envelopingObstacle[dir + 'Max'] - obstacleMargin + 1, (secondEnvelopingObstacle[dir + 'Min'] +
- envelopingObstacle[dir + 'Max']) / 2) :
- min((envelopingObstacle[dir + 'Min'] + obstacleMargin - 1), ((secondEnvelopingObstacle[dir + 'Max'] +
- envelopingObstacle[dir + 'Min']) / 2));
- // We are not going anywhere. If this happens for the first
- // time, do nothing. Otherwise, try to go to the extreme of
- // the obstacle pair in the current direction.
- if (fromPoint.x === envelopWaypoint.x &&
- fromPoint.y === envelopWaypoint.y) {
- if (forceObstacleBreak) {
- envelopWaypoint[dir] = waypointUseMax ?
- max(envelopingObstacle[dir + 'Max'], secondEnvelopingObstacle[dir + 'Max']) + 1 :
- min(envelopingObstacle[dir + 'Min'], secondEnvelopingObstacle[dir + 'Min']) - 1;
- }
- // Toggle on if off, and the opposite
- forceObstacleBreak = !forceObstacleBreak;
- }
- else {
- // This point is not identical to previous.
- // Clear break trigger.
- forceObstacleBreak = false;
- }
- }
- segments = [{
- start: fromPoint,
- end: envelopWaypoint
- }];
- }
- else { // If not enveloping, use standard pivot calculation
- pivot = pivotPoint(fromPoint, {
- x: dirIsX ? toPoint.x : fromPoint.x,
- y: dirIsX ? fromPoint.y : toPoint.y
- }, dirIsX);
- segments = [{
- start: fromPoint,
- end: {
- x: pivot.x,
- y: pivot.y
- }
- }];
- // Pivot before goal, use a waypoint to dodge obstacle
- if (pivot[dirIsX ? 'x' : 'y'] !== toPoint[dirIsX ? 'x' : 'y']) {
- // Find direction of waypoint
- waypointUseMax = getDodgeDirection(pivot.obstacle, pivot, toPoint, !dirIsX, bounds);
- // Cut waypoint to hard bounds
- limitObstacleToBounds(pivot.obstacle, options.hardBounds);
- waypoint = {
- x: dirIsX ?
- pivot.x :
- pivot.obstacle[waypointUseMax ? 'xMax' : 'xMin'] +
- (waypointUseMax ? 1 : -1),
- y: dirIsX ?
- pivot.obstacle[waypointUseMax ? 'yMax' : 'yMin'] +
- (waypointUseMax ? 1 : -1) :
- pivot.y
- };
- // We're changing direction here, store that to make sure we
- // also change direction when adding the last segment array
- // after handling waypoint.
- dirIsX = !dirIsX;
- segments = segments.concat(clearPathTo({
- x: pivot.x,
- y: pivot.y
- }, waypoint, dirIsX));
- }
- }
- // Get segments for the other direction too
- // Recursion is our friend
- segments = segments.concat(clearPathTo(segments[segments.length - 1].end, toPoint, !dirIsX));
- return segments;
- }
- // eslint-disable-next-line valid-jsdoc
- /**
- * Extract point to outside of obstacle in whichever direction is
- * closest. Returns new point outside obstacle.
- * @private
- */
- function extractFromObstacle(obstacle, point, goalPoint) {
- var dirIsX = min(obstacle.xMax - point.x,
- point.x - obstacle.xMin) <
- min(obstacle.yMax - point.y,
- point.y - obstacle.yMin),
- bounds = {
- soft: options.hardBounds,
- hard: options.hardBounds
- },
- useMax = getDodgeDirection(obstacle,
- point,
- goalPoint,
- dirIsX,
- bounds);
- return dirIsX ? {
- y: point.y,
- x: obstacle[useMax ? 'xMax' : 'xMin'] + (useMax ? 1 : -1)
- } : {
- x: point.x,
- y: obstacle[useMax ? 'yMax' : 'yMin'] + (useMax ? 1 : -1)
- };
- }
- // Cut the obstacle array to soft bounds for optimization in large
- // datasets.
- chartObstacles =
- chartObstacles.slice(startObstacleIx, endObstacleIx + 1);
- // If an obstacle envelops the end point, move it out of there and add
- // a little segment to where it was.
- if ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
- extractedEndPoint = extractFromObstacle(chartObstacles[endObstacleIx], end, start);
- endSegments.push({
- end: end,
- start: extractedEndPoint
- });
- end = extractedEndPoint;
- }
- // If it's still inside one or more obstacles, get out of there by
- // force-moving towards the start point.
- while ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
- useMax = end[dir] - start[dir] < 0;
- extractedEndPoint = {
- x: end.x,
- y: end.y
- };
- extractedEndPoint[dir] = chartObstacles[endObstacleIx][useMax ? dir + 'Max' : dir + 'Min'] + (useMax ? 1 : -1);
- endSegments.push({
- end: end,
- start: extractedEndPoint
- });
- end = extractedEndPoint;
- }
- // Find the path
- segments = clearPathTo(start, end, dirIsX);
- // Add the end-point segments
- segments = segments.concat(endSegments.reverse());
- return {
- path: pathFromSegments(segments),
- obstacles: segments
- };
- };
- fastAvoid.requiresObstacles = true;
- // Define the available pathfinding algorithms.
- // Algorithms take up to 3 arguments: starting point, ending point, and an
- // options object.
- var algorithms = {
- fastAvoid: fastAvoid,
- straight: straight,
- simpleConnect: simpleConnect
- };
- return algorithms;
- });
- _registerModule(_modules, 'Gantt/Pathfinder.js', [_modules['Gantt/Connection.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js'], _modules['Gantt/PathfinderAlgorithms.js']], function (Connection, Chart, H, D, Point, U, pathfinderAlgorithms) {
- /* *
- *
- * (c) 2016 Highsoft AS
- * Authors: Øystein Moseng, Lars A. V. Cabrera
- *
- * License: www.highcharts.com/license
- *
- * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
- *
- * */
- /**
- * The default pathfinder algorithm to use for a chart. It is possible to define
- * your own algorithms by adding them to the
- * `Highcharts.Pathfinder.prototype.algorithms`
- * object before the chart has been created.
- *
- * The default algorithms are as follows:
- *
- * `straight`: Draws a straight line between the connecting
- * points. Does not avoid other points when drawing.
- *
- * `simpleConnect`: Finds a path between the points using right angles
- * only. Takes only starting/ending points into
- * account, and will not avoid other points.
- *
- * `fastAvoid`: Finds a path between the points using right angles
- * only. Will attempt to avoid other points, but its
- * focus is performance over accuracy. Works well with
- * less dense datasets.
- *
- * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
- */
- ''; // detach doclets above
- var defaultOptions = D.defaultOptions;
- var addEvent = U.addEvent,
- defined = U.defined,
- error = U.error,
- extend = U.extend,
- merge = U.merge,
- objectEach = U.objectEach,
- pick = U.pick,
- splat = U.splat;
- var deg2rad = H.deg2rad,
- max = Math.max,
- min = Math.min;
- /*
- @todo:
- - Document how to write your own algorithms
- - Consider adding a Point.pathTo method that wraps creating a connection
- and rendering it
- */
- // Set default Pathfinder options
- extend(defaultOptions, {
- /**
- * The Pathfinder module allows you to define connections between any two
- * points, represented as lines - optionally with markers for the start
- * and/or end points. Multiple algorithms are available for calculating how
- * the connecting lines are drawn.
- *
- * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
- * charts, the connectors are used to draw dependencies between tasks.
- *
- * @see [dependency](series.gantt.data.dependency)
- *
- * @sample gantt/pathfinder/demo
- * Pathfinder connections
- *
- * @declare Highcharts.ConnectorsOptions
- * @product gantt
- * @optionparent connectors
- */
- connectors: {
- /**
- * Enable connectors for this chart. Requires Highcharts Gantt.
- *
- * @type {boolean}
- * @default true
- * @since 6.2.0
- * @apioption connectors.enabled
- */
- /**
- * Set the default dash style for this chart's connecting lines.
- *
- * @type {string}
- * @default solid
- * @since 6.2.0
- * @apioption connectors.dashStyle
- */
- /**
- * Set the default color for this chart's Pathfinder connecting lines.
- * Defaults to the color of the point being connected.
- *
- * @type {Highcharts.ColorString}
- * @since 6.2.0
- * @apioption connectors.lineColor
- */
- /**
- * Set the default pathfinder margin to use, in pixels. Some Pathfinder
- * algorithms attempt to avoid obstacles, such as other points in the
- * chart. These algorithms use this margin to determine how close lines
- * can be to an obstacle. The default is to compute this automatically
- * from the size of the obstacles in the chart.
- *
- * To draw connecting lines close to existing points, set this to a low
- * number. For more space around existing points, set this number
- * higher.
- *
- * @sample gantt/pathfinder/algorithm-margin
- * Small algorithmMargin
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.algorithmMargin
- */
- /**
- * Set the default pathfinder algorithm to use for this chart. It is
- * possible to define your own algorithms by adding them to the
- * Highcharts.Pathfinder.prototype.algorithms object before the chart
- * has been created.
- *
- * The default algorithms are as follows:
- *
- * `straight`: Draws a straight line between the connecting
- * points. Does not avoid other points when drawing.
- *
- * `simpleConnect`: Finds a path between the points using right angles
- * only. Takes only starting/ending points into
- * account, and will not avoid other points.
- *
- * `fastAvoid`: Finds a path between the points using right angles
- * only. Will attempt to avoid other points, but its
- * focus is performance over accuracy. Works well with
- * less dense datasets.
- *
- * Default value: `straight` is used as default for most series types,
- * while `simpleConnect` is used as default for Gantt series, to show
- * dependencies between points.
- *
- * @sample gantt/pathfinder/demo
- * Different types used
- *
- * @type {Highcharts.PathfinderTypeValue}
- * @default undefined
- * @since 6.2.0
- */
- type: 'straight',
- /**
- * Set the default pixel width for this chart's Pathfinder connecting
- * lines.
- *
- * @since 6.2.0
- */
- lineWidth: 1,
- /**
- * Marker options for this chart's Pathfinder connectors. Note that
- * this option is overridden by the `startMarker` and `endMarker`
- * options.
- *
- * @declare Highcharts.ConnectorsMarkerOptions
- * @since 6.2.0
- */
- marker: {
- /**
- * Set the radius of the connector markers. The default is
- * automatically computed based on the algorithmMargin setting.
- *
- * Setting marker.width and marker.height will override this
- * setting.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.radius
- */
- /**
- * Set the width of the connector markers. If not supplied, this
- * is inferred from the marker radius.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.width
- */
- /**
- * Set the height of the connector markers. If not supplied, this
- * is inferred from the marker radius.
- *
- * @type {number}
- * @since 6.2.0
- * @apioption connectors.marker.height
- */
- /**
- * Set the color of the connector markers. By default this is the
- * same as the connector color.
- *
- * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
- * @since 6.2.0
- * @apioption connectors.marker.color
- */
- /**
- * Set the line/border color of the connector markers. By default
- * this is the same as the marker color.
- *
- * @type {Highcharts.ColorString}
- * @since 6.2.0
- * @apioption connectors.marker.lineColor
- */
- /**
- * Enable markers for the connectors.
- */
- enabled: false,
- /**
- * Horizontal alignment of the markers relative to the points.
- *
- * @type {Highcharts.AlignValue}
- */
- align: 'center',
- /**
- * Vertical alignment of the markers relative to the points.
- *
- * @type {Highcharts.VerticalAlignValue}
- */
- verticalAlign: 'middle',
- /**
- * Whether or not to draw the markers inside the points.
- */
- inside: false,
- /**
- * Set the line/border width of the pathfinder markers.
- */
- lineWidth: 1
- },
- /**
- * Marker options specific to the start markers for this chart's
- * Pathfinder connectors. Overrides the generic marker options.
- *
- * @declare Highcharts.ConnectorsStartMarkerOptions
- * @extends connectors.marker
- * @since 6.2.0
- */
- startMarker: {
- /**
- * Set the symbol of the connector start markers.
- */
- symbol: 'diamond'
- },
- /**
- * Marker options specific to the end markers for this chart's
- * Pathfinder connectors. Overrides the generic marker options.
- *
- * @declare Highcharts.ConnectorsEndMarkerOptions
- * @extends connectors.marker
- * @since 6.2.0
- */
- endMarker: {
- /**
- * Set the symbol of the connector end markers.
- */
- symbol: 'arrow-filled'
- }
- }
- });
- /**
- * Override Pathfinder connector options for a series. Requires Highcharts Gantt
- * to be loaded.
- *
- * @declare Highcharts.SeriesConnectorsOptionsObject
- * @extends connectors
- * @since 6.2.0
- * @excluding enabled, algorithmMargin
- * @product gantt
- * @apioption plotOptions.series.connectors
- */
- /**
- * Connect to a point. This option can be either a string, referring to the ID
- * of another point, or an object, or an array of either. If the option is an
- * array, each element defines a connection.
- *
- * @sample gantt/pathfinder/demo
- * Different connection types
- *
- * @declare Highcharts.XrangePointConnectorsOptionsObject
- * @type {string|Array<string|*>|*}
- * @extends plotOptions.series.connectors
- * @since 6.2.0
- * @excluding enabled
- * @product gantt
- * @requires highcharts-gantt
- * @apioption series.xrange.data.connect
- */
- /**
- * The ID of the point to connect to.
- *
- * @type {string}
- * @since 6.2.0
- * @product gantt
- * @apioption series.xrange.data.connect.to
- */
- /**
- * Get point bounding box using plotX/plotY and shapeArgs. If using
- * graphic.getBBox() directly, the bbox will be affected by animation.
- *
- * @private
- * @function
- *
- * @param {Highcharts.Point} point
- * The point to get BB of.
- *
- * @return {Highcharts.Dictionary<number>|null}
- * Result xMax, xMin, yMax, yMin.
- */
- function getPointBB(point) {
- var shapeArgs = point.shapeArgs,
- bb;
- // Prefer using shapeArgs (columns)
- if (shapeArgs) {
- return {
- xMin: shapeArgs.x || 0,
- xMax: (shapeArgs.x || 0) + (shapeArgs.width || 0),
- yMin: shapeArgs.y || 0,
- yMax: (shapeArgs.y || 0) + (shapeArgs.height || 0)
- };
- }
- // Otherwise use plotX/plotY and bb
- bb = point.graphic && point.graphic.getBBox();
- return bb ? {
- xMin: point.plotX - bb.width / 2,
- xMax: point.plotX + bb.width / 2,
- yMin: point.plotY - bb.height / 2,
- yMax: point.plotY + bb.height / 2
- } : null;
- }
- /**
- * Calculate margin to place around obstacles for the pathfinder in pixels.
- * Returns a minimum of 1 pixel margin.
- *
- * @private
- * @function
- *
- * @param {Array<object>} obstacles
- * Obstacles to calculate margin from.
- *
- * @return {number}
- * The calculated margin in pixels. At least 1.
- */
- function calculateObstacleMargin(obstacles) {
- var len = obstacles.length,
- i = 0,
- j,
- obstacleDistance,
- distances = [],
- // Compute smallest distance between two rectangles
- distance = function (a,
- b,
- bbMargin) {
- // Count the distance even if we are slightly off
- var margin = pick(bbMargin, 10),
- yOverlap = a.yMax + margin > b.yMin - margin &&
- a.yMin - margin < b.yMax + margin,
- xOverlap = a.xMax + margin > b.xMin - margin &&
- a.xMin - margin < b.xMax + margin,
- xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
- yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
- // If the rectangles collide, try recomputing with smaller margin.
- // If they collide anyway, discard the obstacle.
- if (xOverlap && yOverlap) {
- return (margin ?
- distance(a, b, Math.floor(margin / 2)) :
- Infinity);
- }
- return min(xDistance, yDistance);
- };
- // Go over all obstacles and compare them to the others.
- for (; i < len; ++i) {
- // Compare to all obstacles ahead. We will already have compared this
- // obstacle to the ones before.
- for (j = i + 1; j < len; ++j) {
- obstacleDistance = distance(obstacles[i], obstacles[j]);
- // TODO: Magic number 80
- if (obstacleDistance < 80) { // Ignore large distances
- distances.push(obstacleDistance);
- }
- }
- }
- // Ensure we always have at least one value, even in very spaceous charts
- distances.push(80);
- return max(Math.floor(distances.sort(function (a, b) {
- return (a - b);
- })[
- // Discard first 10% of the relevant distances, and then grab
- // the smallest one.
- Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
- ), 1 // 1 is the minimum margin
- );
- }
- /* eslint-disable no-invalid-this, valid-jsdoc */
- /**
- * The Pathfinder class.
- *
- * @private
- * @class
- * @name Highcharts.Pathfinder
- *
- * @param {Highcharts.Chart} chart
- * The chart to operate on.
- */
- var Pathfinder = /** @class */ (function () {
- function Pathfinder(chart) {
- /* *
- *
- * Properties
- *
- * */
- this.chart = void 0;
- this.chartObstacles = void 0;
- this.chartObstacleMetrics = void 0;
- this.connections = void 0;
- this.group = void 0;
- this.lineObstacles = void 0;
- this.init(chart);
- }
- /**
- * @name Highcharts.Pathfinder#algorithms
- * @type {Highcharts.Dictionary<Function>}
- */
- /**
- * Initialize the Pathfinder object.
- *
- * @function Highcharts.Pathfinder#init
- *
- * @param {Highcharts.Chart} chart
- * The chart context.
- */
- Pathfinder.prototype.init = function (chart) {
- // Initialize pathfinder with chart context
- this.chart = chart;
- // Init connection reference list
- this.connections = [];
- // Recalculate paths/obstacles on chart redraw
- addEvent(chart, 'redraw', function () {
- this.pathfinder.update();
- });
- };
- /**
- * Update Pathfinder connections from scratch.
- *
- * @function Highcharts.Pathfinder#update
- *
- * @param {boolean} [deferRender]
- * Whether or not to defer rendering of connections until
- * series.afterAnimate event has fired. Used on first render.
- */
- Pathfinder.prototype.update = function (deferRender) {
- var chart = this.chart,
- pathfinder = this,
- oldConnections = pathfinder.connections;
- // Rebuild pathfinder connections from options
- pathfinder.connections = [];
- chart.series.forEach(function (series) {
- if (series.visible && !series.options.isInternal) {
- series.points.forEach(function (point) {
- var ganttPointOptions = point.options;
- // For Gantt series the connect could be
- // defined as a dependency
- if (ganttPointOptions && ganttPointOptions.dependency) {
- ganttPointOptions.connect = ganttPointOptions.dependency;
- }
- var to,
- connects = (point.options &&
- point.options.connect &&
- splat(point.options.connect));
- if (point.visible && point.isInside !== false && connects) {
- connects.forEach(function (connect) {
- to = chart.get(typeof connect === 'string' ?
- connect : connect.to);
- if (to instanceof Point &&
- to.series.visible &&
- to.visible &&
- to.isInside !== false) {
- // Add new connection
- pathfinder.connections.push(new Connection(point, // from
- to, typeof connect === 'string' ?
- {} :
- connect));
- }
- });
- }
- });
- }
- });
- // Clear connections that should not be updated, and move old info over
- // to new connections.
- for (var j = 0, k = void 0, found = void 0, lenOld = oldConnections.length, lenNew = pathfinder.connections.length; j < lenOld; ++j) {
- found = false;
- for (k = 0; k < lenNew; ++k) {
- if (oldConnections[j].fromPoint ===
- pathfinder.connections[k].fromPoint &&
- oldConnections[j].toPoint ===
- pathfinder.connections[k].toPoint) {
- pathfinder.connections[k].graphics =
- oldConnections[j].graphics;
- found = true;
- break;
- }
- }
- if (!found) {
- oldConnections[j].destroy();
- }
- }
- // Clear obstacles to force recalculation. This must be done on every
- // redraw in case positions have changed. Recalculation is handled in
- // Connection.getPath on demand.
- delete this.chartObstacles;
- delete this.lineObstacles;
- // Draw the pending connections
- pathfinder.renderConnections(deferRender);
- };
- /**
- * Draw the chart's connecting paths.
- *
- * @function Highcharts.Pathfinder#renderConnections
- *
- * @param {boolean} [deferRender]
- * Whether or not to defer render until series animation is finished.
- * Used on first render.
- */
- Pathfinder.prototype.renderConnections = function (deferRender) {
- if (deferRender) {
- // Render after series are done animating
- this.chart.series.forEach(function (series) {
- var render = function () {
- // Find pathfinder connections belonging to this series
- // that haven't rendered, and render them now.
- var pathfinder = series.chart.pathfinder,
- conns = pathfinder && pathfinder.connections || [];
- conns.forEach(function (connection) {
- if (connection.fromPoint &&
- connection.fromPoint.series === series) {
- connection.render();
- }
- });
- if (series.pathfinderRemoveRenderEvent) {
- series.pathfinderRemoveRenderEvent();
- delete series.pathfinderRemoveRenderEvent;
- }
- };
- if (series.options.animation === false) {
- render();
- }
- else {
- series.pathfinderRemoveRenderEvent = addEvent(series, 'afterAnimate', render);
- }
- });
- }
- else {
- // Go through connections and render them
- this.connections.forEach(function (connection) {
- connection.render();
- });
- }
- };
- /**
- * Get obstacles for the points in the chart. Does not include connecting
- * lines from Pathfinder. Applies algorithmMargin to the obstacles.
- *
- * @function Highcharts.Pathfinder#getChartObstacles
- *
- * @param {object} options
- * Options for the calculation. Currenlty only
- * options.algorithmMargin.
- *
- * @return {Array<object>}
- * An array of calculated obstacles. Each obstacle is defined as an
- * object with xMin, xMax, yMin and yMax properties.
- */
- Pathfinder.prototype.getChartObstacles = function (options) {
- var obstacles = [],
- series = this.chart.series,
- margin = pick(options.algorithmMargin, 0),
- calculatedMargin;
- for (var i = 0, sLen = series.length; i < sLen; ++i) {
- if (series[i].visible && !series[i].options.isInternal) {
- for (var j = 0, pLen = series[i].points.length, bb = void 0, point = void 0; j < pLen; ++j) {
- point = series[i].points[j];
- if (point.visible) {
- bb = getPointBB(point);
- if (bb) {
- obstacles.push({
- xMin: bb.xMin - margin,
- xMax: bb.xMax + margin,
- yMin: bb.yMin - margin,
- yMax: bb.yMax + margin
- });
- }
- }
- }
- }
- }
- // Sort obstacles by xMin for optimization
- obstacles = obstacles.sort(function (a, b) {
- return a.xMin - b.xMin;
- });
- // Add auto-calculated margin if the option is not defined
- if (!defined(options.algorithmMargin)) {
- calculatedMargin =
- options.algorithmMargin =
- calculateObstacleMargin(obstacles);
- obstacles.forEach(function (obstacle) {
- obstacle.xMin -= calculatedMargin;
- obstacle.xMax += calculatedMargin;
- obstacle.yMin -= calculatedMargin;
- obstacle.yMax += calculatedMargin;
- });
- }
- return obstacles;
- };
- /**
- * Utility function to get metrics for obstacles:
- * - Widest obstacle width
- * - Tallest obstacle height
- *
- * @function Highcharts.Pathfinder#getObstacleMetrics
- *
- * @param {Array<object>} obstacles
- * An array of obstacles to inspect.
- *
- * @return {object}
- * The calculated metrics, as an object with maxHeight and maxWidth
- * properties.
- */
- Pathfinder.prototype.getObstacleMetrics = function (obstacles) {
- var maxWidth = 0,
- maxHeight = 0,
- width,
- height,
- i = obstacles.length;
- while (i--) {
- width = obstacles[i].xMax - obstacles[i].xMin;
- height = obstacles[i].yMax - obstacles[i].yMin;
- if (maxWidth < width) {
- maxWidth = width;
- }
- if (maxHeight < height) {
- maxHeight = height;
- }
- }
- return {
- maxHeight: maxHeight,
- maxWidth: maxWidth
- };
- };
- /**
- * Utility to get which direction to start the pathfinding algorithm
- * (X vs Y), calculated from a set of marker options.
- *
- * @function Highcharts.Pathfinder#getAlgorithmStartDirection
- *
- * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
- * Marker options to calculate from.
- *
- * @return {boolean}
- * Returns true for X, false for Y, and undefined for autocalculate.
- */
- Pathfinder.prototype.getAlgorithmStartDirection = function (markerOptions) {
- var xCenter = markerOptions.align !== 'left' &&
- markerOptions.align !== 'right', yCenter = markerOptions.verticalAlign !== 'top' &&
- markerOptions.verticalAlign !== 'bottom', undef;
- return xCenter ?
- (yCenter ? undef : false) : // x is centered
- (yCenter ? true : undef); // x is off-center
- };
- return Pathfinder;
- }());
- Pathfinder.prototype.algorithms = pathfinderAlgorithms;
- // Add to Highcharts namespace
- H.Pathfinder = Pathfinder;
- // Add pathfinding capabilities to Points
- extend(Point.prototype, /** @lends Point.prototype */ {
- /**
- * Get coordinates of anchor point for pathfinder connection.
- *
- * @private
- * @function Highcharts.Point#getPathfinderAnchorPoint
- *
- * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
- * Connection options for position on point.
- *
- * @return {Highcharts.PositionObject}
- * An object with x/y properties for the position. Coordinates are
- * in plot values, not relative to point.
- */
- getPathfinderAnchorPoint: function (markerOptions) {
- var bb = getPointBB(this),
- x,
- y;
- switch (markerOptions.align) { // eslint-disable-line default-case
- case 'right':
- x = 'xMax';
- break;
- case 'left':
- x = 'xMin';
- }
- switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
- case 'top':
- y = 'yMin';
- break;
- case 'bottom':
- y = 'yMax';
- }
- return {
- x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
- y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
- };
- },
- /**
- * Utility to get the angle from one point to another.
- *
- * @private
- * @function Highcharts.Point#getRadiansToVector
- *
- * @param {Highcharts.PositionObject} v1
- * The first vector, as an object with x/y properties.
- *
- * @param {Highcharts.PositionObject} v2
- * The second vector, as an object with x/y properties.
- *
- * @return {number}
- * The angle in degrees
- */
- getRadiansToVector: function (v1, v2) {
- var box;
- if (!defined(v2)) {
- box = getPointBB(this);
- if (box) {
- v2 = {
- x: (box.xMin + box.xMax) / 2,
- y: (box.yMin + box.yMax) / 2
- };
- }
- }
- return Math.atan2(v2.y - v1.y, v1.x - v2.x);
- },
- /**
- * Utility to get the position of the marker, based on the path angle and
- * the marker's radius.
- *
- * @private
- * @function Highcharts.Point#getMarkerVector
- *
- * @param {number} radians
- * The angle in radians from the point center to another vector.
- *
- * @param {number} markerRadius
- * The radius of the marker, to calculate the additional distance to
- * the center of the marker.
- *
- * @param {object} anchor
- * The anchor point of the path and marker as an object with x/y
- * properties.
- *
- * @return {object}
- * The marker vector as an object with x/y properties.
- */
- getMarkerVector: function (radians, markerRadius, anchor) {
- var twoPI = Math.PI * 2.0,
- theta = radians,
- bb = getPointBB(this),
- rectWidth = bb.xMax - bb.xMin,
- rectHeight = bb.yMax - bb.yMin,
- rAtan = Math.atan2(rectHeight,
- rectWidth),
- tanTheta = 1,
- leftOrRightRegion = false,
- rectHalfWidth = rectWidth / 2.0,
- rectHalfHeight = rectHeight / 2.0,
- rectHorizontalCenter = bb.xMin + rectHalfWidth,
- rectVerticalCenter = bb.yMin + rectHalfHeight,
- edgePoint = {
- x: rectHorizontalCenter,
- y: rectVerticalCenter
- },
- xFactor = 1,
- yFactor = 1;
- while (theta < -Math.PI) {
- theta += twoPI;
- }
- while (theta > Math.PI) {
- theta -= twoPI;
- }
- tanTheta = Math.tan(theta);
- if ((theta > -rAtan) && (theta <= rAtan)) {
- // Right side
- yFactor = -1;
- leftOrRightRegion = true;
- }
- else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
- // Top side
- yFactor = -1;
- }
- else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
- // Left side
- xFactor = -1;
- leftOrRightRegion = true;
- }
- else {
- // Bottom side
- xFactor = -1;
- }
- // Correct the edgePoint according to the placement of the marker
- if (leftOrRightRegion) {
- edgePoint.x += xFactor * (rectHalfWidth);
- edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
- }
- else {
- edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
- edgePoint.y += yFactor * (rectHalfHeight);
- }
- if (anchor.x !== rectHorizontalCenter) {
- edgePoint.x = anchor.x;
- }
- if (anchor.y !== rectVerticalCenter) {
- edgePoint.y = anchor.y;
- }
- return {
- x: edgePoint.x + (markerRadius * Math.cos(theta)),
- y: edgePoint.y - (markerRadius * Math.sin(theta))
- };
- }
- });
- /**
- * Warn if using legacy options. Copy the options over. Note that this will
- * still break if using the legacy options in chart.update, addSeries etc.
- * @private
- */
- function warnLegacy(chart) {
- if (chart.options.pathfinder ||
- chart.series.reduce(function (acc, series) {
- if (series.options) {
- merge(true, (series.options.connectors = series.options.connectors ||
- {}), series.options.pathfinder);
- }
- return acc || series.options && series.options.pathfinder;
- }, false)) {
- merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
- error('WARNING: Pathfinder options have been renamed. ' +
- 'Use "chart.connectors" or "series.connectors" instead.');
- }
- }
- // Initialize Pathfinder for charts
- Chart.prototype.callbacks.push(function (chart) {
- var options = chart.options;
- if (options.connectors.enabled !== false) {
- warnLegacy(chart);
- this.pathfinder = new Pathfinder(this);
- this.pathfinder.update(true); // First draw, defer render
- }
- });
- return Pathfinder;
- });
- _registerModule(_modules, 'masters/modules/pathfinder.src.js', [], function () {
- });
- }));
|