80714e54c828984c70d4dffd2a7d12a8231b9921.svn-base 65 KB

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