index.js 2.2 KB

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