@carbon/charts 0.32.8 → 0.32.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/build/demo/data/area.d.ts +17 -0
  3. package/build/demo/data/bar.d.ts +51 -0
  4. package/build/demo/data/gauge.d.ts +40 -0
  5. package/build/demo/data/index.d.ts +6 -0
  6. package/build/demo/data/line.d.ts +26 -0
  7. package/build/demo/data/scatter.d.ts +18 -0
  8. package/build/src/charts/gauge.d.ts +6 -0
  9. package/build/src/charts/index.d.ts +1 -0
  10. package/build/src/components/essentials/tooltip-bar.d.ts +2 -2
  11. package/build/src/components/essentials/tooltip-radar.d.ts +2 -1
  12. package/build/src/components/essentials/tooltip.d.ts +2 -2
  13. package/build/src/components/graphs/gauge.d.ts +26 -0
  14. package/build/src/components/index.d.ts +1 -0
  15. package/build/src/configuration.d.ts +2 -1
  16. package/build/src/interfaces/axis-scales.d.ts +2 -0
  17. package/build/src/interfaces/charts.d.ts +20 -0
  18. package/build/src/interfaces/components.d.ts +2 -0
  19. package/build/src/interfaces/enums.d.ts +31 -1
  20. package/build/src/interfaces/events.d.ts +9 -0
  21. package/build/src/interfaces/truncation.d.ts +17 -0
  22. package/build/src/tools.d.ts +9 -0
  23. package/bundle.js +1 -1
  24. package/chart.js +21 -22
  25. package/chart.js.map +1 -1
  26. package/charts/gauge.d.ts +6 -0
  27. package/charts/gauge.js +41 -0
  28. package/charts/gauge.js.map +1 -0
  29. package/charts/index.d.ts +1 -0
  30. package/charts/index.js +1 -0
  31. package/charts/index.js.map +1 -1
  32. package/components/axes/axis.js +61 -1
  33. package/components/axes/axis.js.map +1 -1
  34. package/components/essentials/legend.js +39 -6
  35. package/components/essentials/legend.js.map +1 -1
  36. package/components/essentials/tooltip-bar.d.ts +2 -2
  37. package/components/essentials/tooltip-bar.js +20 -7
  38. package/components/essentials/tooltip-bar.js.map +1 -1
  39. package/components/essentials/tooltip-pie.js +3 -0
  40. package/components/essentials/tooltip-pie.js.map +1 -1
  41. package/components/essentials/tooltip-radar.d.ts +2 -1
  42. package/components/essentials/tooltip-radar.js +1 -1
  43. package/components/essentials/tooltip-radar.js.map +1 -1
  44. package/components/essentials/tooltip-scatter.js +6 -0
  45. package/components/essentials/tooltip-scatter.js.map +1 -1
  46. package/components/essentials/tooltip.d.ts +2 -2
  47. package/components/essentials/tooltip.js +11 -6
  48. package/components/essentials/tooltip.js.map +1 -1
  49. package/components/graphs/area-stacked.js +7 -4
  50. package/components/graphs/area-stacked.js.map +1 -1
  51. package/components/graphs/gauge.d.ts +26 -0
  52. package/components/graphs/gauge.js +301 -0
  53. package/components/graphs/gauge.js.map +1 -0
  54. package/components/graphs/line.js +13 -7
  55. package/components/graphs/line.js.map +1 -1
  56. package/components/graphs/scatter-stacked.js +1 -1
  57. package/components/graphs/scatter-stacked.js.map +1 -1
  58. package/components/index.d.ts +1 -0
  59. package/components/index.js +1 -0
  60. package/components/index.js.map +1 -1
  61. package/configuration.d.ts +2 -1
  62. package/configuration.js +100 -65
  63. package/configuration.js.map +1 -1
  64. package/demo/data/area.d.ts +17 -0
  65. package/demo/data/area.js +45 -19
  66. package/demo/data/area.js.map +1 -1
  67. package/demo/data/bar.d.ts +51 -0
  68. package/demo/data/bar.js +52 -0
  69. package/demo/data/bar.js.map +1 -1
  70. package/demo/data/bundle.js +1 -1
  71. package/demo/data/donut.js +10 -10
  72. package/demo/data/donut.js.map +1 -1
  73. package/demo/data/gauge.d.ts +40 -0
  74. package/demo/data/gauge.js +41 -0
  75. package/demo/data/gauge.js.map +1 -0
  76. package/demo/data/index.d.ts +6 -0
  77. package/demo/data/index.js +163 -120
  78. package/demo/data/index.js.map +1 -1
  79. package/demo/data/line.d.ts +26 -0
  80. package/demo/data/line.js +37 -0
  81. package/demo/data/line.js.map +1 -1
  82. package/demo/data/scatter.d.ts +18 -0
  83. package/demo/data/scatter.js +35 -0
  84. package/demo/data/scatter.js.map +1 -1
  85. package/demo/styles.css +80 -0
  86. package/demo/styles.css.map +1 -1
  87. package/demo/styles.min.css +1 -1
  88. package/demo/styles.min.css.map +1 -1
  89. package/demo/tsconfig.tsbuildinfo +62 -23
  90. package/interfaces/axis-scales.d.ts +2 -0
  91. package/interfaces/axis-scales.js.map +1 -1
  92. package/interfaces/charts.d.ts +20 -0
  93. package/interfaces/charts.js.map +1 -1
  94. package/interfaces/components.d.ts +2 -0
  95. package/interfaces/components.js.map +1 -1
  96. package/interfaces/enums.d.ts +31 -1
  97. package/interfaces/enums.js +34 -0
  98. package/interfaces/enums.js.map +1 -1
  99. package/interfaces/events.d.ts +9 -0
  100. package/interfaces/events.js +10 -0
  101. package/interfaces/events.js.map +1 -1
  102. package/interfaces/truncation.d.ts +17 -0
  103. package/interfaces/truncation.js +1 -0
  104. package/interfaces/truncation.js.map +1 -0
  105. package/model.js +15 -0
  106. package/model.js.map +1 -1
  107. package/package.json +1 -1
  108. package/styles/components/_tooltip.scss +2 -0
  109. package/styles/graphs/_gauge.scss +19 -0
  110. package/styles/graphs/index.scss +1 -0
  111. package/styles-g10.css +21 -0
  112. package/styles-g10.css.map +1 -1
  113. package/styles-g10.min.css +1 -1
  114. package/styles-g10.min.css.map +1 -1
  115. package/styles-g100.css +21 -0
  116. package/styles-g100.css.map +1 -1
  117. package/styles-g100.min.css +1 -1
  118. package/styles-g100.min.css.map +1 -1
  119. package/styles-g90.css +21 -0
  120. package/styles-g90.css.map +1 -1
  121. package/styles-g90.min.css +1 -1
  122. package/styles-g90.min.css.map +1 -1
  123. package/styles.css +21 -0
  124. package/styles.css.map +1 -1
  125. package/styles.min.css +1 -1
  126. package/styles.min.css.map +1 -1
  127. package/tools.d.ts +9 -0
  128. package/tools.js +24 -1
  129. package/tools.js.map +1 -1
  130. package/tsconfig.tsbuildinfo +106 -40
