@carbon/charts 0.30.5 → 0.30.9

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 (152) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +14 -8
  3. package/build/demo/data/bar.d.ts +56 -94
  4. package/build/demo/data/bubble.d.ts +58 -13
  5. package/build/demo/data/donut.d.ts +3 -6
  6. package/build/demo/data/line.d.ts +35 -35
  7. package/build/demo/data/pie.d.ts +3 -6
  8. package/build/demo/data/scatter.d.ts +33 -20
  9. package/build/demo/data/step.d.ts +15 -16
  10. package/build/demo/data/time-series-axis.d.ts +12 -48
  11. package/build/src/charts/bar-grouped.d.ts +2 -2
  12. package/build/src/charts/bar-simple.d.ts +2 -4
  13. package/build/src/components/essentials/legend.d.ts +0 -4
  14. package/build/src/components/essentials/tooltip-bar.d.ts +1 -1
  15. package/build/src/components/essentials/tooltip-pie.d.ts +5 -0
  16. package/build/src/components/essentials/tooltip-scatter.d.ts +1 -1
  17. package/build/src/components/graphs/bar-grouped.d.ts +6 -4
  18. package/build/src/components/graphs/bar-simple.d.ts +0 -1
  19. package/build/src/components/graphs/bar-stacked.d.ts +0 -1
  20. package/build/src/components/graphs/bubble.d.ts +0 -1
  21. package/build/src/components/graphs/line.d.ts +3 -1
  22. package/build/src/components/graphs/pie.d.ts +0 -1
  23. package/build/src/components/graphs/scatter.d.ts +0 -1
  24. package/build/src/components/index.d.ts +1 -0
  25. package/build/src/interfaces/axis-scales.d.ts +4 -16
  26. package/build/src/interfaces/charts.d.ts +23 -1
  27. package/build/src/interfaces/enums.d.ts +0 -4
  28. package/build/src/interfaces/events.d.ts +20 -0
  29. package/build/src/model-pie.d.ts +1 -7
  30. package/build/src/model.d.ts +31 -13
  31. package/build/src/services/scales-cartesian.d.ts +11 -3
  32. package/build/src/tools.d.ts +2 -2
  33. package/build/stories/tutorials.stories.d.ts +1 -0
  34. package/bundle.js +1 -1
  35. package/chart.js +2 -2
  36. package/chart.js.map +1 -1
  37. package/charts/bar-grouped.d.ts +2 -2
  38. package/charts/bar-grouped.js.map +1 -1
  39. package/charts/bar-simple.d.ts +2 -4
  40. package/charts/bar-simple.js +0 -2
  41. package/charts/bar-simple.js.map +1 -1
  42. package/charts/donut.js +2 -2
  43. package/charts/donut.js.map +1 -1
  44. package/charts/pie.js +2 -2
  45. package/charts/pie.js.map +1 -1
  46. package/components/axes/grid.js +12 -19
  47. package/components/axes/grid.js.map +1 -1
  48. package/components/component.js +1 -1
  49. package/components/component.js.map +1 -1
  50. package/components/essentials/legend.d.ts +0 -4
  51. package/components/essentials/legend.js +8 -22
  52. package/components/essentials/legend.js.map +1 -1
  53. package/components/essentials/title.js +4 -4
  54. package/components/essentials/title.js.map +1 -1
  55. package/components/essentials/tooltip-bar.d.ts +1 -1
  56. package/components/essentials/tooltip-bar.js +13 -5
  57. package/components/essentials/tooltip-bar.js.map +1 -1
  58. package/components/essentials/tooltip-pie.d.ts +5 -0
  59. package/components/essentials/tooltip-pie.js +40 -0
  60. package/components/essentials/tooltip-pie.js.map +1 -0
  61. package/components/essentials/tooltip-scatter.d.ts +1 -1
  62. package/components/essentials/tooltip-scatter.js +8 -6
  63. package/components/essentials/tooltip-scatter.js.map +1 -1
  64. package/components/essentials/tooltip.js +14 -17
  65. package/components/essentials/tooltip.js.map +1 -1
  66. package/components/graphs/bar-grouped.d.ts +6 -4
  67. package/components/graphs/bar-grouped.js +60 -32
  68. package/components/graphs/bar-grouped.js.map +1 -1
  69. package/components/graphs/bar-simple.d.ts +0 -1
  70. package/components/graphs/bar-simple.js +12 -30
  71. package/components/graphs/bar-simple.js.map +1 -1
  72. package/components/graphs/bar-stacked.d.ts +0 -1
  73. package/components/graphs/bar-stacked.js +26 -108
  74. package/components/graphs/bar-stacked.js.map +1 -1
  75. package/components/graphs/bar.js.map +1 -1
  76. package/components/graphs/bubble.d.ts +0 -1
  77. package/components/graphs/bubble.js +16 -20
  78. package/components/graphs/bubble.js.map +1 -1
  79. package/components/graphs/donut.js +1 -1
  80. package/components/graphs/donut.js.map +1 -1
  81. package/components/graphs/line.d.ts +3 -1
  82. package/components/graphs/line.js +41 -30
  83. package/components/graphs/line.js.map +1 -1
  84. package/components/graphs/pie.d.ts +0 -1
  85. package/components/graphs/pie.js +13 -20
  86. package/components/graphs/pie.js.map +1 -1
  87. package/components/graphs/scatter.d.ts +0 -1
  88. package/components/graphs/scatter.js +26 -41
  89. package/components/graphs/scatter.js.map +1 -1
  90. package/components/index.d.ts +1 -0
  91. package/components/index.js +1 -0
  92. package/components/index.js.map +1 -1
  93. package/configuration.js +7 -0
  94. package/configuration.js.map +1 -1
  95. package/demo/data/bar.d.ts +56 -94
  96. package/demo/data/bar.js +106 -271
  97. package/demo/data/bar.js.map +1 -1
  98. package/demo/data/bubble.d.ts +58 -13
  99. package/demo/data/bubble.js +74 -174
  100. package/demo/data/bubble.js.map +1 -1
  101. package/demo/data/bundle.js +1 -1
  102. package/demo/data/donut.d.ts +3 -6
  103. package/demo/data/index.js +22 -4
  104. package/demo/data/index.js.map +1 -1
  105. package/demo/data/line.d.ts +35 -35
  106. package/demo/data/line.js +70 -196
  107. package/demo/data/line.js.map +1 -1
  108. package/demo/data/pie.d.ts +3 -6
  109. package/demo/data/pie.js +8 -10
  110. package/demo/data/pie.js.map +1 -1
  111. package/demo/data/scatter.d.ts +33 -20
  112. package/demo/data/scatter.js +50 -68
  113. package/demo/data/scatter.js.map +1 -1
  114. package/demo/data/step.d.ts +15 -16
  115. package/demo/data/time-series-axis.d.ts +12 -48
  116. package/demo/data/time-series-axis.js +34 -46
  117. package/demo/data/time-series-axis.js.map +1 -1
  118. package/demo/styles.css +28 -0
  119. package/demo/styles.css.map +1 -1
  120. package/demo/styles.min.css +1 -1
  121. package/demo/styles.min.css.map +1 -1
  122. package/demo/tsconfig.tsbuildinfo +38 -37
  123. package/interfaces/axis-scales.d.ts +4 -16
  124. package/interfaces/axis-scales.js.map +1 -1
  125. package/interfaces/charts.d.ts +23 -1
  126. package/interfaces/charts.js.map +1 -1
  127. package/interfaces/enums.d.ts +0 -4
  128. package/interfaces/enums.js +0 -5
  129. package/interfaces/enums.js.map +1 -1
  130. package/interfaces/events.d.ts +20 -0
  131. package/interfaces/events.js +23 -0
  132. package/interfaces/events.js.map +1 -1
  133. package/model-pie.d.ts +1 -7
  134. package/model-pie.js +2 -107
  135. package/model-pie.js.map +1 -1
  136. package/model.d.ts +31 -13
  137. package/model.js +200 -76
  138. package/model.js.map +1 -1
  139. package/package.json +3 -1
  140. package/services/essentials/dom-utils.js +3 -2
  141. package/services/essentials/dom-utils.js.map +1 -1
  142. package/services/scales-cartesian.d.ts +11 -3
  143. package/services/scales-cartesian.js +104 -122
  144. package/services/scales-cartesian.js.map +1 -1
  145. package/tools.d.ts +2 -2
  146. package/tools.js +23 -2
  147. package/tools.js.map +1 -1
  148. package/tsconfig.tsbuildinfo +87 -88
  149. package/build/src/model-simple-bar.d.ts +0 -11
  150. package/model-simple-bar.d.ts +0 -11
  151. package/model-simple-bar.js +0 -88
  152. package/model-simple-bar.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"title.js","sourceRoot":"","sources":["title.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;IAA2B,yBAAS;IAApC;QAAA,qEAqFC;QApFA,UAAI,GAAG,OAAO,CAAC;;IAoFhB,CAAC;IAlFA;;OAEG;IACH,6BAAa,GAAb;QACC,+EAA+E;QAC/E,IAAM,cAAc,GAAG,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC;QAChH,IAAM,K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CAAC,CAAC;SACtD;aAAM;YACN,OAAO,GAAG,CAAC;SACX;IACF,CAAC;IACF,YAAC;AAAD,CAAC,AArFD,CAA2B,SAAS,GAqFnC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipTypes } from \"./../../interfaces\";\n\nexport class Title extends Component {\n\ttype = \"title\";\n\n\t/**\n\t * Truncates title creating ellipses and attaching tooltip for exposing full title.\n\t */\n\ttruncateTitle() {\n\t\t// get a reference to the title elements to calculate the size the title can be\n\t\tconst containerWidth = DOMUtils.getSVGElementSize(this.services.domUtils.getMainSVG(), { useAttr: true }).width;\n\t\tconst title = DOMUtils.appendOrSelect(this.parent, \"text.title\");\n\n\t\t// sanity check to prevent stack overflow on binary search\n\t\tif (containerWidth <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// check if the title is too big for the containing svg\n\t\tif (title.node().getComputedTextLength() > containerWidth) {\n\t\t\t// append the ellipses to their own tspan to calculate the text length\n\t\t\ttitle.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// get the bounding width including the elipses '...'\n\t\t\tconst tspanLength = DOMUtils.appendOrSelect(title, \"tspan\").node().getComputedTextLength();\n\t\t\tconst truncatedSize = Math.floor(containerWidth - tspanLength);\n\t\t\tconst titleString = this.model.getOptions().title;\n\n\t\t\t// get the index for creating the max length substring that fit within the svg\n\t\t\t// use one less than the index to avoid crowding (the elipsis)\n\t\t\tconst substringIndex = this.getSubstringIndex(title.node(), 0, titleString.length - 1, truncatedSize);\n\n\t\t\t// use the substring as the title\n\t\t\ttitle.text(titleString.substring(0, substringIndex - 1))\n\t\t\t\t.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// add events for displaying the tooltip with the title\n\t\t\tconst self = this;\n\t\t\ttitle\n\t\t\t\t.on(\"mouseenter\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(\"show-tooltip\", {\n\t\t\t\t\t\thoveredElement: title,\n\t\t\t\t\t\ttype: TooltipTypes.TITLE\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.on(\"mouseout\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(\"hide-tooltip\", {\n\t\t\t\t\t\thoveredElement: title,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t}\n\t}\n\n\trender() {\n\t\tconst svg = this.getContainerSVG();\n\n\t\tconst text = DOMUtils.appendOrSelect(svg, \"text.title\");\n\t\ttext.attr(\"x\", 0)\n\t\t\t.attr(\"y\", 20)\n\t\t\t.text(this.model.getOptions().title);\n\n\t\t// title needs to first render so that we can check for overflow\n\t\tthis.truncateTitle();\n\t}\n\n\t/**\n\t * Returns the index for a maximum length substring that is less than the width parameter.\n\t * @param title the title node used for getting the text lengths of substrings\n\t * @param start the start index for the binary search\n\t * @param end the end index for the binary search\n\t * @param width the width of the svg container that holds the title\n\t */\n\tprotected getSubstringIndex(title, start, end, width) {\n\t\tconst mid = Math.floor((end + start) / 2);\n\t\tif (title.getSubStringLength(0, mid) > width) {\n\t\t\treturn this.getSubstringIndex(title, start, mid, width);\n\t\t} else if (title.getSubStringLength(0, mid) < width) {\n\t\t\tif (title.getSubStringLength(0, mid + 1) > width) {\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t\treturn this.getSubstringIndex(title, mid, end, width);\n\t\t} else {\n\t\t\treturn mid;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"title.js","sourceRoot":"","sources":["title.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE1D;IAA2B,yBAAS;IAApC;QAAA,qEAqFC;QApFA,UAAI,GAAG,OAAO,CAAC;;IAoFhB,CAAC;IAlFA;;OAEG;IACH,6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CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE;YACpD,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE;gBACjD,OAAO,GAAG,CAAC;aACX;YACD,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SACtD;aAAM;YACN,OAAO,GAAG,CAAC;SACX;IACF,CAAC;IACF,YAAC;AAAD,CAAC,AArFD,CAA2B,SAAS,GAqFnC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipTypes, Events } from \"./../../interfaces\";\n\nexport class Title extends Component {\n\ttype = \"title\";\n\n\t/**\n\t * Truncates title creating ellipses and attaching tooltip for exposing full title.\n\t */\n\ttruncateTitle() {\n\t\t// get a reference to the title elements to calculate the size the title can be\n\t\tconst containerWidth = DOMUtils.getSVGElementSize(this.services.domUtils.getMainSVG(), { useAttr: true }).width;\n\t\tconst title = DOMUtils.appendOrSelect(this.parent, \"text.title\");\n\n\t\t// sanity check to prevent stack overflow on binary search\n\t\tif (containerWidth <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// check if the title is too big for the containing svg\n\t\tif (title.node().getComputedTextLength() > containerWidth) {\n\t\t\t// append the ellipses to their own tspan to calculate the text length\n\t\t\ttitle.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// get the bounding width including the elipses '...'\n\t\t\tconst tspanLength = DOMUtils.appendOrSelect(title, \"tspan\").node().getComputedTextLength();\n\t\t\tconst truncatedSize = Math.floor(containerWidth - tspanLength);\n\t\t\tconst titleString = this.model.getOptions().title;\n\n\t\t\t// get the index for creating the max length substring that fit within the svg\n\t\t\t// use one less than the index to avoid crowding (the elipsis)\n\t\t\tconst substringIndex = this.getSubstringIndex(title.node(), 0, titleString.length - 1, truncatedSize);\n\n\t\t\t// use the substring as the title\n\t\t\ttitle.text(titleString.substring(0, substringIndex - 1))\n\t\t\t\t.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// add events for displaying the tooltip with the title\n\t\t\tconst self = this;\n\t\t\ttitle\n\t\t\t\t.on(\"mouseenter\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\t\t\thoveredElement: title,\n\t\t\t\t\t\ttype: TooltipTypes.TITLE\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.on(\"mouseout\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE, {\n\t\t\t\t\t\thoveredElement: title\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t}\n\t}\n\n\trender() {\n\t\tconst svg = this.getContainerSVG();\n\n\t\tconst text = DOMUtils.appendOrSelect(svg, \"text.title\");\n\t\ttext.attr(\"x\", 0)\n\t\t\t.attr(\"y\", 20)\n\t\t\t.text(this.model.getOptions().title);\n\n\t\t// title needs to first render so that we can check for overflow\n\t\tthis.truncateTitle();\n\t}\n\n\t/**\n\t * Returns the index for a maximum length substring that is less than the width parameter.\n\t * @param title the title node used for getting the text lengths of substrings\n\t * @param start the start index for the binary search\n\t * @param end the end index for the binary search\n\t * @param width the width of the svg container that holds the title\n\t */\n\tprotected getSubstringIndex(title, start, end, width) {\n\t\tconst mid = Math.floor((end + start) / 2);\n\t\tif (title.getSubStringLength(0, mid) > width) {\n\t\t\treturn this.getSubstringIndex(title, start, mid, width);\n\t\t} else if (title.getSubStringLength(0, mid) < width) {\n\t\t\tif (title.getSubStringLength(0, mid + 1) > width) {\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t\treturn this.getSubstringIndex(title, mid, end, width);\n\t\t} else {\n\t\t\treturn mid;\n\t\t}\n\t}\n}\n"]}
