市长热线演示版

highcharts-more.src.js 62KB

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