@carbon/charts 0.32.9 → 0.33.0

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 (187) hide show
  1. package/CHANGELOG.md +331 -145
  2. package/README.md +18 -8
  3. package/axis-chart.js +20 -20
  4. package/axis-chart.js.map +1 -1
  5. package/build/demo/data/area.d.ts +17 -0
  6. package/build/demo/data/bar.d.ts +71 -0
  7. package/build/demo/data/line.d.ts +55 -0
  8. package/build/demo/data/scatter.d.ts +18 -0
  9. package/build/src/components/essentials/tooltip-bar.d.ts +2 -2
  10. package/build/src/components/essentials/tooltip-radar.d.ts +2 -1
  11. package/build/src/components/essentials/tooltip.d.ts +2 -2
  12. package/build/src/interfaces/axis-scales.d.ts +2 -0
  13. package/build/src/interfaces/charts.d.ts +5 -0
  14. package/build/src/interfaces/components.d.ts +2 -0
  15. package/build/src/interfaces/enums.d.ts +12 -1
  16. package/build/src/interfaces/truncation.d.ts +17 -0
  17. package/build/src/model.d.ts +1 -0
  18. package/build/src/tools.d.ts +9 -0
  19. package/bundle.js +1 -1
  20. package/charts/area-stacked.js +3 -3
  21. package/charts/area-stacked.js.map +1 -1
  22. package/charts/area.js +3 -3
  23. package/charts/area.js.map +1 -1
  24. package/charts/bar-grouped.js +3 -3
  25. package/charts/bar-grouped.js.map +1 -1
  26. package/charts/bar-simple.js +3 -3
  27. package/charts/bar-simple.js.map +1 -1
  28. package/charts/bar-stacked.js +3 -3
  29. package/charts/bar-stacked.js.map +1 -1
  30. package/charts/bubble.js +3 -3
  31. package/charts/bubble.js.map +1 -1
  32. package/charts/donut.js +3 -3
  33. package/charts/donut.js.map +1 -1
  34. package/charts/gauge.js +2 -1
  35. package/charts/gauge.js.map +1 -1
  36. package/charts/line.js +3 -3
  37. package/charts/line.js.map +1 -1
  38. package/charts/pie.js +3 -3
  39. package/charts/pie.js.map +1 -1
  40. package/charts/radar.js +1 -1
  41. package/charts/radar.js.map +1 -1
  42. package/charts/scatter.js +3 -3
  43. package/charts/scatter.js.map +1 -1
  44. package/components/axes/axis.js +76 -14
  45. package/components/axes/axis.js.map +1 -1
  46. package/components/axes/grid.js +1 -1
  47. package/components/axes/grid.js.map +1 -1
  48. package/components/axes/ruler.js +2 -2
  49. package/components/axes/ruler.js.map +1 -1
  50. package/components/axes/two-dimensional-axes.js +3 -3
  51. package/components/axes/two-dimensional-axes.js.map +1 -1
  52. package/components/axes/zero-line.js +1 -1
  53. package/components/axes/zero-line.js.map +1 -1
  54. package/components/essentials/legend.js +53 -11
  55. package/components/essentials/legend.js.map +1 -1
  56. package/components/essentials/threshold.js +9 -9
  57. package/components/essentials/threshold.js.map +1 -1
  58. package/components/essentials/title.js +2 -2
  59. package/components/essentials/title.js.map +1 -1
  60. package/components/essentials/tooltip-bar.d.ts +2 -2
  61. package/components/essentials/tooltip-bar.js +24 -10
  62. package/components/essentials/tooltip-bar.js.map +1 -1
  63. package/components/essentials/tooltip-pie.js +3 -0
  64. package/components/essentials/tooltip-pie.js.map +1 -1
  65. package/components/essentials/tooltip-radar.d.ts +2 -1
  66. package/components/essentials/tooltip-radar.js +1 -1
  67. package/components/essentials/tooltip-radar.js.map +1 -1
  68. package/components/essentials/tooltip-scatter.js +6 -0
  69. package/components/essentials/tooltip-scatter.js.map +1 -1
  70. package/components/essentials/tooltip.d.ts +2 -2
  71. package/components/essentials/tooltip.js +16 -11
  72. package/components/essentials/tooltip.js.map +1 -1
  73. package/components/graphs/area-stacked.js +8 -7
  74. package/components/graphs/area-stacked.js.map +1 -1
  75. package/components/graphs/bar-grouped.js +7 -7
  76. package/components/graphs/bar-grouped.js.map +1 -1
  77. package/components/graphs/bar-simple.js +6 -6
  78. package/components/graphs/bar-simple.js.map +1 -1
  79. package/components/graphs/bar-stacked.js +6 -6
  80. package/components/graphs/bar-stacked.js.map +1 -1
  81. package/components/graphs/gauge.js +7 -5
  82. package/components/graphs/gauge.js.map +1 -1
  83. package/components/graphs/line.js +14 -10
  84. package/components/graphs/line.js.map +1 -1
  85. package/components/graphs/pie.js +12 -12
  86. package/components/graphs/pie.js.map +1 -1
  87. package/components/graphs/radar.js +11 -11
  88. package/components/graphs/radar.js.map +1 -1
  89. package/components/graphs/scatter-stacked.js +2 -4
  90. package/components/graphs/scatter-stacked.js.map +1 -1
  91. package/components/graphs/scatter.js +6 -8
  92. package/components/graphs/scatter.js.map +1 -1
  93. package/components/graphs/skeleton.js +3 -3
  94. package/components/graphs/skeleton.js.map +1 -1
  95. package/components/layout/layout.js +10 -4
  96. package/components/layout/layout.js.map +1 -1
  97. package/configuration.js +26 -8
  98. package/configuration.js.map +1 -1
  99. package/demo/create-codesandbox.js +19 -19
  100. package/demo/create-codesandbox.js.map +1 -1
  101. package/demo/data/area.d.ts +17 -0
  102. package/demo/data/area.js +26 -0
  103. package/demo/data/area.js.map +1 -1
  104. package/demo/data/bar.d.ts +71 -0
  105. package/demo/data/bar.js +176 -95
  106. package/demo/data/bar.js.map +1 -1
  107. package/demo/data/bubble.js +29 -29
  108. package/demo/data/bubble.js.map +1 -1
  109. package/demo/data/bundle.js +1 -1
  110. package/demo/data/index.js +39 -1
  111. package/demo/data/index.js.map +1 -1
  112. package/demo/data/line.d.ts +55 -0
  113. package/demo/data/line.js +149 -50
  114. package/demo/data/line.js.map +1 -1
  115. package/demo/data/pie.js +5 -5
  116. package/demo/data/pie.js.map +1 -1
  117. package/demo/data/radar.js +12 -12
  118. package/demo/data/radar.js.map +1 -1
  119. package/demo/data/scatter.d.ts +18 -0
  120. package/demo/data/scatter.js +73 -22
  121. package/demo/data/scatter.js.map +1 -1
  122. package/demo/data/step.js +6 -6
  123. package/demo/data/step.js.map +1 -1
  124. package/demo/data/time-series-axis.js +107 -107
  125. package/demo/data/time-series-axis.js.map +1 -1
  126. package/demo/styles.css +32 -0
  127. package/demo/styles.css.map +1 -1
  128. package/demo/styles.min.css +1 -1
  129. package/demo/styles.min.css.map +1 -1
  130. package/demo/tsconfig.tsbuildinfo +50 -27
  131. package/interfaces/a11y.js.map +1 -1
  132. package/interfaces/axis-scales.d.ts +2 -0
  133. package/interfaces/axis-scales.js.map +1 -1
  134. package/interfaces/charts.d.ts +5 -0
  135. package/interfaces/charts.js.map +1 -1
  136. package/interfaces/components.d.ts +2 -0
  137. package/interfaces/components.js.map +1 -1
  138. package/interfaces/enums.d.ts +12 -1
  139. package/interfaces/enums.js +12 -0
  140. package/interfaces/enums.js.map +1 -1
  141. package/interfaces/events.js.map +1 -1
  142. package/interfaces/truncation.d.ts +17 -0
  143. package/interfaces/truncation.js +1 -0
  144. package/interfaces/truncation.js.map +1 -0
  145. package/model.d.ts +1 -0
  146. package/model.js +61 -5
  147. package/model.js.map +1 -1
  148. package/package.json +1 -1
  149. package/polyfills.js +1 -1
  150. package/polyfills.js.map +1 -1
  151. package/services/angle-utils.js +8 -8
  152. package/services/angle-utils.js.map +1 -1
  153. package/services/colorPalettes.js +2 -2
  154. package/services/colorPalettes.js.map +1 -1
  155. package/services/colors.js +1 -1
  156. package/services/colors.js.map +1 -1
  157. package/services/curves.js +2 -2
  158. package/services/curves.js.map +1 -1
  159. package/services/essentials/dom-utils.js +6 -6
  160. package/services/essentials/dom-utils.js.map +1 -1
  161. package/services/essentials/events.js +1 -1
  162. package/services/essentials/events.js.map +1 -1
  163. package/services/scales-cartesian.js +17 -17
  164. package/services/scales-cartesian.js.map +1 -1
  165. package/services/time-series.js +2 -2
  166. package/services/time-series.js.map +1 -1
  167. package/styles/components/_tooltip.scss +2 -0
  168. package/styles-g10.css +8 -0
  169. package/styles-g10.css.map +1 -1
  170. package/styles-g10.min.css +1 -1
  171. package/styles-g10.min.css.map +1 -1
  172. package/styles-g100.css +8 -0
  173. package/styles-g100.css.map +1 -1
  174. package/styles-g100.min.css +1 -1
  175. package/styles-g100.min.css.map +1 -1
  176. package/styles-g90.css +8 -0
  177. package/styles-g90.css.map +1 -1
  178. package/styles-g90.min.css +1 -1
  179. package/styles-g90.min.css.map +1 -1
  180. package/styles.css +8 -0
  181. package/styles.css.map +1 -1
  182. package/styles.min.css +1 -1
  183. package/styles.min.css.map +1 -1
  184. package/tools.d.ts +9 -0
  185. package/tools.js +32 -7
  186. package/tools.js.map +1 -1
  187. package/tsconfig.tsbuildinfo +87 -69
