oldie.src.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733
  1. /**
  2. * @license Highcharts JS v8.2.2 (2020-10-22)
  3. *
  4. * Old IE (v6, v7, v8) module for Highcharts v6+.
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/oldie', ['highcharts'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'Extensions/Math3D.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  33. /* *
  34. *
  35. * (c) 2010-2020 Torstein Honsi
  36. *
  37. * License: www.highcharts.com/license
  38. *
  39. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  40. *
  41. * */
  42. var pick = U.pick;
  43. // Mathematical Functionility
  44. var deg2rad = H.deg2rad;
  45. /* eslint-disable max-len */
  46. /**
  47. * Apply 3-D rotation
  48. * Euler Angles (XYZ):
  49. * cosA = cos(Alfa|Roll)
  50. * cosB = cos(Beta|Pitch)
  51. * cosG = cos(Gamma|Yaw)
  52. *
  53. * Composite rotation:
  54. * | cosB * cosG | cosB * sinG | -sinB |
  55. * | sinA * sinB * cosG - cosA * sinG | sinA * sinB * sinG + cosA * cosG | sinA * cosB |
  56. * | cosA * sinB * cosG + sinA * sinG | cosA * sinB * sinG - sinA * cosG | cosA * cosB |
  57. *
  58. * Now, Gamma/Yaw is not used (angle=0), so we assume cosG = 1 and sinG = 0, so
  59. * we get:
  60. * | cosB | 0 | - sinB |
  61. * | sinA * sinB | cosA | sinA * cosB |
  62. * | cosA * sinB | - sinA | cosA * cosB |
  63. *
  64. * But in browsers, y is reversed, so we get sinA => -sinA. The general result
  65. * is:
  66. * | cosB | 0 | - sinB | | x | | px |
  67. * | - sinA * sinB | cosA | - sinA * cosB | x | y | = | py |
  68. * | cosA * sinB | sinA | cosA * cosB | | z | | pz |
  69. *
  70. * @private
  71. * @function rotate3D
  72. */
  73. /* eslint-enable max-len */
  74. /**
  75. * @private
  76. * @param {number} x
  77. * X coordinate
  78. * @param {number} y
  79. * Y coordinate
  80. * @param {number} z
  81. * Z coordinate
  82. * @param {Highcharts.Rotation3dObject} angles
  83. * Rotation angles
  84. * @return {Highcharts.Rotation3dObject}
  85. * Rotated position
  86. */
  87. function rotate3D(x, y, z, angles) {
  88. return {
  89. x: angles.cosB * x - angles.sinB * z,
  90. y: -angles.sinA * angles.sinB * x + angles.cosA * y -
  91. angles.cosB * angles.sinA * z,
  92. z: angles.cosA * angles.sinB * x + angles.sinA * y +
  93. angles.cosA * angles.cosB * z
  94. };
  95. }
  96. /**
  97. * Perspective3D function is available in global Highcharts scope because is
  98. * needed also outside of perspective() function (#8042).
  99. * @private
  100. * @function Highcharts.perspective3D
  101. *
  102. * @param {Highcharts.Position3dObject} coordinate
  103. * 3D position
  104. *
  105. * @param {Highcharts.Position3dObject} origin
  106. * 3D root position
  107. *
  108. * @param {number} distance
  109. * Perspective distance
  110. *
  111. * @return {Highcharts.PositionObject}
  112. * Perspective 3D Position
  113. *
  114. * @requires highcharts-3d
  115. */
  116. var perspective3D = H.perspective3D = function (coordinate,
  117. origin,
  118. distance) {
  119. var projection = ((distance > 0) && (distance < Number.POSITIVE_INFINITY)) ?
  120. distance / (coordinate.z + origin.z + distance) :
  121. 1;
  122. return {
  123. x: coordinate.x * projection,
  124. y: coordinate.y * projection
  125. };
  126. };
  127. /**
  128. * Transforms a given array of points according to the angles in chart.options.
  129. *
  130. * @private
  131. * @function Highcharts.perspective
  132. *
  133. * @param {Array<Highcharts.Position3dObject>} points
  134. * The array of points
  135. *
  136. * @param {Highcharts.Chart} chart
  137. * The chart
  138. *
  139. * @param {boolean} [insidePlotArea]
  140. * Whether to verifiy that the points are inside the plotArea
  141. *
  142. * @param {boolean} [useInvertedPersp]
  143. * Whether to use inverted perspective in calculations
  144. *
  145. * @return {Array<Highcharts.Position3dObject>}
  146. * An array of transformed points
  147. *
  148. * @requires highcharts-3d
  149. */
  150. var perspective = H.perspective = function (points,
  151. chart,
  152. insidePlotArea,
  153. useInvertedPersp) {
  154. var options3d = chart.options.chart.options3d,
  155. /* The useInvertedPersp argument is used for
  156. * inverted charts with already inverted elements,
  157. * such as dataLabels or tooltip positions.
  158. */
  159. inverted = pick(useInvertedPersp,
  160. insidePlotArea ? chart.inverted : false),
  161. origin = {
  162. x: chart.plotWidth / 2,
  163. y: chart.plotHeight / 2,
  164. z: options3d.depth / 2,
  165. vd: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0)
  166. },
  167. scale = chart.scale3d || 1,
  168. beta = deg2rad * options3d.beta * (inverted ? -1 : 1),
  169. alpha = deg2rad * options3d.alpha * (inverted ? -1 : 1),
  170. angles = {
  171. cosA: Math.cos(alpha),
  172. cosB: Math.cos(-beta),
  173. sinA: Math.sin(alpha),
  174. sinB: Math.sin(-beta)
  175. };
  176. if (!insidePlotArea) {
  177. origin.x += chart.plotLeft;
  178. origin.y += chart.plotTop;
  179. }
  180. // Transform each point
  181. return points.map(function (point) {
  182. var rotated = rotate3D((inverted ? point.y : point.x) - origin.x, (inverted ? point.x : point.y) - origin.y, (point.z || 0) - origin.z,
  183. angles),
  184. // Apply perspective
  185. coordinate = perspective3D(rotated,
  186. origin,
  187. origin.vd);
  188. // Apply translation
  189. coordinate.x = coordinate.x * scale + origin.x;
  190. coordinate.y = coordinate.y * scale + origin.y;
  191. coordinate.z = rotated.z * scale + origin.z;
  192. return {
  193. x: (inverted ? coordinate.y : coordinate.x),
  194. y: (inverted ? coordinate.x : coordinate.y),
  195. z: coordinate.z
  196. };
  197. });
  198. };
  199. /**
  200. * Calculate a distance from camera to points - made for calculating zIndex of
  201. * scatter points.
  202. *
  203. * @private
  204. * @function Highcharts.pointCameraDistance
  205. *
  206. * @param {Highcharts.Dictionary<number>} coordinates
  207. * Coordinates of the specific point
  208. *
  209. * @param {Highcharts.Chart} chart
  210. * Related chart
  211. *
  212. * @return {number}
  213. * Distance from camera to point
  214. *
  215. * @requires highcharts-3d
  216. */
  217. var pointCameraDistance = H.pointCameraDistance = function (coordinates,
  218. chart) {
  219. var options3d = chart.options.chart.options3d,
  220. cameraPosition = {
  221. x: chart.plotWidth / 2,
  222. y: chart.plotHeight / 2,
  223. z: pick(options3d.depth, 1) * pick(options3d.viewDistance, 0) +
  224. options3d.depth
  225. },
  226. // Added support for objects with plotX or x coordinates.
  227. distance = Math.sqrt(Math.pow(cameraPosition.x - pick(coordinates.plotX,
  228. coordinates.x), 2) +
  229. Math.pow(cameraPosition.y - pick(coordinates.plotY,
  230. coordinates.y), 2) +
  231. Math.pow(cameraPosition.z - pick(coordinates.plotZ,
  232. coordinates.z), 2));
  233. return distance;
  234. };
  235. /**
  236. * Calculate area of a 2D polygon using Shoelace algorithm
  237. * https://en.wikipedia.org/wiki/Shoelace_formula
  238. *
  239. * @private
  240. * @function Highcharts.shapeArea
  241. *
  242. * @param {Array<Highcharts.PositionObject>} vertexes
  243. * 2D Polygon
  244. *
  245. * @return {number}
  246. * Calculated area
  247. *
  248. * @requires highcharts-3d
  249. */
  250. var shapeArea = H.shapeArea = function (vertexes) {
  251. var area = 0,
  252. i,
  253. j;
  254. for (i = 0; i < vertexes.length; i++) {
  255. j = (i + 1) % vertexes.length;
  256. area += vertexes[i].x * vertexes[j].y - vertexes[j].x * vertexes[i].y;
  257. }
  258. return area / 2;
  259. };
  260. /**
  261. * Calculate area of a 3D polygon after perspective projection
  262. *
  263. * @private
  264. * @function Highcharts.shapeArea3d
  265. *
  266. * @param {Array<Highcharts.Position3dObject>} vertexes
  267. * 3D Polygon
  268. *
  269. * @param {Highcharts.Chart} chart
  270. * Related chart
  271. *
  272. * @param {boolean} [insidePlotArea]
  273. * Whether to verifiy that the points are inside the plotArea
  274. *
  275. * @return {number}
  276. * Calculated area
  277. *
  278. * @requires highcharts-3d
  279. */
  280. var shapeArea3D = H.shapeArea3d = function (vertexes,
  281. chart,
  282. insidePlotArea) {
  283. return shapeArea(perspective(vertexes,
  284. chart,
  285. insidePlotArea));
  286. };
  287. var mathModule = {
  288. perspective: perspective,
  289. perspective3D: perspective3D,
  290. pointCameraDistance: pointCameraDistance,
  291. shapeArea: shapeArea,
  292. shapeArea3D: shapeArea3D
  293. };
  294. return mathModule;
  295. });
  296. _registerModule(_modules, 'Core/Renderer/SVG/SVGRenderer3D.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js']], function (A, Color, H, Math3D, SVGElement, SVGRenderer, U) {
  297. /* *
  298. *
  299. * (c) 2010-2020 Torstein Honsi
  300. *
  301. * Extensions to the SVGRenderer class to enable 3D shapes
  302. *
  303. * License: www.highcharts.com/license
  304. *
  305. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  306. *
  307. * */
  308. var animObject = A.animObject;
  309. var color = Color.parse;
  310. var perspective = Math3D.perspective,
  311. shapeArea = Math3D.shapeArea;
  312. var defined = U.defined,
  313. extend = U.extend,
  314. merge = U.merge,
  315. objectEach = U.objectEach,
  316. pick = U.pick;
  317. var cos = Math.cos,
  318. PI = Math.PI,
  319. sin = Math.sin;
  320. var charts = H.charts,
  321. deg2rad = H.deg2rad,
  322. // internal:
  323. dFactor,
  324. element3dMethods,
  325. cuboidMethods;
  326. /*
  327. EXTENSION TO THE SVG-RENDERER TO ENABLE 3D SHAPES
  328. */
  329. // HELPER METHODS
  330. dFactor = (4 * (Math.sqrt(2) - 1) / 3) / (PI / 2);
  331. /* eslint-disable no-invalid-this, valid-jsdoc */
  332. /**
  333. * Method to construct a curved path. Can 'wrap' around more then 180 degrees.
  334. * @private
  335. */
  336. function curveTo(cx, cy, rx, ry, start, end, dx, dy) {
  337. var result = [],
  338. arcAngle = end - start;
  339. if ((end > start) && (end - start > Math.PI / 2 + 0.0001)) {
  340. result = result.concat(curveTo(cx, cy, rx, ry, start, start + (Math.PI / 2), dx, dy));
  341. result = result.concat(curveTo(cx, cy, rx, ry, start + (Math.PI / 2), end, dx, dy));
  342. return result;
  343. }
  344. if ((end < start) && (start - end > Math.PI / 2 + 0.0001)) {
  345. result = result.concat(curveTo(cx, cy, rx, ry, start, start - (Math.PI / 2), dx, dy));
  346. result = result.concat(curveTo(cx, cy, rx, ry, start - (Math.PI / 2), end, dx, dy));
  347. return result;
  348. }
  349. return [[
  350. 'C',
  351. cx + (rx * Math.cos(start)) -
  352. ((rx * dFactor * arcAngle) * Math.sin(start)) + dx,
  353. cy + (ry * Math.sin(start)) +
  354. ((ry * dFactor * arcAngle) * Math.cos(start)) + dy,
  355. cx + (rx * Math.cos(end)) +
  356. ((rx * dFactor * arcAngle) * Math.sin(end)) + dx,
  357. cy + (ry * Math.sin(end)) -
  358. ((ry * dFactor * arcAngle) * Math.cos(end)) + dy,
  359. cx + (rx * Math.cos(end)) + dx,
  360. cy + (ry * Math.sin(end)) + dy
  361. ]];
  362. }
  363. SVGRenderer.prototype.toLinePath = function (points, closed) {
  364. var result = [];
  365. // Put "L x y" for each point
  366. points.forEach(function (point) {
  367. result.push(['L', point.x, point.y]);
  368. });
  369. if (points.length) {
  370. // Set the first element to M
  371. result[0][0] = 'M';
  372. // If it is a closed line, add Z
  373. if (closed) {
  374. result.push(['Z']);
  375. }
  376. }
  377. return result;
  378. };
  379. SVGRenderer.prototype.toLineSegments = function (points) {
  380. var result = [],
  381. m = true;
  382. points.forEach(function (point) {
  383. result.push(m ? ['M', point.x, point.y] : ['L', point.x, point.y]);
  384. m = !m;
  385. });
  386. return result;
  387. };
  388. // A 3-D Face is defined by it's 3D vertexes, and is only visible if it's
  389. // vertexes are counter-clockwise (Back-face culling). It is used as a
  390. // polyhedron Element
  391. SVGRenderer.prototype.face3d = function (args) {
  392. var renderer = this,
  393. ret = this.createElement('path');
  394. ret.vertexes = [];
  395. ret.insidePlotArea = false;
  396. ret.enabled = true;
  397. ret.attr = function (hash) {
  398. if (typeof hash === 'object' &&
  399. (defined(hash.enabled) ||
  400. defined(hash.vertexes) ||
  401. defined(hash.insidePlotArea))) {
  402. this.enabled = pick(hash.enabled, this.enabled);
  403. this.vertexes = pick(hash.vertexes, this.vertexes);
  404. this.insidePlotArea = pick(hash.insidePlotArea, this.insidePlotArea);
  405. delete hash.enabled;
  406. delete hash.vertexes;
  407. delete hash.insidePlotArea;
  408. var chart = charts[renderer.chartIndex],
  409. vertexes2d = perspective(this.vertexes,
  410. chart,
  411. this.insidePlotArea),
  412. path = renderer.toLinePath(vertexes2d,
  413. true),
  414. area = shapeArea(vertexes2d),
  415. visibility = (this.enabled && area > 0) ? 'visible' : 'hidden';
  416. hash.d = path;
  417. hash.visibility = visibility;
  418. }
  419. return SVGElement.prototype.attr.apply(this, arguments);
  420. };
  421. ret.animate = function (params) {
  422. if (typeof params === 'object' &&
  423. (defined(params.enabled) ||
  424. defined(params.vertexes) ||
  425. defined(params.insidePlotArea))) {
  426. this.enabled = pick(params.enabled, this.enabled);
  427. this.vertexes = pick(params.vertexes, this.vertexes);
  428. this.insidePlotArea = pick(params.insidePlotArea, this.insidePlotArea);
  429. delete params.enabled;
  430. delete params.vertexes;
  431. delete params.insidePlotArea;
  432. var chart = charts[renderer.chartIndex],
  433. vertexes2d = perspective(this.vertexes,
  434. chart,
  435. this.insidePlotArea),
  436. path = renderer.toLinePath(vertexes2d,
  437. true),
  438. area = shapeArea(vertexes2d),
  439. visibility = (this.enabled && area > 0) ? 'visible' : 'hidden';
  440. params.d = path;
  441. this.attr('visibility', visibility);
  442. }
  443. return SVGElement.prototype.animate.apply(this, arguments);
  444. };
  445. return ret.attr(args);
  446. };
  447. // A Polyhedron is a handy way of defining a group of 3-D faces. It's only
  448. // attribute is `faces`, an array of attributes of each one of it's Face3D
  449. // instances.
  450. SVGRenderer.prototype.polyhedron = function (args) {
  451. var renderer = this,
  452. result = this.g(),
  453. destroy = result.destroy;
  454. if (!this.styledMode) {
  455. result.attr({
  456. 'stroke-linejoin': 'round'
  457. });
  458. }
  459. result.faces = [];
  460. // destroy all children
  461. result.destroy = function () {
  462. for (var i = 0; i < result.faces.length; i++) {
  463. result.faces[i].destroy();
  464. }
  465. return destroy.call(this);
  466. };
  467. result.attr = function (hash, val, complete, continueAnimation) {
  468. if (typeof hash === 'object' && defined(hash.faces)) {
  469. while (result.faces.length > hash.faces.length) {
  470. result.faces.pop().destroy();
  471. }
  472. while (result.faces.length < hash.faces.length) {
  473. result.faces.push(renderer.face3d().add(result));
  474. }
  475. for (var i = 0; i < hash.faces.length; i++) {
  476. if (renderer.styledMode) {
  477. delete hash.faces[i].fill;
  478. }
  479. result.faces[i].attr(hash.faces[i], null, complete, continueAnimation);
  480. }
  481. delete hash.faces;
  482. }
  483. return SVGElement.prototype.attr.apply(this, arguments);
  484. };
  485. result.animate = function (params, duration, complete) {
  486. if (params && params.faces) {
  487. while (result.faces.length > params.faces.length) {
  488. result.faces.pop().destroy();
  489. }
  490. while (result.faces.length < params.faces.length) {
  491. result.faces.push(renderer.face3d().add(result));
  492. }
  493. for (var i = 0; i < params.faces.length; i++) {
  494. result.faces[i].animate(params.faces[i], duration, complete);
  495. }
  496. delete params.faces;
  497. }
  498. return SVGElement.prototype.animate.apply(this, arguments);
  499. };
  500. return result.attr(args);
  501. };
  502. // Base, abstract prototype member for 3D elements
  503. element3dMethods = {
  504. /**
  505. * The init is used by base - renderer.Element
  506. * @private
  507. */
  508. initArgs: function (args) {
  509. var elem3d = this,
  510. renderer = elem3d.renderer,
  511. paths = renderer[elem3d.pathType + 'Path'](args),
  512. zIndexes = paths.zIndexes;
  513. // build parts
  514. elem3d.parts.forEach(function (part) {
  515. elem3d[part] = renderer.path(paths[part]).attr({
  516. 'class': 'highcharts-3d-' + part,
  517. zIndex: zIndexes[part] || 0
  518. }).add(elem3d);
  519. });
  520. elem3d.attr({
  521. 'stroke-linejoin': 'round',
  522. zIndex: zIndexes.group
  523. });
  524. // store original destroy
  525. elem3d.originalDestroy = elem3d.destroy;
  526. elem3d.destroy = elem3d.destroyParts;
  527. // Store information if any side of element was rendered by force.
  528. elem3d.forcedSides = paths.forcedSides;
  529. },
  530. /**
  531. * Single property setter that applies options to each part
  532. * @private
  533. */
  534. singleSetterForParts: function (prop, val, values, verb, duration, complete) {
  535. var elem3d = this,
  536. newAttr = {},
  537. optionsToApply = [null,
  538. null, (verb || 'attr'),
  539. duration,
  540. complete],
  541. hasZIndexes = values && values.zIndexes;
  542. if (!values) {
  543. newAttr[prop] = val;
  544. optionsToApply[0] = newAttr;
  545. }
  546. else {
  547. // It is needed to deal with the whole group zIndexing
  548. // in case of graph rotation
  549. if (hasZIndexes && hasZIndexes.group) {
  550. this.attr({
  551. zIndex: hasZIndexes.group
  552. });
  553. }
  554. objectEach(values, function (partVal, part) {
  555. newAttr[part] = {};
  556. newAttr[part][prop] = partVal;
  557. // include zIndexes if provided
  558. if (hasZIndexes) {
  559. newAttr[part].zIndex = values.zIndexes[part] || 0;
  560. }
  561. });
  562. optionsToApply[1] = newAttr;
  563. }
  564. return elem3d.processParts.apply(elem3d, optionsToApply);
  565. },
  566. /**
  567. * Calls function for each part. Used for attr, animate and destroy.
  568. * @private
  569. */
  570. processParts: function (props, partsProps, verb, duration, complete) {
  571. var elem3d = this;
  572. elem3d.parts.forEach(function (part) {
  573. // if different props for different parts
  574. if (partsProps) {
  575. props = pick(partsProps[part], false);
  576. }
  577. // only if something to set, but allow undefined
  578. if (props !== false) {
  579. elem3d[part][verb](props, duration, complete);
  580. }
  581. });
  582. return elem3d;
  583. },
  584. /**
  585. * Destroy all parts
  586. * @private
  587. */
  588. destroyParts: function () {
  589. this.processParts(null, null, 'destroy');
  590. return this.originalDestroy();
  591. }
  592. };
  593. // CUBOID
  594. cuboidMethods = merge(element3dMethods, {
  595. parts: ['front', 'top', 'side'],
  596. pathType: 'cuboid',
  597. attr: function (args, val, complete, continueAnimation) {
  598. // Resolve setting attributes by string name
  599. if (typeof args === 'string' && typeof val !== 'undefined') {
  600. var key = args;
  601. args = {};
  602. args[key] = val;
  603. }
  604. if (args.shapeArgs || defined(args.x)) {
  605. return this.singleSetterForParts('d', null, this.renderer[this.pathType + 'Path'](args.shapeArgs || args));
  606. }
  607. return SVGElement.prototype.attr.call(this, args, void 0, complete, continueAnimation);
  608. },
  609. animate: function (args, duration, complete) {
  610. if (defined(args.x) && defined(args.y)) {
  611. var paths = this.renderer[this.pathType + 'Path'](args),
  612. forcedSides = paths.forcedSides;
  613. this.singleSetterForParts('d', null, paths, 'animate', duration, complete);
  614. this.attr({
  615. zIndex: paths.zIndexes.group
  616. });
  617. // If sides that are forced to render changed, recalculate colors.
  618. if (forcedSides !== this.forcedSides) {
  619. this.forcedSides = forcedSides;
  620. cuboidMethods.fillSetter.call(this, this.fill);
  621. }
  622. }
  623. else {
  624. SVGElement.prototype.animate.call(this, args, duration, complete);
  625. }
  626. return this;
  627. },
  628. fillSetter: function (fill) {
  629. var elem3d = this;
  630. elem3d.forcedSides = elem3d.forcedSides || [];
  631. elem3d.singleSetterForParts('fill', null, {
  632. front: fill,
  633. // Do not change color if side was forced to render.
  634. top: color(fill).brighten(elem3d.forcedSides.indexOf('top') >= 0 ? 0 : 0.1).get(),
  635. side: color(fill).brighten(elem3d.forcedSides.indexOf('side') >= 0 ? 0 : -0.1).get()
  636. });
  637. // fill for animation getter (#6776)
  638. elem3d.color = elem3d.fill = fill;
  639. return elem3d;
  640. }
  641. });
  642. // set them up
  643. SVGRenderer.prototype.elements3d = {
  644. base: element3dMethods,
  645. cuboid: cuboidMethods
  646. };
  647. /**
  648. * return result, generalization
  649. * @private
  650. * @requires highcharts-3d
  651. */
  652. SVGRenderer.prototype.element3d = function (type, shapeArgs) {
  653. // base
  654. var ret = this.g();
  655. // extend
  656. extend(ret, this.elements3d[type]);
  657. // init
  658. ret.initArgs(shapeArgs);
  659. // return
  660. return ret;
  661. };
  662. // generelized, so now use simply
  663. SVGRenderer.prototype.cuboid = function (shapeArgs) {
  664. return this.element3d('cuboid', shapeArgs);
  665. };
  666. // Generates a cuboid path and zIndexes
  667. SVGRenderer.prototype.cuboidPath = function (shapeArgs) {
  668. var x = shapeArgs.x,
  669. y = shapeArgs.y,
  670. z = shapeArgs.z || 0,
  671. // For side calculation (right/left)
  672. // there is a need for height (and other shapeArgs arguments)
  673. // to be at least 1px
  674. h = shapeArgs.height,
  675. w = shapeArgs.width,
  676. d = shapeArgs.depth,
  677. chart = charts[this.chartIndex],
  678. front,
  679. back,
  680. top,
  681. bottom,
  682. left,
  683. right,
  684. shape,
  685. path1,
  686. path2,
  687. path3,
  688. isFront,
  689. isTop,
  690. isRight,
  691. options3d = chart.options.chart.options3d,
  692. alpha = options3d.alpha,
  693. // Priority for x axis is the biggest,
  694. // because of x direction has biggest influence on zIndex
  695. incrementX = 1000000,
  696. // y axis has the smallest priority in case of our charts
  697. // (needs to be set because of stacking)
  698. incrementY = 10,
  699. incrementZ = 100,
  700. zIndex = 0,
  701. // The 8 corners of the cube
  702. pArr = [{
  703. x: x,
  704. y: y,
  705. z: z
  706. }, {
  707. x: x + w,
  708. y: y,
  709. z: z
  710. }, {
  711. x: x + w,
  712. y: y + h,
  713. z: z
  714. }, {
  715. x: x,
  716. y: y + h,
  717. z: z
  718. }, {
  719. x: x,
  720. y: y + h,
  721. z: z + d
  722. }, {
  723. x: x + w,
  724. y: y + h,
  725. z: z + d
  726. }, {
  727. x: x + w,
  728. y: y,
  729. z: z + d
  730. }, {
  731. x: x,
  732. y: y,
  733. z: z + d
  734. }],
  735. forcedSides = [],
  736. pickShape;
  737. // apply perspective
  738. pArr = perspective(pArr, chart, shapeArgs.insidePlotArea);
  739. /**
  740. * helper method to decide which side is visible
  741. * @private
  742. */
  743. function mapSidePath(i) {
  744. // Added support for 0 value in columns, where height is 0
  745. // but the shape is rendered.
  746. // Height is used from 1st to 6th element of pArr
  747. if (h === 0 && i > 1 && i < 6) { // [2, 3, 4, 5]
  748. return {
  749. x: pArr[i].x,
  750. // when height is 0 instead of cuboid we render plane
  751. // so it is needed to add fake 10 height to imitate cuboid
  752. // for side calculation
  753. y: pArr[i].y + 10,
  754. z: pArr[i].z
  755. };
  756. }
  757. // It is needed to calculate dummy sides (front/back) for breaking
  758. // points in case of x and depth values. If column has side,
  759. // it means that x values of front and back side are different.
  760. if (pArr[0].x === pArr[7].x && i >= 4) { // [4, 5, 6, 7]
  761. return {
  762. x: pArr[i].x + 10,
  763. // when height is 0 instead of cuboid we render plane
  764. // so it is needed to add fake 10 height to imitate cuboid
  765. // for side calculation
  766. y: pArr[i].y,
  767. z: pArr[i].z
  768. };
  769. }
  770. // Added dummy depth
  771. if (d === 0 && i < 2 || i > 5) { // [0, 1, 6, 7]
  772. return {
  773. x: pArr[i].x,
  774. // when height is 0 instead of cuboid we render plane
  775. // so it is needed to add fake 10 height to imitate cuboid
  776. // for side calculation
  777. y: pArr[i].y,
  778. z: pArr[i].z + 10
  779. };
  780. }
  781. return pArr[i];
  782. }
  783. /**
  784. * method creating the final side
  785. * @private
  786. */
  787. function mapPath(i) {
  788. return pArr[i];
  789. }
  790. /**
  791. * First value - path with specific face
  792. * Second value - added information about side for later calculations.
  793. * Possible second values are 0 for path1, 1 for path2 and -1 for no path
  794. * chosen.
  795. * Third value - string containing information about current side
  796. * of cuboid for forcing side rendering.
  797. * @private
  798. */
  799. pickShape = function (verticesIndex1, verticesIndex2, side) {
  800. var ret = [[], -1],
  801. // An array of vertices for cuboid face
  802. face1 = verticesIndex1.map(mapPath),
  803. face2 = verticesIndex2.map(mapPath),
  804. // dummy face is calculated the same way as standard face,
  805. // but if cuboid height is 0 additional height is added so it is
  806. // possible to use this vertices array for visible face calculation
  807. dummyFace1 = verticesIndex1.map(mapSidePath),
  808. dummyFace2 = verticesIndex2.map(mapSidePath);
  809. if (shapeArea(face1) < 0) {
  810. ret = [face1, 0];
  811. }
  812. else if (shapeArea(face2) < 0) {
  813. ret = [face2, 1];
  814. }
  815. else if (side) {
  816. forcedSides.push(side);
  817. if (shapeArea(dummyFace1) < 0) {
  818. ret = [face1, 0];
  819. }
  820. else if (shapeArea(dummyFace2) < 0) {
  821. ret = [face2, 1];
  822. }
  823. else {
  824. ret = [face1, 0]; // force side calculation.
  825. }
  826. }
  827. return ret;
  828. };
  829. // front or back
  830. front = [3, 2, 1, 0];
  831. back = [7, 6, 5, 4];
  832. shape = pickShape(front, back, 'front');
  833. path1 = shape[0];
  834. isFront = shape[1];
  835. // top or bottom
  836. top = [1, 6, 7, 0];
  837. bottom = [4, 5, 2, 3];
  838. shape = pickShape(top, bottom, 'top');
  839. path2 = shape[0];
  840. isTop = shape[1];
  841. // side
  842. right = [1, 2, 5, 6];
  843. left = [0, 7, 4, 3];
  844. shape = pickShape(right, left, 'side');
  845. path3 = shape[0];
  846. isRight = shape[1];
  847. /* New block used for calculating zIndex. It is basing on X, Y and Z
  848. position of specific columns. All zIndexes (for X, Y and Z values) are
  849. added to the final zIndex, where every value has different priority. The
  850. biggest priority is in X and Z directions, the lowest index is for
  851. stacked columns (Y direction and the same X and Z positions). Big
  852. differences between priorities is made because we need to ensure that
  853. even for big changes in Y and Z parameters all columns will be drawn
  854. correctly. */
  855. if (isRight === 1) {
  856. // It is needed to connect value with current chart width
  857. // for big chart size.
  858. zIndex += incrementX * (chart.plotWidth - x);
  859. }
  860. else if (!isRight) {
  861. zIndex += incrementX * x;
  862. }
  863. zIndex += incrementY * (!isTop ||
  864. // Numbers checked empirically
  865. (alpha >= 0 && alpha <= 180 || alpha < 360 && alpha > 357.5) ?
  866. chart.plotHeight - y : 10 + y);
  867. if (isFront === 1) {
  868. zIndex += incrementZ * (z);
  869. }
  870. else if (!isFront) {
  871. zIndex += incrementZ * (1000 - z);
  872. }
  873. return {
  874. front: this.toLinePath(path1, true),
  875. top: this.toLinePath(path2, true),
  876. side: this.toLinePath(path3, true),
  877. zIndexes: {
  878. group: Math.round(zIndex)
  879. },
  880. forcedSides: forcedSides,
  881. // additional info about zIndexes
  882. isFront: isFront,
  883. isTop: isTop
  884. }; // #4774
  885. };
  886. // SECTORS //
  887. SVGRenderer.prototype.arc3d = function (attribs) {
  888. var wrapper = this.g(), renderer = wrapper.renderer, customAttribs = ['x', 'y', 'r', 'innerR', 'start', 'end', 'depth'];
  889. /**
  890. * Get custom attributes. Don't mutate the original object and return an
  891. * object with only custom attr.
  892. * @private
  893. */
  894. function suckOutCustom(params) {
  895. var hasCA = false,
  896. ca = {},
  897. key;
  898. params = merge(params); // Don't mutate the original object
  899. for (key in params) {
  900. if (customAttribs.indexOf(key) !== -1) {
  901. ca[key] = params[key];
  902. delete params[key];
  903. hasCA = true;
  904. }
  905. }
  906. return hasCA ? [ca, params] : false;
  907. }
  908. attribs = merge(attribs);
  909. attribs.alpha = (attribs.alpha || 0) * deg2rad;
  910. attribs.beta = (attribs.beta || 0) * deg2rad;
  911. // Create the different sub sections of the shape
  912. wrapper.top = renderer.path();
  913. wrapper.side1 = renderer.path();
  914. wrapper.side2 = renderer.path();
  915. wrapper.inn = renderer.path();
  916. wrapper.out = renderer.path();
  917. // Add all faces
  918. wrapper.onAdd = function () {
  919. var parent = wrapper.parentGroup,
  920. className = wrapper.attr('class');
  921. wrapper.top.add(wrapper);
  922. // These faces are added outside the wrapper group because the z index
  923. // relates to neighbour elements as well
  924. ['out', 'inn', 'side1', 'side2'].forEach(function (face) {
  925. wrapper[face]
  926. .attr({
  927. 'class': className + ' highcharts-3d-side'
  928. })
  929. .add(parent);
  930. });
  931. };
  932. // Cascade to faces
  933. ['addClass', 'removeClass'].forEach(function (fn) {
  934. wrapper[fn] = function () {
  935. var args = arguments;
  936. ['top', 'out', 'inn', 'side1', 'side2'].forEach(function (face) {
  937. wrapper[face][fn].apply(wrapper[face], args);
  938. });
  939. };
  940. });
  941. /**
  942. * Compute the transformed paths and set them to the composite shapes
  943. * @private
  944. */
  945. wrapper.setPaths = function (attribs) {
  946. var paths = wrapper.renderer.arc3dPath(attribs),
  947. zIndex = paths.zTop * 100;
  948. wrapper.attribs = attribs;
  949. wrapper.top.attr({ d: paths.top, zIndex: paths.zTop });
  950. wrapper.inn.attr({ d: paths.inn, zIndex: paths.zInn });
  951. wrapper.out.attr({ d: paths.out, zIndex: paths.zOut });
  952. wrapper.side1.attr({ d: paths.side1, zIndex: paths.zSide1 });
  953. wrapper.side2.attr({ d: paths.side2, zIndex: paths.zSide2 });
  954. // show all children
  955. wrapper.zIndex = zIndex;
  956. wrapper.attr({ zIndex: zIndex });
  957. // Set the radial gradient center the first time
  958. if (attribs.center) {
  959. wrapper.top.setRadialReference(attribs.center);
  960. delete attribs.center;
  961. }
  962. };
  963. wrapper.setPaths(attribs);
  964. /**
  965. * Apply the fill to the top and a darker shade to the sides
  966. * @private
  967. */
  968. wrapper.fillSetter = function (value) {
  969. var darker = color(value).brighten(-0.1).get();
  970. this.fill = value;
  971. this.side1.attr({ fill: darker });
  972. this.side2.attr({ fill: darker });
  973. this.inn.attr({ fill: darker });
  974. this.out.attr({ fill: darker });
  975. this.top.attr({ fill: value });
  976. return this;
  977. };
  978. // Apply the same value to all. These properties cascade down to the
  979. // children when set to the composite arc3d.
  980. ['opacity', 'translateX', 'translateY', 'visibility'].forEach(function (setter) {
  981. wrapper[setter + 'Setter'] = function (value, key) {
  982. wrapper[key] = value;
  983. ['out', 'inn', 'side1', 'side2', 'top'].forEach(function (el) {
  984. wrapper[el].attr(key, value);
  985. });
  986. };
  987. });
  988. // Override attr to remove shape attributes and use those to set child paths
  989. wrapper.attr = function (params) {
  990. var ca,
  991. paramArr;
  992. if (typeof params === 'object') {
  993. paramArr = suckOutCustom(params);
  994. if (paramArr) {
  995. ca = paramArr[0];
  996. arguments[0] = paramArr[1];
  997. extend(wrapper.attribs, ca);
  998. wrapper.setPaths(wrapper.attribs);
  999. }
  1000. }
  1001. return SVGElement.prototype.attr.apply(wrapper, arguments);
  1002. };
  1003. // Override the animate function by sucking out custom parameters related to
  1004. // the shapes directly, and update the shapes from the animation step.
  1005. wrapper.animate = function (params, animation, complete) {
  1006. var paramArr,
  1007. from = this.attribs,
  1008. to,
  1009. anim,
  1010. randomProp = 'data-' + Math.random().toString(26).substring(2, 9);
  1011. // Attribute-line properties connected to 3D. These shouldn't have been
  1012. // in the attribs collection in the first place.
  1013. delete params.center;
  1014. delete params.z;
  1015. delete params.alpha;
  1016. delete params.beta;
  1017. anim = animObject(pick(animation, this.renderer.globalAnimation));
  1018. if (anim.duration) {
  1019. paramArr = suckOutCustom(params);
  1020. // Params need to have a property in order for the step to run
  1021. // (#5765, #7097, #7437)
  1022. wrapper[randomProp] = 0;
  1023. params[randomProp] = 1;
  1024. wrapper[randomProp + 'Setter'] = H.noop;
  1025. if (paramArr) {
  1026. to = paramArr[0]; // custom attr
  1027. anim.step = function (a, fx) {
  1028. /**
  1029. * @private
  1030. */
  1031. function interpolate(key) {
  1032. return from[key] + (pick(to[key], from[key]) -
  1033. from[key]) * fx.pos;
  1034. }
  1035. if (fx.prop === randomProp) {
  1036. fx.elem.setPaths(merge(from, {
  1037. x: interpolate('x'),
  1038. y: interpolate('y'),
  1039. r: interpolate('r'),
  1040. innerR: interpolate('innerR'),
  1041. start: interpolate('start'),
  1042. end: interpolate('end'),
  1043. depth: interpolate('depth')
  1044. }));
  1045. }
  1046. };
  1047. }
  1048. animation = anim; // Only when duration (#5572)
  1049. }
  1050. return SVGElement.prototype.animate.call(this, params, animation, complete);
  1051. };
  1052. // destroy all children
  1053. wrapper.destroy = function () {
  1054. this.top.destroy();
  1055. this.out.destroy();
  1056. this.inn.destroy();
  1057. this.side1.destroy();
  1058. this.side2.destroy();
  1059. return SVGElement.prototype.destroy.call(this);
  1060. };
  1061. // hide all children
  1062. wrapper.hide = function () {
  1063. this.top.hide();
  1064. this.out.hide();
  1065. this.inn.hide();
  1066. this.side1.hide();
  1067. this.side2.hide();
  1068. };
  1069. wrapper.show = function (inherit) {
  1070. this.top.show(inherit);
  1071. this.out.show(inherit);
  1072. this.inn.show(inherit);
  1073. this.side1.show(inherit);
  1074. this.side2.show(inherit);
  1075. };
  1076. return wrapper;
  1077. };
  1078. // Generate the paths required to draw a 3D arc
  1079. SVGRenderer.prototype.arc3dPath = function (shapeArgs) {
  1080. var cx = shapeArgs.x, // x coordinate of the center
  1081. cy = shapeArgs.y, // y coordinate of the center
  1082. start = shapeArgs.start, // start angle
  1083. end = shapeArgs.end - 0.00001, // end angle
  1084. r = shapeArgs.r, // radius
  1085. ir = shapeArgs.innerR || 0, // inner radius
  1086. d = shapeArgs.depth || 0, // depth
  1087. alpha = shapeArgs.alpha, // alpha rotation of the chart
  1088. beta = shapeArgs.beta; // beta rotation of the chart
  1089. // Derived Variables
  1090. var cs = Math.cos(start), // cosinus of the start angle
  1091. ss = Math.sin(start), // sinus of the start angle
  1092. ce = Math.cos(end), // cosinus of the end angle
  1093. se = Math.sin(end), // sinus of the end angle
  1094. rx = r * Math.cos(beta), // x-radius
  1095. ry = r * Math.cos(alpha), // y-radius
  1096. irx = ir * Math.cos(beta), // x-radius (inner)
  1097. iry = ir * Math.cos(alpha), // y-radius (inner)
  1098. dx = d * Math.sin(beta), // distance between top and bottom in x
  1099. dy = d * Math.sin(alpha); // distance between top and bottom in y
  1100. // TOP
  1101. var top = [
  1102. ['M',
  1103. cx + (rx * cs),
  1104. cy + (ry * ss)]
  1105. ];
  1106. top = top.concat(curveTo(cx, cy, rx, ry, start, end, 0, 0));
  1107. top.push([
  1108. 'L', cx + (irx * ce), cy + (iry * se)
  1109. ]);
  1110. top = top.concat(curveTo(cx, cy, irx, iry, end, start, 0, 0));
  1111. top.push(['Z']);
  1112. // OUTSIDE
  1113. var b = (beta > 0 ? Math.PI / 2 : 0),
  1114. a = (alpha > 0 ? 0 : Math.PI / 2);
  1115. var start2 = start > -b ? start : (end > -b ? -b : start),
  1116. end2 = end < PI - a ? end : (start < PI - a ? PI - a : end),
  1117. midEnd = 2 * PI - a;
  1118. // When slice goes over bottom middle, need to add both, left and right
  1119. // outer side. Additionally, when we cross right hand edge, create sharp
  1120. // edge. Outer shape/wall:
  1121. //
  1122. // -------
  1123. // / ^ \
  1124. // 4) / / \ \ 1)
  1125. // / / \ \
  1126. // / / \ \
  1127. // (c)=> ==== ==== <=(d)
  1128. // \ \ / /
  1129. // \ \<=(a)/ /
  1130. // \ \ / / <=(b)
  1131. // 3) \ v / 2)
  1132. // -------
  1133. //
  1134. // (a) - inner side
  1135. // (b) - outer side
  1136. // (c) - left edge (sharp)
  1137. // (d) - right edge (sharp)
  1138. // 1..n - rendering order for startAngle = 0, when set to e.g 90, order
  1139. // changes clockwise (1->2, 2->3, n->1) and counterclockwise for negative
  1140. // startAngle
  1141. var out = [
  1142. ['M',
  1143. cx + (rx * cos(start2)),
  1144. cy + (ry * sin(start2))]
  1145. ];
  1146. out = out.concat(curveTo(cx, cy, rx, ry, start2, end2, 0, 0));
  1147. // When shape is wide, it can cross both, (c) and (d) edges, when using
  1148. // startAngle
  1149. if (end > midEnd && start < midEnd) {
  1150. // Go to outer side
  1151. out.push([
  1152. 'L', cx + (rx * cos(end2)) + dx, cy + (ry * sin(end2)) + dy
  1153. ]);
  1154. // Curve to the right edge of the slice (d)
  1155. out = out.concat(curveTo(cx, cy, rx, ry, end2, midEnd, dx, dy));
  1156. // Go to the inner side
  1157. out.push([
  1158. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  1159. ]);
  1160. // Curve to the true end of the slice
  1161. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end, 0, 0));
  1162. // Go to the outer side
  1163. out.push([
  1164. 'L', cx + (rx * cos(end)) + dx, cy + (ry * sin(end)) + dy
  1165. ]);
  1166. // Go back to middle (d)
  1167. out = out.concat(curveTo(cx, cy, rx, ry, end, midEnd, dx, dy));
  1168. out.push([
  1169. 'L', cx + (rx * cos(midEnd)), cy + (ry * sin(midEnd))
  1170. ]);
  1171. // Go back to the left edge
  1172. out = out.concat(curveTo(cx, cy, rx, ry, midEnd, end2, 0, 0));
  1173. // But shape can cross also only (c) edge:
  1174. }
  1175. else if (end > PI - a && start < PI - a) {
  1176. // Go to outer side
  1177. out.push([
  1178. 'L',
  1179. cx + (rx * Math.cos(end2)) + dx,
  1180. cy + (ry * Math.sin(end2)) + dy
  1181. ]);
  1182. // Curve to the true end of the slice
  1183. out = out.concat(curveTo(cx, cy, rx, ry, end2, end, dx, dy));
  1184. // Go to the inner side
  1185. out.push([
  1186. 'L', cx + (rx * Math.cos(end)), cy + (ry * Math.sin(end))
  1187. ]);
  1188. // Go back to the artifical end2
  1189. out = out.concat(curveTo(cx, cy, rx, ry, end, end2, 0, 0));
  1190. }
  1191. out.push([
  1192. 'L', cx + (rx * Math.cos(end2)) + dx, cy + (ry * Math.sin(end2)) + dy
  1193. ]);
  1194. out = out.concat(curveTo(cx, cy, rx, ry, end2, start2, dx, dy));
  1195. out.push(['Z']);
  1196. // INSIDE
  1197. var inn = [
  1198. ['M',
  1199. cx + (irx * cs),
  1200. cy + (iry * ss)]
  1201. ];
  1202. inn = inn.concat(curveTo(cx, cy, irx, iry, start, end, 0, 0));
  1203. inn.push([
  1204. 'L', cx + (irx * Math.cos(end)) + dx, cy + (iry * Math.sin(end)) + dy
  1205. ]);
  1206. inn = inn.concat(curveTo(cx, cy, irx, iry, end, start, dx, dy));
  1207. inn.push(['Z']);
  1208. // SIDES
  1209. var side1 = [
  1210. ['M',
  1211. cx + (rx * cs),
  1212. cy + (ry * ss)],
  1213. ['L',
  1214. cx + (rx * cs) + dx,
  1215. cy + (ry * ss) + dy],
  1216. ['L',
  1217. cx + (irx * cs) + dx,
  1218. cy + (iry * ss) + dy],
  1219. ['L',
  1220. cx + (irx * cs),
  1221. cy + (iry * ss)],
  1222. ['Z']
  1223. ];
  1224. var side2 = [
  1225. ['M',
  1226. cx + (rx * ce),
  1227. cy + (ry * se)],
  1228. ['L',
  1229. cx + (rx * ce) + dx,
  1230. cy + (ry * se) + dy],
  1231. ['L',
  1232. cx + (irx * ce) + dx,
  1233. cy + (iry * se) + dy],
  1234. ['L',
  1235. cx + (irx * ce),
  1236. cy + (iry * se)],
  1237. ['Z']
  1238. ];
  1239. // correction for changed position of vanishing point caused by alpha and
  1240. // beta rotations
  1241. var angleCorr = Math.atan2(dy, -dx),
  1242. angleEnd = Math.abs(end + angleCorr),
  1243. angleStart = Math.abs(start + angleCorr),
  1244. angleMid = Math.abs((start + end) / 2 + angleCorr);
  1245. /**
  1246. * set to 0-PI range
  1247. * @private
  1248. */
  1249. function toZeroPIRange(angle) {
  1250. angle = angle % (2 * Math.PI);
  1251. if (angle > Math.PI) {
  1252. angle = 2 * Math.PI - angle;
  1253. }
  1254. return angle;
  1255. }
  1256. angleEnd = toZeroPIRange(angleEnd);
  1257. angleStart = toZeroPIRange(angleStart);
  1258. angleMid = toZeroPIRange(angleMid);
  1259. // *1e5 is to compensate pInt in zIndexSetter
  1260. var incPrecision = 1e5,
  1261. a1 = angleMid * incPrecision,
  1262. a2 = angleStart * incPrecision,
  1263. a3 = angleEnd * incPrecision;
  1264. return {
  1265. top: top,
  1266. // max angle is PI, so this is always higher
  1267. zTop: Math.PI * incPrecision + 1,
  1268. out: out,
  1269. zOut: Math.max(a1, a2, a3),
  1270. inn: inn,
  1271. zInn: Math.max(a1, a2, a3),
  1272. side1: side1,
  1273. zSide1: a3 * 0.99,
  1274. side2: side2,
  1275. zSide2: a2 * 0.99
  1276. };
  1277. };
  1278. return SVGRenderer;
  1279. });
  1280. _registerModule(_modules, 'Extensions/Oldie/VMLAxis3D.js', [_modules['Core/Utilities.js']], function (U) {
  1281. /* *
  1282. *
  1283. * (c) 2010-2020 Torstein Honsi
  1284. *
  1285. * Extension to the VML Renderer
  1286. *
  1287. * License: www.highcharts.com/license
  1288. *
  1289. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1290. *
  1291. * */
  1292. var addEvent = U.addEvent;
  1293. /* eslint-disable valid-jsdoc */
  1294. var VMLAxis3DAdditions = /** @class */ (function () {
  1295. /* *
  1296. *
  1297. * Constructors
  1298. *
  1299. * */
  1300. function VMLAxis3DAdditions(axis) {
  1301. this.axis = axis;
  1302. }
  1303. return VMLAxis3DAdditions;
  1304. }());
  1305. var VMLAxis3D = /** @class */ (function () {
  1306. function VMLAxis3D() {
  1307. }
  1308. /* *
  1309. *
  1310. * Static Properties
  1311. *
  1312. * */
  1313. VMLAxis3D.compose = function (AxisClass) {
  1314. AxisClass.keepProps.push('vml');
  1315. addEvent(AxisClass, 'init', VMLAxis3D.onInit);
  1316. addEvent(AxisClass, 'render', VMLAxis3D.onRender);
  1317. };
  1318. /**
  1319. * @private
  1320. */
  1321. VMLAxis3D.onInit = function () {
  1322. var axis = this;
  1323. if (!axis.vml) {
  1324. axis.vml = new VMLAxis3DAdditions(axis);
  1325. }
  1326. };
  1327. /**
  1328. * @private
  1329. */
  1330. VMLAxis3D.onRender = function () {
  1331. var axis = this;
  1332. var vml = axis.vml;
  1333. // VML doesn't support a negative z-index
  1334. if (vml.sideFrame) {
  1335. vml.sideFrame.css({ zIndex: 0 });
  1336. vml.sideFrame.front.attr({
  1337. fill: vml.sideFrame.color
  1338. });
  1339. }
  1340. if (vml.bottomFrame) {
  1341. vml.bottomFrame.css({ zIndex: 1 });
  1342. vml.bottomFrame.front.attr({
  1343. fill: vml.bottomFrame.color
  1344. });
  1345. }
  1346. if (vml.backFrame) {
  1347. vml.backFrame.css({ zIndex: 0 });
  1348. vml.backFrame.front.attr({
  1349. fill: vml.backFrame.color
  1350. });
  1351. }
  1352. };
  1353. return VMLAxis3D;
  1354. }());
  1355. return VMLAxis3D;
  1356. });
  1357. _registerModule(_modules, 'Extensions/Oldie/VMLRenderer3D.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js'], _modules['Extensions/Oldie/VMLAxis3D.js']], function (Axis, U, VMLAxis3D) {
  1358. /* *
  1359. *
  1360. * (c) 2010-2020 Torstein Honsi
  1361. *
  1362. * Extension to the VML Renderer
  1363. *
  1364. * License: www.highcharts.com/license
  1365. *
  1366. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1367. *
  1368. * */
  1369. var setOptions = U.setOptions;
  1370. var VMLRenderer3D = /** @class */ (function () {
  1371. function VMLRenderer3D() {
  1372. }
  1373. /* *
  1374. *
  1375. * Static Properties
  1376. *
  1377. * */
  1378. VMLRenderer3D.compose = function (vmlClass, svgClass) {
  1379. var svgProto = svgClass.prototype;
  1380. var vmlProto = vmlClass.prototype;
  1381. setOptions({ animate: false });
  1382. vmlProto.face3d = svgProto.face3d;
  1383. vmlProto.polyhedron = svgProto.polyhedron;
  1384. vmlProto.elements3d = svgProto.elements3d;
  1385. vmlProto.element3d = svgProto.element3d;
  1386. vmlProto.cuboid = svgProto.cuboid;
  1387. vmlProto.cuboidPath = svgProto.cuboidPath;
  1388. vmlProto.toLinePath = svgProto.toLinePath;
  1389. vmlProto.toLineSegments = svgProto.toLineSegments;
  1390. vmlProto.arc3d = function (shapeArgs) {
  1391. var result = svgProto.arc3d.call(this,
  1392. shapeArgs);
  1393. result.css({ zIndex: result.zIndex });
  1394. return result;
  1395. };
  1396. vmlProto.arc3dPath = svgProto.arc3dPath;
  1397. VMLAxis3D.compose(Axis);
  1398. };
  1399. return VMLRenderer3D;
  1400. }());
  1401. return VMLRenderer3D;
  1402. });
  1403. _registerModule(_modules, 'Extensions/Oldie/Oldie.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Core/Pointer.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Renderer/SVG/SVGRenderer3D.js'], _modules['Core/Utilities.js'], _modules['Extensions/Oldie/VMLRenderer3D.js']], function (Chart, Color, H, Pointer, SVGElement, SVGRenderer, U, VMLRenderer3D) {
  1404. /* *
  1405. *
  1406. * (c) 2010-2020 Torstein Honsi
  1407. *
  1408. * License: www.highcharts.com/license
  1409. *
  1410. * Support for old IE browsers (6, 7 and 8) in Highcharts v6+.
  1411. *
  1412. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1413. *
  1414. * */
  1415. var color = Color.parse;
  1416. var deg2rad = H.deg2rad,
  1417. doc = H.doc,
  1418. noop = H.noop,
  1419. svg = H.svg,
  1420. win = H.win;
  1421. var addEvent = U.addEvent,
  1422. createElement = U.createElement,
  1423. css = U.css,
  1424. defined = U.defined,
  1425. discardElement = U.discardElement,
  1426. erase = U.erase,
  1427. extend = U.extend,
  1428. extendClass = U.extendClass,
  1429. getOptions = U.getOptions,
  1430. isArray = U.isArray,
  1431. isNumber = U.isNumber,
  1432. isObject = U.isObject,
  1433. merge = U.merge,
  1434. offset = U.offset,
  1435. pick = U.pick,
  1436. pInt = U.pInt,
  1437. setOptions = U.setOptions,
  1438. uniqueKey = U.uniqueKey;
  1439. var VMLRenderer,
  1440. VMLElement;
  1441. /**
  1442. * Path to the pattern image required by VML browsers in order to
  1443. * draw radial gradients.
  1444. *
  1445. * @type {string}
  1446. * @default http://code.highcharts.com/{version}/gfx/vml-radial-gradient.png
  1447. * @since 2.3.0
  1448. * @requires modules/oldie
  1449. * @apioption global.VMLRadialGradientURL
  1450. */
  1451. getOptions().global.VMLRadialGradientURL =
  1452. 'http://code.highcharts.com/8.2.2/gfx/vml-radial-gradient.png';
  1453. // Utilites
  1454. if (doc && !doc.defaultView) {
  1455. H.getStyle = U.getStyle = function (el, prop) {
  1456. var val,
  1457. alias = {
  1458. width: 'clientWidth',
  1459. height: 'clientHeight'
  1460. }[prop];
  1461. if (el.style[prop]) {
  1462. return pInt(el.style[prop]);
  1463. }
  1464. if (prop === 'opacity') {
  1465. prop = 'filter';
  1466. }
  1467. // Getting the rendered width and height
  1468. if (alias) {
  1469. el.style.zoom = 1;
  1470. return Math.max(el[alias] - 2 * U.getStyle(el, 'padding'), 0);
  1471. }
  1472. val = el.currentStyle[prop.replace(/\-(\w)/g, function (a, b) {
  1473. return b.toUpperCase();
  1474. })];
  1475. if (prop === 'filter') {
  1476. val = val.replace(/alpha\(opacity=([0-9]+)\)/, function (a, b) {
  1477. return (b / 100);
  1478. });
  1479. }
  1480. return val === '' ? 1 : pInt(val);
  1481. };
  1482. }
  1483. /* eslint-disable no-invalid-this, valid-jsdoc */
  1484. if (!svg) {
  1485. // Prevent wrapping from creating false offsetWidths in export in legacy IE.
  1486. // This applies only to charts for export, where IE runs the SVGRenderer
  1487. // instead of the VMLRenderer
  1488. // (#1079, #1063)
  1489. addEvent(SVGElement, 'afterInit', function () {
  1490. if (this.element.nodeName === 'text') {
  1491. this.css({
  1492. position: 'absolute'
  1493. });
  1494. }
  1495. });
  1496. /**
  1497. * Old IE override for pointer normalize, adds chartX and chartY to event
  1498. * arguments.
  1499. *
  1500. * @ignore
  1501. * @function Highcharts.Pointer#normalize
  1502. * @param {global.PointerEvent} e
  1503. * @param {boolean} [chartPosition=false]
  1504. * @return {Highcharts.PointerEventObject}
  1505. */
  1506. Pointer.prototype.normalize = function (e, chartPosition) {
  1507. e = e || win.event;
  1508. if (!e.target) {
  1509. e.target = e.srcElement;
  1510. }
  1511. // Get mouse position
  1512. if (!chartPosition) {
  1513. this.chartPosition = chartPosition = offset(this.chart.container);
  1514. }
  1515. return extend(e, {
  1516. // #2005, #2129: the second case is for IE10 quirks mode within
  1517. // framesets
  1518. chartX: Math.round(Math.max(e.x, e.clientX - chartPosition.left)),
  1519. chartY: Math.round(e.y)
  1520. });
  1521. };
  1522. /**
  1523. * Further sanitize the mock-SVG that is generated when exporting charts in
  1524. * oldIE.
  1525. *
  1526. * @private
  1527. * @function Highcharts.Chart#ieSanitizeSVG
  1528. */
  1529. Chart.prototype.ieSanitizeSVG = function (svg) {
  1530. svg = svg
  1531. .replace(/<IMG /g, '<image ')
  1532. .replace(/<(\/?)TITLE>/g, '<$1title>')
  1533. .replace(/height=([^" ]+)/g, 'height="$1"')
  1534. .replace(/width=([^" ]+)/g, 'width="$1"')
  1535. .replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>')
  1536. .replace(/ id=([^" >]+)/g, ' id="$1"') // #4003
  1537. .replace(/class=([^" >]+)/g, 'class="$1"')
  1538. .replace(/ transform /g, ' ')
  1539. .replace(/:(path|rect)/g, '$1')
  1540. .replace(/style="([^"]+)"/g, function (s) {
  1541. return s.toLowerCase();
  1542. });
  1543. return svg;
  1544. };
  1545. /**
  1546. * VML namespaces can't be added until after complete. Listening
  1547. * for Perini's doScroll hack is not enough.
  1548. *
  1549. * @private
  1550. * @function Highcharts.Chart#isReadyToRender
  1551. */
  1552. Chart.prototype.isReadyToRender = function () {
  1553. var chart = this;
  1554. // Note: win == win.top is required
  1555. if (!svg &&
  1556. (win == win.top && // eslint-disable-line eqeqeq
  1557. doc.readyState !== 'complete')) {
  1558. doc.attachEvent('onreadystatechange', function () {
  1559. doc.detachEvent('onreadystatechange', chart.firstRender);
  1560. if (doc.readyState === 'complete') {
  1561. chart.firstRender();
  1562. }
  1563. });
  1564. return false;
  1565. }
  1566. return true;
  1567. };
  1568. // IE compatibility hack for generating SVG content that it doesn't really
  1569. // understand. Used by the exporting module.
  1570. if (!doc.createElementNS) {
  1571. doc.createElementNS = function (ns, tagName) {
  1572. return doc.createElement(tagName);
  1573. };
  1574. }
  1575. /**
  1576. * Old IE polyfill for addEventListener, called from inside the addEvent
  1577. * function.
  1578. *
  1579. * @private
  1580. * @function Highcharts.addEventListenerPolyfill<T>
  1581. * @param {string} type
  1582. * @param {Highcharts.EventCallbackFunction<T>} fn
  1583. * @return {void}
  1584. */
  1585. H.addEventListenerPolyfill = function (type, fn) {
  1586. var el = this;
  1587. /**
  1588. * @private
  1589. */
  1590. function wrappedFn(e) {
  1591. e.target = e.srcElement || win; // #2820
  1592. fn.call(el, e);
  1593. }
  1594. if (el.attachEvent) {
  1595. if (!el.hcEventsIE) {
  1596. el.hcEventsIE = {};
  1597. }
  1598. // unique function string (#6746)
  1599. if (!fn.hcKey) {
  1600. fn.hcKey = uniqueKey();
  1601. }
  1602. // Link wrapped fn with original fn, so we can get this in
  1603. // removeEvent
  1604. el.hcEventsIE[fn.hcKey] = wrappedFn;
  1605. el.attachEvent('on' + type, wrappedFn);
  1606. }
  1607. };
  1608. /**
  1609. * @private
  1610. * @function Highcharts.removeEventListenerPolyfill<T>
  1611. * @param {string} type
  1612. * @param {Highcharts.EventCallbackFunction<T>} fn
  1613. * @return {void}
  1614. */
  1615. H.removeEventListenerPolyfill = function (type, fn) {
  1616. if (this.detachEvent) {
  1617. fn = this.hcEventsIE[fn.hcKey];
  1618. this.detachEvent('on' + type, fn);
  1619. }
  1620. };
  1621. /**
  1622. * The VML element wrapper.
  1623. *
  1624. * @private
  1625. * @class
  1626. * @name Highcharts.VMLElement
  1627. *
  1628. * @augments Highcharts.SVGElement
  1629. */
  1630. VMLElement = {
  1631. docMode8: doc && doc.documentMode === 8,
  1632. /**
  1633. * Initialize a new VML element wrapper. It builds the markup as a
  1634. * string to minimize DOM traffic.
  1635. *
  1636. * @function Highcharts.VMLElement#init
  1637. * @param {Highcharts.VMLRenderer} renderer
  1638. * @param {string} nodeName
  1639. */
  1640. init: function (renderer, nodeName) {
  1641. var wrapper = this, markup = ['<', nodeName, ' filled="f" stroked="f"'], style = ['position: ', 'absolute', ';'], isDiv = nodeName === 'div';
  1642. // divs and shapes need size
  1643. if (nodeName === 'shape' || isDiv) {
  1644. style.push('left:0;top:0;width:1px;height:1px;');
  1645. }
  1646. style.push('visibility: ', isDiv ? 'hidden' : 'visible');
  1647. markup.push(' style="', style.join(''), '"/>');
  1648. // create element with default attributes and style
  1649. if (nodeName) {
  1650. markup = isDiv || nodeName === 'span' || nodeName === 'img' ?
  1651. markup.join('') :
  1652. renderer.prepVML(markup);
  1653. wrapper.element = createElement(markup);
  1654. }
  1655. wrapper.renderer = renderer;
  1656. },
  1657. /**
  1658. * Add the node to the given parent
  1659. *
  1660. * @function Highcharts.VMLElement
  1661. * @param {Highcharts.VMLElement} parent
  1662. * @return {Highcharts.VMLElement}
  1663. */
  1664. add: function (parent) {
  1665. var wrapper = this,
  1666. renderer = wrapper.renderer,
  1667. element = wrapper.element,
  1668. box = renderer.box,
  1669. inverted = parent && parent.inverted,
  1670. // get the parent node
  1671. parentNode = parent ?
  1672. parent.element || parent :
  1673. box;
  1674. if (parent) {
  1675. this.parentGroup = parent;
  1676. }
  1677. // if the parent group is inverted, apply inversion on all children
  1678. if (inverted) { // only on groups
  1679. renderer.invertChild(element, parentNode);
  1680. }
  1681. // append it
  1682. parentNode.appendChild(element);
  1683. // align text after adding to be able to read offset
  1684. wrapper.added = true;
  1685. if (wrapper.alignOnAdd && !wrapper.deferUpdateTransform) {
  1686. wrapper.updateTransform();
  1687. }
  1688. // fire an event for internal hooks
  1689. if (wrapper.onAdd) {
  1690. wrapper.onAdd();
  1691. }
  1692. // IE8 Standards can't set the class name before the element is
  1693. // appended
  1694. if (this.className) {
  1695. this.attr('class', this.className);
  1696. }
  1697. return wrapper;
  1698. },
  1699. /**
  1700. * VML always uses htmlUpdateTransform
  1701. *
  1702. * @function Highcharts.VMLElement#updateTransform
  1703. */
  1704. updateTransform: SVGElement.prototype.htmlUpdateTransform,
  1705. /**
  1706. * Set the rotation of a span with oldIE's filter
  1707. *
  1708. * @function Highcharts.VMLElement#setSpanRotation
  1709. * @return {void}
  1710. */
  1711. setSpanRotation: function () {
  1712. // Adjust for alignment and rotation. Rotation of useHTML content is
  1713. // not yet implemented but it can probably be implemented for
  1714. // Firefox 3.5+ on user request. FF3.5+ has support for CSS3
  1715. // transform. The getBBox method also needs to be updated to
  1716. // compensate for the rotation, like it currently does for SVG.
  1717. // Test case: https://jsfiddle.net/highcharts/Ybt44/
  1718. var rotation = this.rotation,
  1719. costheta = Math.cos(rotation * deg2rad),
  1720. sintheta = Math.sin(rotation * deg2rad);
  1721. css(this.element, {
  1722. filter: rotation ? [
  1723. 'progid:DXImageTransform.Microsoft.Matrix(M11=', costheta,
  1724. ', M12=', -sintheta, ', M21=', sintheta, ', M22=', costheta,
  1725. ', sizingMethod=\'auto expand\')'
  1726. ].join('') : 'none'
  1727. });
  1728. },
  1729. /**
  1730. * Get the positioning correction for the span after rotating.
  1731. *
  1732. * @function Highcharts.VMLElement#getSpanCorrection
  1733. */
  1734. getSpanCorrection: function (width, baseline, alignCorrection, rotation, align) {
  1735. var costheta = rotation ? Math.cos(rotation * deg2rad) : 1,
  1736. sintheta = rotation ? Math.sin(rotation * deg2rad) : 0,
  1737. height = pick(this.elemHeight,
  1738. this.element.offsetHeight),
  1739. quad,
  1740. nonLeft = align && align !== 'left';
  1741. // correct x and y
  1742. this.xCorr = (costheta < 0 && -width);
  1743. this.yCorr = (sintheta < 0 && -height);
  1744. // correct for baseline and corners spilling out after rotation
  1745. quad = costheta * sintheta < 0;
  1746. this.xCorr += (sintheta *
  1747. baseline *
  1748. (quad ? 1 - alignCorrection : alignCorrection));
  1749. this.yCorr -= (costheta *
  1750. baseline *
  1751. (rotation ? (quad ? alignCorrection : 1 - alignCorrection) : 1));
  1752. // correct for the length/height of the text
  1753. if (nonLeft) {
  1754. this.xCorr -=
  1755. width * alignCorrection * (costheta < 0 ? -1 : 1);
  1756. if (rotation) {
  1757. this.yCorr -= (height *
  1758. alignCorrection *
  1759. (sintheta < 0 ? -1 : 1));
  1760. }
  1761. css(this.element, {
  1762. textAlign: align
  1763. });
  1764. }
  1765. },
  1766. /**
  1767. * Converts a subset of an SVG path definition to its VML counterpart.
  1768. * Takes an array as the parameter and returns a string.
  1769. *
  1770. * @function Highcharts.VMLElement#pathToVML
  1771. */
  1772. pathToVML: function (value) {
  1773. // convert paths
  1774. var i = value.length,
  1775. path = [];
  1776. while (i--) {
  1777. // Multiply by 10 to allow subpixel precision.
  1778. // Substracting half a pixel seems to make the coordinates
  1779. // align with SVG, but this hasn't been tested thoroughly
  1780. if (isNumber(value[i])) {
  1781. path[i] = Math.round(value[i] * 10) - 5;
  1782. }
  1783. else if (value[i] === 'Z') { // close the path
  1784. path[i] = 'x';
  1785. }
  1786. else {
  1787. path[i] = value[i];
  1788. // When the start X and end X coordinates of an arc are too
  1789. // close, they are rounded to the same value above. In this
  1790. // case, substract or add 1 from the end X and Y positions.
  1791. // #186, #760, #1371, #1410.
  1792. if (value.isArc &&
  1793. (value[i] === 'wa' || value[i] === 'at')) {
  1794. // Start and end X
  1795. if (path[i + 5] === path[i + 7]) {
  1796. path[i + 7] +=
  1797. value[i + 7] > value[i + 5] ? 1 : -1;
  1798. }
  1799. // Start and end Y
  1800. if (path[i + 6] === path[i + 8]) {
  1801. path[i + 8] +=
  1802. value[i + 8] > value[i + 6] ? 1 : -1;
  1803. }
  1804. }
  1805. }
  1806. }
  1807. return path.join(' ') || 'x';
  1808. },
  1809. /**
  1810. * Set the element's clipping to a predefined rectangle
  1811. *
  1812. * @function Highcharts.VMLElement#clip
  1813. * @param {Highcharts.VMLClipRectObject} clipRect
  1814. * @return {Highcharts.VMLElement}
  1815. */
  1816. clip: function (clipRect) {
  1817. var wrapper = this,
  1818. clipMembers,
  1819. cssRet;
  1820. if (clipRect) {
  1821. clipMembers = clipRect.members;
  1822. // Ensure unique list of elements (#1258)
  1823. erase(clipMembers, wrapper);
  1824. clipMembers.push(wrapper);
  1825. wrapper.destroyClip = function () {
  1826. erase(clipMembers, wrapper);
  1827. };
  1828. cssRet = clipRect.getCSS(wrapper);
  1829. }
  1830. else {
  1831. if (wrapper.destroyClip) {
  1832. wrapper.destroyClip();
  1833. }
  1834. cssRet = {
  1835. clip: wrapper.docMode8 ? 'inherit' : 'rect(auto)'
  1836. }; // #1214
  1837. }
  1838. return wrapper.css(cssRet);
  1839. },
  1840. /**
  1841. * Set styles for the element
  1842. *
  1843. * @function Highcharts.VMLElement#css
  1844. * @param {Highcharts.CSSObject} styles
  1845. * @return {Highcharts.VMLElement}
  1846. */
  1847. css: SVGElement.prototype.htmlCss,
  1848. /**
  1849. * Removes a child either by removeChild or move to garbageBin.
  1850. * Issue 490; in VML removeChild results in Orphaned nodes according to
  1851. * sIEve, discardElement does not.
  1852. *
  1853. * @function Highcharts.VMLElement#safeRemoveChild
  1854. * @param {Highcharts.HTMLDOMElement} element
  1855. * @return {void}
  1856. */
  1857. safeRemoveChild: function (element) {
  1858. // discardElement will detach the node from its parent before
  1859. // attaching it to the garbage bin. Therefore it is important that
  1860. // the node is attached and have parent.
  1861. if (element.parentNode) {
  1862. discardElement(element);
  1863. }
  1864. },
  1865. /**
  1866. * Extend element.destroy by removing it from the clip members array
  1867. *
  1868. * @function Highcharts.VMLElement#destroy
  1869. */
  1870. destroy: function () {
  1871. if (this.destroyClip) {
  1872. this.destroyClip();
  1873. }
  1874. return SVGElement.prototype.destroy.apply(this);
  1875. },
  1876. /**
  1877. * Add an event listener. VML override for normalizing event parameters.
  1878. *
  1879. * @function Highcharts.VMLElement#on
  1880. * @param {string} eventType
  1881. * @param {Function} handler
  1882. * @return {Highcharts.VMLElement}
  1883. */
  1884. on: function (eventType, handler) {
  1885. // simplest possible event model for internal use
  1886. this.element['on' + eventType] = function () {
  1887. var e = win.event;
  1888. e.target = e.srcElement;
  1889. handler(e);
  1890. };
  1891. return this;
  1892. },
  1893. /**
  1894. * In stacked columns, cut off the shadows so that they don't overlap
  1895. *
  1896. * @function Highcharts.VMLElement#cutOffPath
  1897. * @param {string} path
  1898. * @param {number} length
  1899. * @return {string}
  1900. */
  1901. cutOffPath: function (path, length) {
  1902. var len;
  1903. // The extra comma tricks the trailing comma remover in
  1904. // "gulp scripts" task
  1905. path = path.split(/[ ,]/);
  1906. len = path.length;
  1907. if (len === 9 || len === 11) {
  1908. path[len - 4] = path[len - 2] =
  1909. pInt(path[len - 2]) - 10 * length;
  1910. }
  1911. return path.join(' ');
  1912. },
  1913. /**
  1914. * Apply a drop shadow by copying elements and giving them different
  1915. * strokes.
  1916. *
  1917. * @function Highcharts.VMLElement#shadow
  1918. * @param {Highcharts.ShadowOptionsObject} shadowOptions
  1919. * @param {Highcharts.VMLElement} group
  1920. * @param {boolean} cutOff
  1921. * @return {Highcharts.VMLElement}
  1922. */
  1923. shadow: function (shadowOptions, group, cutOff) {
  1924. var shadows = [],
  1925. i,
  1926. element = this.element,
  1927. renderer = this.renderer,
  1928. shadow,
  1929. elemStyle = element.style,
  1930. markup,
  1931. path = element.path,
  1932. strokeWidth,
  1933. modifiedPath,
  1934. shadowWidth,
  1935. shadowElementOpacity;
  1936. // some times empty paths are not strings
  1937. if (path && typeof path.value !== 'string') {
  1938. path = 'x';
  1939. }
  1940. modifiedPath = path;
  1941. if (shadowOptions) {
  1942. shadowWidth = pick(shadowOptions.width, 3);
  1943. shadowElementOpacity =
  1944. (shadowOptions.opacity || 0.15) / shadowWidth;
  1945. for (i = 1; i <= 3; i++) {
  1946. strokeWidth = (shadowWidth * 2) + 1 - (2 * i);
  1947. // Cut off shadows for stacked column items
  1948. if (cutOff) {
  1949. modifiedPath = this.cutOffPath(path.value, strokeWidth + 0.5);
  1950. }
  1951. markup = [
  1952. '<shape isShadow="true" strokeweight="', strokeWidth,
  1953. '" filled="false" path="', modifiedPath,
  1954. '" coordsize="10 10" style="', element.style.cssText,
  1955. '" />'
  1956. ];
  1957. shadow = createElement(renderer.prepVML(markup), null, {
  1958. left: pInt(elemStyle.left) +
  1959. pick(shadowOptions.offsetX, 1),
  1960. top: pInt(elemStyle.top) +
  1961. pick(shadowOptions.offsetY, 1)
  1962. });
  1963. if (cutOff) {
  1964. shadow.cutOff = strokeWidth + 1;
  1965. }
  1966. // apply the opacity
  1967. markup = [
  1968. '<stroke color="',
  1969. shadowOptions.color || '#000000',
  1970. '" opacity="', shadowElementOpacity * i, '"/>'
  1971. ];
  1972. createElement(renderer.prepVML(markup), null, null, shadow);
  1973. // insert it
  1974. if (group) {
  1975. group.element.appendChild(shadow);
  1976. }
  1977. else {
  1978. element.parentNode
  1979. .insertBefore(shadow, element);
  1980. }
  1981. // record it
  1982. shadows.push(shadow);
  1983. }
  1984. this.shadows = shadows;
  1985. }
  1986. return this;
  1987. },
  1988. updateShadows: noop,
  1989. setAttr: function (key, value) {
  1990. if (this.docMode8) { // IE8 setAttribute bug
  1991. this.element[key] = value;
  1992. }
  1993. else {
  1994. this.element.setAttribute(key, value);
  1995. }
  1996. },
  1997. getAttr: function (key) {
  1998. if (this.docMode8) { // IE8 setAttribute bug
  1999. return this.element[key];
  2000. }
  2001. return this.element.getAttribute(key);
  2002. },
  2003. classSetter: function (value) {
  2004. // IE8 Standards mode has problems retrieving the className unless
  2005. // set like this. IE8 Standards can't set the class name before the
  2006. // element is appended.
  2007. (this.added ? this.element : this).className = value;
  2008. },
  2009. dashstyleSetter: function (value, key, element) {
  2010. var strokeElem = element.getElementsByTagName('stroke')[0] ||
  2011. createElement(this.renderer.prepVML(['<stroke/>']),
  2012. null,
  2013. null,
  2014. element);
  2015. strokeElem[key] = value || 'solid';
  2016. // Because changing stroke-width will change the dash length and
  2017. // cause an epileptic effect
  2018. this[key] = value;
  2019. },
  2020. dSetter: function (value, key, element) {
  2021. var i,
  2022. shadows = this.shadows;
  2023. value = value || [];
  2024. // Used in getter for animation
  2025. this.d = value.join && value.join(' ');
  2026. element.path = value = this.pathToVML(value);
  2027. // update shadows
  2028. if (shadows) {
  2029. i = shadows.length;
  2030. while (i--) {
  2031. shadows[i].path = shadows[i].cutOff ?
  2032. this.cutOffPath(value, shadows[i].cutOff) :
  2033. value;
  2034. }
  2035. }
  2036. this.setAttr(key, value);
  2037. },
  2038. fillSetter: function (value, key, element) {
  2039. var nodeName = element.nodeName;
  2040. if (nodeName === 'SPAN') { // text color
  2041. element.style.color = value;
  2042. }
  2043. else if (nodeName !== 'IMG') { // #1336
  2044. element.filled = value !== 'none';
  2045. this.setAttr('fillcolor', this.renderer.color(value, element, key, this));
  2046. }
  2047. },
  2048. 'fill-opacitySetter': function (value, key, element) {
  2049. createElement(this.renderer.prepVML(['<', key.split('-')[0], ' opacity="', value, '"/>']), null, null, element);
  2050. },
  2051. // Don't bother - animation is too slow and filters introduce artifacts
  2052. opacitySetter: noop,
  2053. rotationSetter: function (value, key, element) {
  2054. var style = element.style;
  2055. // style is for #1873:
  2056. this[key] = style[key] = value;
  2057. // Correction for the 1x1 size of the shape container. Used in gauge
  2058. // needles.
  2059. style.left =
  2060. -Math.round(Math.sin(value * deg2rad) + 1) + 'px';
  2061. style.top =
  2062. Math.round(Math.cos(value * deg2rad)) + 'px';
  2063. },
  2064. strokeSetter: function (value, key, element) {
  2065. this.setAttr('strokecolor', this.renderer.color(value, element, key, this));
  2066. },
  2067. 'stroke-widthSetter': function (value, key, element) {
  2068. element.stroked = !!value; // VML "stroked" attribute
  2069. this[key] = value; // used in getter, issue #113
  2070. if (isNumber(value)) {
  2071. value += 'px';
  2072. }
  2073. this.setAttr('strokeweight', value);
  2074. },
  2075. titleSetter: function (value, key) {
  2076. this.setAttr(key, value);
  2077. },
  2078. visibilitySetter: function (value, key, element) {
  2079. // Handle inherited visibility
  2080. if (value === 'inherit') {
  2081. value = 'visible';
  2082. }
  2083. // Let the shadow follow the main element
  2084. if (this.shadows) {
  2085. this.shadows.forEach(function (shadow) {
  2086. shadow.style[key] = value;
  2087. });
  2088. }
  2089. // Instead of toggling the visibility CSS property, move the div out
  2090. // of the viewport. This works around #61 and #586
  2091. if (element.nodeName === 'DIV') {
  2092. value = value === 'hidden' ? '-999em' : 0;
  2093. // In order to redraw, IE7 needs the div to be visible when
  2094. // tucked away outside the viewport. So the visibility is
  2095. // actually opposite of the expected value. This applies to the
  2096. // tooltip only.
  2097. if (!this.docMode8) {
  2098. element.style[key] = value ? 'visible' : 'hidden';
  2099. }
  2100. key = 'top';
  2101. }
  2102. element.style[key] = value;
  2103. },
  2104. xSetter: function (value, key, element) {
  2105. this[key] = value; // used in getter
  2106. if (key === 'x') {
  2107. key = 'left';
  2108. }
  2109. else if (key === 'y') {
  2110. key = 'top';
  2111. }
  2112. // clipping rectangle special
  2113. if (this.updateClipping) {
  2114. // the key is now 'left' or 'top' for 'x' and 'y'
  2115. this[key] = value;
  2116. this.updateClipping();
  2117. }
  2118. else {
  2119. // normal
  2120. element.style[key] = value;
  2121. }
  2122. },
  2123. zIndexSetter: function (value, key, element) {
  2124. element.style[key] = value;
  2125. },
  2126. fillGetter: function () {
  2127. return this.getAttr('fillcolor') || '';
  2128. },
  2129. strokeGetter: function () {
  2130. return this.getAttr('strokecolor') || '';
  2131. },
  2132. // #7850
  2133. classGetter: function () {
  2134. return this.getAttr('className') || '';
  2135. }
  2136. };
  2137. VMLElement['stroke-opacitySetter'] =
  2138. VMLElement['fill-opacitySetter'];
  2139. H.VMLElement = VMLElement = extendClass(SVGElement, VMLElement);
  2140. // Some shared setters
  2141. VMLElement.prototype.ySetter =
  2142. VMLElement.prototype.widthSetter =
  2143. VMLElement.prototype.heightSetter =
  2144. VMLElement.prototype.xSetter;
  2145. /**
  2146. * The VML renderer
  2147. *
  2148. * @private
  2149. * @class
  2150. * @name Highcharts.VMLRenderer
  2151. *
  2152. * @augments Highcharts.SVGRenderer
  2153. */
  2154. var VMLRendererExtension = {
  2155. Element: VMLElement,
  2156. isIE8: win.navigator.userAgent.indexOf('MSIE 8.0') > -1,
  2157. /**
  2158. * Initialize the VMLRenderer.
  2159. *
  2160. * @function Highcharts.VMLRenderer#init
  2161. * @param {Highcharts.HTMLDOMElement} container
  2162. * @param {number} width
  2163. * @param {number} height
  2164. * @return {void}
  2165. */
  2166. init: function (container,
  2167. width,
  2168. height) {
  2169. var renderer = this,
  2170. boxWrapper,
  2171. box,
  2172. css;
  2173. // Extended SVGRenderer member
  2174. this.crispPolyLine = SVGRenderer.prototype.crispPolyLine;
  2175. renderer.alignedObjects = [];
  2176. boxWrapper = renderer.createElement('div')
  2177. .css({ position: 'relative' });
  2178. box = boxWrapper.element;
  2179. container.appendChild(boxWrapper.element);
  2180. // generate the containing box
  2181. renderer.isVML = true;
  2182. renderer.box = box;
  2183. renderer.boxWrapper = boxWrapper;
  2184. renderer.gradients = {};
  2185. renderer.cache = {}; // Cache for numerical bounding boxes
  2186. renderer.cacheKeys = [];
  2187. renderer.imgCount = 0;
  2188. renderer.setSize(width, height, false);
  2189. // The only way to make IE6 and IE7 print is to use a global
  2190. // namespace. However, with IE8 the only way to make the dynamic
  2191. // shapes visible in screen and print mode seems to be to add the
  2192. // xmlns attribute and the behaviour style inline.
  2193. if (!doc.namespaces.hcv) {
  2194. doc.namespaces.add('hcv', 'urn:schemas-microsoft-com:vml');
  2195. // Setup default CSS (#2153, #2368, #2384)
  2196. css = 'hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke' +
  2197. '{ behavior:url(#default#VML); display: inline-block; } ';
  2198. try {
  2199. doc.createStyleSheet().cssText = css;
  2200. }
  2201. catch (e) {
  2202. doc.styleSheets[0].cssText += css;
  2203. }
  2204. }
  2205. },
  2206. /**
  2207. * Detect whether the renderer is hidden. This happens when one of the
  2208. * parent elements has display: none
  2209. *
  2210. * @function Highcharts.VMLRenderer#isHidden
  2211. */
  2212. isHidden: function () {
  2213. return !this.box.offsetWidth;
  2214. },
  2215. /**
  2216. * Define a clipping rectangle. In VML it is accomplished by storing the
  2217. * values for setting the CSS style to all associated members.
  2218. *
  2219. * @function Highcharts.VMLRenderer#clipRect
  2220. * @param {number|Highcharts.SizeObject} x
  2221. * @param {number} y
  2222. * @param {number} width
  2223. * @param {number} height
  2224. * @return {Highcharts.VMLElement}
  2225. */
  2226. clipRect: function (x, y, width, height) {
  2227. // create a dummy element
  2228. var clipRect = this.createElement(),
  2229. isObj = isObject(x);
  2230. // mimic a rectangle with its style object for automatic updating in
  2231. // attr
  2232. return extend(clipRect, {
  2233. members: [],
  2234. count: 0,
  2235. left: (isObj ? x.x : x) + 1,
  2236. top: (isObj ? x.y : y) + 1,
  2237. width: (isObj ? x.width : width) - 1,
  2238. height: (isObj ? x.height : height) - 1,
  2239. getCSS: function (wrapper) {
  2240. var element = wrapper.element, nodeName = element.nodeName, isShape = nodeName === 'shape', inverted = wrapper.inverted, rect = this, top = rect.top - (isShape ? element.offsetTop : 0), left = rect.left, right = left + rect.width, bottom = top + rect.height, ret = {
  2241. clip: 'rect(' +
  2242. Math.round(inverted ? left : top) + 'px,' +
  2243. Math.round(inverted ? bottom : right) + 'px,' +
  2244. Math.round(inverted ? right : bottom) + 'px,' +
  2245. Math.round(inverted ? top : left) + 'px)'
  2246. };
  2247. // issue 74 workaround
  2248. if (!inverted && wrapper.docMode8 && nodeName === 'DIV') {
  2249. extend(ret, {
  2250. width: right + 'px',
  2251. height: bottom + 'px'
  2252. });
  2253. }
  2254. return ret;
  2255. },
  2256. // used in attr and animation to update the clipping of all
  2257. // members
  2258. updateClipping: function () {
  2259. clipRect.members.forEach(function (member) {
  2260. // Member.element is falsy on deleted series, like in
  2261. // stock/members/series-remove demo. Should be removed
  2262. // from members, but this will do.
  2263. if (member.element) {
  2264. member.css(clipRect.getCSS(member));
  2265. }
  2266. });
  2267. }
  2268. });
  2269. },
  2270. /**
  2271. * Take a color and return it if it's a string, make it a gradient if
  2272. * it's a gradient configuration object, and apply opacity.
  2273. *
  2274. * @function Highcharts.VMLRenderer#color<T>
  2275. *
  2276. * @param {T} color
  2277. * The color or config object
  2278. *
  2279. * @return {T}
  2280. */
  2281. color: function (colorOption, elem, prop, wrapper) {
  2282. var renderer = this,
  2283. colorObject,
  2284. regexRgba = /^rgba/,
  2285. markup,
  2286. fillType,
  2287. ret = 'none';
  2288. // Check for linear or radial gradient
  2289. if (colorOption &&
  2290. colorOption.linearGradient) {
  2291. fillType = 'gradient';
  2292. }
  2293. else if (colorOption &&
  2294. colorOption.radialGradient) {
  2295. fillType = 'pattern';
  2296. }
  2297. if (fillType) {
  2298. var stopColor, stopOpacity, gradient = (colorOption.linearGradient ||
  2299. colorOption.radialGradient), x1, y1, x2, y2, opacity1, opacity2, color1, color2, fillAttr = '', stops = colorOption.stops, firstStop, lastStop, colors = [], addFillNode = function () {
  2300. // Add the fill subnode. When colors attribute is used,
  2301. // the meanings of opacity and o:opacity2 are reversed.
  2302. markup = ['<fill colors="' + colors.join(',') +
  2303. '" opacity="', opacity2, '" o:opacity2="',
  2304. opacity1, '" type="', fillType, '" ', fillAttr,
  2305. 'focus="100%" method="any" />'];
  2306. createElement(renderer.prepVML(markup), null, null, elem);
  2307. };
  2308. // Extend from 0 to 1
  2309. firstStop = stops[0];
  2310. lastStop = stops[stops.length - 1];
  2311. if (firstStop[0] > 0) {
  2312. stops.unshift([
  2313. 0,
  2314. firstStop[1]
  2315. ]);
  2316. }
  2317. if (lastStop[0] < 1) {
  2318. stops.push([
  2319. 1,
  2320. lastStop[1]
  2321. ]);
  2322. }
  2323. // Compute the stops
  2324. stops.forEach(function (stop, i) {
  2325. if (regexRgba.test(stop[1])) {
  2326. colorObject = color(stop[1]);
  2327. stopColor = colorObject.get('rgb');
  2328. stopOpacity = colorObject.get('a');
  2329. }
  2330. else {
  2331. stopColor = stop[1];
  2332. stopOpacity = 1;
  2333. }
  2334. // Build the color attribute
  2335. colors.push((stop[0] * 100) + '% ' + stopColor);
  2336. // Only start and end opacities are allowed, so we use the
  2337. // first and the last
  2338. if (!i) {
  2339. opacity1 = stopOpacity;
  2340. color2 = stopColor;
  2341. }
  2342. else {
  2343. opacity2 = stopOpacity;
  2344. color1 = stopColor;
  2345. }
  2346. });
  2347. // Apply the gradient to fills only.
  2348. if (prop === 'fill') {
  2349. // Handle linear gradient angle
  2350. if (fillType === 'gradient') {
  2351. x1 = gradient.x1 || gradient[0] || 0;
  2352. y1 = gradient.y1 || gradient[1] || 0;
  2353. x2 = gradient.x2 || gradient[2] || 0;
  2354. y2 = gradient.y2 || gradient[3] || 0;
  2355. fillAttr = 'angle="' + (90 - Math.atan((y2 - y1) / // y vector
  2356. (x2 - x1) // x vector
  2357. ) * 180 / Math.PI) + '"';
  2358. addFillNode();
  2359. // Radial (circular) gradient
  2360. }
  2361. else {
  2362. var r = gradient.r,
  2363. sizex = r * 2,
  2364. sizey = r * 2,
  2365. cx = gradient.cx,
  2366. cy = gradient.cy,
  2367. radialReference = elem.radialReference,
  2368. bBox,
  2369. applyRadialGradient = function () {
  2370. if (radialReference) {
  2371. bBox = wrapper.getBBox();
  2372. cx += (radialReference[0] - bBox.x) /
  2373. bBox.width - 0.5;
  2374. cy += (radialReference[1] - bBox.y) /
  2375. bBox.height - 0.5;
  2376. sizex *= radialReference[2] / bBox.width;
  2377. sizey *= radialReference[2] / bBox.height;
  2378. }
  2379. fillAttr =
  2380. 'src="' + getOptions().global.VMLRadialGradientURL +
  2381. '" ' +
  2382. 'size="' + sizex + ',' + sizey + '" ' +
  2383. 'origin="0.5,0.5" ' +
  2384. 'position="' + cx + ',' + cy + '" ' +
  2385. 'color2="' + color2 + '" ';
  2386. addFillNode();
  2387. };
  2388. // Apply radial gradient
  2389. if (wrapper.added) {
  2390. applyRadialGradient();
  2391. }
  2392. else {
  2393. // We need to know the bounding box to get the size
  2394. // and position right
  2395. wrapper.onAdd = applyRadialGradient;
  2396. }
  2397. // The fill element's color attribute is broken in IE8
  2398. // standards mode, so we need to set the parent shape's
  2399. // fillcolor attribute instead.
  2400. ret = color1;
  2401. }
  2402. // Gradients are not supported for VML stroke, return the first
  2403. // color. #722.
  2404. }
  2405. else {
  2406. ret = stopColor;
  2407. }
  2408. // If the color is an rgba color, split it and add a fill node
  2409. // to hold the opacity component
  2410. }
  2411. else if (regexRgba.test(colorOption) && elem.tagName !== 'IMG') {
  2412. colorObject = color(colorOption);
  2413. wrapper[prop + '-opacitySetter'](colorObject.get('a'), prop, elem);
  2414. ret = colorObject.get('rgb');
  2415. }
  2416. else {
  2417. // 'stroke' or 'fill' node
  2418. var propNodes = elem.getElementsByTagName(prop);
  2419. if (propNodes.length) {
  2420. propNodes[0].opacity = 1;
  2421. propNodes[0].type = 'solid';
  2422. }
  2423. ret = colorOption;
  2424. }
  2425. return ret;
  2426. },
  2427. /**
  2428. * Take a VML string and prepare it for either IE8 or IE6/IE7.
  2429. *
  2430. * @function Highcharts.VMLRenderer#prepVML
  2431. *
  2432. * @param {Array<(number|string)>} markup
  2433. * A string array of the VML markup to prepare
  2434. *
  2435. * @return {string}
  2436. */
  2437. prepVML: function (markup) {
  2438. var vmlStyle = 'display:inline-block;behavior:url(#default#VML);',
  2439. isIE8 = this.isIE8;
  2440. markup = markup.join('');
  2441. if (isIE8) { // add xmlns and style inline
  2442. markup = markup.replace('/>', ' xmlns="urn:schemas-microsoft-com:vml" />');
  2443. if (markup.indexOf('style="') === -1) {
  2444. markup = markup.replace('/>', ' style="' + vmlStyle + '" />');
  2445. }
  2446. else {
  2447. markup = markup.replace('style="', 'style="' + vmlStyle);
  2448. }
  2449. }
  2450. else { // add namespace
  2451. markup = markup.replace('<', '<hcv:');
  2452. }
  2453. return markup;
  2454. },
  2455. /**
  2456. * Create rotated and aligned text
  2457. *
  2458. * @function Highcharts.VMLRenderer#text
  2459. *
  2460. * @param {string} str
  2461. *
  2462. * @param {number} x
  2463. *
  2464. * @param {number} y
  2465. */
  2466. text: SVGRenderer.prototype.html,
  2467. /**
  2468. * Create and return a path element
  2469. *
  2470. * @function Highcharts.VMLRenderer#path
  2471. *
  2472. * @param {Highcharts.VMLAttributes|Highcharts.VMLPathArray} [path]
  2473. */
  2474. path: function (path) {
  2475. var attr = {
  2476. // subpixel precision down to 0.1 (width and height = 1px)
  2477. coordsize: '10 10'
  2478. };
  2479. if (isArray(path)) {
  2480. attr.d = path;
  2481. }
  2482. else if (isObject(path)) { // attributes
  2483. extend(attr, path);
  2484. }
  2485. // create the shape
  2486. return this.createElement('shape').attr(attr);
  2487. },
  2488. /**
  2489. * Create and return a circle element. In VML circles are implemented as
  2490. * shapes, which is faster than v:oval
  2491. *
  2492. * @function Highcharts.VMLRenderer#circle
  2493. * @param {number|Highcharts.Dictionary<number>} x
  2494. * @param {number} [y]
  2495. * @param {number} [r]
  2496. * @return {Highcharts.VMLElement}
  2497. */
  2498. circle: function (x, y, r) {
  2499. var circle = this.symbol('circle');
  2500. if (isObject(x)) {
  2501. r = x.r;
  2502. y = x.y;
  2503. x = x.x;
  2504. }
  2505. circle.isCircle = true; // Causes x and y to mean center (#1682)
  2506. circle.r = r;
  2507. return circle.attr({ x: x, y: y });
  2508. },
  2509. /**
  2510. * Create a group using an outer div and an inner v:group to allow
  2511. * rotating and flipping. A simple v:group would have problems with
  2512. * positioning child HTML elements and CSS clip.
  2513. *
  2514. * @function Highcharts.VMLRenderer#g
  2515. *
  2516. * @param {string} name
  2517. * The name of the group
  2518. *
  2519. * @return {Highcharts.VMLElement}
  2520. */
  2521. g: function (name) {
  2522. var wrapper,
  2523. attribs;
  2524. // set the class name
  2525. if (name) {
  2526. attribs = {
  2527. 'className': 'highcharts-' + name,
  2528. 'class': 'highcharts-' + name
  2529. };
  2530. }
  2531. // the div to hold HTML and clipping
  2532. wrapper = this.createElement('div').attr(attribs);
  2533. return wrapper;
  2534. },
  2535. /**
  2536. * VML override to create a regular HTML image.
  2537. *
  2538. * @function Highcharts.VMLRenderer#image
  2539. *
  2540. * @param {string} src
  2541. *
  2542. * @param {number} x
  2543. *
  2544. * @param {number} y
  2545. *
  2546. * @param {number} width
  2547. *
  2548. * @param {number} height
  2549. * @return {Highcharts.VMLElement}
  2550. */
  2551. image: function (src, x, y, width, height) {
  2552. var obj = this.createElement('img').attr({ src: src });
  2553. if (arguments.length > 1) {
  2554. obj.attr({
  2555. x: x,
  2556. y: y,
  2557. width: width,
  2558. height: height
  2559. });
  2560. }
  2561. return obj;
  2562. },
  2563. /**
  2564. * For rectangles, VML uses a shape for rect to overcome bugs and
  2565. * rotation problems
  2566. *
  2567. * @function Highcharts.VMLRenderer#createElement
  2568. * @param {string} nodeName
  2569. * @return {Highcharts.VMLElement}
  2570. */
  2571. createElement: function (nodeName) {
  2572. return nodeName === 'rect' ?
  2573. this.symbol(nodeName) :
  2574. SVGRenderer.prototype.createElement.call(this, nodeName);
  2575. },
  2576. /**
  2577. * In the VML renderer, each child of an inverted div (group) is
  2578. * inverted
  2579. *
  2580. * @function Highcharts.VMLRenderer#invertChild
  2581. *
  2582. * @param {Highcharts.HTMLDOMElement} element
  2583. *
  2584. * @param {Highcharts.HTMLDOMElement} parentNode
  2585. */
  2586. invertChild: function (element, parentNode) {
  2587. var ren = this,
  2588. parentStyle = parentNode.style,
  2589. imgStyle = element.tagName === 'IMG' && element.style; // #1111
  2590. css(element, {
  2591. flip: 'x',
  2592. left: pInt(parentStyle.width) -
  2593. (imgStyle ? pInt(imgStyle.top) : 1),
  2594. top: pInt(parentStyle.height) -
  2595. (imgStyle ? pInt(imgStyle.left) : 1),
  2596. rotation: -90
  2597. });
  2598. // Recursively invert child elements, needed for nested composite
  2599. // shapes like box plots and error bars. #1680, #1806.
  2600. [].forEach.call(element.childNodes, function (child) {
  2601. ren.invertChild(child, element);
  2602. });
  2603. },
  2604. /**
  2605. * Symbol definitions that override the parent SVG renderer's symbols
  2606. *
  2607. * @name Highcharts.VMLRenderer#symbols
  2608. * @type {Highcharts.Dictionary<Function>}
  2609. */
  2610. symbols: {
  2611. // VML specific arc function
  2612. arc: function (x, y, w, h, options) {
  2613. var start = options.start,
  2614. end = options.end,
  2615. radius = options.r || w || h,
  2616. innerRadius = options.innerR,
  2617. cosStart = Math.cos(start),
  2618. sinStart = Math.sin(start),
  2619. cosEnd = Math.cos(end),
  2620. sinEnd = Math.sin(end),
  2621. ret;
  2622. if (end - start === 0) { // no angle, don't show it.
  2623. return ['x'];
  2624. }
  2625. ret = [
  2626. 'wa',
  2627. x - radius,
  2628. y - radius,
  2629. x + radius,
  2630. y + radius,
  2631. x + radius * cosStart,
  2632. y + radius * sinStart,
  2633. x + radius * cosEnd,
  2634. y + radius * sinEnd // end y
  2635. ];
  2636. if (options.open && !innerRadius) {
  2637. ret.push('e', 'M', x, // - innerRadius,
  2638. y // - innerRadius
  2639. );
  2640. }
  2641. ret.push('at', // anti clockwise arc to
  2642. x - innerRadius, // left
  2643. y - innerRadius, // top
  2644. x + innerRadius, // right
  2645. y + innerRadius, // bottom
  2646. x + innerRadius * cosEnd, // start x
  2647. y + innerRadius * sinEnd, // start y
  2648. x + innerRadius * cosStart, // end x
  2649. y + innerRadius * sinStart, // end y
  2650. 'x', // finish path
  2651. 'e' // close
  2652. );
  2653. ret.isArc = true;
  2654. return ret;
  2655. },
  2656. // Add circle symbol path. This performs significantly faster than
  2657. // v:oval.
  2658. circle: function (x, y, w, h, wrapper) {
  2659. if (wrapper && defined(wrapper.r)) {
  2660. w = h = 2 * wrapper.r;
  2661. }
  2662. // Center correction, #1682
  2663. if (wrapper && wrapper.isCircle) {
  2664. x -= w / 2;
  2665. y -= h / 2;
  2666. }
  2667. // Return the path
  2668. return [
  2669. 'wa',
  2670. x,
  2671. y,
  2672. x + w,
  2673. y + h,
  2674. x + w,
  2675. y + h / 2,
  2676. x + w,
  2677. y + h / 2,
  2678. 'e' // close
  2679. ];
  2680. },
  2681. /**
  2682. * Add rectangle symbol path which eases rotation and omits arcsize
  2683. * problems compared to the built-in VML roundrect shape. When
  2684. * borders are not rounded, use the simpler square path, else use
  2685. * the callout path without the arrow.
  2686. */
  2687. rect: function (x, y, w, h, options) {
  2688. return SVGRenderer.prototype.symbols[!defined(options) || !options.r ? 'square' : 'callout'].call(0, x, y, w, h, options);
  2689. }
  2690. }
  2691. };
  2692. H.VMLRenderer = VMLRenderer = function () {
  2693. this.init.apply(this, arguments);
  2694. };
  2695. VMLRenderer.prototype = merge(VMLRenderer.prototype, SVGRenderer.prototype, VMLRendererExtension);
  2696. // general renderer
  2697. H.Renderer = VMLRenderer;
  2698. // 3D additions
  2699. VMLRenderer3D.compose(VMLRenderer, SVGRenderer);
  2700. }
  2701. SVGRenderer.prototype.getSpanWidth = function (wrapper, tspan) {
  2702. var renderer = this,
  2703. bBox = wrapper.getBBox(true),
  2704. actualWidth = bBox.width;
  2705. // Old IE cannot measure the actualWidth for SVG elements (#2314)
  2706. if (!svg && renderer.forExport) {
  2707. actualWidth = renderer.measureSpanWidth(tspan.firstChild.data, wrapper.styles);
  2708. }
  2709. return actualWidth;
  2710. };
  2711. // This method is used with exporting in old IE, when emulating SVG (see #2314)
  2712. SVGRenderer.prototype.measureSpanWidth = function (text, styles) {
  2713. var measuringSpan = doc.createElement('span'),
  2714. offsetWidth,
  2715. textNode = doc.createTextNode(text);
  2716. measuringSpan.appendChild(textNode);
  2717. css(measuringSpan, styles);
  2718. this.box.appendChild(measuringSpan);
  2719. offsetWidth = measuringSpan.offsetWidth;
  2720. discardElement(measuringSpan); // #2463
  2721. return offsetWidth;
  2722. };
  2723. });
  2724. _registerModule(_modules, 'masters/modules/oldie.src.js', [], function () {
  2725. });
  2726. }));