b3d821eb72d1fcb190d652edb9f9bbd1787ae88f.svn-base 94 KB

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