Oldie.js 49 KB

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