@@ -1 +1 @@
1
- {"version":3,"file":"legend.js","sourceRoot":"","sources":["legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,O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E,CAAC,CAAC;iBACb,KAAK,EAAE,CAAC;QACX,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;gBAC5D,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC;aAC5B,CAAC,CAAC;YAEH,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,IAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAS,CAAC;YAEnD,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;YAEjD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CACjC,MAAM,CAAC,MAAM,CAAC,aAAa,EAC3B;gBACC,cAAc,EAAE,WAAW;aAC3B,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACF,aAAC;AAAD,CAAC,AAjRD,CAA4B,SAAS,GAiRpC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { LegendOrientations, Roles, Events } from \"../../interfaces\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class Legend extends Component {\n\ttype = \"legend\";\n\n\trender() {\n\t\tconst svg = this.getContainerSVG().attr(\n\t\t\t\"role\",\n\t\t\tRoles.GRAPHICS_DOCUMENT\n\t\t);\n\t\tconst options = this.model.getOptions();\n\t\tconst legendItems = svg\n\t\t\t.selectAll(\"g.legend-item\")\n\t\t\t.data(this.model.getDataGroups(), (dataGroup) => dataGroup.name);\n\n\t\t// this.getLegendItemArray()\n\n\t\tconst addedLegendItems = legendItems\n\t\t\t.enter()\n\t\t\t.append(\"g\")\n\t\t\t.classed(\"legend-item\", true);\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\taddedLegendItems\n\t\t\t.append(\"rect\")\n\t\t\t.classed(\"checkbox\", true)\n\t\t\t.merge(legendItems.select(\"rect.checkbox\"))\n\t\t\t.attr(\"width\", checkboxRadius * 2)\n\t\t\t.attr(\"height\", checkboxRadius * 2)\n\t\t\t.attr(\"rx\", 1)\n\t\t\t.attr(\"ry\", 1)\n\t\t\t.style(\"fill\", (d) => {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE\n\t\t\t\t\t? this.model.getStrokeColor(d.name)\n\t\t\t\t\t: null;\n\t\t\t})\n\t\t\t.classed(\"active\", function (d, i) {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE;\n\t\t\t});\n\n\t\taddedLegendItems\n\t\t\t.append(\"text\")\n\t\t\t.merge(legendItems.select(\"text\"))\n\t\t\t.html((d) => d.name)\n\t\t\t.attr(\"alignment-baseline\", \"middle\");\n\n\t\tthis.breakItemsIntoLines(addedLegendItems);\n\n\t\t// Remove old elements as needed.\n\t\tlegendItems\n\t\t\t.exit()\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"click\", null)\n\t\t\t.on(\"mouseout\", null)\n\t\t\t.remove();\n\n\t\tconst legendClickable = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"legend\",\n\t\t\t\"clickable\"\n\t\t);\n\t\tsvg.classed(\"clickable\", legendClickable);\n\n\t\tif (legendClickable && addedLegendItems.size() > 0) {\n\t\t\tthis.addEventListeners();\n\t\t}\n\t}\n\n\tbreakItemsIntoLines(addedLegendItems) {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\t\tconst legendItemsHorizontalSpacing =\n\t\t\toptions.legend.items.horizontalSpace;\n\t\tconst legendItemsVerticalSpacing = options.legend.items.verticalSpace;\n\t\tconst legendTextYOffset = options.legend.items.textYOffset;\n\t\tconst spaceNeededForCheckbox =\n\t\t\tcheckboxRadius * 2 + options.legend.checkbox.spaceAfter;\n\n\t\t// Check if there are disabled legend items\n\t\tconst { DISABLED } = options.legend.items.status;\n\t\tconst dataGroups = this.model.getDataGroups();\n\t\tconst hasDeactivatedItems = dataGroups.some(\n\t\t\t(dataGroup) => dataGroup.status === DISABLED\n\t\t);\n\n\t\tconst legendOrientation = Tools.getProperty(\n\t\t\toptions,\n\t\t\t\"legend\",\n\t\t\t\"orientation\"\n\t\t);\n\n\t\t// Keep track of line numbers and positions\n\t\tlet startingPoint = 0;\n\t\tlet lineNumber = 0;\n\t\tlet itemIndexInLine = 0;\n\t\tlet lastYPosition;\n\t\taddedLegendItems\n\t\t\t.merge(svg.selectAll(\"g.legend-item\"))\n\t\t\t.each(function (d, i) {\n\t\t\t\tconst legendItem = select(this);\n\t\t\t\tconst previousLegendItem = select(\n\t\t\t\t\tsvg.selectAll(\"g.legend-item\").nodes()[i - 1]\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\titemIndexInLine === 0 ||\n\t\t\t\t\tpreviousLegendItem.empty() ||\n\t\t\t\t\tlegendOrientation === LegendOrientations.VERTICAL\n\t\t\t\t) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tlegendOrientation === LegendOrientations.VERTICAL &&\n\t\t\t\t\t\ti !== 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst svgDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tself.parent,\n\t\t\t\t\t\t{ useAttr: true }\n\t\t\t\t\t);\n\t\t\t\t\tconst legendItemTextDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tselect(this).select(\"text\"),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\t\t\t\t\tconst lastLegendItemTextDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tpreviousLegendItem.select(\"text\"),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\t\t\t\t\tstartingPoint =\n\t\t\t\t\t\tstartingPoint +\n\t\t\t\t\t\tlastLegendItemTextDimensions.width +\n\t\t\t\t\t\tspaceNeededForCheckbox +\n\t\t\t\t\t\tlegendItemsHorizontalSpacing;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartingPoint +\n\t\t\t\t\t\t\tspaceNeededForCheckbox +\n\t\t\t\t\t\t\tlegendItemTextDimensions.width >\n\t\t\t\t\t\tsvgDimensions.width\n\t\t\t\t\t) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t\tstartingPoint = 0;\n\t\t\t\t\t\titemIndexInLine = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst yOffset = 0;\n\n\t\t\t\t// Position checkbox\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tlegendItem\n\t\t\t\t\t.select(\"rect.checkbox\")\n\t\t\t\t\t.attr(\"x\", startingPoint)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\tyOffset + lineNumber * legendItemsVerticalSpacing\n\t\t\t\t\t);\n\n\t\t\t\t// Position text\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tconst yPosition =\n\t\t\t\t\tlegendTextYOffset + lineNumber * legendItemsVerticalSpacing;\n\t\t\t\tlegendItem\n\t\t\t\t\t.select(\"text\")\n\t\t\t\t\t.attr(\"x\", startingPoint + spaceNeededForCheckbox)\n\t\t\t\t\t.attr(\"y\", yOffset + yPosition);\n\n\t\t\t\tlastYPosition = yPosition;\n\n\t\t\t\t// Render checkbox check icon\n\t\t\t\tif (\n\t\t\t\t\thasDeactivatedItems &&\n\t\t\t\t\tlegendItem.select(\"g.check\").empty()\n\t\t\t\t) {\n\t\t\t\t\tlegendItem.append(\"g\").classed(\"check\", true).html(`\n\t\t\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 32 32\" aria-hidden=\"true\"\n\t\t\t\t\t\t\t\tstyle=\"will-change: transform;\">\n\t\t\t\t\t\t\t\t<path d=\"M13 21.2l-7.1-7.1-1.4 1.4 7.1 7.1L13 24 27.1 9.9l-1.4-1.5z\"></path>\n\t\t\t\t\t\t\t\t<title>Checkmark</title>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t`);\n\n\t\t\t\t\tlegendItem\n\t\t\t\t\t\t.select(\"g.check svg\")\n\t\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\n\t\t\t\t\t\t\t\"x\",\n\t\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"x\")\n\t\t\t\t\t\t\t) + 0.5\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.attr(\n\t\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"y\")\n\t\t\t\t\t\t\t) + 0.5\n\t\t\t\t\t\t);\n\t\t\t\t} else if (\n\t\t\t\t\t!hasDeactivatedItems &&\n\t\t\t\t\t!legendItem.select(\"g.check\").empty()\n\t\t\t\t) {\n\t\t\t\t\tlegendItem.select(\"g.check\").remove();\n\t\t\t\t}\n\n\t\t\t\titemIndexInLine++;\n\t\t\t});\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\tsvg.selectAll(\"g.legend-item\")\n\t\t\t.on(\"mouseover\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_HOVER, {\n\t\t\t\t\thoveredElement: select(this),\n\t\t\t\t});\n\n\t\t\t\t// Configs\n\t\t\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem\n\t\t\t\t\t.append(\"rect\")\n\t\t\t\t\t.classed(\"hover-stroke\", true)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"x\",\n\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\thoveredItem.select(\"rect.checkbox\").attr(\"x\")\n\t\t\t\t\t\t) - 2\n\t\t\t\t\t)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\thoveredItem.select(\"rect.checkbox\").attr(\"y\")\n\t\t\t\t\t\t) - 2\n\t\t\t\t\t)\n\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"rx\", 3)\n\t\t\t\t\t.attr(\"ry\", 3)\n\t\t\t\t\t.lower();\n\t\t\t})\n\t\t\t.on(\"click\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_CLICK, {\n\t\t\t\t\tclickedElement: select(this),\n\t\t\t\t});\n\n\t\t\t\tconst clickedItem = select(this);\n\t\t\t\tconst clickedItemData = clickedItem.datum() as any;\n\n\t\t\t\tself.model.toggleDataLabel(clickedItemData.name);\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.select(\"rect.hover-stroke\").remove();\n\n\t\t\t\tself.services.events.dispatchEvent(\n\t\t\t\t\tEvents.Legend.ITEM_MOUSEOUT,\n\t\t\t\t\t{\n\t\t\t\t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a,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;gBAC5D,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC;aAC5B,CAAC,CAAC;YAEH,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,IAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAS,CAAC;YAEnD,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC,CAAC;aACD,EAAE,CAAC,WAAW,EAAE;YAChB,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,IAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAS,CAAC;YACnD,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,mBAAmB,EAAE;gBACtD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;oBACxD,cAAc,EAAE,WAAW;oBAC3B,IAAI,EAAE,YAAY,CAAC,MAAM;iBACzB,CAAC,CAAC;aACF;QACF,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;YAEjD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAExD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CACjC,MAAM,CAAC,MAAM,CAAC,aAAa,EAC3B;gBACC,cAAc,EAAE,WAAW;aAC3B,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACF,aAAC;AAAD,CAAC,AAlUD,CAA4B,SAAS,GAkUpC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { LegendOrientations, Roles, Events, TooltipTypes, TruncationTypes } from \"../../interfaces\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class Legend extends Component {\n\ttype = \"legend\";\n\n\trender() {\n\t\tconst svg = this.getContainerSVG().attr(\n\t\t\t\"role\",\n\t\t\tRoles.GRAPHICS_DOCUMENT\n\t\t);\n\t\tconst options = this.model.getOptions();\n\t\tconst legendOptions = Tools.getProperty(options, \"legend\");\n\t\tconst legendItems = svg\n\t\t\t.selectAll(\"g.legend-item\")\n\t\t\t.data(this.model.getDataGroups(), (dataGroup) => dataGroup.name);\n\n\t\t// this.getLegendItemArray()\n\n\t\tconst addedLegendItems = legendItems\n\t\t\t.enter()\n\t\t\t.append(\"g\")\n\t\t\t.classed(\"legend-item\", true);\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\t// Truncation\n\t\t// get user provided custom values for truncation\n\t\tconst truncationType = Tools.getProperty(\n\t\t\tlegendOptions,\n\t\t\t\"truncation\",\n\t\t\t\"type\"\n\t\t);\n\t\tconst truncationThreshold = Tools.getProperty(\n\t\t\tlegendOptions,\n\t\t\t\"truncation\",\n\t\t\t\"threshold\"\n\t\t);\n\t\tconst truncationNumCharacter = Tools.getProperty(\n\t\t\tlegendOptions,\n\t\t\t\"truncation\",\n\t\t\t\"numCharacter\"\n\t\t);\n\n\t\taddedLegendItems\n\t\t\t.append(\"rect\")\n\t\t\t.classed(\"checkbox\", true)\n\t\t\t.merge(legendItems.select(\"rect.checkbox\"))\n\t\t\t.attr(\"width\", checkboxRadius * 2)\n\t\t\t.attr(\"height\", checkboxRadius * 2)\n\t\t\t.attr(\"rx\", 1)\n\t\t\t.attr(\"ry\", 1)\n\t\t\t.style(\"fill\", (d) => {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE\n\t\t\t\t\t? this.model.getStrokeColor(d.name)\n\t\t\t\t\t: null;\n\t\t\t})\n\t\t\t.classed(\"active\", function (d, i) {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE;\n\t\t\t});\n\t\tconst addedLegendItemsText = addedLegendItems\n\t\t\t.append(\"text\")\n\t\t\t.merge(legendItems.select(\"text\"));\n\n\t\t// truncate the legend label if it's too long\n\t\tif (truncationType !== TruncationTypes.NONE) {\n\t\t\taddedLegendItemsText\n\t\t\t\t.html(function(d) {\n\t\t\t\t\tif (d.name.length > truncationThreshold) {\n\t\t\t\t\t\treturn Tools.truncateLabel(d.name, truncationType, truncationNumCharacter);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn d.name;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t} else {\n\t\t\taddedLegendItemsText\n\t\t\t\t.html((d) => d.name);\n\t\t}\n\n\t\tthis.breakItemsIntoLines(addedLegendItems);\n\n\t\t// Remove old elements as needed.\n\t\tlegendItems\n\t\t\t.exit()\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"click\", null)\n\t\t\t.on(\"mouseout\", null)\n\t\t\t.remove();\n\n\t\tconst legendClickable = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"legend\",\n\t\t\t\"clickable\"\n\t\t);\n\t\tsvg.classed(\"clickable\", legendClickable);\n\n\t\tif (legendClickable && addedLegendItems.size() > 0) {\n\t\t\tthis.addEventListeners();\n\t\t}\n\t}\n\n\tbreakItemsIntoLines(addedLegendItems) {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\t\tconst legendItemsHorizontalSpacing =\n\t\t\toptions.legend.items.horizontalSpace;\n\t\tconst legendItemsVerticalSpacing = options.legend.items.verticalSpace;\n\t\tconst legendTextYOffset = options.legend.items.textYOffset;\n\t\tconst spaceNeededForCheckbox =\n\t\t\tcheckboxRadius * 2 + options.legend.checkbox.spaceAfter;\n\n\t\t// Check if there are disabled legend items\n\t\tconst { DISABLED } = options.legend.items.status;\n\t\tconst dataGroups = this.model.getDataGroups();\n\t\tconst hasDeactivatedItems = dataGroups.some(\n\t\t\t(dataGroup) => dataGroup.status === DISABLED\n\t\t);\n\n\t\tconst legendOrientation = Tools.getProperty(\n\t\t\toptions,\n\t\t\t\"legend\",\n\t\t\t\"orientation\"\n\t\t);\n\n\t\t// Keep track of line numbers and positions\n\t\tlet startingPoint = 0;\n\t\tlet lineNumber = 0;\n\t\tlet itemIndexInLine = 0;\n\t\tlet lastYPosition;\n\t\taddedLegendItems\n\t\t\t.merge(svg.selectAll(\"g.legend-item\"))\n\t\t\t.each(function (d, i) {\n\t\t\t\tconst legendItem = select(this);\n\t\t\t\tconst previousLegendItem = select(\n\t\t\t\t\tsvg.selectAll(\"g.legend-item\").nodes()[i - 1]\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\titemIndexInLine === 0 ||\n\t\t\t\t\tpreviousLegendItem.empty() ||\n\t\t\t\t\tlegendOrientation === LegendOrientations.VERTICAL\n\t\t\t\t) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tlegendOrientation === LegendOrientations.VERTICAL &&\n\t\t\t\t\t\ti !== 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst svgDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tself.parent,\n\t\t\t\t\t\t{ useAttr: true }\n\t\t\t\t\t);\n\t\t\t\t\tconst legendItemTextDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tselect(this).select(\"text\"),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\t\t\t\t\tconst lastLegendItemTextDimensions = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tpreviousLegendItem.select(\"text\"),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\t\t\t\t\tstartingPoint =\n\t\t\t\t\t\tstartingPoint +\n\t\t\t\t\t\tlastLegendItemTextDimensions.width +\n\t\t\t\t\t\tspaceNeededForCheckbox +\n\t\t\t\t\t\tlegendItemsHorizontalSpacing;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartingPoint +\n\t\t\t\t\t\t\tspaceNeededForCheckbox +\n\t\t\t\t\t\t\tlegendItemTextDimensions.width >\n\t\t\t\t\t\tsvgDimensions.width\n\t\t\t\t\t) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t\tstartingPoint = 0;\n\t\t\t\t\t\titemIndexInLine = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst yOffset = 0;\n\n\t\t\t\t// Position checkbox\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tlegendItem\n\t\t\t\t\t.select(\"rect.checkbox\")\n\t\t\t\t\t.attr(\"x\", startingPoint)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\tyOffset + lineNumber * legendItemsVerticalSpacing\n\t\t\t\t\t);\n\n\t\t\t\t// Position text\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tconst yPosition =\n\t\t\t\t\tlegendTextYOffset + lineNumber * legendItemsVerticalSpacing;\n\t\t\t\tlegendItem\n\t\t\t\t\t.select(\"text\")\n\t\t\t\t\t.attr(\"x\", startingPoint + spaceNeededForCheckbox)\n\t\t\t\t\t.attr(\"y\", yOffset + yPosition + 2);\n\n\t\t\t\tlastYPosition = yPosition;\n\n\t\t\t\t// Render checkbox check icon\n\t\t\t\tif (\n\t\t\t\t\thasDeactivatedItems &&\n\t\t\t\t\tlegendItem.select(\"g.check\").empty()\n\t\t\t\t) {\n\t\t\t\t\tlegendItem.append(\"g\").classed(\"check\", true).html(`\n\t\t\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 32 32\" aria-hidden=\"true\"\n\t\t\t\t\t\t\t\tstyle=\"will-change: transform;\">\n\t\t\t\t\t\t\t\t<path d=\"M13 21.2l-7.1-7.1-1.4 1.4 7.1 7.1L13 24 27.1 9.9l-1.4-1.5z\"></path>\n\t\t\t\t\t\t\t\t<title>Checkmark</title>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t`);\n\n\t\t\t\t\tlegendItem\n\t\t\t\t\t\t.select(\"g.check svg\")\n\t\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\n\t\t\t\t\t\t\t\"x\",\n\t\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"x\")\n\t\t\t\t\t\t\t) + 0.5\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.attr(\n\t\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"y\")\n\t\t\t\t\t\t\t) + 0.5\n\t\t\t\t\t\t);\n\t\t\t\t} else if (\n\t\t\t\t\t!hasDeactivatedItems &&\n\t\t\t\t\t!legendItem.select(\"g.check\").empty()\n\t\t\t\t) {\n\t\t\t\t\tlegendItem.select(\"g.check\").remove();\n\t\t\t\t}\n\n\t\t\t\titemIndexInLine++;\n\t\t\t});\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\t\tconst legendOptions = Tools.getProperty(options, \"legend\");\n\t\tconst truncationThreshold = Tools.getProperty(\n\t\t\tlegendOptions,\n\t\t\t\"truncation\",\n\t\t\t\"threshold\"\n\t\t);\n\n\t\tsvg.selectAll(\"g.legend-item\")\n\t\t\t.on(\"mouseover\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_HOVER, {\n\t\t\t\t\thoveredElement: select(this),\n\t\t\t\t});\n\n\t\t\t\t// Configs\n\t\t\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem\n\t\t\t\t\t.append(\"rect\")\n\t\t\t\t\t.classed(\"hover-stroke\", true)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"x\",\n\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\thoveredItem.select(\"rect.checkbox\").attr(\"x\")\n\t\t\t\t\t\t) - 2\n\t\t\t\t\t)\n\t\t\t\t\t.attr(\n\t\t\t\t\t\t\"y\",\n\t\t\t\t\t\tparseFloat(\n\t\t\t\t\t\t\thoveredItem.select(\"rect.checkbox\").attr(\"y\")\n\t\t\t\t\t\t) - 2\n\t\t\t\t\t)\n\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"rx\", 3)\n\t\t\t\t\t.attr(\"ry\", 3)\n\t\t\t\t\t.lower();\n\t\t\t})\n\t\t\t.on(\"click\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_CLICK, {\n\t\t\t\t\tclickedElement: select(this),\n\t\t\t\t});\n\n\t\t\t\tconst clickedItem = select(this);\n\t\t\t\tconst clickedItemData = clickedItem.datum() as any;\n\n\t\t\t\tself.model.toggleDataLabel(clickedItemData.name);\n\t\t\t})\n\t\t\t.on(\"mousemove\", function () {\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\tconst hoveredItemData = hoveredItem.datum() as any;\n\t\t\t\tif (hoveredItemData.name.length > truncationThreshold) {\n\t\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\t\thoveredElement: hoveredItem,\n\t\t\t\t\ttype: TooltipTypes.LEGEND,\n\t\t\t\t});\n\t\t\t\t}\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.select(\"rect.hover-stroke\").remove();\n\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE);\n\n\t\t\t\tself.services.events.dispatchEvent(\n\t\t\t\t\tEvents.Legend.ITEM_MOUSEOUT,\n\t\t\t\t\t{\n\t\t\t\t\t\thoveredElement: hoveredItem,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t});\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Tooltip } from "./tooltip";
2
- import { TooltipPosition } from "./../../interfaces";
2
+ import { TooltipPosition, TooltipTypes } from "./../../interfaces";
3
3
  export declare class TooltipBar extends Tooltip {
4
4
  init(): void;
5
5
  /**
@@ -18,7 +18,7 @@ export declare class TooltipBar extends Tooltip {
18
18
  * Returns the html for the bar single point tooltip
19
19
  * @param data associated values for the hovered bar
20
20
  */
21
- getTooltipHTML(data: any): string;
21
+ getTooltipHTML(data: any, type: TooltipTypes): string;
22
22
  /**
23
23
  * Multip tooltips for bar charts include totals for each stack
24
24
  * @param data
@@ -39,7 +39,9 @@ var TooltipBar = /** @class */ (function (_super) {
39
39
  if ((e.detail.type === TooltipTypes.DATAPOINT &&
40
40
  Tools.getProperty(_this.model.getOptions(), "tooltip", "datapoint", "enabled")) ||
41
41
  (e.detail.type === TooltipTypes.GRIDLINE &&
42
- Tools.getProperty(_this.model.getOptions(), "tooltip", "gridline", "enabled"))) {
42
+ Tools.getProperty(_this.model.getOptions(), "tooltip", "gridline", "enabled")) ||
43
+ (e.detail.type === TooltipTypes.LEGEND) ||
44
+ (e.detail.type === TooltipTypes.AXISLABEL)) {
43
45
  var data = e.detail.hoveredElement.datum();
44
46
  var hoveredElement = e.detail.hoveredElement.node();
45
47
  var defaultHTML = void 0;
@@ -55,7 +57,7 @@ var TooltipBar = /** @class */ (function (_super) {
55
57
  else {
56
58
  data = e.detail.hoveredElement.datum();
57
59
  }
58
- defaultHTML = _this.getTooltipHTML(data);
60
+ defaultHTML = _this.getTooltipHTML(data, e.detail.type);
59
61
  }
60
62
  // if there is a provided tooltip HTML function call it and pass the defaultHTML
61
63
  if (Tools.getProperty(_this.model.getOptions(), "tooltip", "customHTML")) {
@@ -67,9 +69,14 @@ var TooltipBar = /** @class */ (function (_super) {
67
69
  // default tooltip
68
70
  tooltipTextContainer.html(defaultHTML);
69
71
  }
70
- var position = _this.getTooltipPosition(hoveredElement, data);
71
- // Position the tooltip relative to the bars
72
- _this.positionTooltip(e.detail.multidata ? undefined : position);
72
+ if ((e.detail.type === TooltipTypes.LEGEND) || (e.detail.type === TooltipTypes.AXISLABEL)) {
73
+ _this.positionTooltip();
74
+ }
75
+ else {
76
+ var position = _this.getTooltipPosition(hoveredElement, data);
77
+ // Position the tooltip relative to the bars
78
+ _this.positionTooltip(e.detail.multidata ? undefined : position);
79
+ }
73
80
  }
74
81
  else if (e.detail.type === TooltipTypes.TITLE) {
75
82
  // use the chart size to enforce a max width on the tooltip
@@ -81,7 +88,7 @@ var TooltipBar = /** @class */ (function (_super) {
81
88
  // use tooltip.ts to get the tooltip html for titles
82
89
  tooltipTextContainer.html(_super.prototype.getTooltipHTML.call(_this, e.detail.hoveredElement, TooltipTypes.TITLE));
83
90
  // get the position based on the title positioning (static)
84
- var position = _super.prototype.getTooltipPosition.call(_this, e.detail.hoveredElement.node());
91
+ var position = _super.prototype.getTooltipPosition.call(_this, e.detail.hoveredElement.node(), e.detail.type);
85
92
  _this.positionTooltip(position);
86
93
  }
87
94
  // Fade in
@@ -132,7 +139,13 @@ var TooltipBar = /** @class */ (function (_super) {
132
139
  * Returns the html for the bar single point tooltip
133
140
  * @param data associated values for the hovered bar
134
141
  */
135
- TooltipBar.prototype.getTooltipHTML = function (data) {
142
+ TooltipBar.prototype.getTooltipHTML = function (data, type) {
143
+ if (type === TooltipTypes.LEGEND) {
144
+ return "<div class=\"legend-tooltip\"><p class=\"label\">" + data.name + "</p></div>";
145
+ }
146
+ else if (type === TooltipTypes.AXISLABEL) {
147
+ return "<div class=\"axis-tooltip\"><p class=\"label\">" + data + "</p></div>";
148
+ }
136
149
  var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter")
137
150
  ? this.model.getOptions().tooltip.valueFormatter(data.value)
138
151
  : data.value.toLocaleString("en");
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-bar.js","sourceRoot":"","sources":["tooltip-bar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACN,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,MAAM,GACN,MAAM,oBAAoB,CAAC;AAE5B,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;IAAgC,8BAAO;IAAvC;;IAuPA,CAAC;IAtPA,yBAAI,GAAJ;QAAA,iBAsHC;QArHA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACpC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,OAAO,EACP,QAAQ,CACR,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,cAAc,CACrC,MAAM,EACN,SAAO,QAAQ,CAAC,MAAM,UAAK,WAAW,cAAW,CACjD,CAAC;QAEF,oCAAoC;QACpC,IAAM,oBAAoB,GAAG,QAAQ,CAAC,cAAc,CACnD,IAAI,CAAC,OAAO,EACZ,iBAAiB,CACjB,CAAC;QACF,IAAI,CAAC,OA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AW,CACxB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB;YACA,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC;YACvD,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE9B,OAAO,CACN,4BAA4B;YAC5B,MAAM;iBACJ,GAAG,CAAC,UAAC,SAAS;gBACd,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACvC,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB;oBACA,CAAC,CAAC,KAAI,CAAC,KAAK;yBACT,UAAU,EAAE;yBACZ,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC;oBAC1C,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAExC,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAC/C,SAAS,CAAC,YAAY,EACtB,SAAS,CAAC,KAAK,CACf,CAAC;gBAEF,OAAO,0GAGuB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACP,CAAC,CAAC;iBACD,IAAI,CAAC,EAAE,CAAC;aACV,mHAGsB,KAAK,uDAGrB,CAAA,CACN,CAAC;IACH,CAAC;IACF,iBAAC;AAAD,CAAC,AAvPD,CAAgC,OAAO,GAuPtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport {\n\tTooltipPosition,\n\tTooltipTypes,\n\tCartesianOrientations,\n\tEvents,\n} from \"./../../interfaces\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class TooltipBar extends Tooltip {\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"style\",\n\t\t\t\"prefix\"\n\t\t);\n\t\tthis.tooltip = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${settings.prefix}--${chartprefix}--tooltip`\n\t\t);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(\n\t\t\tthis.tooltip,\n\t\t\t\"div.content-box\"\n\t\t);\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.SHOW, (e) => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif (\n\t\t\t\t(e.detail.type === TooltipTypes.DATAPOINT &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"datapoint\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.GRIDLINE &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"gridline\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t))\n\t\t\t) {\n\t\t\t\tlet data = e.detail.hoveredElement.datum() as any;\n\t\t\t\tconst hoveredElement = e.detail.hoveredElement.node();\n\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tif (e.detail.data) {\n\t\t\t\t\t\tdata = e.detail.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdata = e.detail.hoveredElement.datum();\n\t\t\t\t\t}\n\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it and pass the defaultHTML\n\t\t\t\tif (\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"customHTML\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\t\tthis.model\n\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t.tooltip.customHTML(data, defaultHTML)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\tconst position = this.getTooltipPosition(hoveredElement, data);\n\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position);\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\t// use the chart size to enforce a max width on the tooltip\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(\n\t\t\t\t\tholder,\n\t\t\t\t\t`svg.${settings.prefix}--${chartprefix}--chart-svg`\n\t\t\t\t);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax =\n\t\t\t\t\tDOMUtils.getSVGElementSize(chart).width *\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"title\",\n\t\t\t\t\t\t\"width\"\n\t\t\t\t\t);\n\t\t\t\tthis.tooltip.style(\"max-width\", tooltipMax);\n\n\t\t\t\t// use tooltip.ts to get the tooltip html for titles\n\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\tsuper.getTooltipHTML(\n\t\t\t\t\t\te.detail.hoveredElement,\n\t\t\t\t\t\tTooltipTypes.TITLE\n\t\t\t\t\t)\n\t\t\t\t);\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(\n\t\t\t\t\te.detail.hoveredElement.node()\n\t\t\t\t);\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.HIDE, () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\t/**\n\t * Get the position of the tooltip relative to the active hovered bar. Tooltip should appear above\n\t * positive valued data and below negative value data.\n\t * @param hoveredElement\n\t */\n\tgetTooltipPosition(hoveredElement, data?: any) {\n\t\tif (data === undefined) {\n\t\t\tdata = select(hoveredElement).datum() as any;\n\t\t}\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder())\n\t\t\t.node()\n\t\t\t.getBoundingClientRect();\n\t\tconst barPosition = hoveredElement.getBoundingClientRect();\n\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t// if there is a negative value bar chart, need to place the tooltip below the bar\n\t\tif (data.value <= 0) {\n\t\t\t// negative bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft:\n\t\t\t\t\tbarPosition.left -\n\t\t\t\t\tholderPosition.left +\n\t\t\t\t\tbarPosition.width / 2,\n\t\t\t\ttop: barPosition.bottom - holderPosition.top + verticalOffset,\n\t\t\t};\n\n\t\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t\t} else {\n\t\t\t// positive bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft:\n\t\t\t\t\tbarPosition.left -\n\t\t\t\t\tholderPosition.left +\n\t\t\t\t\tbarPosition.width / 2,\n\t\t\t\ttop: barPosition.top - holderPosition.top - verticalOffset,\n\t\t\t};\n\n\t\t\treturn { placement: TooltipPosition.TOP, position: tooltipPos };\n\t\t}\n\t}\n\n\t/**\n\t * Returns the html for the bar single point tooltip\n\t * @param data associated values for the hovered bar\n\t */\n\tgetTooltipHTML(data: any) {\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(data.value)\n\t\t\t: data.value.toLocaleString(\"en\");\n\n\t\treturn `<div class=\"datapoint-tooltip\"><p class=\"value\">${formattedValue}</p></div>`;\n\t}\n\n\t/**\n\t * Multip tooltips for bar charts include totals for each stack\n\t * @param data\n\t */\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\tpoints.reverse();\n\t\t// in a vertical bar chart the tooltip should display in order of the drawn bars\n\t\t// in horizontal stacked bar, the order of the segments from Left to Right are displayed top down in tooltip\n\t\tif (\n\t\t\tthis.services.cartesianScales.getOrientation() ===\n\t\t\tCartesianOrientations.VERTICAL\n\t\t) {\n\t\t\tpoints.reverse();\n\t\t}\n\n\t\t// get the total for the stacked tooltip\n\t\tlet total = points.reduce((sum, item) => sum + item.value, 0);\n\n\t\t// format the total value\n\t\ttotal = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(total)\n\t\t\t: total.toLocaleString(\"en\");\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tpoints\n\t\t\t\t.map((datapoint) => {\n\t\t\t\t\tconst formattedValue = Tools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t)\n\t\t\t\t\t\t? this.model\n\t\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t\t.tooltip.valueFormatter(datapoint.value)\n\t\t\t\t\t\t: datapoint.value.toLocaleString(\"en\");\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatapoint.datasetLabel,\n\t\t\t\t\t\tdatapoint.label\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t`<li>\n\t\t\t\t\t<div class='total-val'>\n\t\t\t\t\t\t<p class='label'>Total</p>\n\t\t\t\t\t\t<p class='value'>${total}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t</ul>`\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"tooltip-bar.js","sourceRoot":"","sources":["tooltip-bar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACN,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,MAAM,GACN,MAAM,oBAAoB,CAAC;AAE5B,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;IAAgC,8BAAO;IAAvC;;IAmQA,CAAC;IAlQA,yBAAI,GAAJ;QAAA,iBA4HC;QA3HA,2BAA2B;QAC3B,IAAM,MAAM,GAAG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O,CAAC,cAAc,CAAC,KAAK,CAAC;YACvD,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE9B,OAAO,CACN,4BAA4B;YAC5B,MAAM;iBACJ,GAAG,CAAC,UAAC,SAAS;gBACd,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACvC,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB;oBACA,CAAC,CAAC,KAAI,CAAC,KAAK;yBACT,UAAU,EAAE;yBACZ,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC;oBAC1C,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAExC,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAC/C,SAAS,CAAC,YAAY,EACtB,SAAS,CAAC,KAAK,CACf,CAAC;gBAEF,OAAO,0GAGuB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACP,CAAC,CAAC;iBACD,IAAI,CAAC,EAAE,CAAC;aACV,mHAGsB,KAAK,uDAGrB,CAAA,CACN,CAAC;IACH,CAAC;IACF,iBAAC;AAAD,CAAC,AAnQD,CAAgC,OAAO,GAmQtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport {\n\tTooltipPosition,\n\tTooltipTypes,\n\tCartesianOrientations,\n\tEvents,\n} from \"./../../interfaces\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class TooltipBar extends Tooltip {\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"style\",\n\t\t\t\"prefix\"\n\t\t);\n\t\tthis.tooltip = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${settings.prefix}--${chartprefix}--tooltip`\n\t\t);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(\n\t\t\tthis.tooltip,\n\t\t\t\"div.content-box\"\n\t\t);\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.SHOW, (e) => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif (\n\t\t\t\t(e.detail.type === TooltipTypes.DATAPOINT &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"datapoint\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.GRIDLINE &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"gridline\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.LEGEND) ||\n\t\t\t\t(e.detail.type === TooltipTypes.AXISLABEL)\n\t\t\t) {\n\t\t\t\tlet data = e.detail.hoveredElement.datum() as any;\n\t\t\t\tconst hoveredElement = e.detail.hoveredElement.node();\n\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tif (e.detail.data) {\n\t\t\t\t\t\tdata = e.detail.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdata = e.detail.hoveredElement.datum();\n\t\t\t\t\t}\n\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data, e.detail.type);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it and pass the defaultHTML\n\t\t\t\tif (\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"customHTML\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\t\tthis.model\n\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t.tooltip.customHTML(data, defaultHTML)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\t\t\t\tif ((e.detail.type === TooltipTypes.LEGEND) || (e.detail.type === TooltipTypes.AXISLABEL)) {\n\t\t\t\t\tthis.positionTooltip();\n\t\t\t\t} else {\n\t\t\t\t\tconst position = this.getTooltipPosition(hoveredElement, data);\n\t\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position);\n\t\t\t\t}\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\t// use the chart size to enforce a max width on the tooltip\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(\n\t\t\t\t\tholder,\n\t\t\t\t\t`svg.${settings.prefix}--${chartprefix}--chart-svg`\n\t\t\t\t);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax =\n\t\t\t\t\tDOMUtils.getSVGElementSize(chart).width *\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"title\",\n\t\t\t\t\t\t\"width\"\n\t\t\t\t\t);\n\t\t\t\tthis.tooltip.style(\"max-width\", tooltipMax);\n\n\t\t\t\t// use tooltip.ts to get the tooltip html for titles\n\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\tsuper.getTooltipHTML(\n\t\t\t\t\t\te.detail.hoveredElement,\n\t\t\t\t\t\tTooltipTypes.TITLE\n\t\t\t\t\t)\n\t\t\t\t);\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(\n\t\t\t\t\te.detail.hoveredElement.node(),\n\t\t\t\t\te.detail.type\n\t\t\t\t);\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.HIDE, () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\t/**\n\t * Get the position of the tooltip relative to the active hovered bar. Tooltip should appear above\n\t * positive valued data and below negative value data.\n\t * @param hoveredElement\n\t */\n\tgetTooltipPosition(hoveredElement, data?: any) {\n\t\tif (data === undefined) {\n\t\t\tdata = select(hoveredElement).datum() as any;\n\t\t}\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder())\n\t\t\t.node()\n\t\t\t.getBoundingClientRect();\n\t\tconst barPosition = hoveredElement.getBoundingClientRect();\n\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t// if there is a negative value bar chart, need to place the tooltip below the bar\n\t\tif (data.value <= 0) {\n\t\t\t// negative bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft:\n\t\t\t\t\tbarPosition.left -\n\t\t\t\t\tholderPosition.left +\n\t\t\t\t\tbarPosition.width / 2,\n\t\t\t\ttop: barPosition.bottom - holderPosition.top + verticalOffset,\n\t\t\t};\n\n\t\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t\t} else {\n\t\t\t// positive bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft:\n\t\t\t\t\tbarPosition.left -\n\t\t\t\t\tholderPosition.left +\n\t\t\t\t\tbarPosition.width / 2,\n\t\t\t\ttop: barPosition.top - holderPosition.top - verticalOffset,\n\t\t\t};\n\n\t\t\treturn { placement: TooltipPosition.TOP, position: tooltipPos };\n\t\t}\n\t}\n\n\t/**\n\t * Returns the html for the bar single point tooltip\n\t * @param data associated values for the hovered bar\n\t */\n\tgetTooltipHTML(data: any, type: TooltipTypes) {\n\t\tif (type === TooltipTypes.LEGEND) {\n\t\t\treturn `<div class=\"legend-tooltip\"><p class=\"label\">${data.name}</p></div>`;\n\t\t} else if (type === TooltipTypes.AXISLABEL) {\n\t\t\treturn `<div class=\"axis-tooltip\"><p class=\"label\">${data}</p></div>`;\n\t\t}\n\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(data.value)\n\t\t\t: data.value.toLocaleString(\"en\");\n\n\t\treturn `<div class=\"datapoint-tooltip\"><p class=\"value\">${formattedValue}</p></div>`;\n\t}\n\n\t/**\n\t * Multip tooltips for bar charts include totals for each stack\n\t * @param data\n\t */\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\tpoints.reverse();\n\t\t// in a vertical bar chart the tooltip should display in order of the drawn bars\n\t\t// in horizontal stacked bar, the order of the segments from Left to Right are displayed top down in tooltip\n\t\tif (\n\t\t\tthis.services.cartesianScales.getOrientation() ===\n\t\t\tCartesianOrientations.VERTICAL\n\t\t) {\n\t\t\tpoints.reverse();\n\t\t}\n\n\t\t// get the total for the stacked tooltip\n\t\tlet total = points.reduce((sum, item) => sum + item.value, 0);\n\n\t\t// format the total value\n\t\ttotal = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(total)\n\t\t\t: total.toLocaleString(\"en\");\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tpoints\n\t\t\t\t.map((datapoint) => {\n\t\t\t\t\tconst formattedValue = Tools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t)\n\t\t\t\t\t\t? this.model\n\t\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t\t.tooltip.valueFormatter(datapoint.value)\n\t\t\t\t\t\t: datapoint.value.toLocaleString(\"en\");\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatapoint.datasetLabel,\n\t\t\t\t\t\tdatapoint.label\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t`<li>\n\t\t\t\t\t<div class='total-val'>\n\t\t\t\t\t\t<p class='label'>Total</p>\n\t\t\t\t\t\t<p class='value'>${total}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t</ul>`\n\t\t);\n\t}\n}\n"]}
@@ -25,6 +25,9 @@ var TooltipPie = /** @class */ (function (_super) {
25
25
  var title = this.model.getOptions().title;
26
26
  return "<div class=\"title-tooltip\"><text>" + title + "</text></div>";
27
27
  }
28
+ else if (type === TooltipTypes.LEGEND) {
29
+ return "<div class=\"legend-tooltip\"><p class=\"label\">" + d.name + "</p></div>";
30
+ }
28
31
  var dataVal = d.data;
29
32
  var groupMapsTo = this.model.getOptions().data.groupMapsTo;
30
33
  // format the value if needed
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-pie.js","sourceRoot":"","sources":["tooltip-pie.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;IAAgC,8BAAO;IAAvC;;IA4BA,CAAC;IA3BA,mCAAc,GAAd,UAAe,CAAM,EAAE,IAAkB;QACxC,mDAAmD;QACnD,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC;YAC5C,OAAO,wCAAoC,KAAK,kBAAe,CAAC;SAChE;QAED,IAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC;QACf,IAAA,sDAAW,CAAkC;QAErD,6BAA6B;QAC7B,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACvC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB;YACA,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/D,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEtC,4EAA4E;QAC5E,IAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QAEnC,OAAO,mEACc,KAAK,yCACL,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,iBAAC;AAAD,CAAC,AA5BD,CAAgC,OAAO,GA4BtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"../../interfaces\";\n\nexport class TooltipPie extends Tooltip {\n\tgetTooltipHTML(d: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t}\n\n\t\tconst dataVal = d.data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(dataVal.value)\n\t\t\t: dataVal.value.toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"tooltip-pie.js","sourceRoot":"","sources":["tooltip-pie.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;IAAgC,8BAAO;IAAvC;;IA8BA,CAAC;IA7BA,mCAAc,GAAd,UAAe,CAAM,EAAE,IAAkB;QACxC,mDAAmD;QACnD,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC;YAC5C,OAAO,wCAAoC,KAAK,kBAAe,CAAC;SAChE;aAAM,IAAI,IAAI,KAAK,YAAY,CAAC,MAAM,EAAE;YACxC,OAAO,sDAAgD,CAAC,CAAC,IAAI,eAAY,CAAC;SAC1E;QAED,IAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC;QACf,IAAA,sDAAW,CAAkC;QAErD,6BAA6B;QAC7B,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACvC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB;YACA,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/D,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEtC,4EAA4E;QAC5E,IAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QAEnC,OAAO,mEACc,KAAK,yCACL,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,iBAAC;AAAD,CAAC,AA9BD,CAAgC,OAAO,GA8BtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"../../interfaces\";\n\nexport class TooltipPie extends Tooltip {\n\tgetTooltipHTML(d: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t} else if (type === TooltipTypes.LEGEND) {\n\t\t\treturn `<div class=\"legend-tooltip\"><p class=\"label\">${d.name}</p></div>`;\n\t\t}\n\n\t\tconst dataVal = d.data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model.getOptions().tooltip.valueFormatter(dataVal.value)\n\t\t\t: dataVal.value.toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`;\n\t}\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Tooltip } from "./tooltip";
2
+ import { TooltipTypes } from "../../interfaces";
2
3
  export declare class TooltipRadar extends Tooltip {
3
- getMultilineTooltipHTML(data: any): string;
4
+ getMultilineTooltipHTML(data: any, type: TooltipTypes): string;
4
5
  }
@@ -18,7 +18,7 @@ var TooltipRadar = /** @class */ (function (_super) {
18
18
  function TooltipRadar() {
19
19
  return _super !== null && _super.apply(this, arguments) || this;
20
20
  }
21
- TooltipRadar.prototype.getMultilineTooltipHTML = function (data) {
21
+ TooltipRadar.prototype.getMultilineTooltipHTML = function (data, type) {
22
22
  var _this = this;
23
23
  var options = this.model.getOptions();
24
24
  var groupMapsTo = options.data.groupMapsTo;
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-radar.js","sourceRoot":"","sources":["tooltip-radar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;IAAkC,gCAAO;IAAzC;;IAwCA,CAAC;IAvCA,8CAAuB,GAAvB,UAAwB,IAAS;QAAjC,iBAsCC;QArCA,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QAChC,IAAA,sCAAW,CAAkB;QAC/B,IAAA,uBAAqC,EAAnC,gBAAK,EAAE,gBAA4B,CAAC;QAE5C,uDAAuD;QACvD,IAAI,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAnB,CAAmB,CAAC,CAAC;QAEzC,OAAO,CACN,4BAA4B;YAC5B,IAAI;iBACF,GAAG,CAAC,UAAC,KAAK;gBACV,IAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CACnD,OAAO,EACP,SAAS,EACT,gBAAgB,CAChB,CAAC;gBACF,IAAM,cAAc,GAAG,0BAA0B;oBAChD,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC1C,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAEhB,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAC/C,KAAK,CAAC,WAAW,CAAC,CAClB,CAAC;gBAEF,OAAO,0GAGuB,cAAc,wEACxB,KAAK,CAAC,WAAW,CAAC,6CAClB,cAAc,0CAE7B,CAAC;YACP,CAAC,CAAC;iBACD,IAAI,CAAC,EAAE,CAAC;YACV,OAAO,CACP,CAAC;IACH,CAAC;IACF,mBAAC;AAAD,CAAC,AAxCD,CAAkC,OAAO,GAwCxC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\n\nexport class TooltipRadar extends Tooltip {\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst options = this.model.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\t\tconst { angle, value } = options.radar.axes;\n\n\t\t// sort them so they are in the same order as the graph\n\t\tdata.sort((a, b) => b[value] - a[value]);\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tdata\n\t\t\t\t.map((datum) => {\n\t\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t);\n\t\t\t\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t\t\t\t? userProvidedValueFormatter(datum[value])\n\t\t\t\t\t\t: datum[value];\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatum[groupMapsTo]\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t\"</ul>\"\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"tooltip-radar.js","sourceRoot":"","sources":["tooltip-radar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC;IAAkC,gCAAO;IAAzC;;IAwCA,CAAC;IAvCA,8CAAuB,GAAvB,UAAwB,IAAS,EAAE,IAAkB;QAArD,iBAsCC;QArCA,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QAChC,IAAA,sCAAW,CAAkB;QAC/B,IAAA,uBAAqC,EAAnC,gBAAK,EAAE,gBAA4B,CAAC;QAE5C,uDAAuD;QACvD,IAAI,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAnB,CAAmB,CAAC,CAAC;QAEzC,OAAO,CACN,4BAA4B;YAC5B,IAAI;iBACF,GAAG,CAAC,UAAC,KAAK;gBACV,IAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CACnD,OAAO,EACP,SAAS,EACT,gBAAgB,CAChB,CAAC;gBACF,IAAM,cAAc,GAAG,0BAA0B;oBAChD,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC1C,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAEhB,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAC/C,KAAK,CAAC,WAAW,CAAC,CAClB,CAAC;gBAEF,OAAO,0GAGuB,cAAc,wEACxB,KAAK,CAAC,WAAW,CAAC,6CAClB,cAAc,0CAE7B,CAAC;YACP,CAAC,CAAC;iBACD,IAAI,CAAC,EAAE,CAAC;YACV,OAAO,CACP,CAAC;IACH,CAAC;IACF,mBAAC;AAAD,CAAC,AAxCD,CAAkC,OAAO,GAwCxC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"../../interfaces\";\n\nexport class TooltipRadar extends Tooltip {\n\tgetMultilineTooltipHTML(data: any, type: TooltipTypes) {\n\t\tconst options = this.model.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\t\tconst { angle, value } = options.radar.axes;\n\n\t\t// sort them so they are in the same order as the graph\n\t\tdata.sort((a, b) => b[value] - a[value]);\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tdata\n\t\t\t\t.map((datum) => {\n\t\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t);\n\t\t\t\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t\t\t\t? userProvidedValueFormatter(datum[value])\n\t\t\t\t\t\t: datum[value];\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatum[groupMapsTo]\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t\"</ul>\"\n\t\t);\n\t}\n}\n"]}
@@ -24,6 +24,12 @@ var TooltipScatter = /** @class */ (function (_super) {
24
24
  // the main tooltip component handles title styles
25
25
  return _super.prototype.getTooltipHTML.call(this, datum, type);
26
26
  }
27
+ else if (type === TooltipTypes.LEGEND) {
28
+ return "<div class=\"legend-tooltip\"><p class=\"label\">" + datum.name + "</p></div>";
29
+ }
30
+ else if (type === TooltipTypes.AXISLABEL) {
31
+ return "<div class=\"axis-tooltip\"><p class=\"label\">" + datum + "</p></div>";
32
+ }
27
33
  var groupMapsTo = this.model.getOptions().data.groupMapsTo;
28
34
  var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
29
35
  var userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter");
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-scatter.js","sourceRoot":"","sources":["tooltip-scatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;IAAoC,kCAAO;IAA3C;;IA6BA,CAAC;IA5BA,uCAAc,GAAd,UAAe,KAAU,EAAE,IAAkB;QAC5C,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,kDAAkD;YAClD,OAAO,iBAAM,cAAc,YAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACzC;QAEO,IAAA,sDAAW,CAAkC;QACrD,IAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,kBAAkB,EAAE,CAAC;QAE3E,IAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CACnD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB,CAAC;QACF,IAAM,cAAc,GAAG,0BAA0B;YAChD,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACpD,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE/C,2GAA2G;QAC3G,IAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QAErE,OAAO,oFAEwB,cAAc,oEACxB,KAAK,CAAC,WAAW,CAAC,yCAClB,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,qBAAC;AAAD,CAAC,AA7BD,CAAoC,OAAO,GA6B1C","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"./../../interfaces\";\n\nexport class TooltipScatter extends Tooltip {\n\tgetTooltipHTML(datum: any, type: TooltipTypes) {\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\t// the main tooltip component handles title styles\n\t\t\treturn super.getTooltipHTML(datum, type);\n\t\t}\n\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t);\n\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t? userProvidedValueFormatter(datum[rangeIdentifier])\n\t\t\t: datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\tconst indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);\n\n\t\treturn `\n\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"tooltip-scatter.js","sourceRoot":"","sources":["tooltip-scatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;IAAoC,kCAAO;IAA3C;;IAiCA,CAAC;IAhCA,uCAAc,GAAd,UAAe,KAAU,EAAE,IAAkB;QAC5C,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,kDAAkD;YAClD,OAAO,iBAAM,cAAc,YAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACzC;aAAM,IAAI,IAAI,KAAK,YAAY,CAAC,MAAM,EAAE;YACxC,OAAO,sDAAgD,KAAK,CAAC,IAAI,eAAY,CAAC;SAC9E;aAAM,IAAI,IAAI,KAAK,YAAY,CAAC,SAAS,EAAE;YAC3C,OAAO,oDAA8C,KAAK,eAAY,CAAC;SACvE;QAEO,IAAA,sDAAW,CAAkC;QACrD,IAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,kBAAkB,EAAE,CAAC;QAE3E,IAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CACnD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,SAAS,EACT,gBAAgB,CAChB,CAAC;QACF,IAAM,cAAc,GAAG,0BAA0B;YAChD,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACpD,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE/C,2GAA2G;QAC3G,IAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QAErE,OAAO,oFAEwB,cAAc,oEACxB,KAAK,CAAC,WAAW,CAAC,yCAClB,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,qBAAC;AAAD,CAAC,AAjCD,CAAoC,OAAO,GAiC1C","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"./../../interfaces\";\n\nexport class TooltipScatter extends Tooltip {\n\tgetTooltipHTML(datum: any, type: TooltipTypes) {\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\t// the main tooltip component handles title styles\n\t\t\treturn super.getTooltipHTML(datum, type);\n\t\t} else if (type === TooltipTypes.LEGEND) {\n\t\t\treturn `<div class=\"legend-tooltip\"><p class=\"label\">${datum.name}</p></div>`;\n\t\t} else if (type === TooltipTypes.AXISLABEL) {\n\t\t\treturn `<div class=\"axis-tooltip\"><p class=\"label\">${datum}</p></div>`;\n\t\t}\n\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t);\n\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t? userProvidedValueFormatter(datum[rangeIdentifier])\n\t\t\t: datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\tconst indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);\n\n\t\treturn `\n\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`;\n\t}\n}\n"]}
@@ -9,9 +9,9 @@ export declare class Tooltip extends Component {
9
9
  constructor(model: ChartModel, services: any, configs?: any);
10
10
  init(): void;
11
11
  getTooltipHTML(data: any, type: TooltipTypes): string;
12
- getMultilineTooltipHTML(data: any): string;
12
+ getMultilineTooltipHTML(data: any, type: TooltipTypes): string;
13
13
  render(): void;
14
- getTooltipPosition(hoveredElement: any): {
14
+ getTooltipPosition(hoveredElement: any, type: TooltipTypes): {
15
15
  placement: TooltipPosition;
16
16
  position: {
17
17
  left: number;
@@ -45,17 +45,19 @@ var Tooltip = /** @class */ (function (_super) {
45
45
  if ((e.detail.type === TooltipTypes.DATAPOINT &&
46
46
  Tools.getProperty(_this.model.getOptions(), "tooltip", "datapoint", "enabled")) ||
47
47
  (e.detail.type === TooltipTypes.GRIDLINE &&
48
- Tools.getProperty(_this.model.getOptions(), "tooltip", "gridline", "enabled"))) {
48
+ Tools.getProperty(_this.model.getOptions(), "tooltip", "gridline", "enabled")) ||
49
+ (e.detail.type === TooltipTypes.LEGEND) ||
50
+ (e.detail.type === TooltipTypes.AXISLABEL)) {
49
51
  var data = select(event.target).datum();
50
52
  // Generate default tooltip
51
53
  var defaultHTML = void 0;
52
54
  if (e.detail.multidata) {
53
55
  // multi tooltip
54
56
  data = e.detail.multidata;
55
- defaultHTML = _this.getMultilineTooltipHTML(data);
57
+ defaultHTML = _this.getMultilineTooltipHTML(data, e.detail.type);
56
58
  }
57
59
  else {
58
- defaultHTML = _this.getTooltipHTML(data, TooltipTypes.DATAPOINT);
60
+ defaultHTML = _this.getTooltipHTML(data, e.detail.type);
59
61
  }
60
62
  // if there is a provided tooltip HTML function call it
61
63
  if (Tools.getProperty(_this.model.getOptions(), "tooltip", "customHTML")) {
@@ -77,7 +79,7 @@ var Tooltip = /** @class */ (function (_super) {
77
79
  _this.tooltip.style("max-width", chartWidth);
78
80
  tooltipTextContainer.html(_this.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));
79
81
  // get the position based on the title positioning (static)
80
- var position = _this.getTooltipPosition(e.detail.hoveredElement.node());
82
+ var position = _this.getTooltipPosition(e.detail.hoveredElement.node(), e.detail.type);
81
83
  _this.positionTooltip(position);
82
84
  }
83
85
  // Fade in
@@ -94,6 +96,9 @@ var Tooltip = /** @class */ (function (_super) {
94
96
  var title = this.model.getOptions().title;
95
97
  return "<div class=\"title-tooltip\"><text>" + title + "</text></div>";
96
98
  }
99
+ else if (type === TooltipTypes.LEGEND) {
100
+ return "<div class=\"legend-tooltip\"><p class=\"label\">" + data.name + "</p></div>";
101
+ }
97
102
  // this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data
98
103
  var dataVal = Tools.getProperty(data, "data") ? data.data : data;
99
104
  var groupMapsTo = this.model.getOptions().data.groupMapsTo;
@@ -108,7 +113,7 @@ var Tooltip = /** @class */ (function (_super) {
108
113
  var label = dataVal[groupMapsTo];
109
114
  return "<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">" + label + "</p>\n\t\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t\t</div>";
110
115
  };
111
- Tooltip.prototype.getMultilineTooltipHTML = function (data) {
116
+ Tooltip.prototype.getMultilineTooltipHTML = function (data, type) {
112
117
  var _this = this;
113
118
  // sort them so they are in the same order as the graph
114
119
  data.sort(function (a, b) { return b.value - a.value; });
@@ -135,7 +140,7 @@ var Tooltip = /** @class */ (function (_super) {
135
140
  this.tooltip.classed("hidden", true);
136
141
  };
137
142
  // returns static position based on the element
138
- Tooltip.prototype.getTooltipPosition = function (hoveredElement) {
143
+ Tooltip.prototype.getTooltipPosition = function (hoveredElement, type) {
139
144
  var holderPosition = select(this.services.domUtils.getHolder())
140
145
  .node()
141
146
  .getBoundingClientRect();
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.js","source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AAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;YAGD,IAAA,6EAAgB,CAC6B;YAC9C,IAAI,mBAAmB,KAAK,UAAU,CAAC,IAAI,EAAE;gBAC5C,gBAAgB,IAAI,CAAC,CAAC,CAAC;aACvB;YAED,wDAAwD;YACxD,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,AA5RD,CAA6B,SAAS,GA4RrC","sourcesContent":["import * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select, mouse, event } from \"d3-selection\";\nimport { TooltipTypes, TooltipPosition, Events } from \"../../interfaces\";\n\nexport class Tooltip extends Component {\n\ttype = \"tooltip\";\n\n\ttooltip: any;\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tsuper(model, services, configs);\n\n\t\tthis.init();\n\t}\n\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"style\",\n\t\t\t\"prefix\"\n\t\t);\n\t\tthis.tooltip = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${settings.prefix}--${chartprefix}--tooltip`\n\t\t);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(\n\t\t\tthis.tooltip,\n\t\t\t\"div.content-box\"\n\t\t);\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.SHOW, (e) => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif (\n\t\t\t\t(e.detail.type === TooltipTypes.DATAPOINT &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"datapoint\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.GRIDLINE &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"gridline\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t))\n\t\t\t) {\n\t\t\t\tlet data = select(event.target).datum() as any;\n\n\t\t\t\t// Generate default tooltip\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tTooltipTypes.DATAPOINT\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it\n\t\t\t\tif (\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"customHTML\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\t\tthis.model\n\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t.tooltip.customHTML(data, defaultHTML)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Use default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\t// Position the tooltip\n\t\t\t\tthis.positionTooltip();\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(\n\t\t\t\t\tholder,\n\t\t\t\t\t`svg.${settings.prefix}--${chartprefix}--chart-svg`\n\t\t\t\t);\n\t\t\t\tconst chartWidth =\n\t\t\t\t\tDOMUtils.getSVGElementSize(chart).width *\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"title\",\n\t\t\t\t\t\t\"width\"\n\t\t\t\t\t);\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\tthis.getTooltipHTML(\n\t\t\t\t\t\te.detail.hoveredElement,\n\t\t\t\t\t\tTooltipTypes.TITLE\n\t\t\t\t\t)\n\t\t\t\t);\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(\n\t\t\t\t\te.detail.hoveredElement.node()\n\t\t\t\t);\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.HIDE, () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\tgetTooltipHTML(data: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t}\n\t\t// this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data\n\t\tconst dataVal = Tools.getProperty(data, \"data\") ? data.data : data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model\n\t\t\t\t\t.getOptions()\n\t\t\t\t\t.tooltip.valueFormatter(dataVal[rangeIdentifier])\n\t\t\t: dataVal[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t</div>`;\n\t}\n\n\tgetMultilineTooltipHTML(data: any) {\n\t\t// sort them so they are in the same order as the graph\n\t\tdata.sort((a, b) => b.value - a.value);\n\n\t\t// tells us which value to use\n\t\tconst scaleType = this.services.cartesianScales.getDomainScale()\n\t\t\t.scaleType;\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tdata\n\t\t\t\t.map((datum) => {\n\t\t\t\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\t\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t);\n\t\t\t\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t\t\t\t? userProvidedValueFormatter(datum[rangeIdentifier])\n\t\t\t\t\t\t: datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatum[groupMapsTo]\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t\"</ul>\"\n\t\t);\n\t}\n\n\trender() {\n\t\tthis.tooltip.classed(\"hidden\", true);\n\t}\n\n\t// returns static position based on the element\n\tgetTooltipPosition(hoveredElement) {\n\t\tconst holderPosition = select(this.services.domUtils.getHolder())\n\t\t\t.node()\n\t\t\t.getBoundingClientRect();\n\t\tconst elementPosition = hoveredElement.getBoundingClientRect();\n\n\t\t// get the vertical offset\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.title;\n\n\t\tconst tooltipPos = {\n\t\t\tleft:\n\t\t\t\telementPosition.left -\n\t\t\t\tholderPosition.left +\n\t\t\t\telementPosition.width / 2,\n\t\t\ttop: elementPosition.top - holderPosition.top - verticalOffset,\n\t\t};\n\n\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t}\n\n\tpositionTooltip(positionOverride?: any) {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.tooltip.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\t\tlet pos;\n\n\t\t// override position to place tooltip at {placement:.., position:{top:.. , left:..}}\n\t\tif (positionOverride) {\n\t\t\t// placement determines whether the tooltip is centered above or below the position provided\n\t\t\tconst placement =\n\t\t\t\tpositionOverride.placement === TooltipPosition.TOP\n\t\t\t\t\t? PLACEMENTS.TOP\n\t\t\t\t\t: PLACEMENTS.BOTTOM;\n\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\tpositionOverride.position,\n\t\t\t\ttarget,\n\t\t\t\tplacement\n\t\t\t);\n\t\t} else {\n\t\t\t// Find out whether tooltip should be shown on the left or right side\n\t\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\t[\n\t\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\t\tPLACEMENTS.BOTTOM,\n\t\t\t\t],\n\t\t\t\t() => ({\n\t\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\t\theight: holder.offsetHeight,\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tlet {\n\t\t\t\thorizontalOffset,\n\t\t\t} = this.model.getOptions().tooltip.datapoint;\n\t\t\tif (bestPlacementOption === PLACEMENTS.LEFT) {\n\t\t\t\thorizontalOffset *= -1;\n\t\t\t}\n\n\t\t\t// Get coordinates to where tooltip should be positioned\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0] + horizontalOffset,\n\t\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\tbestPlacementOption\n\t\t\t);\n\t\t}\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n}\n"]}
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["tooltip.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,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;gBACzB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN;gBACC,UAAU,CAAC,KAAK;gBAChB,UAAU,CAAC,IAAI;gBACf,UAAU,CAAC,GAAG;gBACd,UAAU,CAAC,MAAM;aACjB,EACD,cAAM,OAAA,CAAC;gBACN,KAAK,EAAE,MAAM,CAAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;YAGD,IAAA,6EAAgB,CAC6B;YAC9C,IAAI,mBAAmB,KAAK,UAAU,CAAC,IAAI,EAAE;gBAC5C,gBAAgB,IAAI,CAAC,CAAC,CAAC;aACvB;YAED,wDAAwD;YACxD,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,AAjSD,CAA6B,SAAS,GAiSrC","sourcesContent":["import * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select, mouse, event } from \"d3-selection\";\nimport { TooltipTypes, TooltipPosition, Events } from \"../../interfaces\";\n\nexport class Tooltip extends Component {\n\ttype = \"tooltip\";\n\n\ttooltip: any;\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tsuper(model, services, configs);\n\n\t\tthis.init();\n\t}\n\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"style\",\n\t\t\t\"prefix\"\n\t\t);\n\t\tthis.tooltip = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${settings.prefix}--${chartprefix}--tooltip`\n\t\t);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(\n\t\t\tthis.tooltip,\n\t\t\t\"div.content-box\"\n\t\t);\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.SHOW, (e) => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif (\n\t\t\t\t(e.detail.type === TooltipTypes.DATAPOINT &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"datapoint\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.GRIDLINE &&\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"gridline\",\n\t\t\t\t\t\t\"enabled\"\n\t\t\t\t\t)) ||\n\t\t\t\t(e.detail.type === TooltipTypes.LEGEND) ||\n\t\t\t\t(e.detail.type === TooltipTypes.AXISLABEL)\n\t\t\t) {\n\t\t\t\tlet data = select(event.target).datum() as any;\n\n\t\t\t\t// Generate default tooltip\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data, e.detail.type);\n\t\t\t\t} else {\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\te.detail.type\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it\n\t\t\t\tif (\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"customHTML\"\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\t\tthis.model\n\t\t\t\t\t\t\t.getOptions()\n\t\t\t\t\t\t\t.tooltip.customHTML(data, defaultHTML)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Use default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\t// Position the tooltip\n\t\t\t\tthis.positionTooltip();\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(\n\t\t\t\t\tholder,\n\t\t\t\t\t`svg.${settings.prefix}--${chartprefix}--chart-svg`\n\t\t\t\t);\n\t\t\t\tconst chartWidth =\n\t\t\t\t\tDOMUtils.getSVGElementSize(chart).width *\n\t\t\t\t\tTools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"title\",\n\t\t\t\t\t\t\"width\"\n\t\t\t\t\t);\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\t\t\t\ttooltipTextContainer.html(\n\t\t\t\t\tthis.getTooltipHTML(\n\t\t\t\t\t\te.detail.hoveredElement,\n\t\t\t\t\t\tTooltipTypes.TITLE\n\t\t\t\t\t)\n\t\t\t\t);\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(\n\t\t\t\t\te.detail.hoveredElement.node(),\n\t\t\t\t\te.detail.type\n\t\t\t\t);\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(Events.Tooltip.HIDE, () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\tgetTooltipHTML(data: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t} else if (type === TooltipTypes.LEGEND) {\n\t\t\treturn `<div class=\"legend-tooltip\"><p class=\"label\">${data.name}</p></div>`;\n\t\t}\n\t\t// this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data\n\t\tconst dataVal = Tools.getProperty(data, \"data\") ? data.data : data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(\n\t\t\tthis.model.getOptions(),\n\t\t\t\"tooltip\",\n\t\t\t\"valueFormatter\"\n\t\t)\n\t\t\t? this.model\n\t\t\t\t\t.getOptions()\n\t\t\t\t\t.tooltip.valueFormatter(dataVal[rangeIdentifier])\n\t\t\t: dataVal[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t</div>`;\n\t}\n\n\tgetMultilineTooltipHTML(data: any, type: TooltipTypes) {\n\t\t// sort them so they are in the same order as the graph\n\t\tdata.sort((a, b) => b.value - a.value);\n\n\t\t// tells us which value to use\n\t\tconst scaleType = this.services.cartesianScales.getDomainScale()\n\t\t\t.scaleType;\n\n\t\treturn (\n\t\t\t\"<ul class='multi-tooltip'>\" +\n\t\t\tdata\n\t\t\t\t.map((datum) => {\n\t\t\t\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\t\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(\n\t\t\t\t\t\tthis.model.getOptions(),\n\t\t\t\t\t\t\"tooltip\",\n\t\t\t\t\t\t\"valueFormatter\"\n\t\t\t\t\t);\n\t\t\t\t\tconst formattedValue = userProvidedValueFormatter\n\t\t\t\t\t\t? userProvidedValueFormatter(datum[rangeIdentifier])\n\t\t\t\t\t\t: datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\t\tconst indicatorColor = this.model.getStrokeColor(\n\t\t\t\t\t\tdatum[groupMapsTo]\n\t\t\t\t\t);\n\n\t\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t})\n\t\t\t\t.join(\"\") +\n\t\t\t\"</ul>\"\n\t\t);\n\t}\n\n\trender() {\n\t\tthis.tooltip.classed(\"hidden\", true);\n\t}\n\n\t// returns static position based on the element\n\tgetTooltipPosition(hoveredElement, type: TooltipTypes) {\n\t\tconst holderPosition = select(this.services.domUtils.getHolder())\n\t\t\t.node()\n\t\t\t.getBoundingClientRect();\n\t\tconst elementPosition = hoveredElement.getBoundingClientRect();\n\n\t\t// get the vertical offset\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.title;\n\n\t\tconst tooltipPos = {\n\t\t\tleft:\n\t\t\t\telementPosition.left -\n\t\t\t\tholderPosition.left +\n\t\t\t\telementPosition.width / 2,\n\t\t\ttop: elementPosition.top - holderPosition.top - verticalOffset,\n\t\t};\n\n\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t}\n\n\tpositionTooltip(positionOverride?: any) {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.tooltip.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\t\tlet pos;\n\n\t\t// override position to place tooltip at {placement:.., position:{top:.. , left:..}}\n\t\tif (positionOverride) {\n\t\t\t// placement determines whether the tooltip is centered above or below the position provided\n\t\t\tconst placement =\n\t\t\t\tpositionOverride.placement === TooltipPosition.TOP\n\t\t\t\t\t? PLACEMENTS.TOP\n\t\t\t\t\t: PLACEMENTS.BOTTOM;\n\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\tpositionOverride.position,\n\t\t\t\ttarget,\n\t\t\t\tplacement\n\t\t\t);\n\t\t} else {\n\t\t\t// Find out whether tooltip should be shown on the left or right side\n\t\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\t[\n\t\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\t\tPLACEMENTS.BOTTOM,\n\t\t\t\t],\n\t\t\t\t() => ({\n\t\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\t\theight: holder.offsetHeight,\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tlet {\n\t\t\t\thorizontalOffset,\n\t\t\t} = this.model.getOptions().tooltip.datapoint;\n\t\t\tif (bestPlacementOption === PLACEMENTS.LEFT) {\n\t\t\t\thorizontalOffset *= -1;\n\t\t\t}\n\n\t\t\t// Get coordinates to where tooltip should be positioned\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0] + horizontalOffset,\n\t\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\tbestPlacementOption\n\t\t\t);\n\t\t}\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n}\n"]}
@@ -24,11 +24,13 @@ var StackedArea = /** @class */ (function (_super) {
24
24
  _this.type = "area-stacked";
25
25
  _this.handleLegendOnHover = function (event) {
26
26
  var hoveredElement = event.detail.hoveredElement;
27
+ var options = _this.model.getOptions();
28
+ var groupMapsTo = options.data.groupMapsTo;
27
29
  _this.parent
28
30
  .selectAll("path.area")
29
31
  .transition(_this.services.transitions.getTransition("legend-hover-area"))
30
32
  .attr("opacity", function (d) {
31
- if (d[0].group !== hoveredElement.datum().name) {
33
+ if (d[0][groupMapsTo] !== hoveredElement.datum().name) {
32
34
  return Configuration.area.opacity.unselected;
33
35
  }
34
36
  return Configuration.area.opacity.selected;
@@ -54,6 +56,7 @@ var StackedArea = /** @class */ (function (_super) {
54
56
  var svg = this.getContainerSVG();
55
57
  var self = this;
56
58
  var options = this.model.getOptions();
59
+ var groupMapsTo = options.data.groupMapsTo;
57
60
  var mainXScale = this.services.cartesianScales.getMainXScale();
58
61
  var mainYScale = this.services.cartesianScales.getMainYScale();
59
62
  var domainAxisPosition = this.services.cartesianScales.getDomainAxisPosition();
@@ -68,7 +71,7 @@ var StackedArea = /** @class */ (function (_super) {
68
71
  var stackedData = this.model.getStackedData({ percentage: percentage });
69
72
  var areas = svg
70
73
  .selectAll("path.area")
71
- .data(stackedData, function (d) { return d[0].group; });
74
+ .data(stackedData, function (d) { return d[0][groupMapsTo]; });
72
75
  // D3 area generator function
73
76
  this.areaGenerator = area()
74
77
  // @ts-ignore
@@ -80,8 +83,8 @@ var StackedArea = /** @class */ (function (_super) {
80
83
  var enteringAreas = areas.enter().append("path").attr("opacity", 0);
81
84
  enteringAreas
82
85
  .merge(areas)
83
- .data(stackedData, function (d) { return d[0].group; })
84
- .attr("fill", function (d) { return self.model.getFillColor(d[0].group); })
86
+ .data(stackedData, function (d) { return d[0][groupMapsTo]; })
87
+ .attr("fill", function (d) { return self.model.getFillColor(d[0][groupMapsTo]); })
85
88
  .attr("role", Roles.GRAPHICS_SYMBOL)
86
89
  .attr("aria-roledescription", "area")
87
90
  .transition(this.services.transitions.getTransition("area-update-enter", animate))
@@ -1 +1 @@
1
- {"version":3,"file":"area-stacked.js","sourceRoot":"","sources":["area-stacked.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAgB,MAAM,kBAAkB,CAAC;AAE3E,aAAa;AACb,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC;IAAiC,+BAAS;IAA1C;QAAA,qEA+GC;QA9GA,UAAI,GAAG,cAAc,CAAC;QA4EtB,yBAAmB,GAAG,UAAC,KAAkB;YAChC,IAAA,4CAAc,CAAkB;YAExC,KAAI,CAAC,MAAM;iBACT,SAAS,CAAC,WAAW,CAAC;iBACtB,UAAU,CACV,KAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAC5D;iBACA,IAAI,CAAC,SAAS,EAAE,UAAC,CAAC;gBAClB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,cAAc,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE;oBAC/C,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;iBAC7C;gBAED,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAC5C,CAAC,CAAC,CAAC;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,CAAC,CAAC,CAAC;QAEtE,aAAa;aACX,KAAK,CAAC,KAAK,CAAC;aACZ,IAAI,CAAC,WAAW,EAAE,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAV,CAAU,CAAC;aACpC,IAAI,CAAC,MAAM,EAAE,UAAC,CAAC,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAnC,CAAmC,CAAC;aACxD,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,eAAe,CAAC;aACnC,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAC;aACpC,UAAU,CACV,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,aAAa,CACtC,mBAAmB,EACnB,OAAO,CACP,CACD;aACA,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;aACpD,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;aACrB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IA4BD,6BAAO,GAAP;QACC,yBAAyB;QACzB,IAAI,CAAC,MAAM;aACT,SAAS,CAAC,WAAW,CAAC;aACtB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IACF,kBAAC;AAAD,CAAC,AA/GD,CAAiC,SAAS,GA+GzC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport * as Configuration from \"../../configuration\";\nimport { Roles, ScaleTypes, Events, TooltipTypes } from \"../../interfaces\";\n\n// D3 Imports\nimport { area } from \"d3-shape\";\nimport { select, color } from \"d3\";\n\nexport class StackedArea extends Component {\n\ttype = \"area-stacked\";\n\n\tareaGenerator: any;\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct area on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Legend.ITEM_HOVER,\n\t\t\tthis.handleLegendOnHover\n\t\t);\n\n\t\t// Un-highlight area on legend item mouseouts\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Legend.ITEM_MOUSEOUT,\n\t\t\tthis.handleLegendMouseOut\n\t\t);\n\t}\n\n\trender(animate = true) {\n\t\tconst svg = this.getContainerSVG();\n\t\tconst self = this;\n\t\tconst options = this.model.getOptions();\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\n\t\tconst domainAxisPosition = this.services.cartesianScales.getDomainAxisPosition();\n\t\tconst domainScaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\tdomainAxisPosition\n\t\t);\n\t\tconst isTimeSeries = domainScaleType === ScaleTypes.TIME;\n\n\t\tif (!isTimeSeries) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst percentage = Object.keys(options.axes).some(axis => \n\t\t\toptions.axes[axis].percentage\t\n\t\t)\n\t\tconst stackedData = this.model.getStackedData({ percentage });\n\n\t\tconst areas = svg\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.data(stackedData, (d) => d[0].group);\n\n\t\t// D3 area generator function\n\t\tthis.areaGenerator = area()\n\t\t\t// @ts-ignore\n\t\t\t.x((d) => mainXScale(new Date(d.data.sharedStackKey)))\n\t\t\t.y0((d) => mainYScale(d[0]))\n\t\t\t.y1((d) => mainYScale(d[1]))\n\t\t\t.curve(this.services.curves.getD3Curve());\n\n\t\tareas.exit().attr(\"opacity\", 0).remove();\n\n\t\tconst enteringAreas = areas.enter().append(\"path\").attr(\"opacity\", 0);\n\n\t\tenteringAreas\n\t\t\t.merge(areas)\n\t\t\t.data(stackedData, (d) => d[0].group)\n\t\t\t.attr(\"fill\", (d) => self.model.getFillColor(d[0].group))\n\t\t\t.attr(\"role\", Roles.GRAPHICS_SYMBOL)\n\t\t\t.attr(\"aria-roledescription\", \"area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\"area-update-enter\",\n\t\t\t\t\tanimate\n\t\t\t\t)\n\t\t\t)\n\t\t\t.attr(\"opacity\", Configuration.area.opacity.selected)\n\t\t\t.attr(\"class\", \"area\")\n\t\t\t.attr(\"d\", this.areaGenerator);\n\t}\n\n\thandleLegendOnHover = (event: CustomEvent) => {\n\t\tconst { hoveredElement } = event.detail;\n\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\"legend-hover-area\")\n\t\t\t)\n\t\t\t.attr(\"opacity\", (d) => {\n\t\t\t\tif (d[0].group !== hoveredElement.datum().name) {\n\t\t\t\t\treturn Configuration.area.opacity.unselected;\n\t\t\t\t}\n\n\t\t\t\treturn Configuration.area.opacity.selected;\n\t\t\t});\n\t};\n\n\thandleLegendMouseOut = (event: CustomEvent) => {\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\"legend-mouseout-area\")\n\t\t\t)\n\t\t\t.attr(\"opacity\", Configuration.area.opacity.selected);\n\t};\n\n\tdestroy() {\n\t\t// Remove event listeners\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"mousemove\", null)\n\t\t\t.on(\"mouseout\", null);\n\t}\n}\n"]}
1
+ {"version":3,"file":"area-stacked.js","sourceRoot":"","sources":["area-stacked.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAgB,MAAM,kBAAkB,CAAC;AAE3E,aAAa;AAC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AC,WAAW,CAAC,aAAa,CACtC,mBAAmB,EACnB,OAAO,CACP,CACD;aACA,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;aACpD,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;aACrB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IA8BD,6BAAO,GAAP;QACC,yBAAyB;QACzB,IAAI,CAAC,MAAM;aACT,SAAS,CAAC,WAAW,CAAC;aACtB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IACF,kBAAC;AAAD,CAAC,AAnHD,CAAiC,SAAS,GAmHzC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport * as Configuration from \"../../configuration\";\nimport { Roles, ScaleTypes, Events, TooltipTypes } from \"../../interfaces\";\n\n// D3 Imports\nimport { area } from \"d3-shape\";\nimport { select, color } from \"d3\";\n\nexport class StackedArea extends Component {\n\ttype = \"area-stacked\";\n\n\tareaGenerator: any;\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct area on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Legend.ITEM_HOVER,\n\t\t\tthis.handleLegendOnHover\n\t\t);\n\n\t\t// Un-highlight area on legend item mouseouts\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Legend.ITEM_MOUSEOUT,\n\t\t\tthis.handleLegendMouseOut\n\t\t);\n\t}\n\n\trender(animate = true) {\n\t\tconst svg = this.getContainerSVG();\n\t\tconst self = this;\n\t\tconst options = this.model.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\n\t\tconst domainAxisPosition = this.services.cartesianScales.getDomainAxisPosition();\n\t\tconst domainScaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\tdomainAxisPosition\n\t\t);\n\t\tconst isTimeSeries = domainScaleType === ScaleTypes.TIME;\n\n\t\tif (!isTimeSeries) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst percentage = Object.keys(options.axes).some(axis =>\n\t\t\toptions.axes[axis].percentage\n\t\t);\n\n\t\tconst stackedData = this.model.getStackedData({ percentage });\n\n\t\tconst areas = svg\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.data(stackedData, (d) => d[0][groupMapsTo]);\n\n\t\t// D3 area generator function\n\t\tthis.areaGenerator = area()\n\t\t\t// @ts-ignore\n\t\t\t.x((d) => mainXScale(new Date(d.data.sharedStackKey)))\n\t\t\t.y0((d) => mainYScale(d[0]))\n\t\t\t.y1((d) => mainYScale(d[1]))\n\t\t\t.curve(this.services.curves.getD3Curve());\n\n\t\tareas.exit().attr(\"opacity\", 0).remove();\n\n\t\tconst enteringAreas = areas.enter().append(\"path\").attr(\"opacity\", 0);\n\n\t\tenteringAreas\n\t\t\t.merge(areas)\n\t\t\t.data(stackedData, (d) => d[0][groupMapsTo])\n\t\t\t.attr(\"fill\", (d) => self.model.getFillColor(d[0][groupMapsTo]))\n\t\t\t.attr(\"role\", Roles.GRAPHICS_SYMBOL)\n\t\t\t.attr(\"aria-roledescription\", \"area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\"area-update-enter\",\n\t\t\t\t\tanimate\n\t\t\t\t)\n\t\t\t)\n\t\t\t.attr(\"opacity\", Configuration.area.opacity.selected)\n\t\t\t.attr(\"class\", \"area\")\n\t\t\t.attr(\"d\", this.areaGenerator);\n\t}\n\n\thandleLegendOnHover = (event: CustomEvent) => {\n\t\tconst { hoveredElement } = event.detail;\n\t\tconst options = this.model.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\"legend-hover-area\")\n\t\t\t)\n\t\t\t.attr(\"opacity\", (d) => {\n\t\t\t\tif (d[0][groupMapsTo] !== hoveredElement.datum().name) {\n\t\t\t\t\treturn Configuration.area.opacity.unselected;\n\t\t\t\t}\n\n\t\t\t\treturn Configuration.area.opacity.selected;\n\t\t\t});\n\t};\n\n\thandleLegendMouseOut = (event: CustomEvent) => {\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.transition(\n\t\t\t\tthis.services.transitions.getTransition(\"legend-mouseout-area\")\n\t\t\t)\n\t\t\t.attr(\"opacity\", Configuration.area.opacity.selected);\n\t};\n\n\tdestroy() {\n\t\t// Remove event listeners\n\t\tthis.parent\n\t\t\t.selectAll(\"path.area\")\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"mousemove\", null)\n\t\t\t.on(\"mouseout\", null);\n\t}\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { Component } from "../component";
2
+ export declare class Gauge extends Component {
3
+ type: string;
4
+ arc: any;
5
+ backgroundArc: any;
6
+ init(): void;
7
+ getValue(): number;
8
+ getValueRatio(): number;
9
+ getDelta(): number;
10
+ getArcRatio(): number;
11
+ getArcSize(): number;
12
+ getStartAngle(): number;
13
+ getArrow(delta: any): string;
14
+ render(animate?: boolean): void;
15
+ /**
16
+ * draws the value number associated with the Gauge component in the center
17
+ */
18
+ drawValueNumber(): void;
19
+ /**
20
+ * adds the delta number for the gauge
21
+ */
22
+ drawDelta(): void;
23
+ getInnerRadius(): number;
24
+ addEventListeners(): void;
25
+ protected computeRadius(): number;
26
+ }