highcharts-more.src.js 80 KB

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