@@ -13,7 +13,7 @@ var __extends = (this && this.__extends) || (function () {
13
13
  })();
14
14
  import { Component } from "../component";
15
15
  import { Tools } from "../../tools";
16
- import { LegendOrientations, Roles, Events } from "../../interfaces";
16
+ import { LegendOrientations, Roles, Events, TooltipTypes, TruncationTypes } from "../../interfaces";
17
17
  import { DOMUtils } from "../../services";
18
18
  // D3 Imports
19
19
  import { select } from "d3-selection";
@@ -28,6 +28,7 @@ var Legend = /** @class */ (function (_super) {
28
28
  var _this = this;
29
29
  var svg = this.getContainerSVG().attr("role", Roles.GRAPHICS_DOCUMENT);
30
30
  var options = this.model.getOptions();
31
+ var legendOptions = Tools.getProperty(options, "legend");
31
32
  var legendItems = svg
32
33
  .selectAll("g.legend-item")
33
34
  .data(this.model.getDataGroups(), function (dataGroup) { return dataGroup.name; });
@@ -35,9 +36,17 @@ var Legend = /** @class */ (function (_super) {
35
36
  var addedLegendItems = legendItems
36
37
  .enter()
37
38
  .append("g")
38
- .classed("legend-item", true);
39
+ .classed("legend-item", true)
40
+ .classed("active", function (d, i) {
41
+ return d.status === options.legend.items.status.ACTIVE;
42
+ });
39
43
  // Configs
40
44
  var checkboxRadius = options.legend.checkbox.radius;
45
+ // Truncation
46
+ // get user provided custom values for truncation
47
+ var truncationType = Tools.getProperty(legendOptions, "truncation", "type");
48
+ var truncationThreshold = Tools.getProperty(legendOptions, "truncation", "threshold");
49
+ var truncationNumCharacter = Tools.getProperty(legendOptions, "truncation", "numCharacter");
41
50
  addedLegendItems
42
51
  .append("rect")
43
52
  .classed("checkbox", true)
@@ -54,11 +63,23 @@ var Legend = /** @class */ (function (_super) {
54
63
  .classed("active", function (d, i) {
55
64
  return d.status === options.legend.items.status.ACTIVE;
56
65
  });
57
- addedLegendItems
66
+ var addedLegendItemsText = addedLegendItems
58
67
  .append("text")
59
- .merge(legendItems.select("text"))
60
- .html(function (d) { return d.name; })
61
- .attr("alignment-baseline", "middle");
68
+ .merge(legendItems.select("text"));
69
+ // truncate the legend label if it's too long
70
+ if (truncationType !== TruncationTypes.NONE) {
71
+ addedLegendItemsText.html(function (d) {
72
+ if (d.name.length > truncationThreshold) {
73
+ return Tools.truncateLabel(d.name, truncationType, truncationNumCharacter);
74
+ }
75
+ else {
76
+ return d.name;
77
+ }
78
+ });
79
+ }
80
+ else {
81
+ addedLegendItemsText.html(function (d) { return d.name; });
82
+ }
62
83
  this.breakItemsIntoLines(addedLegendItems);
63
84
  // Remove old elements as needed.
64
85
  legendItems
@@ -137,11 +158,19 @@ var Legend = /** @class */ (function (_super) {
137
158
  legendItem
138
159
  .select("text")
139
160
  .attr("x", startingPoint + spaceNeededForCheckbox)
140
- .attr("y", yOffset + yPosition);
161
+ .attr("y", yOffset + yPosition + 3);
141
162
  lastYPosition = yPosition;
163
+ // Test if legendItems are placed in the correct direction
164
+ var testHorizontal = (!legendOrientation ||
165
+ legendOrientation === LegendOrientations.HORIZONTAL) &&
166
+ legendItem.select("rect.checkbox").attr("y") === '0';
167
+ var testVertical = legendOrientation === LegendOrientations.VERTICAL &&
168
+ legendItem.select("rect.checkbox").attr("x") === '0';
169
+ var hasCorrectLegendDirection = testHorizontal || testVertical;
142
170
  // Render checkbox check icon
143
171
  if (hasDeactivatedItems &&
144
- legendItem.select("g.check").empty()) {
172
+ legendItem.select("g.check").empty() &&
173
+ hasCorrectLegendDirection) {
145
174
  legendItem.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");
146
175
  legendItem
147
176
  .select("g.check svg")
@@ -161,10 +190,12 @@ var Legend = /** @class */ (function (_super) {
161
190
  var self = this;
162
191
  var svg = this.getContainerSVG();
163
192
  var options = this.model.getOptions();
193
+ var legendOptions = Tools.getProperty(options, "legend");
194
+ var truncationThreshold = Tools.getProperty(legendOptions, "truncation", "threshold");
164
195
  svg.selectAll("g.legend-item")
165
196
  .on("mouseover", function () {
166
197
  self.services.events.dispatchEvent(Events.Legend.ITEM_HOVER, {
167
- hoveredElement: select(this),
198
+ hoveredElement: select(this)
168
199
  });
169
200
  // Configs
170
201
  var checkboxRadius = options.legend.checkbox.radius;
@@ -182,17 +213,28 @@ var Legend = /** @class */ (function (_super) {
182
213
  })
183
214
  .on("click", function () {
184
215
  self.services.events.dispatchEvent(Events.Legend.ITEM_CLICK, {
185
- clickedElement: select(this),
216
+ clickedElement: select(this)
186
217
  });
187
218
  var clickedItem = select(this);
188
219
  var clickedItemData = clickedItem.datum();
189
220
  self.model.toggleDataLabel(clickedItemData.name);
221
+ })
222
+ .on("mousemove", function () {
223
+ var hoveredItem = select(this);
224
+ var hoveredItemData = hoveredItem.datum();
225
+ if (hoveredItemData.name.length > truncationThreshold) {
226
+ self.services.events.dispatchEvent(Events.Tooltip.SHOW, {
227
+ hoveredElement: hoveredItem,
228
+ type: TooltipTypes.LEGEND
229
+ });
230
+ }
190
231
  })
191
232
  .on("mouseout", function () {
192
233
  var hoveredItem = select(this);
193
234
  hoveredItem.select("rect.hover-stroke").remove();
235
+ self.services.events.dispatchEvent(Events.Tooltip.HIDE);
194
236
  self.services.events.dispatchEvent(Events.Legend.ITEM_MOUSEOUT, {
195
- hoveredElement: hoveredItem,
237
+ hoveredElement: hoveredItem
196
238
  });
197
239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,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC;iBACtC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;iBACb,IAAI,CAAC,IAAI,EAAE,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\t\thoveredElement: hoveredItem,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"legend.js","sourceRoot":"","sources":["legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACN,kBAAkB,EAClB,KAAK,EACL,MAAM,EACN,YAAY,EACZ,eAAe,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;IAA4B,0BAAS;IAArC;QAAA,qEAgVC;QA/UA,UAAI,GAAG,QAAQ,CAAC;;IA+UjB,CAAC;IA7UA,uBAAM,GAAN;QAAA,iBAmGC;QAlGA,IAAM,GAAG,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,CACtC,MAAM,EACN,KAAK,CAAC,iBAAiB,CACvB,CAAC;QACF,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxC,IAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC3D,IAAM,WAAW,GAAG,GAAG;aACrB,SAAS,CAAC,eAAe,CAAC;aAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,UAAC,SAAS,IAAK,OAAA,SAAS,CAAC,IAAI,EAAd,CAAc,CAAC,CAAC;QAElE,4BAA4B;QAE5B,IAAM,gBAAgB,GAAG,WAAW;aAClC,KAAK,EAAE;aACP,MAAM,CAAC,GAAG,CAAC;aAC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AM,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;oBACvD,cAAc,EAAE,WAAW;oBAC3B,IAAI,EAAE,YAAY,CAAC,MAAM;iBACzB,CAAC,CAAC;aACH;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,AAhVD,CAA4B,SAAS,GAgVpC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport {\n\tLegendOrientations,\n\tRoles,\n\tEvents,\n\tTooltipTypes,\n\tTruncationTypes\n} 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\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\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.html(function (d) {\n\t\t\t\tif (d.name.length > truncationThreshold) {\n\t\t\t\t\treturn Tools.truncateLabel(\n\t\t\t\t\t\td.name,\n\t\t\t\t\t\ttruncationType,\n\t\t\t\t\t\ttruncationNumCharacter\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\treturn d.name;\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\taddedLegendItemsText.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 + 3);\n\n\t\t\t\tlastYPosition = yPosition;\n\n\t\t\t\t// Test if legendItems are placed in the correct direction\n\t\t\t\tconst testHorizontal = (!legendOrientation ||\n\t\t\t\t\tlegendOrientation === LegendOrientations.HORIZONTAL) &&\n\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"y\") === '0';\n\n\t\t\t\tconst testVertical = legendOrientation === LegendOrientations.VERTICAL &&\n\t\t\t\t\tlegendItem.select(\"rect.checkbox\").attr(\"x\") === '0';\n\n\t\t\t\tconst hasCorrectLegendDirection = testHorizontal || testVertical;\n\n\t\t\t\t// Render checkbox check icon\n\t\t\t\tif (hasDeactivatedItems &&\n\t\t\t\t\tlegendItem.select(\"g.check\").empty() &&\n\t\t\t\t\thasCorrectLegendDirection\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\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\t\thoveredElement: hoveredItem,\n\t\t\t\t\t\ttype: TooltipTypes.LEGEND\n\t\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"]}
@@ -14,13 +14,13 @@ var __extends = (this && this.__extends) || (function () {
14
14
  import { Component } from "../component";
15
15
  import { Tools } from "../../tools";
16
16
  import { DOMUtils } from "../../services";
17
- import { AxisPositions, Events, ScaleTypes, CartesianOrientations, } from "../../interfaces";
17
+ import { AxisPositions, Events, ScaleTypes, CartesianOrientations } from "../../interfaces";
18
18
  import { select, mouse } from "d3-selection";
19
19
  // Carbon position service
20
20
  import Position, { PLACEMENTS } from "@carbon/utils-position";
21
21
  // import the settings for the css prefix
22
22
  import settings from "carbon-components/es/globals/js/settings";
23
- import { formatTick, computeTimeIntervalName, } from "../../services/time-series";
23
+ import { formatTick, computeTimeIntervalName } from "../../services/time-series";
24
24
  var Threshold = /** @class */ (function (_super) {
25
25
  __extends(Threshold, _super);
26
26
  function Threshold(model, services, configs) {
@@ -105,7 +105,7 @@ var Threshold = /** @class */ (function (_super) {
105
105
  if (scaleType === ScaleTypes.TIME) {
106
106
  var isVertical = [
107
107
  AxisPositions.LEFT,
108
- AxisPositions.RIGHT,
108
+ AxisPositions.RIGHT
109
109
  ].includes(axisPosition);
110
110
  var mainXScale = this.services.cartesianScales.getMainXScale();
111
111
  var mainYScale = this.services.cartesianScales.getMainYScale();
@@ -136,20 +136,20 @@ var Threshold = /** @class */ (function (_super) {
136
136
  // Find out whether threshold label should be shown on the left or right side
137
137
  var bestPlacementOption = this.positionService.findBestPlacementAt({
138
138
  left: mouseRelativePos[0],
139
- top: mouseRelativePos[1],
139
+ top: mouseRelativePos[1]
140
140
  }, target, [
141
141
  PLACEMENTS.RIGHT,
142
142
  PLACEMENTS.LEFT,
143
143
  PLACEMENTS.TOP,
144
- PLACEMENTS.BOTTOM,
144
+ PLACEMENTS.BOTTOM
145
145
  ], function () { return ({
146
146
  width: holder.offsetWidth,
147
- height: holder.offsetHeight,
147
+ height: holder.offsetHeight
148
148
  }); });
149
149
  // Get coordinates to where label should be positioned
150
150
  var pos = this.positionService.findPositionAt({
151
151
  left: mouseRelativePos[0],
152
- top: mouseRelativePos[1],
152
+ top: mouseRelativePos[1]
153
153
  }, target, bestPlacementOption);
154
154
  this.positionService.setElement(target, pos);
155
155
  };
@@ -160,13 +160,13 @@ var Threshold = /** @class */ (function (_super) {
160
160
  .on("mouseover mousemove", function () {
161
161
  self.threshold.classed("active", true);
162
162
  self.services.events.dispatchEvent(Events.Threshold.SHOW, {
163
- hoveredElement: select(self.threshold),
163
+ hoveredElement: select(self.threshold)
164
164
  });
165
165
  })
166
166
  .on("mouseout", function () {
167
167
  self.threshold.classed("active", false);
168
168
  self.services.events.dispatchEvent(Events.Threshold.HIDE, {
169
- hoveredElement: select(self.threshold),
169
+ hoveredElement: select(self.threshold)
170
170
  });
171
171
  });
172
172
  };
@@ -1 +1 @@
1
- {"version":3,"file":"threshold.js","sourceRoot":"","sources":["threshold.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACN,aAAa,EACb,MAAM,EACN,UAAU,EACV,qBAAqB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAChE,OAAO,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,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;QAEF,sDAAsD;QACtD,IAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAC9C;YACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACzB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;SACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,qCAAiB,GAAjB;QACC,IAAM,IAAI,GAAG,IAAI,CAAC;QAElB,6CAA6C;QAC7C,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC;aAC7C,EAAE,CAAC,qBAAqB,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACF,gBAAC;AAAD,CAAC,AArOD,CAA+B,SAAS,GAqOvC","sourcesContent":["import { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\nimport {\n\tAxisPositions,\n\tEvents,\n\tScaleTypes,\n\tCartesianOrientations,\n} from \"../../interfaces\";\nimport { select, mouse } from \"d3-selection\";\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\";\nimport {\n\tformatTick,\n\tcomputeTimeIntervalName,\n} from \"../../services/time-series\";\n\nexport class Threshold extends Component {\n\ttype = \"threshold\";\n\n\tthreshold: any;\n\tthresholdClass: string;\n\tthresholdIdentifierClass: string;\n\n\tlabel: any;\n\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs: any) {\n\t\tsuper(model, services, configs);\n\t}\n\n\trender(animate = false) {\n\t\tconst { value, fillColor, axisPosition, index } = this.configs;\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.thresholdClass = `${settings.prefix}--${chartprefix}--threshold`;\n\t\t// We can have multiple thresholds, set an unique identifier\n\t\tthis.thresholdIdentifierClass = `${axisPosition}-${index}`;\n\n\t\tthis.threshold = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t`g.${this.thresholdClass}.${this.thresholdIdentifierClass}`\n\t\t).raise();\n\t\t// Append threshold hoverable area\n\t\tconst thresholdRect = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`rect.threshold-hoverable-area`\n\t\t);\n\t\t// Append threshold line\n\t\tconst thresholdLine = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`line.threshold-line`\n\t\t);\n\n\t\t// Set threshold line color from configs options\n\t\t// If not defined, the line takes the defined CSS color\n\t\tthresholdLine.style(\"stroke\", fillColor);\n\n\t\tconst scale = this.services.cartesianScales.getScaleByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst isScaleTypeLabels = scaleType === ScaleTypes.LABELS;\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\tconst { cartesianScales } = this.services;\n\t\tconst orientation = cartesianScales.getOrientation();\n\t\tconst getDomainValue = (d) => cartesianScales.getDomainValue(d);\n\t\tconst getRangeValue = (d) => cartesianScales.getRangeValue(d);\n\t\tconst [\n\t\t\tgetXValue,\n\t\t\tgetYValue,\n\t\t] = Tools.flipDomainAndRangeBasedOnOrientation(\n\t\t\tgetDomainValue,\n\t\t\tgetRangeValue,\n\t\t\torientation\n\t\t);\n\n\t\tif (orientation === CartesianOrientations.VERTICAL) {\n\t\t\tconst position =\n\t\t\t\tgetXValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the x scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${position}, ${yScaleStart})`);\n\t\t\t// Set line end point on the y-axis\n\t\t\tthresholdLine.attr(\"y2\", yScaleEnd - yScaleStart);\n\t\t\t// Set hoverable area width and rotate it\n\t\t\tthresholdRect\n\t\t\t\t.attr(\"width\", yScaleEnd - yScaleStart)\n\t\t\t\t.classed(\"rotate\", true);\n\t\t} else {\n\t\t\tconst position =\n\t\t\t\tgetYValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the y scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${xScaleStart}, ${position})`);\n\t\t\t// Set line end point on the x-axis\n\t\t\tthresholdLine.attr(\"x2\", xScaleEnd - xScaleStart);\n\t\t\t// Set hoverable area width\n\t\t\tthresholdRect.attr(\"width\", xScaleEnd - xScaleStart);\n\t\t}\n\n\t\tconst self = this;\n\t\tthis.services.events.addEventListener(Events.Threshold.SHOW, (e) => {\n\t\t\tconst hovered = e.detail.hoveredElement.node();\n\t\t\t// If is this threshold\n\t\t\tif (hovered === self.threshold) {\n\t\t\t\t// Set label position and show it\n\t\t\t\tthis.setThresholdLabelPosition();\n\t\t\t\tthis.label.classed(\"hidden\", false);\n\t\t\t}\n\t\t});\n\n\t\tthis.services.events.addEventListener(Events.Threshold.HIDE, (e) => {\n\t\t\tthis.label.classed(\"hidden\", true);\n\t\t});\n\n\t\tthis.appendThresholdLabel();\n\n\t\tthis.addEventListeners();\n\t}\n\n\tgetFormattedValue() {\n\t\tconst { value, axisPosition } = this.configs;\n\t\tconst options = this.model.getOptions();\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\n\t\t// If scale is time, format the threshold date as the ticks format\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst isVertical = [\n\t\t\t\tAxisPositions.LEFT,\n\t\t\t\tAxisPositions.RIGHT,\n\t\t\t].includes(axisPosition);\n\t\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\t\tconst scale = isVertical ? mainYScale : mainXScale;\n\n\t\t\tconst timeScaleOptions = Tools.getProperty(options, \"timeScale\");\n\t\t\tconst timeInterval = computeTimeIntervalName(scale.ticks());\n\t\t\treturn formatTick(value, 0, timeInterval, timeScaleOptions);\n\t\t}\n\n\t\treturn value.toLocaleString(\"en\");\n\t}\n\n\tappendThresholdLabel() {\n\t\tconst {\n\t\t\tvalue,\n\t\t\tvalueFormatter,\n\t\t\tfillColor,\n\t\t\tlabel = \"Threshold\",\n\t\t} = this.configs;\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\t// Format the threshold value using valueFormatter if defined in user-provided options\n\t\tconst formattedValue = valueFormatter\n\t\t\t? valueFormatter(value)\n\t\t\t: this.getFormattedValue();\n\n\t\tthis.label = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${this.thresholdClass}--label.${this.thresholdIdentifierClass}`\n\t\t);\n\t\tthis.label\n\t\t\t.html(`${label}: ${formattedValue}`)\n\t\t\t.classed(\"hidden\", true)\n\t\t\t.style(\"background-color\", fillColor);\n\t}\n\n\tsetThresholdLabelPosition() {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.label.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\n\t\t// Find out whether threshold label should be shown on the left or right side\n\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t},\n\t\t\ttarget,\n\t\t\t[\n\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\tPLACEMENTS.BOTTOM,\n\t\t\t],\n\t\t\t() => ({\n\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\theight: holder.offsetHeight,\n\t\t\t})\n\t\t);\n\n\t\t// Get coordinates to where label should be positioned\n\t\tconst pos = this.positionService.findPositionAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t},\n\t\t\ttarget,\n\t\t\tbestPlacementOption\n\t\t);\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\n\t\t// Add events to the threshold hoverable area\n\t\tDOMUtils.appendOrSelect(this.threshold, \"rect\")\n\t\t\t.on(\"mouseover mousemove\", function () {\n\t\t\t\tself.threshold.classed(\"active\", true);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.SHOW, {\n\t\t\t\t\thoveredElement: select(self.threshold),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tself.threshold.classed(\"active\", false);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.HIDE, {\n\t\t\t\t\thoveredElement: select(self.threshold),\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"threshold.js","sourceRoot":"","sources":["threshold.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACN,aAAa,EACb,MAAM,EACN,UAAU,EACV,qBAAqB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAChE,OAAO,EACN,UAAU,EACV,uBAAuB,EACvB,MAAM,4BAA4B,CAAC;AAEpC;IAA+B,6BAAS;IAWvC,mBAAY,KAAiB,EAAE,QAAa,EAAE,OAAY;QAA1D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAC/B;QAZD,UAAI,GAAG,WAAW,CAAC;QAQnB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;;IAIjC,CAAC;IAED,0BAAM,GAAN,UAAO,OAAe;QAAtB,iBA6GC;QA7GM,wBAAA,EAAA,eAAe;QACf,IAAA,iBAAwD,EAAtD,gBAAK,EAAE,wBAAS,EAAE,8B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AI,CAAC;QAElB,6CAA6C;QAC7C,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC;aAC7C,EAAE,CAAC,qBAAqB,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACF,gBAAC;AAAD,CAAC,AArOD,CAA+B,SAAS,GAqOvC","sourcesContent":["import { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\nimport {\n\tAxisPositions,\n\tEvents,\n\tScaleTypes,\n\tCartesianOrientations\n} from \"../../interfaces\";\nimport { select, mouse } from \"d3-selection\";\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\";\nimport {\n\tformatTick,\n\tcomputeTimeIntervalName\n} from \"../../services/time-series\";\n\nexport class Threshold extends Component {\n\ttype = \"threshold\";\n\n\tthreshold: any;\n\tthresholdClass: string;\n\tthresholdIdentifierClass: string;\n\n\tlabel: any;\n\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs: any) {\n\t\tsuper(model, services, configs);\n\t}\n\n\trender(animate = false) {\n\t\tconst { value, fillColor, axisPosition, index } = this.configs;\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.thresholdClass = `${settings.prefix}--${chartprefix}--threshold`;\n\t\t// We can have multiple thresholds, set an unique identifier\n\t\tthis.thresholdIdentifierClass = `${axisPosition}-${index}`;\n\n\t\tthis.threshold = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t`g.${this.thresholdClass}.${this.thresholdIdentifierClass}`\n\t\t).raise();\n\t\t// Append threshold hoverable area\n\t\tconst thresholdRect = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`rect.threshold-hoverable-area`\n\t\t);\n\t\t// Append threshold line\n\t\tconst thresholdLine = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`line.threshold-line`\n\t\t);\n\n\t\t// Set threshold line color from configs options\n\t\t// If not defined, the line takes the defined CSS color\n\t\tthresholdLine.style(\"stroke\", fillColor);\n\n\t\tconst scale = this.services.cartesianScales.getScaleByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst isScaleTypeLabels = scaleType === ScaleTypes.LABELS;\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\tconst { cartesianScales } = this.services;\n\t\tconst orientation = cartesianScales.getOrientation();\n\t\tconst getDomainValue = (d) => cartesianScales.getDomainValue(d);\n\t\tconst getRangeValue = (d) => cartesianScales.getRangeValue(d);\n\t\tconst [\n\t\t\tgetXValue,\n\t\t\tgetYValue\n\t\t] = Tools.flipDomainAndRangeBasedOnOrientation(\n\t\t\tgetDomainValue,\n\t\t\tgetRangeValue,\n\t\t\torientation\n\t\t);\n\n\t\tif (orientation === CartesianOrientations.VERTICAL) {\n\t\t\tconst position =\n\t\t\t\tgetXValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the x scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${position}, ${yScaleStart})`);\n\t\t\t// Set line end point on the y-axis\n\t\t\tthresholdLine.attr(\"y2\", yScaleEnd - yScaleStart);\n\t\t\t// Set hoverable area width and rotate it\n\t\t\tthresholdRect\n\t\t\t\t.attr(\"width\", yScaleEnd - yScaleStart)\n\t\t\t\t.classed(\"rotate\", true);\n\t\t} else {\n\t\t\tconst position =\n\t\t\t\tgetYValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the y scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${xScaleStart}, ${position})`);\n\t\t\t// Set line end point on the x-axis\n\t\t\tthresholdLine.attr(\"x2\", xScaleEnd - xScaleStart);\n\t\t\t// Set hoverable area width\n\t\t\tthresholdRect.attr(\"width\", xScaleEnd - xScaleStart);\n\t\t}\n\n\t\tconst self = this;\n\t\tthis.services.events.addEventListener(Events.Threshold.SHOW, (e) => {\n\t\t\tconst hovered = e.detail.hoveredElement.node();\n\t\t\t// If is this threshold\n\t\t\tif (hovered === self.threshold) {\n\t\t\t\t// Set label position and show it\n\t\t\t\tthis.setThresholdLabelPosition();\n\t\t\t\tthis.label.classed(\"hidden\", false);\n\t\t\t}\n\t\t});\n\n\t\tthis.services.events.addEventListener(Events.Threshold.HIDE, (e) => {\n\t\t\tthis.label.classed(\"hidden\", true);\n\t\t});\n\n\t\tthis.appendThresholdLabel();\n\n\t\tthis.addEventListeners();\n\t}\n\n\tgetFormattedValue() {\n\t\tconst { value, axisPosition } = this.configs;\n\t\tconst options = this.model.getOptions();\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\n\t\t// If scale is time, format the threshold date as the ticks format\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst isVertical = [\n\t\t\t\tAxisPositions.LEFT,\n\t\t\t\tAxisPositions.RIGHT\n\t\t\t].includes(axisPosition);\n\t\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\t\tconst scale = isVertical ? mainYScale : mainXScale;\n\n\t\t\tconst timeScaleOptions = Tools.getProperty(options, \"timeScale\");\n\t\t\tconst timeInterval = computeTimeIntervalName(scale.ticks());\n\t\t\treturn formatTick(value, 0, timeInterval, timeScaleOptions);\n\t\t}\n\n\t\treturn value.toLocaleString(\"en\");\n\t}\n\n\tappendThresholdLabel() {\n\t\tconst {\n\t\t\tvalue,\n\t\t\tvalueFormatter,\n\t\t\tfillColor,\n\t\t\tlabel = \"Threshold\"\n\t\t} = this.configs;\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\t// Format the threshold value using valueFormatter if defined in user-provided options\n\t\tconst formattedValue = valueFormatter\n\t\t\t? valueFormatter(value)\n\t\t\t: this.getFormattedValue();\n\n\t\tthis.label = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${this.thresholdClass}--label.${this.thresholdIdentifierClass}`\n\t\t);\n\t\tthis.label\n\t\t\t.html(`${label}: ${formattedValue}`)\n\t\t\t.classed(\"hidden\", true)\n\t\t\t.style(\"background-color\", fillColor);\n\t}\n\n\tsetThresholdLabelPosition() {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.label.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\n\t\t// Find out whether threshold label should be shown on the left or right side\n\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t},\n\t\t\ttarget,\n\t\t\t[\n\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\tPLACEMENTS.BOTTOM\n\t\t\t],\n\t\t\t() => ({\n\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\theight: holder.offsetHeight\n\t\t\t})\n\t\t);\n\n\t\t// Get coordinates to where label should be positioned\n\t\tconst pos = this.positionService.findPositionAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t},\n\t\t\ttarget,\n\t\t\tbestPlacementOption\n\t\t);\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\n\t\t// Add events to the threshold hoverable area\n\t\tDOMUtils.appendOrSelect(this.threshold, \"rect\")\n\t\t\t.on(\"mouseover mousemove\", function () {\n\t\t\t\tself.threshold.classed(\"active\", true);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.SHOW, {\n\t\t\t\t\thoveredElement: select(self.threshold)\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tself.threshold.classed(\"active\", false);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.HIDE, {\n\t\t\t\t\thoveredElement: select(self.threshold)\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n"]}
@@ -57,12 +57,12 @@ var Title = /** @class */ (function (_super) {
57
57
  .on("mouseenter", function () {
58
58
  self_1.services.events.dispatchEvent(Events.Tooltip.SHOW, {
59
59
  hoveredElement: title,
60
- type: TooltipTypes.TITLE,
60
+ type: TooltipTypes.TITLE
61
61
  });
62
62
  })
63
63
  .on("mouseout", function () {
64
64
  self_1.services.events.dispatchEvent(Events.Tooltip.HIDE, {
65
- hoveredElement: title,
65
+ hoveredElement: title
66
66
  });
67
67
  });
68
68
  }
@@ -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,EAAE,MAAM,oBAAoB,CAAC;AAE1D;IAA2B,yBAAS;IAApC;QAAA,qEA6FC;QA5FA,UAAI,GAAG,OAAO,CAAC;;IA4FhB,CAAC;IA1FA;;OAEG;IACH,6BAAa,GAAb;QACC,+EAA+E;QAC/E,IAAM,cAAc,GAAG,QAAQ,CAAC,iBAAiB,CAChD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,EACnC,EAAE,OAAO,EAAE,IAAI,EAAE,CACjB,CAAC,KAAK,CAAC;QACR,IAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAEjE,0DAA0D;QAC1D,IAAI,cAAc,IAAI,CAAC,EAAE;YACxB,OAAO;SACP;QAED,uDAAuD;QACvD,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,qBAAqB,EAAE,GAAG,cAAc,EAAE;YAC1D,sEAAsE;YACtE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElC,qDAAqD;YACrD,IAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC;iBACzD,IAAI,EAAE;iBACN,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CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC;QAEpE,gEAAgE;QAChE,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACO,iCAAiB,GAA3B,UAA4B,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK;QACnD,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE;YAC7C,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SACxD;aAAM,IAAI,KAAK,CAAC,kBAAkB,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,AA7FD,CAA2B,SAAS,GA6FnC","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(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t).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\").text(\"...\");\n\n\t\t\t// get the bounding width including the elipses '...'\n\t\t\tconst tspanLength = DOMUtils.appendOrSelect(title, \"tspan\")\n\t\t\t\t.node()\n\t\t\t\t.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(\n\t\t\t\ttitle.node(),\n\t\t\t\t0,\n\t\t\t\ttitleString.length - 1,\n\t\t\t\ttruncatedSize\n\t\t\t);\n\n\t\t\t// use the substring as the title\n\t\t\ttitle\n\t\t\t\t.html(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).attr(\"y\", 20).html(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,qEA6FC;QA5FA,UAAI,GAAG,OAAO,CAAC;;IA4FhB,CAAC;IA1FA;;OAEG;IACH,6BAAa,GAAb;QACC,+EAA+E;QAC/E,IAAM,cAAc,GAAG,QAAQ,CAAC,iBAAiB,CAChD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,EACnC,EAAE,OAAO,EAAE,IAAI,EAAE,CACjB,CAAC,KAAK,CAAC;QACR,IAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAEjE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AAG,CAAC;SACX;IACF,CAAC;IACF,YAAC;AAAD,CAAC,AA7FD,CAA2B,SAAS,GA6FnC","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(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t).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\").text(\"...\");\n\n\t\t\t// get the bounding width including the elipses '...'\n\t\t\tconst tspanLength = DOMUtils.appendOrSelect(title, \"tspan\")\n\t\t\t\t.node()\n\t\t\t\t.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(\n\t\t\t\ttitle.node(),\n\t\t\t\t0,\n\t\t\t\ttitleString.length - 1,\n\t\t\t\ttruncatedSize\n\t\t\t);\n\n\t\t\t// use the substring as the title\n\t\t\ttitle\n\t\t\t\t.html(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).attr(\"y\", 20).html(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,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
@@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || (function () {
14
14
  import { Tooltip } from "./tooltip";
15
15
  import { Tools } from "../../tools";
16
16
  import { DOMUtils } from "../../services";
17
- import { TooltipPosition, TooltipTypes, CartesianOrientations, Events, } from "./../../interfaces";
17
+ import { TooltipPosition, TooltipTypes, CartesianOrientations, Events } from "./../../interfaces";
18
18
  // import the settings for the css prefix
19
19
  import settings from "carbon-components/es/globals/js/settings";
20
20
  // D3 Imports
@@ -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,15 @@ 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 ||
73
+ e.detail.type === TooltipTypes.AXISLABEL) {
74
+ _this.positionTooltip();
75
+ }
76
+ else {
77
+ var position = _this.getTooltipPosition(hoveredElement, data);
78
+ // Position the tooltip relative to the bars
79
+ _this.positionTooltip(e.detail.multidata ? undefined : position);
80
+ }
73
81
  }
74
82
  else if (e.detail.type === TooltipTypes.TITLE) {
75
83
  // use the chart size to enforce a max width on the tooltip
@@ -81,7 +89,7 @@ var TooltipBar = /** @class */ (function (_super) {
81
89
  // use tooltip.ts to get the tooltip html for titles
82
90
  tooltipTextContainer.html(_super.prototype.getTooltipHTML.call(_this, e.detail.hoveredElement, TooltipTypes.TITLE));
83
91
  // get the position based on the title positioning (static)
84
- var position = _super.prototype.getTooltipPosition.call(_this, e.detail.hoveredElement.node());
92
+ var position = _super.prototype.getTooltipPosition.call(_this, e.detail.hoveredElement.node(), e.detail.type);
85
93
  _this.positionTooltip(position);
86
94
  }
87
95
  // Fade in
@@ -113,7 +121,7 @@ var TooltipBar = /** @class */ (function (_super) {
113
121
  left: barPosition.left -
114
122
  holderPosition.left +
115
123
  barPosition.width / 2,
116
- top: barPosition.bottom - holderPosition.top + verticalOffset,
124
+ top: barPosition.bottom - holderPosition.top + verticalOffset
117
125
  };
118
126
  return { placement: TooltipPosition.BOTTOM, position: tooltipPos };
119
127
  }
@@ -123,7 +131,7 @@ var TooltipBar = /** @class */ (function (_super) {
123
131
  left: barPosition.left -
124
132
  holderPosition.left +
125
133
  barPosition.width / 2,
126
- top: barPosition.top - holderPosition.top - verticalOffset,
134
+ top: barPosition.top - holderPosition.top - verticalOffset
127
135
  };
128
136
  return { placement: TooltipPosition.TOP, position: tooltipPos };
129
137
  }
@@ -132,7 +140,13 @@ var TooltipBar = /** @class */ (function (_super) {
132
140
  * Returns the html for the bar single point tooltip
133
141
  * @param data associated values for the hovered bar
134
142
  */
135
- TooltipBar.prototype.getTooltipHTML = function (data) {
143
+ TooltipBar.prototype.getTooltipHTML = function (data, type) {
144
+ if (type === TooltipTypes.LEGEND) {
145
+ return "<div class=\"legend-tooltip\"><p class=\"label\">" + data.name + "</p></div>";
146
+ }
147
+ else if (type === TooltipTypes.AXISLABEL) {
148
+ return "<div class=\"axis-tooltip\"><p class=\"label\">" + data + "</p></div>";
149
+ }
136
150
  var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter")
137
151
  ? this.model.getOptions().tooltip.valueFormatter(data.value)
138
152
  : 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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I,IAAK,OAAA,GAAG,GAAG,IAAI,CAAC,KAAK,EAAhB,CAAgB,EAAE,CAAC,CAAC,CAAC;QAE9D,yBAAyB;QACzB,KAAK,GAAG,KAAK,CAAC,WAAW,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,EACN,MAAM,oBAAoB,CAAC;AAE5B,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,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BAAgB,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,AA3QD,CAAgC,OAAO,GA2QtC","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\te.detail.type === TooltipTypes.LEGEND ||\n\t\t\t\te.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 (\n\t\t\t\t\te.detail.type === TooltipTypes.LEGEND ||\n\t\t\t\t\te.detail.type === TooltipTypes.AXISLABEL\n\t\t\t\t) {\n\t\t\t\t\tthis.positionTooltip();\n\t\t\t\t} else {\n\t\t\t\t\tconst position = this.getTooltipPosition(\n\t\t\t\t\t\thoveredElement,\n\t\t\t\t\t\tdata\n\t\t\t\t\t);\n\t\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\t\tthis.positionTooltip(\n\t\t\t\t\t\te.detail.multidata ? undefined : position\n\t\t\t\t\t);\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"]}