highcharts-more.src.js 63 KB

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