index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. (function (global, factory) {
  20. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  21. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  22. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['echarts-ssr-client'] = {}));
  23. }(this, (function (exports) { 'use strict';
  24. /**
  25. * AUTO-GENERATED FILE. DO NOT MODIFY.
  26. */
  27. /*
  28. * Licensed to the Apache Software Foundation (ASF) under one
  29. * or more contributor license agreements. See the NOTICE file
  30. * distributed with this work for additional information
  31. * regarding copyright ownership. The ASF licenses this file
  32. * to you under the Apache License, Version 2.0 (the
  33. * "License"); you may not use this file except in compliance
  34. * with the License. You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing,
  39. * software distributed under the License is distributed on an
  40. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41. * KIND, either express or implied. See the License for the
  42. * specific language governing permissions and limitations
  43. * under the License.
  44. */
  45. function hydrate(dom, options) {
  46. var svgRoot = dom.querySelector('svg');
  47. if (!svgRoot) {
  48. console.error('No SVG element found in the DOM.');
  49. return;
  50. }
  51. function getIndex(child, attr) {
  52. var index = child.getAttribute(attr);
  53. if (index) {
  54. return parseInt(index, 10);
  55. } else {
  56. return undefined;
  57. }
  58. }
  59. var listeners = options.on || {};
  60. var _loop_1 = function (rawEvtName) {
  61. if (!listeners.hasOwnProperty(rawEvtName)) {
  62. return "continue";
  63. }
  64. var eventName = rawEvtName;
  65. var listener = listeners[eventName];
  66. if (!isFunction(listener)) {
  67. return "continue";
  68. }
  69. svgRoot.addEventListener(eventName, function (event) {
  70. var targetEl = event.target;
  71. if (!targetEl || !isFunction(targetEl.getAttribute)) {
  72. return;
  73. }
  74. var type = targetEl.getAttribute('ecmeta_ssr_type');
  75. var silent = targetEl.getAttribute('ecmeta_silent') === 'true';
  76. if (!type || silent) {
  77. return;
  78. }
  79. listener({
  80. type: eventName,
  81. ssrType: type,
  82. seriesIndex: getIndex(targetEl, 'ecmeta_series_index'),
  83. dataIndex: getIndex(targetEl, 'ecmeta_data_index'),
  84. event: event
  85. });
  86. });
  87. };
  88. for (var rawEvtName in listeners) {
  89. _loop_1(rawEvtName);
  90. }
  91. }
  92. function isFunction(value) {
  93. return typeof value === 'function';
  94. }
  95. exports.hydrate = hydrate;
  96. Object.defineProperty(exports, '__esModule', { value: true });
  97. })));
  98. //# sourceMappingURL=index.js.map