@@ -7,7 +7,7 @@ export declare class TooltipBar extends Tooltip {
7
7
  * positive valued data and below negative value data.
8
8
  * @param hoveredElement
9
9
  */
10
- getTooltipPosition(hoveredElement: any): {
10
+ getTooltipPosition(hoveredElement: any, data?: any): {
11
11
  placement: TooltipPosition;
12
12
  position: {
13
13
  left: number;
@@ -16,7 +16,7 @@ import { Tools } from "../../tools";
16
16
  import { DOMUtils } from "../../services";
17
17
  import { TooltipPosition, TooltipTypes, CartesianOrientations } from "./../../interfaces/enums";
18
18
  // import the settings for the css prefix
19
- import settings from "carbon-components/src/globals/js/settings";
19
+ import settings from "carbon-components/es/globals/js/settings";
20
20
  // D3 Imports
21
21
  import { select } from "d3-selection";
22
22
  var TooltipBar = /** @class */ (function (_super) {
@@ -47,7 +47,13 @@ var TooltipBar = /** @class */ (function (_super) {
47
47
  defaultHTML = _this.getMultilineTooltipHTML(data);
48
48
  }
49
49
  else {
50
- defaultHTML = _this.getTooltipHTML(e.detail.hoveredElement.datum());
50
+ if (e.detail.data) {
51
+ data = e.detail.data;
52
+ }
53
+ else {
54
+ data = e.detail.hoveredElement.datum();
55
+ }
56
+ defaultHTML = _this.getTooltipHTML(data);
51
57
  }
52
58
  // if there is a provided tooltip HTML function call it and pass the defaultHTML
53
59
  if (Tools.getProperty(_this.model.getOptions(), "tooltip", "customHTML")) {
@@ -57,7 +63,7 @@ var TooltipBar = /** @class */ (function (_super) {
57
63
  // default tooltip
58
64
  tooltipTextContainer.html(defaultHTML);
59
65
  }
60
- var position = _this.getTooltipPosition(hoveredElement);
66
+ var position = _this.getTooltipPosition(hoveredElement, data);
61
67
  // Position the tooltip relative to the bars
62
68
  _this.positionTooltip(e.detail.multidata ? undefined : position);
63
69
  }
@@ -86,8 +92,10 @@ var TooltipBar = /** @class */ (function (_super) {
86
92
  * positive valued data and below negative value data.
87
93
  * @param hoveredElement
88
94
  */
89
- TooltipBar.prototype.getTooltipPosition = function (hoveredElement) {
90
- var data = select(hoveredElement).datum();
95
+ TooltipBar.prototype.getTooltipPosition = function (hoveredElement, data) {
96
+ if (data === undefined) {
97
+ data = select(hoveredElement).datum();
98
+ }
91
99
  var holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();
92
100
  var barPosition = hoveredElement.getBoundingClientRect();
93
101
  var verticalOffset = this.model.getOptions().tooltip.datapoint.verticalOffset;
@@ -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,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,yCAAyC;AACzC,OAAO,QAAQ,MAAM,2CAA2C,CAAC;AAEjE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;IAAgC,8BAAO;IAAvC;;IA2JA,CAAC;IA1JA,yBAAI,GAAJ;QAAA,iBA+DC;QA9DA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAClF,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,SAAO,QAAQ,CAAC,MAAM,UAAK,WAAW,cAAW,CAAC,CAAC;QAElG,oCAAoC;QACpC,IAAM,oBAAoB,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACtF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAEtC,6DAA6D;QAC7D,IAAI,CAAC,QAAQ,CAAC,MA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SAAS;gBACnB,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;oBAChG,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAEvG,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1F,OAAO,0GAGwB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AA3JD,CAAgC,OAAO,GA2JtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/src/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(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\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(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\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\tdefaultHTML = this.getTooltipHTML(e.detail.hoveredElement.datum());\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 (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\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);\n\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position );\n\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(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\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(super.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(e.detail.hoveredElement.node());\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(\"hide-tooltip\", () => {\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) {\n\t\tconst data = select(hoveredElement).datum() as any;\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().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: (barPosition.left - holderPosition.left) + barPosition.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: (barPosition.left - holderPosition.left) + barPosition.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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : 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 (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(total) : total.toLocaleString(\"en\");\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapoint.value) : datapoint.value.toLocaleString(\"en\");\n\n\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\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\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}).join(\"\") +\n\t\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}\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,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;IAAgC,8BAAO;IAAvC;;IAmKA,CAAC;IAlKA,yBAAI,GAAJ;QAAA,iBAqEC;QApEA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAClF,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,SAAO,QAAQ,CAAC,MAAM,UAAK,WAAW,cAAW,CAAC,CAAC;QAElG,oCAAoC;QACpC,IAAM,oBAAoB,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACtF,IAAI,CAAC,OAAO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K,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACjF,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEnF,OAAQ,4BAA4B;YACnC,MAAM,CAAC,GAAG,CAAC,UAAA,SAAS;gBACnB,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;oBAChG,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAEvG,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1F,OAAO,0GAGwB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AAnKD,CAAgC,OAAO,GAmKtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\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(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\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(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\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 (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\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\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(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\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(super.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(e.detail.hoveredElement.node());\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(\"hide-tooltip\", () => {\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()).node().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: (barPosition.left - holderPosition.left) + barPosition.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: (barPosition.left - holderPosition.left) + barPosition.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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : 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 (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(total) : total.toLocaleString(\"en\");\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapoint.value) : datapoint.value.toLocaleString(\"en\");\n\n\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\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\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}).join(\"\") +\n\t\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}\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { Tooltip } from "./tooltip";
2
+ import { TooltipTypes } from "../../interfaces";
3
+ export declare class TooltipPie extends Tooltip {
4
+ getTooltipHTML(d: any, type: TooltipTypes): string;
5
+ }
@@ -0,0 +1,40 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { Tooltip } from "./tooltip";
15
+ import { Tools } from "../../tools";
16
+ import { TooltipTypes } from "../../interfaces";
17
+ var TooltipPie = /** @class */ (function (_super) {
18
+ __extends(TooltipPie, _super);
19
+ function TooltipPie() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ TooltipPie.prototype.getTooltipHTML = function (d, type) {
23
+ // check if it is getting styles for a tooltip type
24
+ if (type === TooltipTypes.TITLE) {
25
+ var title = this.model.getOptions().title;
26
+ return "<div class=\"title-tooltip\"><text>" + title + "</text></div>";
27
+ }
28
+ var dataVal = d.data;
29
+ var groupMapsTo = this.model.getOptions().data.groupMapsTo;
30
+ // format the value if needed
31
+ var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter") ?
32
+ this.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString("en");
33
+ // pie charts don't have a dataset label since they only support one dataset
34
+ var label = dataVal[groupMapsTo];
35
+ return ("<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>");
36
+ };
37
+ return TooltipPie;
38
+ }(Tooltip));
39
+ export { TooltipPie };
40
+ //# sourceMappingURL=../../../src/components/essentials/tooltip-pie.js.map
@@ -0,0 +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;;IAyBA,CAAC;IAxBA,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,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;YAChG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEnG,4EAA4E;QAC5E,IAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QAEnC,OAAO,CACN,mEACoB,KAAK,yCACL,cAAc,uBAC3B,CACP,CAAC;IACH,CAAC;IACF,iBAAC;AAAD,CAAC,AAzBD,CAAgC,OAAO,GAyBtC","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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal.value) : 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 (\n\t\t\t`<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\t);\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Tooltip } from "./tooltip";
2
2
  import { TooltipTypes } from "./../../interfaces";
3
3
  export declare class TooltipScatter extends Tooltip {
4
- getTooltipHTML(data: any, type: TooltipTypes): string;
4
+ getTooltipHTML(datum: any, type: TooltipTypes): string;
5
5
  }
@@ -19,16 +19,18 @@ var TooltipScatter = /** @class */ (function (_super) {
19
19
  function TooltipScatter() {
20
20
  return _super !== null && _super.apply(this, arguments) || this;
21
21
  }
22
- TooltipScatter.prototype.getTooltipHTML = function (data, type) {
22
+ TooltipScatter.prototype.getTooltipHTML = function (datum, type) {
23
23
  if (type === TooltipTypes.TITLE) {
24
24
  // the main tooltip component handles title styles
25
- return _super.prototype.getTooltipHTML.call(this, data, type);
25
+ return _super.prototype.getTooltipHTML.call(this, datum, type);
26
26
  }
27
- var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter") ?
28
- this.model.getOptions().tooltip.valueFormatter(data.value) : data.value.toLocaleString("en");
27
+ var groupMapsTo = this.model.getOptions().data.groupMapsTo;
28
+ var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
29
+ var userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter");
30
+ var formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString("en");
29
31
  // For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.
30
- var indicatorColor = this.model.getStrokeColor(data.datasetLabel, data.label);
31
- return "\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\">" + data.datasetLabel + "</p>\n\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t</div>";
32
+ var indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);
33
+ return "\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>";
32
34
  };
33
35
  return TooltipScatter;
34
36
  }(Tooltip));
@@ -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;AAGlD;IAAoC,kCAAO;IAA3C;;IAoBA,CAAC;IAnBA,uCAAc,GAAd,UAAe,IAAS,EAAE,IAAkB;QAC3C,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,kDAAkD;YAClD,OAAO,iBAAM,cAAc,YAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACxC;QAED,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;YAChG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE7F,2GAA2G;QAC3G,IAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhF,OAAO,oFAEwB,cAAc,oEACxB,IAAI,CAAC,YAAY,yCACjB,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,qBAAC;AAAD,CAAC,AApBD,CAAoC,OAAO,GAoB1C","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"./../../interfaces\";\n\n\nexport class TooltipScatter extends Tooltip {\n\tgetTooltipHTML(data: 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(data, type);\n\t\t}\n\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : data.value.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(data.datasetLabel, data.label);\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\">${data.datasetLabel}</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;;IAuBA,CAAC;IAtBA,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,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;QAC3G,IAAM,cAAc,GAAG,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAErJ,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,AAvBD,CAAoC,OAAO,GAuB1C","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(this.model.getOptions(), \"tooltip\", \"valueFormatter\");\n\t\tconst formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : 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"]}
@@ -17,10 +17,10 @@ import { DOMUtils } from "../../services";
17
17
  // Carbon position service
18
18
  import Position, { PLACEMENTS } from "@carbon/utils-position";
19
19
  // import the settings for the css prefix
20
- import settings from "carbon-components/src/globals/js/settings";
20
+ import settings from "carbon-components/es/globals/js/settings";
21
21
  // D3 Imports
22
22
  import { select, mouse, event } from "d3-selection";
23
- import { TooltipTypes, ScaleTypes, TooltipPosition } from "../../interfaces";
23
+ import { TooltipTypes, TooltipPosition } from "../../interfaces";
24
24
  var Tooltip = /** @class */ (function (_super) {
25
25
  __extends(Tooltip, _super);
26
26
  function Tooltip(model, services, configs) {
@@ -91,33 +91,30 @@ var Tooltip = /** @class */ (function (_super) {
91
91
  }
92
92
  // this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data
93
93
  var dataVal = Tools.getProperty(data, "data") ? data.data : data;
94
+ var groupMapsTo = this.model.getOptions().data.groupMapsTo;
95
+ var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
94
96
  // format the value if needed
95
97
  var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter") ?
96
- this.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString("en");
98
+ this.model.getOptions().tooltip.valueFormatter(dataVal[rangeIdentifier]) : dataVal[rangeIdentifier].toLocaleString("en");
97
99
  // pie charts don't have a dataset label since they only support one dataset
98
- var label = dataVal.datasetLabel ? dataVal.datasetLabel : dataVal.label;
100
+ var label = dataVal[groupMapsTo];
99
101
  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>";
100
102
  };
101
103
  Tooltip.prototype.getMultilineTooltipHTML = function (data) {
102
104
  var _this = this;
103
- var points = data;
104
105
  // sort them so they are in the same order as the graph
105
- points.sort(function (a, b) { return b.value - a.value; });
106
+ data.sort(function (a, b) { return b.value - a.value; });
106
107
  // tells us which value to use
107
108
  var scaleType = this.services.cartesianScales.getDomainScale().scaleType;
108
109
  return "<ul class='multi-tooltip'>" +
109
- points.map(function (datapoint) {
110
- // check if the datapoint has multiple values associates (multiple axes)
111
- var datapointValue = datapoint.value;
112
- if (datapointValue instanceof Object) {
113
- // scale type determines which value we care about since it should align with the scale data
114
- datapointValue = scaleType === ScaleTypes.TIME ? datapoint.value.date : datapoint.value.value;
115
- }
116
- var formattedValue = Tools.getProperty(_this.model.getOptions(), "tooltip", "valueFormatter") ?
117
- _this.model.getOptions().tooltip.valueFormatter(datapointValue) : datapointValue.toLocaleString("en");
110
+ data.map(function (datum) {
111
+ var groupMapsTo = _this.model.getOptions().data.groupMapsTo;
112
+ var rangeIdentifier = _this.services.cartesianScales.getRangeIdentifier();
113
+ var userProvidedValueFormatter = Tools.getProperty(_this.model.getOptions(), "tooltip", "valueFormatter");
114
+ var formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString("en");
118
115
  // For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.
119
- var indicatorColor = _this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);
120
- return "\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>";
116
+ var indicatorColor = _this.model.getStrokeColor(datum[groupMapsTo]);
117
+ return "\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>";
121
118
  }).join("") + "</ul>";
122
119
  };
123
120
  Tooltip.prototype.render = function () {
@@ -1 +1 @@
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,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,2CAA2C,CAAC;AAEjE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE7E;IAA6B,2BAAS;IAMrC,iBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QAA3D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAG/B;QATD,UAAI,GAAG,SAAS,CAAC;QAGjB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;QAKhC,KAAI,CAAC,IAAI,EAAE,CAAC;;IACb,CAAC;IAED,sBAAI,GAAJ;QAAA,iBA8DC;QA7DA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1D,IAAM,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AG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC,gBAAgB,CAAC,QAAQ,EACzB,MAAM,EACN,SAAS,CACT,CAAC;SACF;aAAM;YACN,qEAAqE;YACrE,IAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB,CACnE;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;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;YAEI,IAAA,6EAAgB,CAA+C;YACrE,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,AA9MD,CAA6B,SAAS,GA8MrC","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/src/globals/js/settings\";\n\n// D3 Imports\nimport { select, mouse, event } from \"d3-selection\";\nimport { TooltipTypes, ScaleTypes, TooltipPosition } 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(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\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(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\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(data, TooltipTypes.DATAPOINT);\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 (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\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\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\tconst chartWidth = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\n\t\t\t\ttooltipTextContainer.html(this.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\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(\"hide-tooltip\", () => {\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\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal.value) : 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.datasetLabel ? dataVal.datasetLabel : dataVal.label;\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\tconst points = data;\n\n\t\t// sort them so they are in the same order as the graph\n\t\tpoints.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().scaleType;\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\t// check if the datapoint has multiple values associates (multiple axes)\n\t\t\t\tlet datapointValue = datapoint.value;\n\t\t\t\tif (datapointValue instanceof Object) {\n\t\t\t\t\t// scale type determines which value we care about since it should align with the scale data\n\t\t\t\t\tdatapointValue = scaleType === ScaleTypes.TIME ? datapoint.value.date : datapoint.value.value;\n\t\t\t\t}\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapointValue) : datapointValue.toLocaleString(\"en\");\n\n\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\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\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}).join(\"\") + \"</ul>\";\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()).node().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: (elementPosition.left - holderPosition.left) + elementPosition.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 = positionOverride.placement === TooltipPosition.TOP ? PLACEMENTS.TOP : 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 { horizontalOffset } = 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,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE7E;IAA6B,2BAAS;IAMrC,iBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QAA3D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAG/B;QATD,UAAI,GAAG,SAAS,CAAC;QAGjB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;QAKhC,KAAI,CAAC,IAAI,EAAE,CAAC;;IACb,CAAC;IAED,sBAAI,GAAJ;QAAA,iBA8DC;QA7DA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAA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AQ,EACzB,MAAM,EACN,SAAS,CACT,CAAC;SACF;aAAM;YACN,qEAAqE;YACrE,IAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB,CACnE;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;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;YAEI,IAAA,6EAAgB,CAA+C;YACrE,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,AA5MD,CAA6B,SAAS,GA4MrC","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, ScaleTypes, TooltipPosition } 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(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\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(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\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(data, TooltipTypes.DATAPOINT);\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 (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\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\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\tconst chartWidth = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\n\t\t\t\ttooltipTextContainer.html(this.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\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(\"hide-tooltip\", () => {\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(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal[rangeIdentifier]) : 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\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().scaleType;\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tdata.map(datum => {\n\t\t\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\");\n\t\t\t\tconst formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString(\"en\");\n\n\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\tconst indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);\n\n\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}).join(\"\") + \"</ul>\";\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()).node().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: (elementPosition.left - holderPosition.left) + elementPosition.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 = positionOverride.placement === TooltipPosition.TOP ? PLACEMENTS.TOP : 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 { horizontalOffset } = 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"]}
@@ -3,12 +3,14 @@ import { ScaleBand } from "d3-scale";
3
3
  export declare class GroupedBar extends Bar {
4
4
  type: string;
5
5
  groupScale: ScaleBand<any>;
6
+ padding: number;
6
7
  init(): void;
7
- getGroupWidth(): number;
8
- setGroupScale(): void;
9
- getBarWidth(): number;
8
+ protected getDataCorrespondingToLabel(label: string): any;
9
+ protected getGroupWidth(): number;
10
+ protected getTotalGroupPadding(): number;
11
+ protected getBarWidth(): any;
12
+ protected setGroupScale(): void;
10
13
  render(animate: boolean): void;
11
- addLabelsToDataPoints(d: any, index: any): any;
12
14
  handleLegendOnHover: (event: CustomEvent<any>) => void;
13
15
  handleLegendMouseOut: (event: CustomEvent<any>) => void;
14
16
  addEventListeners(): void;
@@ -16,6 +16,7 @@ import { Bar } from "./bar";
16
16
  import { Tools } from "../../tools";
17
17
  import { CartesianOrientations, Events, Roles, TooltipTypes } from "../../interfaces";
18
18
  // D3 Imports
19
+ import { map } from "d3-collection";
19
20
  import { select } from "d3-selection";
20
21
  import { color } from "d3-color";
21
22
  import { scaleBand } from "d3-scale";
@@ -24,12 +25,14 @@ var GroupedBar = /** @class */ (function (_super) {
24
25
  function GroupedBar() {
25
26
  var _this = _super !== null && _super.apply(this, arguments) || this;
26
27
  _this.type = "grouped-bar";
28
+ _this.padding = 5;
27
29
  // Highlight elements that match the hovered legend item
28
30
  _this.handleLegendOnHover = function (event) {
29
31
  var hoveredElement = event.detail.hoveredElement;
32
+ var groupMapsTo = _this.model.getOptions().data.groupMapsTo;
30
33
  _this.parent.selectAll("path.bar")
31
34
  .transition(_this.services.transitions.getTransition("legend-hover-bar"))
32
- .attr("opacity", function (d) { return (d.datasetLabel !== hoveredElement.datum()["key"]) ? 0.3 : 1; });
35
+ .attr("opacity", function (d) { return (d[groupMapsTo] !== hoveredElement.datum()["name"]) ? 0.3 : 1; });
33
36
  };
34
37
  // Un-highlight all elements
35
38
  _this.handleLegendMouseOut = function (event) {
@@ -46,33 +49,65 @@ var GroupedBar = /** @class */ (function (_super) {
46
49
  // Un-highlight circles on legend item mouseouts
47
50
  eventsFragment.addEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);
48
51
  };
52
+ GroupedBar.prototype.getDataCorrespondingToLabel = function (label) {
53
+ var displayData = this.model.getDisplayData();
54
+ var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
55
+ return displayData.filter(function (datum) { return datum[domainIdentifier] === label; });
56
+ };
49
57
  GroupedBar.prototype.getGroupWidth = function () {
50
- var datasets = this.model.getDisplayData().datasets;
51
- var padding = 5;
52
- return datasets.length * this.getBarWidth() + (padding * (datasets.length - 1));
58
+ var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
59
+ var totalGroupPadding = this.getTotalGroupPadding();
60
+ return this.getBarWidth() * numOfActiveDataGroups + totalGroupPadding;
53
61
  };
54
- GroupedBar.prototype.setGroupScale = function () {
55
- var datasets = this.model.getDisplayData().datasets;
56
- this.groupScale = scaleBand()
57
- .domain(datasets.map(function (dataset) { return dataset.label; }))
58
- .rangeRound([0, this.getGroupWidth()]);
62
+ GroupedBar.prototype.getTotalGroupPadding = function () {
63
+ var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
64
+ if (numOfActiveDataGroups === 1) {
65
+ return 0;
66
+ }
67
+ var domainScale = this.services.cartesianScales.getDomainScale();
68
+ var padding = Math.min(5, 5 * (domainScale.step() / 70));
69
+ return padding * (numOfActiveDataGroups - 1);
59
70
  };
60
71
  // Gets the correct width for bars based on options & configurations
61
72
  GroupedBar.prototype.getBarWidth = function () {
62
- var datasets = this.model.getDisplayData().datasets;
73
+ var options = this.model.getOptions();
74
+ var providedWidth = Tools.getProperty(options, "bars", "width");
75
+ var providedMaxWidth = Tools.getProperty(options, "bars", "maxWidth");
76
+ // If there's a provided width, compare with maxWidth and
77
+ // Determine which to return
78
+ if (providedWidth !== null) {
79
+ if (providedMaxWidth === null) {
80
+ return providedWidth;
81
+ }
82
+ else if (providedWidth <= providedMaxWidth) {
83
+ return providedWidth;
84
+ }
85
+ }
86
+ var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
87
+ var totalGroupPadding = this.getTotalGroupPadding();
63
88
  var domainScale = this.services.cartesianScales.getDomainScale();
64
- return Math.min(domainScale.step() / 2 / datasets.length, _super.prototype.getBarWidth.call(this));
89
+ return Math.min(providedMaxWidth, (domainScale.step() - totalGroupPadding) / numOfActiveDataGroups);
90
+ };
91
+ GroupedBar.prototype.setGroupScale = function () {
92
+ this.groupScale = scaleBand()
93
+ .domain(this.model.getActiveDataGroupNames())
94
+ .rangeRound([0, this.getGroupWidth()]);
65
95
  };
66
96
  GroupedBar.prototype.render = function (animate) {
67
97
  var _this = this;
68
98
  // Chart options mixed with the internal configurations
69
99
  var displayData = this.model.getDisplayData();
100
+ var options = this.model.getOptions();
101
+ var groupMapsTo = options.data.groupMapsTo;
102
+ var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
103
+ // Get unique labels
70
104
  this.setGroupScale();
71
105
  // Grab container SVG
72
106
  var svg = this.getContainerSVG();
107
+ var allDataLabels = map(displayData, function (datum) { return datum[domainIdentifier]; }).keys();
73
108
  // Update data on bar groups
74
109
  var barGroups = svg.selectAll("g.bars")
75
- .data(displayData.labels);
110
+ .data(allDataLabels, function (label) { return label; });
76
111
  // Remove dot groups that need to be removed
77
112
  barGroups.exit()
78
113
  .attr("opacity", 0)
@@ -85,9 +120,10 @@ var GroupedBar = /** @class */ (function (_super) {
85
120
  .attr("aria-labelledby", function (d) { return d; });
86
121
  // Update data on all bars
87
122
  var bars = barGroupsEnter.merge(barGroups)
88
- .attr("transform", function (d, i) {
89
- var scaleValue = _this.services.cartesianScales.getDomainValue(d, i);
90
- var translateBy = scaleValue - _this.getGroupWidth() / 2 + _this.getBarWidth();
123
+ .attr("transform", function (label, i) {
124
+ var scaleValue = _this.services.cartesianScales.getDomainValue(label, i);
125
+ var translateBy = scaleValue - _this.getGroupWidth() / 2;
126
+ // const translateBy = scaleValue - this.getGroupWidth(null) / 2 + this.getBarWidth(null);
91
127
  if (_this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {
92
128
  return "translate(" + translateBy + ", 0)";
93
129
  }
@@ -97,7 +133,7 @@ var GroupedBar = /** @class */ (function (_super) {
97
133
  }
98
134
  })
99
135
  .selectAll("path.bar")
100
- .data(function (d, i) { return _this.addLabelsToDataPoints(d, i); });
136
+ .data(function (label) { return _this.getDataCorrespondingToLabel(label); });
101
137
  // Remove bars that are no longer needed
102
138
  bars.exit()
103
139
  .attr("opacity", 0)
@@ -110,7 +146,7 @@ var GroupedBar = /** @class */ (function (_super) {
110
146
  barsEnter.merge(bars)
111
147
  .classed("bar", true)
112
148
  .transition(this.services.transitions.getTransition("bar-update-enter", animate))
113
- .attr("fill", function (d) { return _this.model.getFillScale()[d.datasetLabel](d.label); })
149
+ .attr("fill", function (d) { return _this.model.getFillColor(d[groupMapsTo]); })
114
150
  .attr("d", function (d) {
115
151
  /*
116
152
  * Orientation support for horizontal/vertical bar charts
@@ -118,10 +154,10 @@ var GroupedBar = /** @class */ (function (_super) {
118
154
  * to draw the bars needed, and pass those coordinates down to
119
155
  * generateSVGPathString() to decide whether it needs to flip them
120
156
  */
121
- var centerX = _this.groupScale(d.datasetLabel);
157
+ var startX = _this.groupScale(d[groupMapsTo]);
122
158
  var barWidth = _this.getBarWidth();
123
- var x0 = centerX - barWidth / 2;
124
- var x1 = centerX + barWidth / 2;
159
+ var x0 = startX;
160
+ var x1 = startX + barWidth;
125
161
  var y0 = _this.services.cartesianScales.getRangeValue(0);
126
162
  var y1 = _this.services.cartesianScales.getRangeValue(d.value);
127
163
  return Tools.generateSVGPathString({ x0: x0, x1: x1, y0: y0, y1: y1 }, _this.services.cartesianScales.getOrientation());
@@ -134,15 +170,6 @@ var GroupedBar = /** @class */ (function (_super) {
134
170
  // Add event listeners to elements drawn
135
171
  this.addEventListeners();
136
172
  };
137
- // TODO - This method could be re-used in more graphs
138
- GroupedBar.prototype.addLabelsToDataPoints = function (d, index) {
139
- var datasets = this.model.getDisplayData().datasets;
140
- return datasets.map(function (dataset) { return ({
141
- label: d,
142
- datasetLabel: dataset.label,
143
- value: dataset.data[index].value ? dataset.data[index].value : dataset.data[index]
144
- }); });
145
- };
146
173
  GroupedBar.prototype.addEventListeners = function () {
147
174
  var self = this;
148
175
  this.parent.selectAll("path.bar")
@@ -156,7 +183,7 @@ var GroupedBar = /** @class */ (function (_super) {
156
183
  datum: datum
157
184
  });
158
185
  // Show tooltip
159
- self.services.events.dispatchEvent("show-tooltip", {
186
+ self.services.events.dispatchEvent(Events.Tooltip.SHOW, {
160
187
  hoveredElement: hoveredElement,
161
188
  type: TooltipTypes.DATAPOINT
162
189
  });
@@ -178,15 +205,16 @@ var GroupedBar = /** @class */ (function (_super) {
178
205
  .on("mouseout", function (datum) {
179
206
  var hoveredElement = select(this);
180
207
  hoveredElement.classed("hovered", false);
208
+ var groupMapsTo = self.model.getOptions().data.groupMapsTo;
181
209
  hoveredElement.transition(self.services.transitions.getTransition("graph_element_mouseout_fill_update"))
182
- .attr("fill", function (d) { return self.model.getFillScale()[d.datasetLabel](d.label); });
210
+ .attr("fill", function (d) { return self.model.getFillColor(d[groupMapsTo]); });
183
211
  // Dispatch mouse event
184
212
  self.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOUT, {
185
213
  element: hoveredElement,
186
214
  datum: datum
187
215
  });
188
216
  // Hide tooltip
189
- self.services.events.dispatchEvent("hide-tooltip", { hoveredElement: hoveredElement });
217
+ self.services.events.dispatchEvent(Events.Tooltip.HIDE, { hoveredElement: hoveredElement });
190
218
  });
191
219
  };
192
220
  GroupedBar.prototype.destroy = function () {