highcharts-more.src.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license Highcharts JS v4.1.5 (2015-04-13)
  5. *
  6. * (c) 2009-2014 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. // JSLint options:
  11. /*global Highcharts, HighchartsAdapter, document, window, navigator, setInterval, clearInterval, clearTimeout, setTimeout, location, jQuery, $, console */
  12. (function (Highcharts, UNDEFINED) {
  13. var arrayMin = Highcharts.arrayMin,
  14. arrayMax = Highcharts.arrayMax,
  15. each = Highcharts.each,
  16. extend = Highcharts.extend,
  17. merge = Highcharts.merge,
  18. map = Highcharts.map,
  19. pick = Highcharts.pick,
  20. pInt = Highcharts.pInt,
  21. defaultPlotOptions = Highcharts.getOptions().plotOptions,
  22. seriesTypes = Highcharts.seriesTypes,
  23. extendClass = Highcharts.extendClass,
  24. splat = Highcharts.splat,
  25. wrap = Highcharts.wrap,
  26. Axis = Highcharts.Axis,
  27. Tick = Highcharts.Tick,
  28. Point = Highcharts.Point,
  29. Pointer = Highcharts.Pointer,
  30. CenteredSeriesMixin = Highcharts.CenteredSeriesMixin,
  31. TrackerMixin = Highcharts.TrackerMixin,
  32. Series = Highcharts.Series,
  33. math = Math,
  34. mathRound = math.round,
  35. mathFloor = math.floor,
  36. mathMax = math.max,
  37. Color = Highcharts.Color,
  38. noop = function () {};/**
  39. * The Pane object allows options that are common to a set of X and Y axes.
  40. *
  41. * In the future, this can be extended to basic Highcharts and Highstock.
  42. */
  43. function Pane(options, chart, firstAxis) {
  44. this.init.call(this, options, chart, firstAxis);
  45. }
  46. // Extend the Pane prototype
  47. extend(Pane.prototype, {
  48. /**
  49. * Initiate the Pane object
  50. */
  51. init: function (options, chart, firstAxis) {
  52. var pane = this,
  53. backgroundOption,
  54. defaultOptions = pane.defaultOptions;
  55. pane.chart = chart;
  56. // Set options
  57. if (chart.angular) { // gauges
  58. defaultOptions.background = {}; // gets extended by this.defaultBackgroundOptions
  59. }
  60. pane.options = options = merge(defaultOptions, options);
  61. backgroundOption = options.background;
  62. // To avoid having weighty logic to place, update and remove the backgrounds,
  63. // push them to the first axis' plot bands and borrow the existing logic there.
  64. if (backgroundOption) {
  65. each([].concat(splat(backgroundOption)).reverse(), function (config) {
  66. var backgroundColor = config.backgroundColor, // if defined, replace the old one (specific for gradients)
  67. axisUserOptions = firstAxis.userOptions;
  68. config = merge(pane.defaultBackgroundOptions, config);
  69. if (backgroundColor) {
  70. config.backgroundColor = backgroundColor;
  71. }
  72. config.color = config.backgroundColor; // due to naming in plotBands
  73. firstAxis.options.plotBands.unshift(config);
  74. axisUserOptions.plotBands = axisUserOptions.plotBands || []; // #3176
  75. axisUserOptions.plotBands.unshift(config);
  76. });
  77. }
  78. },
  79. /**
  80. * The default options object
  81. */
  82. defaultOptions: {
  83. // background: {conditional},
  84. center: ['50%', '50%'],
  85. size: '85%',
  86. startAngle: 0
  87. //endAngle: startAngle + 360
  88. },
  89. /**
  90. * The default background options
  91. */
  92. defaultBackgroundOptions: {
  93. shape: 'circle',
  94. borderWidth: 1,
  95. borderColor: 'silver',
  96. backgroundColor: {
  97. linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
  98. stops: [
  99. [0, '#FFF'],
  100. [1, '#DDD']
  101. ]
  102. },
  103. from: -Number.MAX_VALUE, // corrected to axis min
  104. innerRadius: 0,
  105. to: Number.MAX_VALUE, // corrected to axis max
  106. outerRadius: '105%'
  107. }
  108. });
  109. var axisProto = Axis.prototype,
  110. tickProto = Tick.prototype;
  111. /**
  112. * Augmented methods for the x axis in order to hide it completely, used for the X axis in gauges
  113. */
  114. var hiddenAxisMixin = {
  115. getOffset: noop,
  116. redraw: function () {
  117. this.isDirty = false; // prevent setting Y axis dirty
  118. },
  119. render: function () {
  120. this.isDirty = false; // prevent setting Y axis dirty
  121. },
  122. setScale: noop,
  123. setCategories: noop,
  124. setTitle: noop
  125. };
  126. /**
  127. * Augmented methods for the value axis
  128. */
  129. /*jslint unparam: true*/
  130. var radialAxisMixin = {
  131. isRadial: true,
  132. /**
  133. * The default options extend defaultYAxisOptions
  134. */
  135. defaultRadialGaugeOptions: {
  136. labels: {
  137. align: 'center',
  138. x: 0,
  139. y: null // auto
  140. },
  141. minorGridLineWidth: 0,
  142. minorTickInterval: 'auto',
  143. minorTickLength: 10,
  144. minorTickPosition: 'inside',
  145. minorTickWidth: 1,
  146. tickLength: 10,
  147. tickPosition: 'inside',
  148. tickWidth: 2,
  149. title: {
  150. rotation: 0
  151. },
  152. zIndex: 2 // behind dials, points in the series group
  153. },
  154. // Circular axis around the perimeter of a polar chart
  155. defaultRadialXOptions: {
  156. gridLineWidth: 1, // spokes
  157. labels: {
  158. align: null, // auto
  159. distance: 15,
  160. x: 0,
  161. y: null // auto
  162. },
  163. maxPadding: 0,
  164. minPadding: 0,
  165. showLastLabel: false,
  166. tickLength: 0
  167. },
  168. // Radial axis, like a spoke in a polar chart
  169. defaultRadialYOptions: {
  170. gridLineInterpolation: 'circle',
  171. labels: {
  172. align: 'right',
  173. x: -3,
  174. y: -2
  175. },
  176. showLastLabel: false,
  177. title: {
  178. x: 4,
  179. text: null,
  180. rotation: 90
  181. }
  182. },
  183. /**
  184. * Merge and set options
  185. */
  186. setOptions: function (userOptions) {
  187. var options = this.options = merge(
  188. this.defaultOptions,
  189. this.defaultRadialOptions,
  190. userOptions
  191. );
  192. // Make sure the plotBands array is instanciated for each Axis (#2649)
  193. if (!options.plotBands) {
  194. options.plotBands = [];
  195. }
  196. },
  197. /**
  198. * Wrap the getOffset method to return zero offset for title or labels in a radial
  199. * axis
  200. */
  201. getOffset: function () {
  202. // Call the Axis prototype method (the method we're in now is on the instance)
  203. axisProto.getOffset.call(this);
  204. // Title or label offsets are not counted
  205. this.chart.axisOffset[this.side] = 0;
  206. // Set the center array
  207. this.center = this.pane.center = CenteredSeriesMixin.getCenter.call(this.pane);
  208. },
  209. /**
  210. * Get the path for the axis line. This method is also referenced in the getPlotLinePath
  211. * method.
  212. */
  213. getLinePath: function (lineWidth, radius) {
  214. var center = this.center;
  215. radius = pick(radius, center[2] / 2 - this.offset);
  216. return this.chart.renderer.symbols.arc(
  217. this.left + center[0],
  218. this.top + center[1],
  219. radius,
  220. radius,
  221. {
  222. start: this.startAngleRad,
  223. end: this.endAngleRad,
  224. open: true,
  225. innerR: 0
  226. }
  227. );
  228. },
  229. /**
  230. * Override setAxisTranslation by setting the translation to the difference
  231. * in rotation. This allows the translate method to return angle for
  232. * any given value.
  233. */
  234. setAxisTranslation: function () {
  235. // Call uber method
  236. axisProto.setAxisTranslation.call(this);
  237. // Set transA and minPixelPadding
  238. if (this.center) { // it's not defined the first time
  239. if (this.isCircular) {
  240. this.transA = (this.endAngleRad - this.startAngleRad) /
  241. ((this.max - this.min) || 1);
  242. } else {
  243. this.transA = (this.center[2] / 2) / ((this.max - this.min) || 1);
  244. }
  245. if (this.isXAxis) {
  246. this.minPixelPadding = this.transA * this.minPointOffset;
  247. } else {
  248. // This is a workaround for regression #2593, but categories still don't position correctly.
  249. // TODO: Implement true handling of Y axis categories on gauges.
  250. this.minPixelPadding = 0;
  251. }
  252. }
  253. },
  254. /**
  255. * In case of auto connect, add one closestPointRange to the max value right before
  256. * tickPositions are computed, so that ticks will extend passed the real max.
  257. */
  258. beforeSetTickPositions: function () {
  259. if (this.autoConnect) {
  260. this.max += (this.categories && 1) || this.pointRange || this.closestPointRange || 0; // #1197, #2260
  261. }
  262. },
  263. /**
  264. * Override the setAxisSize method to use the arc's circumference as length. This
  265. * allows tickPixelInterval to apply to pixel lengths along the perimeter
  266. */
  267. setAxisSize: function () {
  268. axisProto.setAxisSize.call(this);
  269. if (this.isRadial) {
  270. // Set the center array
  271. this.center = this.pane.center = Highcharts.CenteredSeriesMixin.getCenter.call(this.pane);
  272. // The sector is used in Axis.translate to compute the translation of reversed axis points (#2570)
  273. if (this.isCircular) {
  274. this.sector = this.endAngleRad - this.startAngleRad;
  275. }
  276. // Axis len is used to lay out the ticks
  277. this.len = this.width = this.height = this.center[2] * pick(this.sector, 1) / 2;
  278. }
  279. },
  280. /**
  281. * Returns the x, y coordinate of a point given by a value and a pixel distance
  282. * from center
  283. */
  284. getPosition: function (value, length) {
  285. return this.postTranslate(
  286. this.isCircular ? this.translate(value) : 0, // #2848
  287. pick(this.isCircular ? length : this.translate(value), this.center[2] / 2) - this.offset
  288. );
  289. },
  290. /**
  291. * Translate from intermediate plotX (angle), plotY (axis.len - radius) to final chart coordinates.
  292. */
  293. postTranslate: function (angle, radius) {
  294. var chart = this.chart,
  295. center = this.center;
  296. angle = this.startAngleRad + angle;
  297. return {
  298. x: chart.plotLeft + center[0] + Math.cos(angle) * radius,
  299. y: chart.plotTop + center[1] + Math.sin(angle) * radius
  300. };
  301. },
  302. /**
  303. * Find the path for plot bands along the radial axis
  304. */
  305. getPlotBandPath: function (from, to, options) {
  306. var center = this.center,
  307. startAngleRad = this.startAngleRad,
  308. fullRadius = center[2] / 2,
  309. radii = [
  310. pick(options.outerRadius, '100%'),
  311. options.innerRadius,
  312. pick(options.thickness, 10)
  313. ],
  314. percentRegex = /%$/,
  315. start,
  316. end,
  317. open,
  318. isCircular = this.isCircular, // X axis in a polar chart
  319. ret;
  320. // Polygonal plot bands
  321. if (this.options.gridLineInterpolation === 'polygon') {
  322. ret = this.getPlotLinePath(from).concat(this.getPlotLinePath(to, true));
  323. // Circular grid bands
  324. } else {
  325. // Keep within bounds
  326. from = Math.max(from, this.min);
  327. to = Math.min(to, this.max);
  328. // Plot bands on Y axis (radial axis) - inner and outer radius depend on to and from
  329. if (!isCircular) {
  330. radii[0] = this.translate(from);
  331. radii[1] = this.translate(to);
  332. }
  333. // Convert percentages to pixel values
  334. radii = map(radii, function (radius) {
  335. if (percentRegex.test(radius)) {
  336. radius = (pInt(radius, 10) * fullRadius) / 100;
  337. }
  338. return radius;
  339. });
  340. // Handle full circle
  341. if (options.shape === 'circle' || !isCircular) {
  342. start = -Math.PI / 2;
  343. end = Math.PI * 1.5;
  344. open = true;
  345. } else {
  346. start = startAngleRad + this.translate(from);
  347. end = startAngleRad + this.translate(to);
  348. }
  349. ret = this.chart.renderer.symbols.arc(
  350. this.left + center[0],
  351. this.top + center[1],
  352. radii[0],
  353. radii[0],
  354. {
  355. start: Math.min(start, end), // Math is for reversed yAxis (#3606)
  356. end: Math.max(start, end),
  357. innerR: pick(radii[1], radii[0] - radii[2]),
  358. open: open
  359. }
  360. );
  361. }
  362. return ret;
  363. },
  364. /**
  365. * Find the path for plot lines perpendicular to the radial axis.
  366. */
  367. getPlotLinePath: function (value, reverse) {
  368. var axis = this,
  369. center = axis.center,
  370. chart = axis.chart,
  371. end = axis.getPosition(value),
  372. xAxis,
  373. xy,
  374. tickPositions,
  375. ret;
  376. // Spokes
  377. if (axis.isCircular) {
  378. ret = ['M', center[0] + chart.plotLeft, center[1] + chart.plotTop, 'L', end.x, end.y];
  379. // Concentric circles
  380. } else if (axis.options.gridLineInterpolation === 'circle') {
  381. value = axis.translate(value);
  382. if (value) { // a value of 0 is in the center
  383. ret = axis.getLinePath(0, value);
  384. }
  385. // Concentric polygons
  386. } else {
  387. // Find the X axis in the same pane
  388. each(chart.xAxis, function (a) {
  389. if (a.pane === axis.pane) {
  390. xAxis = a;
  391. }
  392. });
  393. ret = [];
  394. value = axis.translate(value);
  395. tickPositions = xAxis.tickPositions;
  396. if (xAxis.autoConnect) {
  397. tickPositions = tickPositions.concat([tickPositions[0]]);
  398. }
  399. // Reverse the positions for concatenation of polygonal plot bands
  400. if (reverse) {
  401. tickPositions = [].concat(tickPositions).reverse();
  402. }
  403. each(tickPositions, function (pos, i) {
  404. xy = xAxis.getPosition(pos, value);
  405. ret.push(i ? 'L' : 'M', xy.x, xy.y);
  406. });
  407. }
  408. return ret;
  409. },
  410. /**
  411. * Find the position for the axis title, by default inside the gauge
  412. */
  413. getTitlePosition: function () {
  414. var center = this.center,
  415. chart = this.chart,
  416. titleOptions = this.options.title;
  417. return {
  418. x: chart.plotLeft + center[0] + (titleOptions.x || 0),
  419. y: chart.plotTop + center[1] - ({ high: 0.5, middle: 0.25, low: 0 }[titleOptions.align] *
  420. center[2]) + (titleOptions.y || 0)
  421. };
  422. }
  423. };
  424. /*jslint unparam: false*/
  425. /**
  426. * Override axisProto.init to mix in special axis instance functions and function overrides
  427. */
  428. wrap(axisProto, 'init', function (proceed, chart, userOptions) {
  429. var axis = this,
  430. angular = chart.angular,
  431. polar = chart.polar,
  432. isX = userOptions.isX,
  433. isHidden = angular && isX,
  434. isCircular,
  435. startAngleRad,
  436. endAngleRad,
  437. options,
  438. chartOptions = chart.options,
  439. paneIndex = userOptions.pane || 0,
  440. pane,
  441. paneOptions;
  442. // Before prototype.init
  443. if (angular) {
  444. extend(this, isHidden ? hiddenAxisMixin : radialAxisMixin);
  445. isCircular = !isX;
  446. if (isCircular) {
  447. this.defaultRadialOptions = this.defaultRadialGaugeOptions;
  448. }
  449. } else if (polar) {
  450. //extend(this, userOptions.isX ? radialAxisMixin : radialAxisMixin);
  451. extend(this, radialAxisMixin);
  452. isCircular = isX;
  453. this.defaultRadialOptions = isX ? this.defaultRadialXOptions : merge(this.defaultYAxisOptions, this.defaultRadialYOptions);
  454. }
  455. // Run prototype.init
  456. proceed.call(this, chart, userOptions);
  457. if (!isHidden && (angular || polar)) {
  458. options = this.options;
  459. // Create the pane and set the pane options.
  460. if (!chart.panes) {
  461. chart.panes = [];
  462. }
  463. this.pane = pane = chart.panes[paneIndex] = chart.panes[paneIndex] || new Pane(
  464. splat(chartOptions.pane)[paneIndex],
  465. chart,
  466. axis
  467. );
  468. paneOptions = pane.options;
  469. // Disable certain features on angular and polar axes
  470. chart.inverted = false;
  471. chartOptions.chart.zoomType = null;
  472. // Start and end angle options are
  473. // given in degrees relative to top, while internal computations are
  474. // in radians relative to right (like SVG).
  475. this.startAngleRad = startAngleRad = (paneOptions.startAngle - 90) * Math.PI / 180;
  476. this.endAngleRad = endAngleRad = (pick(paneOptions.endAngle, paneOptions.startAngle + 360) - 90) * Math.PI / 180;
  477. this.offset = options.offset || 0;
  478. this.isCircular = isCircular;
  479. // Automatically connect grid lines?
  480. if (isCircular && userOptions.max === UNDEFINED && endAngleRad - startAngleRad === 2 * Math.PI) {
  481. this.autoConnect = true;
  482. }
  483. }
  484. });
  485. /**
  486. * Add special cases within the Tick class' methods for radial axes.
  487. */
  488. wrap(tickProto, 'getPosition', function (proceed, horiz, pos, tickmarkOffset, old) {
  489. var axis = this.axis;
  490. return axis.getPosition ?
  491. axis.getPosition(pos) :
  492. proceed.call(this, horiz, pos, tickmarkOffset, old);
  493. });
  494. /**
  495. * Wrap the getLabelPosition function to find the center position of the label
  496. * based on the distance option
  497. */
  498. wrap(tickProto, 'getLabelPosition', function (proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  499. var axis = this.axis,
  500. optionsY = labelOptions.y,
  501. ret,
  502. centerSlot = 20, // 20 degrees to each side at the top and bottom
  503. align = labelOptions.align,
  504. angle = ((axis.translate(this.pos) + axis.startAngleRad + Math.PI / 2) / Math.PI * 180) % 360;
  505. if (axis.isRadial) {
  506. ret = axis.getPosition(this.pos, (axis.center[2] / 2) + pick(labelOptions.distance, -25));
  507. // Automatically rotated
  508. if (labelOptions.rotation === 'auto') {
  509. label.attr({
  510. rotation: angle
  511. });
  512. // Vertically centered
  513. } else if (optionsY === null) {
  514. optionsY = axis.chart.renderer.fontMetrics(label.styles.fontSize).b - label.getBBox().height / 2;
  515. }
  516. // Automatic alignment
  517. if (align === null) {
  518. if (axis.isCircular) {
  519. if (this.label.getBBox().width > axis.len * axis.tickInterval / (axis.max - axis.min)) { // #3506
  520. centerSlot = 0;
  521. }
  522. if (angle > centerSlot && angle < 180 - centerSlot) {
  523. align = 'left'; // right hemisphere
  524. } else if (angle > 180 + centerSlot && angle < 360 - centerSlot) {
  525. align = 'right'; // left hemisphere
  526. } else {
  527. align = 'center'; // top or bottom
  528. }
  529. } else {
  530. align = 'center';
  531. }
  532. label.attr({
  533. align: align
  534. });
  535. }
  536. ret.x += labelOptions.x;
  537. ret.y += optionsY;
  538. } else {
  539. ret = proceed.call(this, x, y, label, horiz, labelOptions, tickmarkOffset, index, step);
  540. }
  541. return ret;
  542. });
  543. /**
  544. * Wrap the getMarkPath function to return the path of the radial marker
  545. */
  546. wrap(tickProto, 'getMarkPath', function (proceed, x, y, tickLength, tickWidth, horiz, renderer) {
  547. var axis = this.axis,
  548. endPoint,
  549. ret;
  550. if (axis.isRadial) {
  551. endPoint = axis.getPosition(this.pos, axis.center[2] / 2 + tickLength);
  552. ret = [
  553. 'M',
  554. x,
  555. y,
  556. 'L',
  557. endPoint.x,
  558. endPoint.y
  559. ];
  560. } else {
  561. ret = proceed.call(this, x, y, tickLength, tickWidth, horiz, renderer);
  562. }
  563. return ret;
  564. });/*
  565. * The AreaRangeSeries class
  566. *
  567. */
  568. /**
  569. * Extend the default options with map options
  570. */
  571. defaultPlotOptions.arearange = merge(defaultPlotOptions.area, {
  572. lineWidth: 1,
  573. marker: null,
  574. threshold: null,
  575. tooltip: {
  576. pointFormat: '<span style="color:{series.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>'
  577. },
  578. trackByArea: true,
  579. dataLabels: {
  580. align: null,
  581. verticalAlign: null,
  582. xLow: 0,
  583. xHigh: 0,
  584. yLow: 0,
  585. yHigh: 0
  586. },
  587. states: {
  588. hover: {
  589. halo: false
  590. }
  591. }
  592. });
  593. /**
  594. * Add the series type
  595. */
  596. seriesTypes.arearange = extendClass(seriesTypes.area, {
  597. type: 'arearange',
  598. pointArrayMap: ['low', 'high'],
  599. toYData: function (point) {
  600. return [point.low, point.high];
  601. },
  602. pointValKey: 'low',
  603. deferTranslatePolar: true,
  604. /**
  605. * Translate a point's plotHigh from the internal angle and radius measures to
  606. * true plotHigh coordinates. This is an addition of the toXY method found in
  607. * Polar.js, because it runs too early for arearanges to be considered (#3419).
  608. */
  609. highToXY: function (point) {
  610. // Find the polar plotX and plotY
  611. var chart = this.chart,
  612. xy = this.xAxis.postTranslate(point.rectPlotX, this.yAxis.len - point.plotHigh);
  613. point.plotHighX = xy.x - chart.plotLeft;
  614. point.plotHigh = xy.y - chart.plotTop;
  615. },
  616. /**
  617. * Extend getSegments to force null points if the higher value is null. #1703.
  618. */
  619. getSegments: function () {
  620. var series = this;
  621. each(series.points, function (point) {
  622. if (!series.options.connectNulls && (point.low === null || point.high === null)) {
  623. point.y = null;
  624. } else if (point.low === null && point.high !== null) {
  625. point.y = point.high;
  626. }
  627. });
  628. Series.prototype.getSegments.call(this);
  629. },
  630. /**
  631. * Translate data points from raw values x and y to plotX and plotY
  632. */
  633. translate: function () {
  634. var series = this,
  635. yAxis = series.yAxis;
  636. seriesTypes.area.prototype.translate.apply(series);
  637. // Set plotLow and plotHigh
  638. each(series.points, function (point) {
  639. var low = point.low,
  640. high = point.high,
  641. plotY = point.plotY;
  642. if (high === null && low === null) {
  643. point.y = null;
  644. } else if (low === null) {
  645. point.plotLow = point.plotY = null;
  646. point.plotHigh = yAxis.translate(high, 0, 1, 0, 1);
  647. } else if (high === null) {
  648. point.plotLow = plotY;
  649. point.plotHigh = null;
  650. } else {
  651. point.plotLow = plotY;
  652. point.plotHigh = yAxis.translate(high, 0, 1, 0, 1);
  653. }
  654. });
  655. // Postprocess plotHigh
  656. if (this.chart.polar) {
  657. each(this.points, function (point) {
  658. series.highToXY(point);
  659. });
  660. }
  661. },
  662. /**
  663. * Extend the line series' getSegmentPath method by applying the segment
  664. * path to both lower and higher values of the range
  665. */
  666. getSegmentPath: function (segment) {
  667. var lowSegment,
  668. highSegment = [],
  669. i = segment.length,
  670. baseGetSegmentPath = Series.prototype.getSegmentPath,
  671. point,
  672. linePath,
  673. lowerPath,
  674. options = this.options,
  675. step = options.step,
  676. higherPath;
  677. // Remove nulls from low segment
  678. lowSegment = HighchartsAdapter.grep(segment, function (point) {
  679. return point.plotLow !== null;
  680. });
  681. // Make a segment with plotX and plotY for the top values
  682. while (i--) {
  683. point = segment[i];
  684. if (point.plotHigh !== null) {
  685. highSegment.push({
  686. plotX: point.plotHighX || point.plotX, // plotHighX is for polar charts
  687. plotY: point.plotHigh
  688. });
  689. }
  690. }
  691. // Get the paths
  692. lowerPath = baseGetSegmentPath.call(this, lowSegment);
  693. if (step) {
  694. if (step === true) {
  695. step = 'left';
  696. }
  697. options.step = { left: 'right', center: 'center', right: 'left' }[step]; // swap for reading in getSegmentPath
  698. }
  699. higherPath = baseGetSegmentPath.call(this, highSegment);
  700. options.step = step;
  701. // Create a line on both top and bottom of the range
  702. linePath = [].concat(lowerPath, higherPath);
  703. // For the area path, we need to change the 'move' statement into 'lineTo' or 'curveTo'
  704. if (!this.chart.polar) {
  705. higherPath[0] = 'L'; // this probably doesn't work for spline
  706. }
  707. this.areaPath = this.areaPath.concat(lowerPath, higherPath);
  708. return linePath;
  709. },
  710. /**
  711. * Extend the basic drawDataLabels method by running it for both lower and higher
  712. * values.
  713. */
  714. drawDataLabels: function () {
  715. var data = this.data,
  716. length = data.length,
  717. i,
  718. originalDataLabels = [],
  719. seriesProto = Series.prototype,
  720. dataLabelOptions = this.options.dataLabels,
  721. align = dataLabelOptions.align,
  722. point,
  723. inverted = this.chart.inverted;
  724. if (dataLabelOptions.enabled || this._hasPointLabels) {
  725. // Step 1: set preliminary values for plotY and dataLabel and draw the upper labels
  726. i = length;
  727. while (i--) {
  728. point = data[i];
  729. // Set preliminary values
  730. point.y = point.high;
  731. point._plotY = point.plotY;
  732. point.plotY = point.plotHigh;
  733. // Store original data labels and set preliminary label objects to be picked up
  734. // in the uber method
  735. originalDataLabels[i] = point.dataLabel;
  736. point.dataLabel = point.dataLabelUpper;
  737. // Set the default offset
  738. point.below = false;
  739. if (inverted) {
  740. if (!align) {
  741. dataLabelOptions.align = 'left';
  742. }
  743. dataLabelOptions.x = dataLabelOptions.xHigh;
  744. } else {
  745. dataLabelOptions.y = dataLabelOptions.yHigh;
  746. }
  747. }
  748. if (seriesProto.drawDataLabels) {
  749. seriesProto.drawDataLabels.apply(this, arguments); // #1209
  750. }
  751. // Step 2: reorganize and handle data labels for the lower values
  752. i = length;
  753. while (i--) {
  754. point = data[i];
  755. // Move the generated labels from step 1, and reassign the original data labels
  756. point.dataLabelUpper = point.dataLabel;
  757. point.dataLabel = originalDataLabels[i];
  758. // Reset values
  759. point.y = point.low;
  760. point.plotY = point._plotY;
  761. // Set the default offset
  762. point.below = true;
  763. if (inverted) {
  764. if (!align) {
  765. dataLabelOptions.align = 'right';
  766. }
  767. dataLabelOptions.x = dataLabelOptions.xLow;
  768. } else {
  769. dataLabelOptions.y = dataLabelOptions.yLow;
  770. }
  771. }
  772. if (seriesProto.drawDataLabels) {
  773. seriesProto.drawDataLabels.apply(this, arguments);
  774. }
  775. }
  776. dataLabelOptions.align = align;
  777. },
  778. alignDataLabel: function () {
  779. seriesTypes.column.prototype.alignDataLabel.apply(this, arguments);
  780. },
  781. setStackedPoints: noop,
  782. getSymbol: noop,
  783. drawPoints: noop
  784. });/**
  785. * The AreaSplineRangeSeries class
  786. */
  787. defaultPlotOptions.areasplinerange = merge(defaultPlotOptions.arearange);
  788. /**
  789. * AreaSplineRangeSeries object
  790. */
  791. seriesTypes.areasplinerange = extendClass(seriesTypes.arearange, {
  792. type: 'areasplinerange',
  793. getPointSpline: seriesTypes.spline.prototype.getPointSpline
  794. });
  795. (function () {
  796. var colProto = seriesTypes.column.prototype;
  797. /**
  798. * The ColumnRangeSeries class
  799. */
  800. defaultPlotOptions.columnrange = merge(defaultPlotOptions.column, defaultPlotOptions.arearange, {
  801. lineWidth: 1,
  802. pointRange: null
  803. });
  804. /**
  805. * ColumnRangeSeries object
  806. */
  807. seriesTypes.columnrange = extendClass(seriesTypes.arearange, {
  808. type: 'columnrange',
  809. /**
  810. * Translate data points from raw values x and y to plotX and plotY
  811. */
  812. translate: function () {
  813. var series = this,
  814. yAxis = series.yAxis,
  815. plotHigh;
  816. colProto.translate.apply(series);
  817. // Set plotLow and plotHigh
  818. each(series.points, function (point) {
  819. var shapeArgs = point.shapeArgs,
  820. minPointLength = series.options.minPointLength,
  821. heightDifference,
  822. height,
  823. y;
  824. point.tooltipPos = null; // don't inherit from column
  825. point.plotHigh = plotHigh = yAxis.translate(point.high, 0, 1, 0, 1);
  826. point.plotLow = point.plotY;
  827. // adjust shape
  828. y = plotHigh;
  829. height = point.plotY - plotHigh;
  830. if (height < minPointLength) {
  831. heightDifference = (minPointLength - height);
  832. height += heightDifference;
  833. y -= heightDifference / 2;
  834. }
  835. shapeArgs.height = height;
  836. shapeArgs.y = y;
  837. });
  838. },
  839. directTouch: true,
  840. trackerGroups: ['group', 'dataLabelsGroup'],
  841. drawGraph: noop,
  842. pointAttrToOptions: colProto.pointAttrToOptions,
  843. drawPoints: colProto.drawPoints,
  844. drawTracker: colProto.drawTracker,
  845. animate: colProto.animate,
  846. getColumnMetrics: colProto.getColumnMetrics
  847. });
  848. }());
  849. /*
  850. * The GaugeSeries class
  851. */
  852. /**
  853. * Extend the default options
  854. */
  855. defaultPlotOptions.gauge = merge(defaultPlotOptions.line, {
  856. dataLabels: {
  857. enabled: true,
  858. defer: false,
  859. y: 15,
  860. borderWidth: 1,
  861. borderColor: 'silver',
  862. borderRadius: 3,
  863. crop: false,
  864. verticalAlign: 'top',
  865. zIndex: 2
  866. },
  867. dial: {
  868. // radius: '80%',
  869. // backgroundColor: 'black',
  870. // borderColor: 'silver',
  871. // borderWidth: 0,
  872. // baseWidth: 3,
  873. // topWidth: 1,
  874. // baseLength: '70%' // of radius
  875. // rearLength: '10%'
  876. },
  877. pivot: {
  878. //radius: 5,
  879. //borderWidth: 0
  880. //borderColor: 'silver',
  881. //backgroundColor: 'black'
  882. },
  883. tooltip: {
  884. headerFormat: ''
  885. },
  886. showInLegend: false
  887. });
  888. /**
  889. * Extend the point object
  890. */
  891. var GaugePoint = extendClass(Point, {
  892. /**
  893. * Don't do any hover colors or anything
  894. */
  895. setState: function (state) {
  896. this.state = state;
  897. }
  898. });
  899. /**
  900. * Add the series type
  901. */
  902. var GaugeSeries = {
  903. type: 'gauge',
  904. pointClass: GaugePoint,
  905. // chart.angular will be set to true when a gauge series is present, and this will
  906. // be used on the axes
  907. angular: true,
  908. drawGraph: noop,
  909. fixedBox: true,
  910. forceDL: true,
  911. trackerGroups: ['group', 'dataLabelsGroup'],
  912. /**
  913. * Calculate paths etc
  914. */
  915. translate: function () {
  916. var series = this,
  917. yAxis = series.yAxis,
  918. options = series.options,
  919. center = yAxis.center;
  920. series.generatePoints();
  921. each(series.points, function (point) {
  922. var dialOptions = merge(options.dial, point.dial),
  923. radius = (pInt(pick(dialOptions.radius, 80)) * center[2]) / 200,
  924. baseLength = (pInt(pick(dialOptions.baseLength, 70)) * radius) / 100,
  925. rearLength = (pInt(pick(dialOptions.rearLength, 10)) * radius) / 100,
  926. baseWidth = dialOptions.baseWidth || 3,
  927. topWidth = dialOptions.topWidth || 1,
  928. overshoot = options.overshoot,
  929. rotation = yAxis.startAngleRad + yAxis.translate(point.y, null, null, null, true);
  930. // Handle the wrap and overshoot options
  931. if (overshoot && typeof overshoot === 'number') {
  932. overshoot = overshoot / 180 * Math.PI;
  933. rotation = Math.max(yAxis.startAngleRad - overshoot, Math.min(yAxis.endAngleRad + overshoot, rotation));
  934. } else if (options.wrap === false) {
  935. rotation = Math.max(yAxis.startAngleRad, Math.min(yAxis.endAngleRad, rotation));
  936. }
  937. rotation = rotation * 180 / Math.PI;
  938. point.shapeType = 'path';
  939. point.shapeArgs = {
  940. d: dialOptions.path || [
  941. 'M',
  942. -rearLength, -baseWidth / 2,
  943. 'L',
  944. baseLength, -baseWidth / 2,
  945. radius, -topWidth / 2,
  946. radius, topWidth / 2,
  947. baseLength, baseWidth / 2,
  948. -rearLength, baseWidth / 2,
  949. 'z'
  950. ],
  951. translateX: center[0],
  952. translateY: center[1],
  953. rotation: rotation
  954. };
  955. // Positions for data label
  956. point.plotX = center[0];
  957. point.plotY = center[1];
  958. });
  959. },
  960. /**
  961. * Draw the points where each point is one needle
  962. */
  963. drawPoints: function () {
  964. var series = this,
  965. center = series.yAxis.center,
  966. pivot = series.pivot,
  967. options = series.options,
  968. pivotOptions = options.pivot,
  969. renderer = series.chart.renderer;
  970. each(series.points, function (point) {
  971. var graphic = point.graphic,
  972. shapeArgs = point.shapeArgs,
  973. d = shapeArgs.d,
  974. dialOptions = merge(options.dial, point.dial); // #1233
  975. if (graphic) {
  976. graphic.animate(shapeArgs);
  977. shapeArgs.d = d; // animate alters it
  978. } else {
  979. point.graphic = renderer[point.shapeType](shapeArgs)
  980. .attr({
  981. stroke: dialOptions.borderColor || 'none',
  982. 'stroke-width': dialOptions.borderWidth || 0,
  983. fill: dialOptions.backgroundColor || 'black',
  984. rotation: shapeArgs.rotation // required by VML when animation is false
  985. })
  986. .add(series.group);
  987. }
  988. });
  989. // Add or move the pivot
  990. if (pivot) {
  991. pivot.animate({ // #1235
  992. translateX: center[0],
  993. translateY: center[1]
  994. });
  995. } else {
  996. series.pivot = renderer.circle(0, 0, pick(pivotOptions.radius, 5))
  997. .attr({
  998. 'stroke-width': pivotOptions.borderWidth || 0,
  999. stroke: pivotOptions.borderColor || 'silver',
  1000. fill: pivotOptions.backgroundColor || 'black'
  1001. })
  1002. .translate(center[0], center[1])
  1003. .add(series.group);
  1004. }
  1005. },
  1006. /**
  1007. * Animate the arrow up from startAngle
  1008. */
  1009. animate: function (init) {
  1010. var series = this;
  1011. if (!init) {
  1012. each(series.points, function (point) {
  1013. var graphic = point.graphic;
  1014. if (graphic) {
  1015. // start value
  1016. graphic.attr({
  1017. rotation: series.yAxis.startAngleRad * 180 / Math.PI
  1018. });
  1019. // animate
  1020. graphic.animate({
  1021. rotation: point.shapeArgs.rotation
  1022. }, series.options.animation);
  1023. }
  1024. });
  1025. // delete this function to allow it only once
  1026. series.animate = null;
  1027. }
  1028. },
  1029. render: function () {
  1030. this.group = this.plotGroup(
  1031. 'group',
  1032. 'series',
  1033. this.visible ? 'visible' : 'hidden',
  1034. this.options.zIndex,
  1035. this.chart.seriesGroup
  1036. );
  1037. Series.prototype.render.call(this);
  1038. this.group.clip(this.chart.clipRect);
  1039. },
  1040. /**
  1041. * Extend the basic setData method by running processData and generatePoints immediately,
  1042. * in order to access the points from the legend.
  1043. */
  1044. setData: function (data, redraw) {
  1045. Series.prototype.setData.call(this, data, false);
  1046. this.processData();
  1047. this.generatePoints();
  1048. if (pick(redraw, true)) {
  1049. this.chart.redraw();
  1050. }
  1051. },
  1052. /**
  1053. * If the tracking module is loaded, add the point tracker
  1054. */
  1055. drawTracker: TrackerMixin && TrackerMixin.drawTrackerPoint
  1056. };
  1057. seriesTypes.gauge = extendClass(seriesTypes.line, GaugeSeries);
  1058. /* ****************************************************************************
  1059. * Start Box plot series code *
  1060. *****************************************************************************/
  1061. // Set default options
  1062. defaultPlotOptions.boxplot = merge(defaultPlotOptions.column, {
  1063. fillColor: '#FFFFFF',
  1064. lineWidth: 1,
  1065. //medianColor: null,
  1066. medianWidth: 2,
  1067. states: {
  1068. hover: {
  1069. brightness: -0.3
  1070. }
  1071. },
  1072. //stemColor: null,
  1073. //stemDashStyle: 'solid'
  1074. //stemWidth: null,
  1075. threshold: null,
  1076. tooltip: {
  1077. pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {series.name}</b><br/>' + // docs
  1078. 'Maximum: {point.high}<br/>' +
  1079. 'Upper quartile: {point.q3}<br/>' +
  1080. 'Median: {point.median}<br/>' +
  1081. 'Lower quartile: {point.q1}<br/>' +
  1082. 'Minimum: {point.low}<br/>'
  1083. },
  1084. //whiskerColor: null,
  1085. whiskerLength: '50%',
  1086. whiskerWidth: 2
  1087. });
  1088. // Create the series object
  1089. seriesTypes.boxplot = extendClass(seriesTypes.column, {
  1090. type: 'boxplot',
  1091. pointArrayMap: ['low', 'q1', 'median', 'q3', 'high'], // array point configs are mapped to this
  1092. toYData: function (point) { // return a plain array for speedy calculation
  1093. return [point.low, point.q1, point.median, point.q3, point.high];
  1094. },
  1095. pointValKey: 'high', // defines the top of the tracker
  1096. /**
  1097. * One-to-one mapping from options to SVG attributes
  1098. */
  1099. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  1100. fill: 'fillColor',
  1101. stroke: 'color',
  1102. 'stroke-width': 'lineWidth'
  1103. },
  1104. /**
  1105. * Disable data labels for box plot
  1106. */
  1107. drawDataLabels: noop,
  1108. /**
  1109. * Translate data points from raw values x and y to plotX and plotY
  1110. */
  1111. translate: function () {
  1112. var series = this,
  1113. yAxis = series.yAxis,
  1114. pointArrayMap = series.pointArrayMap;
  1115. seriesTypes.column.prototype.translate.apply(series);
  1116. // do the translation on each point dimension
  1117. each(series.points, function (point) {
  1118. each(pointArrayMap, function (key) {
  1119. if (point[key] !== null) {
  1120. point[key + 'Plot'] = yAxis.translate(point[key], 0, 1, 0, 1);
  1121. }
  1122. });
  1123. });
  1124. },
  1125. /**
  1126. * Draw the data points
  1127. */
  1128. drawPoints: function () {
  1129. var series = this, //state = series.state,
  1130. points = series.points,
  1131. options = series.options,
  1132. chart = series.chart,
  1133. renderer = chart.renderer,
  1134. pointAttr,
  1135. q1Plot,
  1136. q3Plot,
  1137. highPlot,
  1138. lowPlot,
  1139. medianPlot,
  1140. crispCorr,
  1141. crispX,
  1142. graphic,
  1143. stemPath,
  1144. stemAttr,
  1145. boxPath,
  1146. whiskersPath,
  1147. whiskersAttr,
  1148. medianPath,
  1149. medianAttr,
  1150. width,
  1151. left,
  1152. right,
  1153. halfWidth,
  1154. shapeArgs,
  1155. color,
  1156. doQuartiles = series.doQuartiles !== false, // error bar inherits this series type but doesn't do quartiles
  1157. whiskerLength = parseInt(series.options.whiskerLength, 10) / 100;
  1158. each(points, function (point) {
  1159. graphic = point.graphic;
  1160. shapeArgs = point.shapeArgs; // the box
  1161. stemAttr = {};
  1162. whiskersAttr = {};
  1163. medianAttr = {};
  1164. color = point.color || series.color;
  1165. if (point.plotY !== UNDEFINED) {
  1166. pointAttr = point.pointAttr[point.selected ? 'selected' : ''];
  1167. // crisp vector coordinates
  1168. width = shapeArgs.width;
  1169. left = mathFloor(shapeArgs.x);
  1170. right = left + width;
  1171. halfWidth = mathRound(width / 2);
  1172. //crispX = mathRound(left + halfWidth) + crispCorr;
  1173. q1Plot = mathFloor(doQuartiles ? point.q1Plot : point.lowPlot);// + crispCorr;
  1174. q3Plot = mathFloor(doQuartiles ? point.q3Plot : point.lowPlot);// + crispCorr;
  1175. highPlot = mathFloor(point.highPlot);// + crispCorr;
  1176. lowPlot = mathFloor(point.lowPlot);// + crispCorr;
  1177. // Stem attributes
  1178. stemAttr.stroke = point.stemColor || options.stemColor || color;
  1179. stemAttr['stroke-width'] = pick(point.stemWidth, options.stemWidth, options.lineWidth);
  1180. stemAttr.dashstyle = point.stemDashStyle || options.stemDashStyle;
  1181. // Whiskers attributes
  1182. whiskersAttr.stroke = point.whiskerColor || options.whiskerColor || color;
  1183. whiskersAttr['stroke-width'] = pick(point.whiskerWidth, options.whiskerWidth, options.lineWidth);
  1184. // Median attributes
  1185. medianAttr.stroke = point.medianColor || options.medianColor || color;
  1186. medianAttr['stroke-width'] = pick(point.medianWidth, options.medianWidth, options.lineWidth);
  1187. // The stem
  1188. crispCorr = (stemAttr['stroke-width'] % 2) / 2;
  1189. crispX = left + halfWidth + crispCorr;
  1190. stemPath = [
  1191. // stem up
  1192. 'M',
  1193. crispX, q3Plot,
  1194. 'L',
  1195. crispX, highPlot,
  1196. // stem down
  1197. 'M',
  1198. crispX, q1Plot,
  1199. 'L',
  1200. crispX, lowPlot
  1201. ];
  1202. // The box
  1203. if (doQuartiles) {
  1204. crispCorr = (pointAttr['stroke-width'] % 2) / 2;
  1205. crispX = mathFloor(crispX) + crispCorr;
  1206. q1Plot = mathFloor(q1Plot) + crispCorr;
  1207. q3Plot = mathFloor(q3Plot) + crispCorr;
  1208. left += crispCorr;
  1209. right += crispCorr;
  1210. boxPath = [
  1211. 'M',
  1212. left, q3Plot,
  1213. 'L',
  1214. left, q1Plot,
  1215. 'L',
  1216. right, q1Plot,
  1217. 'L',
  1218. right, q3Plot,
  1219. 'L',
  1220. left, q3Plot,
  1221. 'z'
  1222. ];
  1223. }
  1224. // The whiskers
  1225. if (whiskerLength) {
  1226. crispCorr = (whiskersAttr['stroke-width'] % 2) / 2;
  1227. highPlot = highPlot + crispCorr;
  1228. lowPlot = lowPlot + crispCorr;
  1229. whiskersPath = [
  1230. // High whisker
  1231. 'M',
  1232. crispX - halfWidth * whiskerLength,
  1233. highPlot,
  1234. 'L',
  1235. crispX + halfWidth * whiskerLength,
  1236. highPlot,
  1237. // Low whisker
  1238. 'M',
  1239. crispX - halfWidth * whiskerLength,
  1240. lowPlot,
  1241. 'L',
  1242. crispX + halfWidth * whiskerLength,
  1243. lowPlot
  1244. ];
  1245. }
  1246. // The median
  1247. crispCorr = (medianAttr['stroke-width'] % 2) / 2;
  1248. medianPlot = mathRound(point.medianPlot) + crispCorr;
  1249. medianPath = [
  1250. 'M',
  1251. left,
  1252. medianPlot,
  1253. 'L',
  1254. right,
  1255. medianPlot
  1256. ];
  1257. // Create or update the graphics
  1258. if (graphic) { // update
  1259. point.stem.animate({ d: stemPath });
  1260. if (whiskerLength) {
  1261. point.whiskers.animate({ d: whiskersPath });
  1262. }
  1263. if (doQuartiles) {
  1264. point.box.animate({ d: boxPath });
  1265. }
  1266. point.medianShape.animate({ d: medianPath });
  1267. } else { // create new
  1268. point.graphic = graphic = renderer.g()
  1269. .add(series.group);
  1270. point.stem = renderer.path(stemPath)
  1271. .attr(stemAttr)
  1272. .add(graphic);
  1273. if (whiskerLength) {
  1274. point.whiskers = renderer.path(whiskersPath)
  1275. .attr(whiskersAttr)
  1276. .add(graphic);
  1277. }
  1278. if (doQuartiles) {
  1279. point.box = renderer.path(boxPath)
  1280. .attr(pointAttr)
  1281. .add(graphic);
  1282. }
  1283. point.medianShape = renderer.path(medianPath)
  1284. .attr(medianAttr)
  1285. .add(graphic);
  1286. }
  1287. }
  1288. });
  1289. },
  1290. setStackedPoints: noop // #3890
  1291. });
  1292. /* ****************************************************************************
  1293. * End Box plot series code *
  1294. *****************************************************************************/
  1295. /* ****************************************************************************
  1296. * Start error bar series code *
  1297. *****************************************************************************/
  1298. // 1 - set default options
  1299. defaultPlotOptions.errorbar = merge(defaultPlotOptions.boxplot, {
  1300. color: '#000000',
  1301. grouping: false,
  1302. linkedTo: ':previous',
  1303. tooltip: {
  1304. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>' // docs
  1305. },
  1306. whiskerWidth: null
  1307. });
  1308. // 2 - Create the series object
  1309. seriesTypes.errorbar = extendClass(seriesTypes.boxplot, {
  1310. type: 'errorbar',
  1311. pointArrayMap: ['low', 'high'], // array point configs are mapped to this
  1312. toYData: function (point) { // return a plain array for speedy calculation
  1313. return [point.low, point.high];
  1314. },
  1315. pointValKey: 'high', // defines the top of the tracker
  1316. doQuartiles: false,
  1317. drawDataLabels: seriesTypes.arearange ? seriesTypes.arearange.prototype.drawDataLabels : noop,
  1318. /**
  1319. * Get the width and X offset, either on top of the linked series column
  1320. * or standalone
  1321. */
  1322. getColumnMetrics: function () {
  1323. return (this.linkedParent && this.linkedParent.columnMetrics) ||
  1324. seriesTypes.column.prototype.getColumnMetrics.call(this);
  1325. }
  1326. });
  1327. /* ****************************************************************************
  1328. * End error bar series code *
  1329. *****************************************************************************/
  1330. /* ****************************************************************************
  1331. * Start Waterfall series code *
  1332. *****************************************************************************/
  1333. // 1 - set default options
  1334. defaultPlotOptions.waterfall = merge(defaultPlotOptions.column, {
  1335. lineWidth: 1,
  1336. lineColor: '#333',
  1337. dashStyle: 'dot',
  1338. borderColor: '#333',
  1339. dataLabels: {
  1340. inside: true
  1341. },
  1342. states: {
  1343. hover: {
  1344. lineWidthPlus: 0 // #3126
  1345. }
  1346. }
  1347. });
  1348. // 2 - Create the series object
  1349. seriesTypes.waterfall = extendClass(seriesTypes.column, {
  1350. type: 'waterfall',
  1351. upColorProp: 'fill',
  1352. pointValKey: 'y',
  1353. /**
  1354. * Translate data points from raw values
  1355. */
  1356. translate: function () {
  1357. var series = this,
  1358. options = series.options,
  1359. yAxis = series.yAxis,
  1360. len,
  1361. i,
  1362. points,
  1363. point,
  1364. shapeArgs,
  1365. stack,
  1366. y,
  1367. yValue,
  1368. previousY,
  1369. previousIntermediate,
  1370. range,
  1371. threshold = options.threshold,
  1372. stacking = options.stacking,
  1373. tooltipY;
  1374. // run column series translate
  1375. seriesTypes.column.prototype.translate.apply(this);
  1376. previousY = previousIntermediate = threshold;
  1377. points = series.points;
  1378. for (i = 0, len = points.length; i < len; i++) {
  1379. // cache current point object
  1380. point = points[i];
  1381. yValue = this.processedYData[i];
  1382. shapeArgs = point.shapeArgs;
  1383. // get current stack
  1384. stack = stacking && yAxis.stacks[(series.negStacks && yValue < threshold ? '-' : '') + series.stackKey];
  1385. range = stack ?
  1386. stack[point.x].points[series.index + ',' + i] :
  1387. [0, yValue];
  1388. // override point value for sums
  1389. // #3710 Update point does not propagate to sum
  1390. if (point.isSum) {
  1391. point.y = yValue;
  1392. } else if (point.isIntermediateSum) {
  1393. point.y = yValue - previousIntermediate; // #3840
  1394. }
  1395. // up points
  1396. y = mathMax(previousY, previousY + point.y) + range[0];
  1397. shapeArgs.y = yAxis.translate(y, 0, 1);
  1398. // sum points
  1399. if (point.isSum) {
  1400. shapeArgs.y = yAxis.translate(range[1], 0, 1);
  1401. shapeArgs.height = yAxis.translate(range[0], 0, 1) - shapeArgs.y;
  1402. } else if (point.isIntermediateSum) {
  1403. shapeArgs.y = yAxis.translate(range[1], 0, 1);
  1404. shapeArgs.height = yAxis.translate(previousIntermediate, 0, 1) - shapeArgs.y;
  1405. previousIntermediate = range[1];
  1406. // If it's not the sum point, update previous stack end position and get
  1407. // shape height (#3886)
  1408. } else {
  1409. if (previousY !== 0) { // Not the first point
  1410. shapeArgs.height = yValue > 0 ?
  1411. yAxis.translate(previousY, 0, 1) - shapeArgs.y :
  1412. yAxis.translate(previousY, 0, 1) - yAxis.translate(previousY - yValue, 0, 1);
  1413. }
  1414. previousY += yValue;
  1415. }
  1416. // #3952 Negative sum or intermediate sum not rendered correctly
  1417. if (shapeArgs.height < 0) {
  1418. shapeArgs.y += shapeArgs.height;
  1419. shapeArgs.height *= -1;
  1420. }
  1421. point.plotY = shapeArgs.y = mathRound(shapeArgs.y) - (series.borderWidth % 2) / 2;
  1422. shapeArgs.height = mathMax(mathRound(shapeArgs.height), 0.001); // #3151
  1423. point.yBottom = shapeArgs.y + shapeArgs.height;
  1424. // Correct tooltip placement (#3014)
  1425. tooltipY = point.plotY + (point.negative ? shapeArgs.height : 0);
  1426. if (series.chart.inverted) {
  1427. point.tooltipPos[0] = yAxis.len - tooltipY;
  1428. } else {
  1429. point.tooltipPos[1] = tooltipY;
  1430. }
  1431. }
  1432. },
  1433. /**
  1434. * Call default processData then override yData to reflect waterfall's extremes on yAxis
  1435. */
  1436. processData: function (force) {
  1437. var series = this,
  1438. options = series.options,
  1439. yData = series.yData,
  1440. points = series.options.data, // #3710 Update point does not propagate to sum
  1441. point,
  1442. dataLength = yData.length,
  1443. threshold = options.threshold || 0,
  1444. subSum,
  1445. sum,
  1446. dataMin,
  1447. dataMax,
  1448. y,
  1449. i;
  1450. sum = subSum = dataMin = dataMax = threshold;
  1451. for (i = 0; i < dataLength; i++) {
  1452. y = yData[i];
  1453. point = points && points[i] ? points[i] : {};
  1454. if (y === "sum" || point.isSum) {
  1455. yData[i] = sum;
  1456. } else if (y === "intermediateSum" || point.isIntermediateSum) {
  1457. yData[i] = subSum;
  1458. } else {
  1459. sum += y;
  1460. subSum += y;
  1461. }
  1462. dataMin = Math.min(sum, dataMin);
  1463. dataMax = Math.max(sum, dataMax);
  1464. }
  1465. Series.prototype.processData.call(this, force);
  1466. // Record extremes
  1467. series.dataMin = dataMin;
  1468. series.dataMax = dataMax;
  1469. },
  1470. /**
  1471. * Return y value or string if point is sum
  1472. */
  1473. toYData: function (pt) {
  1474. if (pt.isSum) {
  1475. return (pt.x === 0 ? null : "sum"); //#3245 Error when first element is Sum or Intermediate Sum
  1476. } else if (pt.isIntermediateSum) {
  1477. return (pt.x === 0 ? null : "intermediateSum"); //#3245
  1478. }
  1479. return pt.y;
  1480. },
  1481. /**
  1482. * Postprocess mapping between options and SVG attributes
  1483. */
  1484. getAttribs: function () {
  1485. seriesTypes.column.prototype.getAttribs.apply(this, arguments);
  1486. var series = this,
  1487. options = series.options,
  1488. stateOptions = options.states,
  1489. upColor = options.upColor || series.color,
  1490. hoverColor = Highcharts.Color(upColor).brighten(0.1).get(),
  1491. seriesDownPointAttr = merge(series.pointAttr),
  1492. upColorProp = series.upColorProp;
  1493. seriesDownPointAttr[''][upColorProp] = upColor;
  1494. seriesDownPointAttr.hover[upColorProp] = stateOptions.hover.upColor || hoverColor;
  1495. seriesDownPointAttr.select[upColorProp] = stateOptions.select.upColor || upColor;
  1496. each(series.points, function (point) {
  1497. if (!point.options.color) {
  1498. // Up color
  1499. if (point.y > 0) {
  1500. point.pointAttr = seriesDownPointAttr;
  1501. point.color = upColor;
  1502. // Down color (#3710, update to negative)
  1503. } else {
  1504. point.pointAttr = series.pointAttr;
  1505. }
  1506. }
  1507. });
  1508. },
  1509. /**
  1510. * Draw columns' connector lines
  1511. */
  1512. getGraphPath: function () {
  1513. var data = this.data,
  1514. length = data.length,
  1515. lineWidth = this.options.lineWidth + this.borderWidth,
  1516. normalizer = mathRound(lineWidth) % 2 / 2,
  1517. path = [],
  1518. M = 'M',
  1519. L = 'L',
  1520. prevArgs,
  1521. pointArgs,
  1522. i,
  1523. d;
  1524. for (i = 1; i < length; i++) {
  1525. pointArgs = data[i].shapeArgs;
  1526. prevArgs = data[i - 1].shapeArgs;
  1527. d = [
  1528. M,
  1529. prevArgs.x + prevArgs.width, prevArgs.y + normalizer,
  1530. L,
  1531. pointArgs.x, prevArgs.y + normalizer
  1532. ];
  1533. if (data[i - 1].y < 0) {
  1534. d[2] += prevArgs.height;
  1535. d[5] += prevArgs.height;
  1536. }
  1537. path = path.concat(d);
  1538. }
  1539. return path;
  1540. },
  1541. /**
  1542. * Extremes are recorded in processData
  1543. */
  1544. getExtremes: noop,
  1545. drawGraph: Series.prototype.drawGraph
  1546. });
  1547. /* ****************************************************************************
  1548. * End Waterfall series code *
  1549. *****************************************************************************/
  1550. /**
  1551. * Set the default options for polygon
  1552. */
  1553. defaultPlotOptions.polygon = merge(defaultPlotOptions.scatter, {
  1554. marker: {
  1555. enabled: false
  1556. }
  1557. });
  1558. /**
  1559. * The polygon series class
  1560. */
  1561. seriesTypes.polygon = extendClass(seriesTypes.scatter, {
  1562. type: 'polygon',
  1563. fillGraph: true,
  1564. // Close all segments
  1565. getSegmentPath: function (segment) {
  1566. return Series.prototype.getSegmentPath.call(this, segment).concat('z');
  1567. },
  1568. drawGraph: Series.prototype.drawGraph,
  1569. drawLegendSymbol: Highcharts.LegendSymbolMixin.drawRectangle
  1570. });
  1571. /* ****************************************************************************
  1572. * Start Bubble series code *
  1573. *****************************************************************************/
  1574. // 1 - set default options
  1575. defaultPlotOptions.bubble = merge(defaultPlotOptions.scatter, {
  1576. dataLabels: {
  1577. formatter: function () { // #2945
  1578. return this.point.z;
  1579. },
  1580. inside: true,
  1581. verticalAlign: 'middle'
  1582. },
  1583. // displayNegative: true,
  1584. marker: {
  1585. // fillOpacity: 0.5,
  1586. lineColor: null, // inherit from series.color
  1587. lineWidth: 1
  1588. },
  1589. minSize: 8,
  1590. maxSize: '20%',
  1591. // negativeColor: null,
  1592. // sizeBy: 'area'
  1593. states: {
  1594. hover: {
  1595. halo: {
  1596. size: 5
  1597. }
  1598. }
  1599. },
  1600. tooltip: {
  1601. pointFormat: '({point.x}, {point.y}), Size: {point.z}'
  1602. },
  1603. turboThreshold: 0,
  1604. zThreshold: 0,
  1605. zoneAxis: 'z'
  1606. });
  1607. var BubblePoint = extendClass(Point, {
  1608. haloPath: function () {
  1609. return Point.prototype.haloPath.call(this, this.shapeArgs.r + this.series.options.states.hover.halo.size);
  1610. },
  1611. ttBelow: false
  1612. });
  1613. // 2 - Create the series object
  1614. seriesTypes.bubble = extendClass(seriesTypes.scatter, {
  1615. type: 'bubble',
  1616. pointClass: BubblePoint,
  1617. pointArrayMap: ['y', 'z'],
  1618. parallelArrays: ['x', 'y', 'z'],
  1619. trackerGroups: ['group', 'dataLabelsGroup'],
  1620. bubblePadding: true,
  1621. zoneAxis: 'z',
  1622. /**
  1623. * Mapping between SVG attributes and the corresponding options
  1624. */
  1625. pointAttrToOptions: {
  1626. stroke: 'lineColor',
  1627. 'stroke-width': 'lineWidth',
  1628. fill: 'fillColor'
  1629. },
  1630. /**
  1631. * Apply the fillOpacity to all fill positions
  1632. */
  1633. applyOpacity: function (fill) {
  1634. var markerOptions = this.options.marker,
  1635. fillOpacity = pick(markerOptions.fillOpacity, 0.5);
  1636. // When called from Legend.colorizeItem, the fill isn't predefined
  1637. fill = fill || markerOptions.fillColor || this.color;
  1638. if (fillOpacity !== 1) {
  1639. fill = Color(fill).setOpacity(fillOpacity).get('rgba');
  1640. }
  1641. return fill;
  1642. },
  1643. /**
  1644. * Extend the convertAttribs method by applying opacity to the fill
  1645. */
  1646. convertAttribs: function () {
  1647. var obj = Series.prototype.convertAttribs.apply(this, arguments);
  1648. obj.fill = this.applyOpacity(obj.fill);
  1649. return obj;
  1650. },
  1651. /**
  1652. * Get the radius for each point based on the minSize, maxSize and each point's Z value. This
  1653. * must be done prior to Series.translate because the axis needs to add padding in
  1654. * accordance with the point sizes.
  1655. */
  1656. getRadii: function (zMin, zMax, minSize, maxSize) {
  1657. var len,
  1658. i,
  1659. pos,
  1660. zData = this.zData,
  1661. radii = [],
  1662. sizeByArea = this.options.sizeBy !== 'width',
  1663. zRange;
  1664. // Set the shape type and arguments to be picked up in drawPoints
  1665. for (i = 0, len = zData.length; i < len; i++) {
  1666. zRange = zMax - zMin;
  1667. pos = zRange > 0 ? // relative size, a number between 0 and 1
  1668. (zData[i] - zMin) / (zMax - zMin) :
  1669. 0.5;
  1670. if (sizeByArea && pos >= 0) {
  1671. pos = Math.sqrt(pos);
  1672. }
  1673. radii.push(math.ceil(minSize + pos * (maxSize - minSize)) / 2);
  1674. }
  1675. this.radii = radii;
  1676. },
  1677. /**
  1678. * Perform animation on the bubbles
  1679. */
  1680. animate: function (init) {
  1681. var animation = this.options.animation;
  1682. if (!init) { // run the animation
  1683. each(this.points, function (point) {
  1684. var graphic = point.graphic,
  1685. shapeArgs = point.shapeArgs;
  1686. if (graphic && shapeArgs) {
  1687. // start values
  1688. graphic.attr('r', 1);
  1689. // animate
  1690. graphic.animate({
  1691. r: shapeArgs.r
  1692. }, animation);
  1693. }
  1694. });
  1695. // delete this function to allow it only once
  1696. this.animate = null;
  1697. }
  1698. },
  1699. /**
  1700. * Extend the base translate method to handle bubble size
  1701. */
  1702. translate: function () {
  1703. var i,
  1704. data = this.data,
  1705. point,
  1706. radius,
  1707. radii = this.radii;
  1708. // Run the parent method
  1709. seriesTypes.scatter.prototype.translate.call(this);
  1710. // Set the shape type and arguments to be picked up in drawPoints
  1711. i = data.length;
  1712. while (i--) {
  1713. point = data[i];
  1714. radius = radii ? radii[i] : 0; // #1737
  1715. if (radius >= this.minPxSize / 2) {
  1716. // Shape arguments
  1717. point.shapeType = 'circle';
  1718. point.shapeArgs = {
  1719. x: point.plotX,
  1720. y: point.plotY,
  1721. r: radius
  1722. };
  1723. // Alignment box for the data label
  1724. point.dlBox = {
  1725. x: point.plotX - radius,
  1726. y: point.plotY - radius,
  1727. width: 2 * radius,
  1728. height: 2 * radius
  1729. };
  1730. } else { // below zThreshold
  1731. point.shapeArgs = point.plotY = point.dlBox = UNDEFINED; // #1691
  1732. }
  1733. }
  1734. },
  1735. /**
  1736. * Get the series' symbol in the legend
  1737. *
  1738. * @param {Object} legend The legend object
  1739. * @param {Object} item The series (this) or point
  1740. */
  1741. drawLegendSymbol: function (legend, item) {
  1742. var radius = pInt(legend.itemStyle.fontSize) / 2;
  1743. item.legendSymbol = this.chart.renderer.circle(
  1744. radius,
  1745. legend.baseline - radius,
  1746. radius
  1747. ).attr({
  1748. zIndex: 3
  1749. }).add(item.legendGroup);
  1750. item.legendSymbol.isMarker = true;
  1751. },
  1752. drawPoints: seriesTypes.column.prototype.drawPoints,
  1753. alignDataLabel: seriesTypes.column.prototype.alignDataLabel,
  1754. buildKDTree: noop,
  1755. applyZones: noop
  1756. });
  1757. /**
  1758. * Add logic to pad each axis with the amount of pixels
  1759. * necessary to avoid the bubbles to overflow.
  1760. */
  1761. Axis.prototype.beforePadding = function () {
  1762. var axis = this,
  1763. axisLength = this.len,
  1764. chart = this.chart,
  1765. pxMin = 0,
  1766. pxMax = axisLength,
  1767. isXAxis = this.isXAxis,
  1768. dataKey = isXAxis ? 'xData' : 'yData',
  1769. min = this.min,
  1770. extremes = {},
  1771. smallestSize = math.min(chart.plotWidth, chart.plotHeight),
  1772. zMin = Number.MAX_VALUE,
  1773. zMax = -Number.MAX_VALUE,
  1774. range = this.max - min,
  1775. transA = axisLength / range,
  1776. activeSeries = [];
  1777. // Handle padding on the second pass, or on redraw
  1778. each(this.series, function (series) {
  1779. var seriesOptions = series.options,
  1780. zData;
  1781. if (series.bubblePadding && (series.visible || !chart.options.chart.ignoreHiddenSeries)) {
  1782. // Correction for #1673
  1783. axis.allowZoomOutside = true;
  1784. // Cache it
  1785. activeSeries.push(series);
  1786. if (isXAxis) { // because X axis is evaluated first
  1787. // For each series, translate the size extremes to pixel values
  1788. each(['minSize', 'maxSize'], function (prop) {
  1789. var length = seriesOptions[prop],
  1790. isPercent = /%$/.test(length);
  1791. length = pInt(length);
  1792. extremes[prop] = isPercent ?
  1793. smallestSize * length / 100 :
  1794. length;
  1795. });
  1796. series.minPxSize = extremes.minSize;
  1797. // Find the min and max Z
  1798. zData = series.zData;
  1799. if (zData.length) { // #1735
  1800. zMin = pick(seriesOptions.zMin, math.min(
  1801. zMin,
  1802. math.max(
  1803. arrayMin(zData),
  1804. seriesOptions.displayNegative === false ? seriesOptions.zThreshold : -Number.MAX_VALUE
  1805. )
  1806. ));
  1807. zMax = pick(seriesOptions.zMax, math.max(zMax, arrayMax(zData)));
  1808. }
  1809. }
  1810. }
  1811. });
  1812. each(activeSeries, function (series) {
  1813. var data = series[dataKey],
  1814. i = data.length,
  1815. radius;
  1816. if (isXAxis) {
  1817. series.getRadii(zMin, zMax, extremes.minSize, extremes.maxSize);
  1818. }
  1819. if (range > 0) {
  1820. while (i--) {
  1821. if (typeof data[i] === 'number') {
  1822. radius = series.radii[i];
  1823. pxMin = Math.min(((data[i] - min) * transA) - radius, pxMin);
  1824. pxMax = Math.max(((data[i] - min) * transA) + radius, pxMax);
  1825. }
  1826. }
  1827. }
  1828. });
  1829. if (activeSeries.length && range > 0 && pick(this.options.min, this.userMin) === UNDEFINED && pick(this.options.max, this.userMax) === UNDEFINED) {
  1830. pxMax -= axisLength;
  1831. transA *= (axisLength + pxMin - pxMax) / axisLength;
  1832. this.min += pxMin / transA;
  1833. this.max += pxMax / transA;
  1834. }
  1835. };
  1836. /* ****************************************************************************
  1837. * End Bubble series code *
  1838. *****************************************************************************/
  1839. (function () {
  1840. /**
  1841. * Extensions for polar charts. Additionally, much of the geometry required for polar charts is
  1842. * gathered in RadialAxes.js.
  1843. *
  1844. */
  1845. var seriesProto = Series.prototype,
  1846. pointerProto = Pointer.prototype,
  1847. colProto;
  1848. /**
  1849. * Search a k-d tree by the point angle, used for shared tooltips in polar charts
  1850. */
  1851. seriesProto.searchPointByAngle = function (e) {
  1852. var series = this,
  1853. chart = series.chart,
  1854. xAxis = series.xAxis,
  1855. center = xAxis.pane.center,
  1856. plotX = e.chartX - center[0] - chart.plotLeft,
  1857. plotY = e.chartY - center[1] - chart.plotTop;
  1858. return this.searchKDTree({
  1859. clientX: 180 + (Math.atan2(plotX, plotY) * (-180 / Math.PI))
  1860. });
  1861. };
  1862. /**
  1863. * Wrap the buildKDTree function so that it searches by angle (clientX) in case of shared tooltip,
  1864. * and by two dimensional distance in case of non-shared.
  1865. */
  1866. wrap(seriesProto, 'buildKDTree', function (proceed) {
  1867. if (this.chart.polar) {
  1868. if (this.kdByAngle) {
  1869. this.searchPoint = this.searchPointByAngle;
  1870. } else {
  1871. this.kdDimensions = 2;
  1872. this.kdComparer = 'distR';
  1873. }
  1874. }
  1875. proceed.apply(this);
  1876. });
  1877. /**
  1878. * Translate a point's plotX and plotY from the internal angle and radius measures to
  1879. * true plotX, plotY coordinates
  1880. */
  1881. seriesProto.toXY = function (point) {
  1882. var xy,
  1883. chart = this.chart,
  1884. plotX = point.plotX,
  1885. plotY = point.plotY,
  1886. clientX;
  1887. // Save rectangular plotX, plotY for later computation
  1888. point.rectPlotX = plotX;
  1889. point.rectPlotY = plotY;
  1890. // Find the polar plotX and plotY
  1891. xy = this.xAxis.postTranslate(point.plotX, this.yAxis.len - plotY);
  1892. point.plotX = point.polarPlotX = xy.x - chart.plotLeft;
  1893. point.plotY = point.polarPlotY = xy.y - chart.plotTop;
  1894. // If shared tooltip, record the angle in degrees in order to align X points. Otherwise,
  1895. // use a standard k-d tree to get the nearest point in two dimensions.
  1896. if (this.kdByAngle) {
  1897. clientX = ((plotX / Math.PI * 180) + this.xAxis.pane.options.startAngle) % 360;
  1898. if (clientX < 0) { // #2665
  1899. clientX += 360;
  1900. }
  1901. point.clientX = clientX;
  1902. } else {
  1903. point.clientX = point.plotX;
  1904. }
  1905. };
  1906. /**
  1907. * Add some special init logic to areas and areasplines
  1908. */
  1909. function initArea(proceed, chart, options) {
  1910. proceed.call(this, chart, options);
  1911. if (this.chart.polar) {
  1912. /**
  1913. * Overridden method to close a segment path. While in a cartesian plane the area
  1914. * goes down to the threshold, in the polar chart it goes to the center.
  1915. */
  1916. this.closeSegment = function (path) {
  1917. var center = this.xAxis.center;
  1918. path.push(
  1919. 'L',
  1920. center[0],
  1921. center[1]
  1922. );
  1923. };
  1924. // Instead of complicated logic to draw an area around the inner area in a stack,
  1925. // just draw it behind
  1926. this.closedStacks = true;
  1927. }
  1928. }
  1929. if (seriesTypes.area) {
  1930. wrap(seriesTypes.area.prototype, 'init', initArea);
  1931. }
  1932. if (seriesTypes.areaspline) {
  1933. wrap(seriesTypes.areaspline.prototype, 'init', initArea);
  1934. }
  1935. if (seriesTypes.spline) {
  1936. /**
  1937. * Overridden method for calculating a spline from one point to the next
  1938. */
  1939. wrap(seriesTypes.spline.prototype, 'getPointSpline', function (proceed, segment, point, i) {
  1940. var ret,
  1941. smoothing = 1.5, // 1 means control points midway between points, 2 means 1/3 from the point, 3 is 1/4 etc;
  1942. denom = smoothing + 1,
  1943. plotX,
  1944. plotY,
  1945. lastPoint,
  1946. nextPoint,
  1947. lastX,
  1948. lastY,
  1949. nextX,
  1950. nextY,
  1951. leftContX,
  1952. leftContY,
  1953. rightContX,
  1954. rightContY,
  1955. distanceLeftControlPoint,
  1956. distanceRightControlPoint,
  1957. leftContAngle,
  1958. rightContAngle,
  1959. jointAngle;
  1960. if (this.chart.polar) {
  1961. plotX = point.plotX;
  1962. plotY = point.plotY;
  1963. lastPoint = segment[i - 1];
  1964. nextPoint = segment[i + 1];
  1965. // Connect ends
  1966. if (this.connectEnds) {
  1967. if (!lastPoint) {
  1968. lastPoint = segment[segment.length - 2]; // not the last but the second last, because the segment is already connected
  1969. }
  1970. if (!nextPoint) {
  1971. nextPoint = segment[1];
  1972. }
  1973. }
  1974. // find control points
  1975. if (lastPoint && nextPoint) {
  1976. lastX = lastPoint.plotX;
  1977. lastY = lastPoint.plotY;
  1978. nextX = nextPoint.plotX;
  1979. nextY = nextPoint.plotY;
  1980. leftContX = (smoothing * plotX + lastX) / denom;
  1981. leftContY = (smoothing * plotY + lastY) / denom;
  1982. rightContX = (smoothing * plotX + nextX) / denom;
  1983. rightContY = (smoothing * plotY + nextY) / denom;
  1984. distanceLeftControlPoint = Math.sqrt(Math.pow(leftContX - plotX, 2) + Math.pow(leftContY - plotY, 2));
  1985. distanceRightControlPoint = Math.sqrt(Math.pow(rightContX - plotX, 2) + Math.pow(rightContY - plotY, 2));
  1986. leftContAngle = Math.atan2(leftContY - plotY, leftContX - plotX);
  1987. rightContAngle = Math.atan2(rightContY - plotY, rightContX - plotX);
  1988. jointAngle = (Math.PI / 2) + ((leftContAngle + rightContAngle) / 2);
  1989. // Ensure the right direction, jointAngle should be in the same quadrant as leftContAngle
  1990. if (Math.abs(leftContAngle - jointAngle) > Math.PI / 2) {
  1991. jointAngle -= Math.PI;
  1992. }
  1993. // Find the corrected control points for a spline straight through the point
  1994. leftContX = plotX + Math.cos(jointAngle) * distanceLeftControlPoint;
  1995. leftContY = plotY + Math.sin(jointAngle) * distanceLeftControlPoint;
  1996. rightContX = plotX + Math.cos(Math.PI + jointAngle) * distanceRightControlPoint;
  1997. rightContY = plotY + Math.sin(Math.PI + jointAngle) * distanceRightControlPoint;
  1998. // Record for drawing in next point
  1999. point.rightContX = rightContX;
  2000. point.rightContY = rightContY;
  2001. }
  2002. // moveTo or lineTo
  2003. if (!i) {
  2004. ret = ['M', plotX, plotY];
  2005. } else { // curve from last point to this
  2006. ret = [
  2007. 'C',
  2008. lastPoint.rightContX || lastPoint.plotX,
  2009. lastPoint.rightContY || lastPoint.plotY,
  2010. leftContX || plotX,
  2011. leftContY || plotY,
  2012. plotX,
  2013. plotY
  2014. ];
  2015. lastPoint.rightContX = lastPoint.rightContY = null; // reset for updating series later
  2016. }
  2017. } else {
  2018. ret = proceed.call(this, segment, point, i);
  2019. }
  2020. return ret;
  2021. });
  2022. }
  2023. /**
  2024. * Extend translate. The plotX and plotY values are computed as if the polar chart were a
  2025. * cartesian plane, where plotX denotes the angle in radians and (yAxis.len - plotY) is the pixel distance from
  2026. * center.
  2027. */
  2028. wrap(seriesProto, 'translate', function (proceed) {
  2029. var chart = this.chart,
  2030. points,
  2031. i;
  2032. // Run uber method
  2033. proceed.call(this);
  2034. // Postprocess plot coordinates
  2035. if (chart.polar) {
  2036. this.kdByAngle = chart.tooltip.shared;
  2037. if (!this.preventPostTranslate) {
  2038. points = this.points;
  2039. i = points.length;
  2040. while (i--) {
  2041. // Translate plotX, plotY from angle and radius to true plot coordinates
  2042. this.toXY(points[i]);
  2043. }
  2044. }
  2045. }
  2046. });
  2047. /**
  2048. * Extend getSegmentPath to allow connecting ends across 0 to provide a closed circle in
  2049. * line-like series.
  2050. */
  2051. wrap(seriesProto, 'getSegmentPath', function (proceed, segment) {
  2052. var points = this.points;
  2053. // Connect the path
  2054. if (this.chart.polar && this.options.connectEnds !== false &&
  2055. segment[segment.length - 1] === points[points.length - 1] && points[0].y !== null) {
  2056. this.connectEnds = true; // re-used in splines
  2057. segment = [].concat(segment, [points[0]]);
  2058. }
  2059. // Run uber method
  2060. return proceed.call(this, segment);
  2061. });
  2062. function polarAnimate(proceed, init) {
  2063. var chart = this.chart,
  2064. animation = this.options.animation,
  2065. group = this.group,
  2066. markerGroup = this.markerGroup,
  2067. center = this.xAxis.center,
  2068. plotLeft = chart.plotLeft,
  2069. plotTop = chart.plotTop,
  2070. attribs;
  2071. // Specific animation for polar charts
  2072. if (chart.polar) {
  2073. // Enable animation on polar charts only in SVG. In VML, the scaling is different, plus animation
  2074. // would be so slow it would't matter.
  2075. if (chart.renderer.isSVG) {
  2076. if (animation === true) {
  2077. animation = {};
  2078. }
  2079. // Initialize the animation
  2080. if (init) {
  2081. // Scale down the group and place it in the center
  2082. attribs = {
  2083. translateX: center[0] + plotLeft,
  2084. translateY: center[1] + plotTop,
  2085. scaleX: 0.001, // #1499
  2086. scaleY: 0.001
  2087. };
  2088. group.attr(attribs);
  2089. if (markerGroup) {
  2090. //markerGroup.attrSetters = group.attrSetters;
  2091. markerGroup.attr(attribs);
  2092. }
  2093. // Run the animation
  2094. } else {
  2095. attribs = {
  2096. translateX: plotLeft,
  2097. translateY: plotTop,
  2098. scaleX: 1,
  2099. scaleY: 1
  2100. };
  2101. group.animate(attribs, animation);
  2102. if (markerGroup) {
  2103. markerGroup.animate(attribs, animation);
  2104. }
  2105. // Delete this function to allow it only once
  2106. this.animate = null;
  2107. }
  2108. }
  2109. // For non-polar charts, revert to the basic animation
  2110. } else {
  2111. proceed.call(this, init);
  2112. }
  2113. }
  2114. // Define the animate method for regular series
  2115. wrap(seriesProto, 'animate', polarAnimate);
  2116. if (seriesTypes.column) {
  2117. colProto = seriesTypes.column.prototype;
  2118. /**
  2119. * Define the animate method for columnseries
  2120. */
  2121. wrap(colProto, 'animate', polarAnimate);
  2122. /**
  2123. * Extend the column prototype's translate method
  2124. */
  2125. wrap(colProto, 'translate', function (proceed) {
  2126. var xAxis = this.xAxis,
  2127. len = this.yAxis.len,
  2128. center = xAxis.center,
  2129. startAngleRad = xAxis.startAngleRad,
  2130. renderer = this.chart.renderer,
  2131. start,
  2132. points,
  2133. point,
  2134. i;
  2135. this.preventPostTranslate = true;
  2136. // Run uber method
  2137. proceed.call(this);
  2138. // Postprocess plot coordinates
  2139. if (xAxis.isRadial) {
  2140. points = this.points;
  2141. i = points.length;
  2142. while (i--) {
  2143. point = points[i];
  2144. start = point.barX + startAngleRad;
  2145. point.shapeType = 'path';
  2146. point.shapeArgs = {
  2147. d: renderer.symbols.arc(
  2148. center[0],
  2149. center[1],
  2150. len - point.plotY,
  2151. null,
  2152. {
  2153. start: start,
  2154. end: start + point.pointWidth,
  2155. innerR: len - pick(point.yBottom, len)
  2156. }
  2157. )
  2158. };
  2159. // Provide correct plotX, plotY for tooltip
  2160. this.toXY(point);
  2161. point.tooltipPos = [point.plotX, point.plotY];
  2162. point.ttBelow = point.plotY > center[1];
  2163. }
  2164. }
  2165. });
  2166. /**
  2167. * Align column data labels outside the columns. #1199.
  2168. */
  2169. wrap(colProto, 'alignDataLabel', function (proceed, point, dataLabel, options, alignTo, isNew) {
  2170. if (this.chart.polar) {
  2171. var angle = point.rectPlotX / Math.PI * 180,
  2172. align,
  2173. verticalAlign;
  2174. // Align nicely outside the perimeter of the columns
  2175. if (options.align === null) {
  2176. if (angle > 20 && angle < 160) {
  2177. align = 'left'; // right hemisphere
  2178. } else if (angle > 200 && angle < 340) {
  2179. align = 'right'; // left hemisphere
  2180. } else {
  2181. align = 'center'; // top or bottom
  2182. }
  2183. options.align = align;
  2184. }
  2185. if (options.verticalAlign === null) {
  2186. if (angle < 45 || angle > 315) {
  2187. verticalAlign = 'bottom'; // top part
  2188. } else if (angle > 135 && angle < 225) {
  2189. verticalAlign = 'top'; // bottom part
  2190. } else {
  2191. verticalAlign = 'middle'; // left or right
  2192. }
  2193. options.verticalAlign = verticalAlign;
  2194. }
  2195. seriesProto.alignDataLabel.call(this, point, dataLabel, options, alignTo, isNew);
  2196. } else {
  2197. proceed.call(this, point, dataLabel, options, alignTo, isNew);
  2198. }
  2199. });
  2200. }
  2201. /**
  2202. * Extend getCoordinates to prepare for polar axis values
  2203. */
  2204. wrap(pointerProto, 'getCoordinates', function (proceed, e) {
  2205. var chart = this.chart,
  2206. ret = {
  2207. xAxis: [],
  2208. yAxis: []
  2209. };
  2210. if (chart.polar) {
  2211. each(chart.axes, function (axis) {
  2212. var isXAxis = axis.isXAxis,
  2213. center = axis.center,
  2214. x = e.chartX - center[0] - chart.plotLeft,
  2215. y = e.chartY - center[1] - chart.plotTop;
  2216. ret[isXAxis ? 'xAxis' : 'yAxis'].push({
  2217. axis: axis,
  2218. value: axis.translate(
  2219. isXAxis ?
  2220. Math.PI - Math.atan2(x, y) : // angle
  2221. Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)), // distance from center
  2222. true
  2223. )
  2224. });
  2225. });
  2226. } else {
  2227. ret = proceed.call(this, e);
  2228. }
  2229. return ret;
  2230. });
  2231. }());
  2232. }(Highcharts));