Oldie.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * Support for old IE browsers (6, 7 and 8) in Highcharts v6+.
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. import Chart from '../../Core/Chart/Chart.js';
  14. import Color from '../../Core/Color/Color.js';
  15. var color = Color.parse;
  16. import H from '../../Core/Globals.js';
  17. var deg2rad = H.deg2rad, doc = H.doc, noop = H.noop, svg = H.svg, win = H.win;
  18. import O from '../../Core/Options.js';
  19. var getOptions = O.getOptions;
  20. import palette from '../../Core/Color/Palette.js';
  21. import Pointer from '../../Core/Pointer.js';
  22. import SVGElement from '../../Core/Renderer/SVG/SVGElement.js';
  23. import SVGRenderer from '../../Core/Renderer/SVG/SVGRenderer3D.js';
  24. import U from '../../Core/Utilities.js';
  25. var addEvent = U.addEvent, createElement = U.createElement, css = U.css, defined = U.defined, discardElement = U.discardElement, erase = U.erase, extend = U.extend, extendClass = U.extendClass, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, pick = U.pick, pInt = U.pInt, uniqueKey = U.uniqueKey;
  26. import VMLRenderer3D from './VMLRenderer3D.js';
  27. var VMLRenderer, VMLElement;
  28. /**
  29. * Path to the pattern image required by VML browsers in order to
  30. * draw radial gradients.
  31. *
  32. * @type {string}
  33. * @default http://code.highcharts.com/{version}/gfx/vml-radial-gradient.png
  34. * @since 2.3.0
  35. * @requires modules/oldie
  36. * @apioption global.VMLRadialGradientURL
  37. */
  38. getOptions().global.VMLRadialGradientURL =
  39. 'http://code.highcharts.com/9.1.0/gfx/vml-radial-gradient.png';
  40. // Utilites
  41. if (doc && !doc.defaultView) {
  42. H.getStyle = U.getStyle = function getStyle(el, prop) {
  43. var val, alias = {
  44. width: 'clientWidth',
  45. height: 'clientHeight'
  46. }[prop];
  47. if (el.style[prop]) {
  48. return pInt(el.style[prop]);
  49. }
  50. if (prop === 'opacity') {
  51. prop = 'filter';
  52. }
  53. // Getting the rendered width and height
  54. if (alias) {
  55. el.style.zoom = 1;
  56. return Math.max(el[alias] - 2 * getStyle(el, 'padding'), 0);
  57. }
  58. val = el.currentStyle[prop.replace(/\-(\w)/g, function (a, b) {
  59. return b.toUpperCase();
  60. })];
  61. if (prop === 'filter') {
  62. val = val.replace(/alpha\(opacity=([0-9]+)\)/, function (a, b) {
  63. return (b / 100);
  64. });
  65. }
  66. return val === '' ? 1 : pInt(val);
  67. };
  68. }
  69. /* eslint-disable no-invalid-this, valid-jsdoc */
  70. if (!svg) {
  71. // Prevent wrapping from creating false offsetWidths in export in legacy IE.
  72. // This applies only to charts for export, where IE runs the SVGRenderer
  73. // instead of the VMLRenderer
  74. // (#1079, #1063)
  75. addEvent(SVGElement, 'afterInit', function () {
  76. if (this.element.nodeName === 'text') {
  77. this.css({
  78. position: 'absolute'
  79. });
  80. }
  81. });
  82. /**
  83. * Old IE override for pointer normalize, adds chartX and chartY to event
  84. * arguments.
  85. *
  86. * @ignore
  87. * @function Highcharts.Pointer#normalize
  88. * @param {global.PointerEvent} e
  89. * @param {boolean} [chartPosition=false]
  90. * @return {Highcharts.PointerEventObject}
  91. */
  92. Pointer.prototype.normalize = function (e, chartPosition) {
  93. e = e || win.event;
  94. if (!e.target) {
  95. e.target = e.srcElement;
  96. }
  97. // Get mouse position
  98. if (!chartPosition) {
  99. this.chartPosition = chartPosition = this.getChartPosition();
  100. }
  101. return extend(e, {
  102. // #2005, #2129: the second case is for IE10 quirks mode within
  103. // framesets
  104. chartX: Math.round(Math.max(e.x, e.clientX - chartPosition.left)),
  105. chartY: Math.round(e.y)
  106. });
  107. };
  108. /**
  109. * Further sanitize the mock-SVG that is generated when exporting charts in
  110. * oldIE.
  111. *
  112. * @private
  113. * @function Highcharts.Chart#ieSanitizeSVG
  114. */
  115. Chart.prototype.ieSanitizeSVG = function (svg) {
  116. svg = svg
  117. .replace(/<IMG /g, '<image ')
  118. .replace(/<(\/?)TITLE>/g, '<$1title>')
  119. .replace(/height=([^" ]+)/g, 'height="$1"')
  120. .replace(/width=([^" ]+)/g, 'width="$1"')
  121. .replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>')
  122. .replace(/ id=([^" >]+)/g, ' id="$1"') // #4003
  123. .replace(/class=([^" >]+)/g, 'class="$1"')
  124. .replace(/ transform /g, ' ')
  125. .replace(/:(path|rect)/g, '$1')
  126. .replace(/style="([^"]+)"/g, function (s) {
  127. return s.toLowerCase();
  128. });
  129. return svg;
  130. };
  131. /**
  132. * VML namespaces can't be added until after complete. Listening
  133. * for Perini's doScroll hack is not enough.
  134. *
  135. * @private
  136. * @function Highcharts.Chart#isReadyToRender
  137. */
  138. Chart.prototype.isReadyToRender = function () {
  139. var chart = this;
  140. // Note: win == win.top is required
  141. if (!svg &&
  142. (win == win.top && // eslint-disable-line eqeqeq
  143. doc.readyState !== 'complete')) {
  144. doc.attachEvent('onreadystatechange', function () {
  145. doc.detachEvent('onreadystatechange', chart.firstRender);
  146. if (doc.readyState === 'complete') {
  147. chart.firstRender();
  148. }
  149. });
  150. return false;
  151. }
  152. return true;
  153. };
  154. // IE compatibility hack for generating SVG content that it doesn't really
  155. // understand. Used by the exporting module.
  156. if (!doc.createElementNS) {
  157. doc.createElementNS = function (ns, tagName) {
  158. return doc.createElement(tagName);
  159. };
  160. }
  161. /**
  162. * Old IE polyfill for addEventListener, called from inside the addEvent
  163. * function.
  164. *
  165. * @private
  166. * @function Highcharts.addEventListenerPolyfill<T>
  167. * @param {string} type
  168. * @param {Highcharts.EventCallbackFunction<T>} fn
  169. * @return {void}
  170. */
  171. H.addEventListenerPolyfill = function (type, fn) {
  172. var el = this;
  173. /**
  174. * @private
  175. */
  176. function wrappedFn(e) {
  177. e.target = e.srcElement || win; // #2820
  178. fn.call(el, e);
  179. }
  180. if (el.attachEvent) {
  181. if (!el.hcEventsIE) {
  182. el.hcEventsIE = {};
  183. }
  184. // unique function string (#6746)
  185. if (!fn.hcKey) {
  186. fn.hcKey = uniqueKey();
  187. }
  188. // Link wrapped fn with original fn, so we can get this in
  189. // removeEvent
  190. el.hcEventsIE[fn.hcKey] = wrappedFn;
  191. el.attachEvent('on' + type, wrappedFn);
  192. }
  193. };
  194. /**
  195. * @private
  196. * @function Highcharts.removeEventListenerPolyfill<T>
  197. * @param {string} type
  198. * @param {Highcharts.EventCallbackFunction<T>} fn
  199. * @return {void}
  200. */
  201. H.removeEventListenerPolyfill = function (type, fn) {
  202. if (this.detachEvent) {
  203. fn = this.hcEventsIE[fn.hcKey];
  204. this.detachEvent('on' + type, fn);
  205. }
  206. };
  207. /**
  208. * The VML element wrapper.
  209. *
  210. * @private
  211. * @class
  212. * @name Highcharts.VMLElement
  213. *
  214. * @augments Highcharts.SVGElement
  215. */
  216. VMLElement = {
  217. docMode8: doc && doc.documentMode === 8,
  218. /**
  219. * Initialize a new VML element wrapper. It builds the markup as a
  220. * string to minimize DOM traffic.
  221. *
  222. * @function Highcharts.VMLElement#init
  223. * @param {Highcharts.VMLRenderer} renderer
  224. * @param {string} nodeName
  225. */
  226. init: function (renderer, nodeName) {
  227. var wrapper = this, markup = ['<', nodeName, ' filled="f" stroked="f"'], style = ['position: ', 'absolute', ';'], isDiv = nodeName === 'div';
  228. // divs and shapes need size
  229. if (nodeName === 'shape' || isDiv) {
  230. style.push('left:0;top:0;width:1px;height:1px;');
  231. }
  232. style.push('visibility: ', isDiv ? 'hidden' : 'visible');
  233. markup.push(' style="', style.join(''), '"/>');
  234. // create element with default attributes and style
  235. if (nodeName) {
  236. markup = isDiv || nodeName === 'span' || nodeName === 'img' ?
  237. markup.join('') :
  238. renderer.prepVML(markup);
  239. wrapper.element = createElement(markup);
  240. }
  241. wrapper.renderer = renderer;
  242. },
  243. /**
  244. * Add the node to the given parent
  245. *
  246. * @function Highcharts.VMLElement
  247. * @param {Highcharts.VMLElement} parent
  248. * @return {Highcharts.VMLElement}
  249. */
  250. add: function (parent) {
  251. var wrapper = this, renderer = wrapper.renderer, element = wrapper.element, box = renderer.box, inverted = parent && parent.inverted,
  252. // get the parent node
  253. parentNode = parent ?
  254. parent.element || parent :
  255. box;
  256. if (parent) {
  257. this.parentGroup = parent;
  258. }
  259. // if the parent group is inverted, apply inversion on all children
  260. if (inverted) { // only on groups
  261. renderer.invertChild(element, parentNode);
  262. }
  263. // append it
  264. parentNode.appendChild(element);
  265. // align text after adding to be able to read offset
  266. wrapper.added = true;
  267. if (wrapper.alignOnAdd && !wrapper.deferUpdateTransform) {
  268. wrapper.updateTransform();
  269. }
  270. // fire an event for internal hooks
  271. if (wrapper.onAdd) {
  272. wrapper.onAdd();
  273. }
  274. // IE8 Standards can't set the class name before the element is
  275. // appended
  276. if (this.className) {
  277. this.attr('class', this.className);
  278. }
  279. return wrapper;
  280. },
  281. /**
  282. * VML always uses htmlUpdateTransform
  283. *
  284. * @function Highcharts.VMLElement#updateTransform
  285. */
  286. updateTransform: SVGElement.prototype.htmlUpdateTransform,
  287. /**
  288. * Set the rotation of a span with oldIE's filter
  289. *
  290. * @function Highcharts.VMLElement#setSpanRotation
  291. * @return {void}
  292. */
  293. setSpanRotation: function () {
  294. // Adjust for alignment and rotation. Rotation of useHTML content is
  295. // not yet implemented but it can probably be implemented for
  296. // Firefox 3.5+ on user request. FF3.5+ has support for CSS3
  297. // transform. The getBBox method also needs to be updated to
  298. // compensate for the rotation, like it currently does for SVG.
  299. // Test case: https://jsfiddle.net/highcharts/Ybt44/
  300. var rotation = this.rotation, costheta = Math.cos(rotation * deg2rad), sintheta = Math.sin(rotation * deg2rad);
  301. css(this.element, {
  302. filter: rotation ? [
  303. 'progid:DXImageTransform.Microsoft.Matrix(M11=', costheta,
  304. ', M12=', -sintheta, ', M21=', sintheta, ', M22=', costheta,
  305. ', sizingMethod=\'auto expand\')'
  306. ].join('') : 'none'
  307. });
  308. },
  309. /**
  310. * Get the positioning correction for the span after rotating.
  311. *
  312. * @function Highcharts.VMLElement#getSpanCorrection
  313. */
  314. getSpanCorrection: function (width, baseline, alignCorrection, rotation, align) {
  315. var costheta = rotation ? Math.cos(rotation * deg2rad) : 1, sintheta = rotation ? Math.sin(rotation * deg2rad) : 0, height = pick(this.elemHeight, this.element.offsetHeight), quad, nonLeft = align && align !== 'left';
  316. // correct x and y
  317. this.xCorr = (costheta < 0 && -width);
  318. this.yCorr = (sintheta < 0 && -height);
  319. // correct for baseline and corners spilling out after rotation
  320. quad = costheta * sintheta < 0;
  321. this.xCorr += (sintheta *
  322. baseline *
  323. (quad ? 1 - alignCorrection : alignCorrection));
  324. this.yCorr -= (costheta *
  325. baseline *
  326. (rotation ? (quad ? alignCorrection : 1 - alignCorrection) : 1));
  327. // correct for the length/height of the text
  328. if (nonLeft) {
  329. this.xCorr -=
  330. width * alignCorrection * (costheta < 0 ? -1 : 1);
  331. if (rotation) {
  332. this.yCorr -= (height *
  333. alignCorrection *
  334. (sintheta < 0 ? -1 : 1));
  335. }
  336. css(this.element, {
  337. textAlign: align
  338. });
  339. }
  340. },
  341. /**
  342. * Converts a subset of an SVG path definition to its VML counterpart.
  343. * Takes an array as the parameter and returns a string.
  344. *
  345. * @function Highcharts.VMLElement#pathToVML
  346. */
  347. pathToVML: function (value) {
  348. // convert paths
  349. var i = value.length, path = [];
  350. while (i--) {
  351. // Multiply by 10 to allow subpixel precision.
  352. // Substracting half a pixel seems to make the coordinates
  353. // align with SVG, but this hasn't been tested thoroughly
  354. if (isNumber(value[i])) {
  355. path[i] = Math.round(value[i] * 10) - 5;
  356. }
  357. else if (value[i] === 'Z') { // close the path
  358. path[i] = 'x';
  359. }
  360. else {
  361. path[i] = value[i];
  362. // When the start X and end X coordinates of an arc are too
  363. // close, they are rounded to the same value above. In this
  364. // case, substract or add 1 from the end X and Y positions.
  365. // #186, #760, #1371, #1410.
  366. if (value.isArc &&
  367. (value[i] === 'wa' || value[i] === 'at')) {
  368. // Start and end X
  369. if (path[i + 5] === path[i + 7]) {
  370. path[i + 7] +=
  371. value[i + 7] > value[i + 5] ? 1 : -1;
  372. }
  373. // Start and end Y
  374. if (path[i + 6] === path[i + 8]) {
  375. path[i + 8] +=
  376. value[i + 8] > value[i + 6] ? 1 : -1;
  377. }
  378. }
  379. }
  380. }
  381. return path.join(' ') || 'x';
  382. },
  383. /**
  384. * Set the element's clipping to a predefined rectangle
  385. *
  386. * @function Highcharts.VMLElement#clip
  387. * @param {Highcharts.VMLClipRectObject} clipRect
  388. * @return {Highcharts.VMLElement}
  389. */
  390. clip: function (clipRect) {
  391. var wrapper = this, clipMembers, cssRet;
  392. if (clipRect) {
  393. clipMembers = clipRect.members;
  394. // Ensure unique list of elements (#1258)
  395. erase(clipMembers, wrapper);
  396. clipMembers.push(wrapper);
  397. wrapper.destroyClip = function () {
  398. erase(clipMembers, wrapper);
  399. };
  400. cssRet = clipRect.getCSS(wrapper);
  401. }
  402. else {
  403. if (wrapper.destroyClip) {
  404. wrapper.destroyClip();
  405. }
  406. cssRet = {
  407. clip: wrapper.docMode8 ? 'inherit' : 'rect(auto)'
  408. }; // #1214
  409. }
  410. return wrapper.css(cssRet);
  411. },
  412. /**
  413. * Set styles for the element
  414. *
  415. * @function Highcharts.VMLElement#css
  416. * @param {Highcharts.CSSObject} styles
  417. * @return {Highcharts.VMLElement}
  418. */
  419. css: SVGElement.prototype.htmlCss,
  420. /**
  421. * Removes a child either by removeChild or move to garbageBin.
  422. * Issue 490; in VML removeChild results in Orphaned nodes according to
  423. * sIEve, discardElement does not.
  424. *
  425. * @function Highcharts.VMLElement#safeRemoveChild
  426. * @param {Highcharts.HTMLDOMElement} element
  427. * @return {void}
  428. */
  429. safeRemoveChild: function (element) {
  430. // discardElement will detach the node from its parent before
  431. // attaching it to the garbage bin. Therefore it is important that
  432. // the node is attached and have parent.
  433. if (element.parentNode) {
  434. discardElement(element);
  435. }
  436. },
  437. /**
  438. * Extend element.destroy by removing it from the clip members array
  439. *
  440. * @function Highcharts.VMLElement#destroy
  441. */
  442. destroy: function () {
  443. if (this.destroyClip) {
  444. this.destroyClip();
  445. }
  446. return SVGElement.prototype.destroy.apply(this);
  447. },
  448. /**
  449. * Add an event listener. VML override for normalizing event parameters.
  450. *
  451. * @function Highcharts.VMLElement#on
  452. * @param {string} eventType
  453. * @param {Function} handler
  454. * @return {Highcharts.VMLElement}
  455. */
  456. on: function (eventType, handler) {
  457. // simplest possible event model for internal use
  458. this.element['on' + eventType] = function () {
  459. var e = win.event;
  460. e.target = e.srcElement;
  461. handler(e);
  462. };
  463. return this;
  464. },
  465. /**
  466. * In stacked columns, cut off the shadows so that they don't overlap
  467. *
  468. * @function Highcharts.VMLElement#cutOffPath
  469. * @param {string} path
  470. * @param {number} length
  471. * @return {string}
  472. */
  473. cutOffPath: function (path, length) {
  474. var len;
  475. // The extra comma tricks the trailing comma remover in
  476. // "gulp scripts" task
  477. path = path.split(/[ ,]/);
  478. len = path.length;
  479. if (len === 9 || len === 11) {
  480. path[len - 4] = path[len - 2] =
  481. pInt(path[len - 2]) - 10 * length;
  482. }
  483. return path.join(' ');
  484. },
  485. /**
  486. * Apply a drop shadow by copying elements and giving them different
  487. * strokes.
  488. *
  489. * @function Highcharts.VMLElement#shadow
  490. * @param {Highcharts.ShadowOptionsObject} shadowOptions
  491. * @param {Highcharts.VMLElement} group
  492. * @param {boolean} cutOff
  493. * @return {Highcharts.VMLElement}
  494. */
  495. shadow: function (shadowOptions, group, cutOff) {
  496. var shadows = [], i, element = this.element, renderer = this.renderer, shadow, elemStyle = element.style, markup, path = element.path, strokeWidth, modifiedPath, shadowWidth, shadowElementOpacity;
  497. // some times empty paths are not strings
  498. if (path && typeof path.value !== 'string') {
  499. path = 'x';
  500. }
  501. modifiedPath = path;
  502. if (shadowOptions) {
  503. shadowWidth = pick(shadowOptions.width, 3);
  504. shadowElementOpacity =
  505. (shadowOptions.opacity || 0.15) / shadowWidth;
  506. for (i = 1; i <= 3; i++) {
  507. strokeWidth = (shadowWidth * 2) + 1 - (2 * i);
  508. // Cut off shadows for stacked column items
  509. if (cutOff) {
  510. modifiedPath = this.cutOffPath(path.value, strokeWidth + 0.5);
  511. }
  512. markup = [
  513. '<shape isShadow="true" strokeweight="', strokeWidth,
  514. '" filled="false" path="', modifiedPath,
  515. '" coordsize="10 10" style="', element.style.cssText,
  516. '" />'
  517. ];
  518. shadow = createElement(renderer.prepVML(markup), null, {
  519. left: (pInt(elemStyle.left) +
  520. pick(shadowOptions.offsetX, 1)) + 'px',
  521. top: (pInt(elemStyle.top) +
  522. pick(shadowOptions.offsetY, 1)) + 'px'
  523. });
  524. if (cutOff) {
  525. shadow.cutOff = strokeWidth + 1;
  526. }
  527. // apply the opacity
  528. markup = [
  529. '<stroke color="',
  530. shadowOptions.color || palette.neutralColor100,
  531. '" opacity="', shadowElementOpacity * i, '"/>'
  532. ];
  533. createElement(renderer.prepVML(markup), null, null, shadow);
  534. // insert it
  535. if (group) {
  536. group.element.appendChild(shadow);
  537. }
  538. else {
  539. element.parentNode
  540. .insertBefore(shadow, element);
  541. }
  542. // record it
  543. shadows.push(shadow);
  544. }
  545. this.shadows = shadows;
  546. }
  547. return this;
  548. },
  549. updateShadows: noop,
  550. setAttr: function (key, value) {
  551. if (this.docMode8) { // IE8 setAttribute bug
  552. this.element[key] = value;
  553. }
  554. else {
  555. this.element.setAttribute(key, value);
  556. }
  557. },
  558. getAttr: function (key) {
  559. if (this.docMode8) { // IE8 setAttribute bug
  560. return this.element[key];
  561. }
  562. return this.element.getAttribute(key);
  563. },
  564. classSetter: function (value) {
  565. // IE8 Standards mode has problems retrieving the className unless
  566. // set like this. IE8 Standards can't set the class name before the
  567. // element is appended.
  568. (this.added ? this.element : this).className = value;
  569. },
  570. dashstyleSetter: function (value, key, element) {
  571. var strokeElem = element.getElementsByTagName('stroke')[0] ||
  572. createElement(this.renderer.prepVML(['<stroke/>']), null, null, element);
  573. strokeElem[key] = value || 'solid';
  574. // Because changing stroke-width will change the dash length and
  575. // cause an epileptic effect
  576. this[key] = value;
  577. },
  578. dSetter: function (value, key, element) {
  579. var i, shadows = this.shadows;
  580. value = value || [];
  581. // Used in getter for animation
  582. this.d = value.join && value.join(' ');
  583. element.path = value = this.pathToVML(value);
  584. // update shadows
  585. if (shadows) {
  586. i = shadows.length;
  587. while (i--) {
  588. shadows[i].path = shadows[i].cutOff ?
  589. this.cutOffPath(value, shadows[i].cutOff) :
  590. value;
  591. }
  592. }
  593. this.setAttr(key, value);
  594. },
  595. fillSetter: function (value, key, element) {
  596. var nodeName = element.nodeName;
  597. if (nodeName === 'SPAN') { // text color
  598. element.style.color = value;
  599. }
  600. else if (nodeName !== 'IMG') { // #1336
  601. element.filled = value !== 'none';
  602. this.setAttr('fillcolor', this.renderer.color(value, element, key, this));
  603. }
  604. },
  605. 'fill-opacitySetter': function (value, key, element) {
  606. createElement(this.renderer.prepVML(['<', key.split('-')[0], ' opacity="', value, '"/>']), null, null, element);
  607. },
  608. // Don't bother - animation is too slow and filters introduce artifacts
  609. opacitySetter: noop,
  610. rotationSetter: function (value, key, element) {
  611. var style = element.style;
  612. // style is for #1873:
  613. this[key] = style[key] = value;
  614. // Correction for the 1x1 size of the shape container. Used in gauge
  615. // needles.
  616. style.left =
  617. -Math.round(Math.sin(value * deg2rad) + 1) + 'px';
  618. style.top =
  619. Math.round(Math.cos(value * deg2rad)) + 'px';
  620. },
  621. strokeSetter: function (value, key, element) {
  622. this.setAttr('strokecolor', this.renderer.color(value, element, key, this));
  623. },
  624. 'stroke-widthSetter': function (value, key, element) {
  625. element.stroked = !!value; // VML "stroked" attribute
  626. this[key] = value; // used in getter, issue #113
  627. if (isNumber(value)) {
  628. value += 'px';
  629. }
  630. this.setAttr('strokeweight', value);
  631. },
  632. titleSetter: function (value, key) {
  633. this.setAttr(key, value);
  634. },
  635. visibilitySetter: function (value, key, element) {
  636. // Handle inherited visibility
  637. if (value === 'inherit') {
  638. value = 'visible';
  639. }
  640. // Let the shadow follow the main element
  641. if (this.shadows) {
  642. this.shadows.forEach(function (shadow) {
  643. shadow.style[key] = value;
  644. });
  645. }
  646. // Instead of toggling the visibility CSS property, move the div out
  647. // of the viewport. This works around #61 and #586
  648. if (element.nodeName === 'DIV') {
  649. value = value === 'hidden' ? '-999em' : 0;
  650. // In order to redraw, IE7 needs the div to be visible when
  651. // tucked away outside the viewport. So the visibility is
  652. // actually opposite of the expected value. This applies to the
  653. // tooltip only.
  654. if (!this.docMode8) {
  655. element.style[key] = value ? 'visible' : 'hidden';
  656. }
  657. key = 'top';
  658. }
  659. element.style[key] = value;
  660. },
  661. xSetter: function (value, key, element) {
  662. this[key] = value; // used in getter
  663. if (key === 'x') {
  664. key = 'left';
  665. }
  666. else if (key === 'y') {
  667. key = 'top';
  668. }
  669. // clipping rectangle special
  670. if (this.updateClipping) {
  671. // the key is now 'left' or 'top' for 'x' and 'y'
  672. this[key] = value;
  673. this.updateClipping();
  674. }
  675. else {
  676. // normal
  677. element.style[key] = value;
  678. }
  679. },
  680. zIndexSetter: function (value, key, element) {
  681. element.style[key] = value;
  682. },
  683. fillGetter: function () {
  684. return this.getAttr('fillcolor') || '';
  685. },
  686. strokeGetter: function () {
  687. return this.getAttr('strokecolor') || '';
  688. },
  689. // #7850
  690. classGetter: function () {
  691. return this.getAttr('className') || '';
  692. }
  693. };
  694. VMLElement['stroke-opacitySetter'] =
  695. VMLElement['fill-opacitySetter'];
  696. H.VMLElement = VMLElement = extendClass(SVGElement, VMLElement);
  697. // Some shared setters
  698. VMLElement.prototype.ySetter =
  699. VMLElement.prototype.widthSetter =
  700. VMLElement.prototype.heightSetter =
  701. VMLElement.prototype.xSetter;
  702. /**
  703. * The VML renderer
  704. *
  705. * @private
  706. * @class
  707. * @name Highcharts.VMLRenderer
  708. *
  709. * @augments Highcharts.SVGRenderer
  710. */
  711. var VMLRendererExtension = {
  712. Element: VMLElement,
  713. isIE8: win.navigator.userAgent.indexOf('MSIE 8.0') > -1,
  714. /**
  715. * Initialize the VMLRenderer.
  716. *
  717. * @function Highcharts.VMLRenderer#init
  718. * @param {Highcharts.HTMLDOMElement} container
  719. * @param {number} width
  720. * @param {number} height
  721. * @return {void}
  722. */
  723. init: function (container, width, height) {
  724. var renderer = this, boxWrapper, box, css;
  725. // Extended SVGRenderer member
  726. this.crispPolyLine = SVGRenderer.prototype.crispPolyLine;
  727. renderer.alignedObjects = [];
  728. boxWrapper = renderer.createElement('div')
  729. .css({ position: 'relative' });
  730. box = boxWrapper.element;
  731. container.appendChild(boxWrapper.element);
  732. // generate the containing box
  733. renderer.isVML = true;
  734. renderer.box = box;
  735. renderer.boxWrapper = boxWrapper;
  736. renderer.gradients = {};
  737. renderer.cache = {}; // Cache for numerical bounding boxes
  738. renderer.cacheKeys = [];
  739. renderer.imgCount = 0;
  740. renderer.setSize(width, height, false);
  741. // The only way to make IE6 and IE7 print is to use a global
  742. // namespace. However, with IE8 the only way to make the dynamic
  743. // shapes visible in screen and print mode seems to be to add the
  744. // xmlns attribute and the behaviour style inline.
  745. if (!doc.namespaces.hcv) {
  746. doc.namespaces.add('hcv', 'urn:schemas-microsoft-com:vml');
  747. // Setup default CSS (#2153, #2368, #2384)
  748. css = 'hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke' +
  749. '{ behavior:url(#default#VML); display: inline-block; } ';
  750. try {
  751. doc.createStyleSheet().cssText = css;
  752. }
  753. catch (e) {
  754. doc.styleSheets[0].cssText += css;
  755. }
  756. }
  757. },
  758. /**
  759. * Detect whether the renderer is hidden. This happens when one of the
  760. * parent elements has display: none
  761. *
  762. * @function Highcharts.VMLRenderer#isHidden
  763. */
  764. isHidden: function () {
  765. return !this.box.offsetWidth;
  766. },
  767. /**
  768. * Define a clipping rectangle. In VML it is accomplished by storing the
  769. * values for setting the CSS style to all associated members.
  770. *
  771. * @function Highcharts.VMLRenderer#clipRect
  772. * @param {number|Highcharts.SizeObject} x
  773. * @param {number} y
  774. * @param {number} width
  775. * @param {number} height
  776. * @return {Highcharts.VMLElement}
  777. */
  778. clipRect: function (x, y, width, height) {
  779. // create a dummy element
  780. var clipRect = this.createElement(), isObj = isObject(x);
  781. // mimic a rectangle with its style object for automatic updating in
  782. // attr
  783. return extend(clipRect, {
  784. members: [],
  785. count: 0,
  786. left: (isObj ? x.x : x) + 1,
  787. top: (isObj ? x.y : y) + 1,
  788. width: (isObj ? x.width : width) - 1,
  789. height: (isObj ? x.height : height) - 1,
  790. getCSS: function (wrapper) {
  791. 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 = {
  792. clip: 'rect(' +
  793. Math.round(inverted ? left : top) + 'px,' +
  794. Math.round(inverted ? bottom : right) + 'px,' +
  795. Math.round(inverted ? right : bottom) + 'px,' +
  796. Math.round(inverted ? top : left) + 'px)'
  797. };
  798. // issue 74 workaround
  799. if (!inverted && wrapper.docMode8 && nodeName === 'DIV') {
  800. extend(ret, {
  801. width: right + 'px',
  802. height: bottom + 'px'
  803. });
  804. }
  805. return ret;
  806. },
  807. // used in attr and animation to update the clipping of all
  808. // members
  809. updateClipping: function () {
  810. clipRect.members.forEach(function (member) {
  811. // Member.element is falsy on deleted series, like in
  812. // stock/members/series-remove demo. Should be removed
  813. // from members, but this will do.
  814. if (member.element) {
  815. member.css(clipRect.getCSS(member));
  816. }
  817. });
  818. }
  819. });
  820. },
  821. /**
  822. * Take a color and return it if it's a string, make it a gradient if
  823. * it's a gradient configuration object, and apply opacity.
  824. *
  825. * @function Highcharts.VMLRenderer#color<T>
  826. *
  827. * @param {T} color
  828. * The color or config object
  829. *
  830. * @return {T}
  831. */
  832. color: function (colorOption, elem, prop, wrapper) {
  833. var renderer = this, colorObject, regexRgba = /^rgba/, markup, fillType, ret = 'none';
  834. // Check for linear or radial gradient
  835. if (colorOption &&
  836. colorOption.linearGradient) {
  837. fillType = 'gradient';
  838. }
  839. else if (colorOption &&
  840. colorOption.radialGradient) {
  841. fillType = 'pattern';
  842. }
  843. if (fillType) {
  844. var stopColor_1, stopOpacity_1, gradient = (colorOption.linearGradient ||
  845. colorOption.radialGradient), x1 = void 0, y1 = void 0, x2 = void 0, y2 = void 0, opacity1_1, opacity2_1, color1_1, color2_1, fillAttr_1 = '', stops = colorOption.stops, firstStop = void 0, lastStop = void 0, colors_1 = [], addFillNode_1 = function () {
  846. // Add the fill subnode. When colors attribute is used,
  847. // the meanings of opacity and o:opacity2 are reversed.
  848. markup = ['<fill colors="' + colors_1.join(',') +
  849. '" opacity="', opacity2_1, '" o:opacity2="',
  850. opacity1_1, '" type="', fillType, '" ', fillAttr_1,
  851. 'focus="100%" method="any" />'];
  852. createElement(renderer.prepVML(markup), null, null, elem);
  853. };
  854. // Extend from 0 to 1
  855. firstStop = stops[0];
  856. lastStop = stops[stops.length - 1];
  857. if (firstStop[0] > 0) {
  858. stops.unshift([
  859. 0,
  860. firstStop[1]
  861. ]);
  862. }
  863. if (lastStop[0] < 1) {
  864. stops.push([
  865. 1,
  866. lastStop[1]
  867. ]);
  868. }
  869. // Compute the stops
  870. stops.forEach(function (stop, i) {
  871. if (regexRgba.test(stop[1])) {
  872. colorObject = color(stop[1]);
  873. stopColor_1 = colorObject.get('rgb');
  874. stopOpacity_1 = colorObject.get('a');
  875. }
  876. else {
  877. stopColor_1 = stop[1];
  878. stopOpacity_1 = 1;
  879. }
  880. // Build the color attribute
  881. colors_1.push((stop[0] * 100) + '% ' + stopColor_1);
  882. // Only start and end opacities are allowed, so we use the
  883. // first and the last
  884. if (!i) {
  885. opacity1_1 = stopOpacity_1;
  886. color2_1 = stopColor_1;
  887. }
  888. else {
  889. opacity2_1 = stopOpacity_1;
  890. color1_1 = stopColor_1;
  891. }
  892. });
  893. // Apply the gradient to fills only.
  894. if (prop === 'fill') {
  895. // Handle linear gradient angle
  896. if (fillType === 'gradient') {
  897. x1 = gradient.x1 || gradient[0] || 0;
  898. y1 = gradient.y1 || gradient[1] || 0;
  899. x2 = gradient.x2 || gradient[2] || 0;
  900. y2 = gradient.y2 || gradient[3] || 0;
  901. fillAttr_1 = 'angle="' + (90 - Math.atan((y2 - y1) / // y vector
  902. (x2 - x1) // x vector
  903. ) * 180 / Math.PI) + '"';
  904. addFillNode_1();
  905. // Radial (circular) gradient
  906. }
  907. else {
  908. var r = gradient.r, sizex_1 = r * 2, sizey_1 = r * 2, cx_1 = gradient.cx, cy_1 = gradient.cy, radialReference_1 = elem.radialReference, bBox_1, applyRadialGradient = function () {
  909. if (radialReference_1) {
  910. bBox_1 = wrapper.getBBox();
  911. cx_1 += (radialReference_1[0] - bBox_1.x) /
  912. bBox_1.width - 0.5;
  913. cy_1 += (radialReference_1[1] - bBox_1.y) /
  914. bBox_1.height - 0.5;
  915. sizex_1 *= radialReference_1[2] / bBox_1.width;
  916. sizey_1 *= radialReference_1[2] / bBox_1.height;
  917. }
  918. fillAttr_1 =
  919. 'src="' + getOptions().global.VMLRadialGradientURL +
  920. '" ' +
  921. 'size="' + sizex_1 + ',' + sizey_1 + '" ' +
  922. 'origin="0.5,0.5" ' +
  923. 'position="' + cx_1 + ',' + cy_1 + '" ' +
  924. 'color2="' + color2_1 + '" ';
  925. addFillNode_1();
  926. };
  927. // Apply radial gradient
  928. if (wrapper.added) {
  929. applyRadialGradient();
  930. }
  931. else {
  932. // We need to know the bounding box to get the size
  933. // and position right
  934. wrapper.onAdd = applyRadialGradient;
  935. }
  936. // The fill element's color attribute is broken in IE8
  937. // standards mode, so we need to set the parent shape's
  938. // fillcolor attribute instead.
  939. ret = color1_1;
  940. }
  941. // Gradients are not supported for VML stroke, return the first
  942. // color. #722.
  943. }
  944. else {
  945. ret = stopColor_1;
  946. }
  947. // If the color is an rgba color, split it and add a fill node
  948. // to hold the opacity component
  949. }
  950. else if (regexRgba.test(colorOption) && elem.tagName !== 'IMG') {
  951. colorObject = color(colorOption);
  952. wrapper[prop + '-opacitySetter'](colorObject.get('a'), prop, elem);
  953. ret = colorObject.get('rgb');
  954. }
  955. else {
  956. // 'stroke' or 'fill' node
  957. var propNodes = elem.getElementsByTagName(prop);
  958. if (propNodes.length) {
  959. propNodes[0].opacity = 1;
  960. propNodes[0].type = 'solid';
  961. }
  962. ret = colorOption;
  963. }
  964. return ret;
  965. },
  966. /**
  967. * Take a VML string and prepare it for either IE8 or IE6/IE7.
  968. *
  969. * @function Highcharts.VMLRenderer#prepVML
  970. *
  971. * @param {Array<(number|string)>} markup
  972. * A string array of the VML markup to prepare
  973. *
  974. * @return {string}
  975. */
  976. prepVML: function (markup) {
  977. var vmlStyle = 'display:inline-block;behavior:url(#default#VML);', isIE8 = this.isIE8;
  978. markup = markup.join('');
  979. if (isIE8) { // add xmlns and style inline
  980. markup = markup.replace('/>', ' xmlns="urn:schemas-microsoft-com:vml" />');
  981. if (markup.indexOf('style="') === -1) {
  982. markup = markup.replace('/>', ' style="' + vmlStyle + '" />');
  983. }
  984. else {
  985. markup = markup.replace('style="', 'style="' + vmlStyle);
  986. }
  987. }
  988. else { // add namespace
  989. markup = markup.replace('<', '<hcv:');
  990. }
  991. return markup;
  992. },
  993. /**
  994. * Create rotated and aligned text
  995. *
  996. * @function Highcharts.VMLRenderer#text
  997. *
  998. * @param {string} str
  999. *
  1000. * @param {number} x
  1001. *
  1002. * @param {number} y
  1003. */
  1004. text: SVGRenderer.prototype.html,
  1005. /**
  1006. * Create and return a path element
  1007. *
  1008. * @function Highcharts.VMLRenderer#path
  1009. *
  1010. * @param {Highcharts.VMLAttributes|Highcharts.VMLPathArray} [path]
  1011. */
  1012. path: function (path) {
  1013. var attr = {
  1014. // subpixel precision down to 0.1 (width and height = 1px)
  1015. coordsize: '10 10'
  1016. };
  1017. if (isArray(path)) {
  1018. attr.d = path;
  1019. }
  1020. else if (isObject(path)) { // attributes
  1021. extend(attr, path);
  1022. }
  1023. // create the shape
  1024. return this.createElement('shape').attr(attr);
  1025. },
  1026. /**
  1027. * Create and return a circle element. In VML circles are implemented as
  1028. * shapes, which is faster than v:oval
  1029. *
  1030. * @function Highcharts.VMLRenderer#circle
  1031. * @param {number|Highcharts.Dictionary<number>} x
  1032. * @param {number} [y]
  1033. * @param {number} [r]
  1034. * @return {Highcharts.VMLElement}
  1035. */
  1036. circle: function (x, y, r) {
  1037. var circle = this.symbol('circle');
  1038. if (isObject(x)) {
  1039. r = x.r;
  1040. y = x.y;
  1041. x = x.x;
  1042. }
  1043. circle.isCircle = true; // Causes x and y to mean center (#1682)
  1044. circle.r = r;
  1045. return circle.attr({ x: x, y: y });
  1046. },
  1047. /**
  1048. * Create a group using an outer div and an inner v:group to allow
  1049. * rotating and flipping. A simple v:group would have problems with
  1050. * positioning child HTML elements and CSS clip.
  1051. *
  1052. * @function Highcharts.VMLRenderer#g
  1053. *
  1054. * @param {string} name
  1055. * The name of the group
  1056. *
  1057. * @return {Highcharts.VMLElement}
  1058. */
  1059. g: function (name) {
  1060. var wrapper, attribs;
  1061. // set the class name
  1062. if (name) {
  1063. attribs = {
  1064. 'className': 'highcharts-' + name,
  1065. 'class': 'highcharts-' + name
  1066. };
  1067. }
  1068. // the div to hold HTML and clipping
  1069. wrapper = this.createElement('div').attr(attribs);
  1070. return wrapper;
  1071. },
  1072. /**
  1073. * VML override to create a regular HTML image.
  1074. *
  1075. * @function Highcharts.VMLRenderer#image
  1076. *
  1077. * @param {string} src
  1078. *
  1079. * @param {number} x
  1080. *
  1081. * @param {number} y
  1082. *
  1083. * @param {number} width
  1084. *
  1085. * @param {number} height
  1086. * @return {Highcharts.VMLElement}
  1087. */
  1088. image: function (src, x, y, width, height) {
  1089. var obj = this.createElement('img').attr({ src: src });
  1090. if (arguments.length > 1) {
  1091. obj.attr({
  1092. x: x,
  1093. y: y,
  1094. width: width,
  1095. height: height
  1096. });
  1097. }
  1098. return obj;
  1099. },
  1100. /**
  1101. * For rectangles, VML uses a shape for rect to overcome bugs and
  1102. * rotation problems
  1103. *
  1104. * @function Highcharts.VMLRenderer#createElement
  1105. * @param {string} nodeName
  1106. * @return {Highcharts.VMLElement}
  1107. */
  1108. createElement: function (nodeName) {
  1109. return nodeName === 'rect' ?
  1110. this.symbol(nodeName) :
  1111. SVGRenderer.prototype.createElement.call(this, nodeName);
  1112. },
  1113. /**
  1114. * In the VML renderer, each child of an inverted div (group) is
  1115. * inverted
  1116. *
  1117. * @function Highcharts.VMLRenderer#invertChild
  1118. *
  1119. * @param {Highcharts.HTMLDOMElement} element
  1120. *
  1121. * @param {Highcharts.HTMLDOMElement} parentNode
  1122. */
  1123. invertChild: function (element, parentNode) {
  1124. var ren = this, parentStyle = parentNode.style, imgStyle = element.tagName === 'IMG' && element.style; // #1111
  1125. css(element, {
  1126. flip: 'x',
  1127. left: (pInt(parentStyle.width) -
  1128. (imgStyle ? pInt(imgStyle.top) : 1)) + 'px',
  1129. top: (pInt(parentStyle.height) -
  1130. (imgStyle ? pInt(imgStyle.left) : 1)) + 'px',
  1131. rotation: -90
  1132. });
  1133. // Recursively invert child elements, needed for nested composite
  1134. // shapes like box plots and error bars. #1680, #1806.
  1135. [].forEach.call(element.childNodes, function (child) {
  1136. ren.invertChild(child, element);
  1137. });
  1138. },
  1139. /**
  1140. * Symbol definitions that override the parent SVG renderer's symbols
  1141. *
  1142. * @name Highcharts.VMLRenderer#symbols
  1143. * @type {Highcharts.Dictionary<Function>}
  1144. */
  1145. symbols: {
  1146. // VML specific arc function
  1147. arc: function (x, y, w, h, options) {
  1148. var start = options.start, end = options.end, radius = options.r || w || h, innerRadius = options.innerR, cosStart = Math.cos(start), sinStart = Math.sin(start), cosEnd = Math.cos(end), sinEnd = Math.sin(end), ret;
  1149. if (end - start === 0) { // no angle, don't show it.
  1150. return ['x'];
  1151. }
  1152. ret = [
  1153. 'wa',
  1154. x - radius,
  1155. y - radius,
  1156. x + radius,
  1157. y + radius,
  1158. x + radius * cosStart,
  1159. y + radius * sinStart,
  1160. x + radius * cosEnd,
  1161. y + radius * sinEnd // end y
  1162. ];
  1163. if (options.open && !innerRadius) {
  1164. ret.push('e', 'M', x, // - innerRadius,
  1165. y // - innerRadius
  1166. );
  1167. }
  1168. ret.push('at', // anti clockwise arc to
  1169. x - innerRadius, // left
  1170. y - innerRadius, // top
  1171. x + innerRadius, // right
  1172. y + innerRadius, // bottom
  1173. x + innerRadius * cosEnd, // start x
  1174. y + innerRadius * sinEnd, // start y
  1175. x + innerRadius * cosStart, // end x
  1176. y + innerRadius * sinStart, // end y
  1177. 'x', // finish path
  1178. 'e' // close
  1179. );
  1180. ret.isArc = true;
  1181. return ret;
  1182. },
  1183. // Add circle symbol path. This performs significantly faster than
  1184. // v:oval.
  1185. circle: function (x, y, w, h, wrapper) {
  1186. if (wrapper && defined(wrapper.r)) {
  1187. w = h = 2 * wrapper.r;
  1188. }
  1189. // Center correction, #1682
  1190. if (wrapper && wrapper.isCircle) {
  1191. x -= w / 2;
  1192. y -= h / 2;
  1193. }
  1194. // Return the path
  1195. return [
  1196. 'wa',
  1197. x,
  1198. y,
  1199. x + w,
  1200. y + h,
  1201. x + w,
  1202. y + h / 2,
  1203. x + w,
  1204. y + h / 2,
  1205. 'e' // close
  1206. ];
  1207. },
  1208. /**
  1209. * Add rectangle symbol path which eases rotation and omits arcsize
  1210. * problems compared to the built-in VML roundrect shape. When
  1211. * borders are not rounded, use the simpler square path, else use
  1212. * the callout path without the arrow.
  1213. */
  1214. rect: function (x, y, w, h, options) {
  1215. return SVGRenderer.prototype.symbols[!defined(options) || !options.r ? 'square' : 'callout'].call(0, x, y, w, h, options);
  1216. }
  1217. }
  1218. };
  1219. H.VMLRenderer = VMLRenderer = function () {
  1220. this.init.apply(this, arguments);
  1221. };
  1222. extend(VMLRenderer.prototype, SVGRenderer.prototype);
  1223. extend(VMLRenderer.prototype, VMLRendererExtension);
  1224. // general renderer
  1225. H.Renderer = VMLRenderer;
  1226. // 3D additions
  1227. VMLRenderer3D.compose(VMLRenderer, SVGRenderer);
  1228. }
  1229. SVGRenderer.prototype.getSpanWidth = function (wrapper, tspan) {
  1230. var renderer = this, bBox = wrapper.getBBox(true), actualWidth = bBox.width;
  1231. // Old IE cannot measure the actualWidth for SVG elements (#2314)
  1232. if (!svg && renderer.forExport) {
  1233. actualWidth = renderer.measureSpanWidth(tspan.firstChild.data, wrapper.styles);
  1234. }
  1235. return actualWidth;
  1236. };
  1237. // This method is used with exporting in old IE, when emulating SVG (see #2314)
  1238. SVGRenderer.prototype.measureSpanWidth = function (text, styles) {
  1239. var measuringSpan = doc.createElement('span'), offsetWidth, textNode = doc.createTextNode(text);
  1240. measuringSpan.appendChild(textNode);
  1241. css(measuringSpan, styles);
  1242. this.box.appendChild(measuringSpan);
  1243. offsetWidth = measuringSpan.offsetWidth;
  1244. discardElement(measuringSpan); // #2463
  1245. return offsetWidth;
  1246. };