@carbon/charts 0.30.4 → 0.30.8
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.
- package/CHANGELOG.md +35 -0
- package/build/demo/data/bar.d.ts +56 -94
- package/build/demo/data/bubble.d.ts +58 -13
- package/build/demo/data/donut.d.ts +3 -6
- package/build/demo/data/line.d.ts +35 -35
- package/build/demo/data/pie.d.ts +3 -6
- package/build/demo/data/scatter.d.ts +33 -20
- package/build/demo/data/step.d.ts +15 -16
- package/build/demo/data/time-series-axis.d.ts +12 -48
- package/build/src/charts/bar-grouped.d.ts +2 -2
- package/build/src/charts/bar-simple.d.ts +2 -4
- package/build/src/components/essentials/legend.d.ts +0 -4
- package/build/src/components/essentials/tooltip-bar.d.ts +1 -1
- package/build/src/components/essentials/tooltip-pie.d.ts +5 -0
- package/build/src/components/essentials/tooltip-scatter.d.ts +1 -1
- package/build/src/components/graphs/bar-grouped.d.ts +6 -4
- package/build/src/components/graphs/bar-simple.d.ts +0 -1
- package/build/src/components/graphs/bar-stacked.d.ts +0 -1
- package/build/src/components/graphs/bubble.d.ts +0 -1
- package/build/src/components/graphs/line.d.ts +3 -1
- package/build/src/components/graphs/pie.d.ts +0 -1
- package/build/src/components/graphs/scatter.d.ts +0 -1
- package/build/src/components/index.d.ts +1 -0
- package/build/src/interfaces/axis-scales.d.ts +4 -16
- package/build/src/interfaces/charts.d.ts +23 -1
- package/build/src/interfaces/enums.d.ts +0 -4
- package/build/src/interfaces/events.d.ts +29 -0
- package/build/src/model-pie.d.ts +1 -7
- package/build/src/model.d.ts +31 -13
- package/build/src/services/scales-cartesian.d.ts +11 -3
- package/build/src/tools.d.ts +2 -2
- package/build/stories/tutorials.stories.d.ts +1 -0
- package/bundle.js +1 -1
- package/chart.js +2 -2
- package/chart.js.map +1 -1
- package/charts/bar-grouped.d.ts +2 -2
- package/charts/bar-grouped.js.map +1 -1
- package/charts/bar-simple.d.ts +2 -4
- package/charts/bar-simple.js +0 -2
- package/charts/bar-simple.js.map +1 -1
- package/charts/donut.js +2 -2
- package/charts/donut.js.map +1 -1
- package/charts/pie.js +2 -2
- package/charts/pie.js.map +1 -1
- package/components/axes/grid.js +12 -19
- package/components/axes/grid.js.map +1 -1
- package/components/component.js +1 -1
- package/components/component.js.map +1 -1
- package/components/essentials/legend.d.ts +0 -4
- package/components/essentials/legend.js +12 -26
- package/components/essentials/legend.js.map +1 -1
- package/components/essentials/title.js +4 -4
- package/components/essentials/title.js.map +1 -1
- package/components/essentials/tooltip-bar.d.ts +1 -1
- package/components/essentials/tooltip-bar.js +13 -5
- package/components/essentials/tooltip-bar.js.map +1 -1
- package/components/essentials/tooltip-pie.d.ts +5 -0
- package/components/essentials/tooltip-pie.js +40 -0
- package/components/essentials/tooltip-pie.js.map +1 -0
- package/components/essentials/tooltip-scatter.d.ts +1 -1
- package/components/essentials/tooltip-scatter.js +8 -6
- package/components/essentials/tooltip-scatter.js.map +1 -1
- package/components/essentials/tooltip.js +14 -17
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/bar-grouped.d.ts +6 -4
- package/components/graphs/bar-grouped.js +64 -36
- package/components/graphs/bar-grouped.js.map +1 -1
- package/components/graphs/bar-simple.d.ts +0 -1
- package/components/graphs/bar-simple.js +16 -34
- package/components/graphs/bar-simple.js.map +1 -1
- package/components/graphs/bar-stacked.d.ts +0 -1
- package/components/graphs/bar-stacked.js +31 -112
- package/components/graphs/bar-stacked.js.map +1 -1
- package/components/graphs/bar.js.map +1 -1
- package/components/graphs/bubble.d.ts +0 -1
- package/components/graphs/bubble.js +16 -20
- package/components/graphs/bubble.js.map +1 -1
- package/components/graphs/donut.js +1 -1
- package/components/graphs/donut.js.map +1 -1
- package/components/graphs/line.d.ts +3 -1
- package/components/graphs/line.js +42 -31
- package/components/graphs/line.js.map +1 -1
- package/components/graphs/pie.d.ts +0 -1
- package/components/graphs/pie.js +15 -22
- package/components/graphs/pie.js.map +1 -1
- package/components/graphs/scatter.d.ts +0 -1
- package/components/graphs/scatter.js +26 -41
- package/components/graphs/scatter.js.map +1 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/index.js.map +1 -1
- package/configuration.js +7 -0
- package/configuration.js.map +1 -1
- package/demo/data/bar.d.ts +56 -94
- package/demo/data/bar.js +106 -271
- package/demo/data/bar.js.map +1 -1
- package/demo/data/bubble.d.ts +58 -13
- package/demo/data/bubble.js +74 -174
- package/demo/data/bubble.js.map +1 -1
- package/demo/data/bundle.js +1 -1
- package/demo/data/donut.d.ts +3 -6
- package/demo/data/index.js +22 -4
- package/demo/data/index.js.map +1 -1
- package/demo/data/line.d.ts +35 -35
- package/demo/data/line.js +70 -196
- package/demo/data/line.js.map +1 -1
- package/demo/data/pie.d.ts +3 -6
- package/demo/data/pie.js +8 -10
- package/demo/data/pie.js.map +1 -1
- package/demo/data/scatter.d.ts +33 -20
- package/demo/data/scatter.js +50 -68
- package/demo/data/scatter.js.map +1 -1
- package/demo/data/step.d.ts +15 -16
- package/demo/data/time-series-axis.d.ts +12 -48
- package/demo/data/time-series-axis.js +34 -46
- package/demo/data/time-series-axis.js.map +1 -1
- package/demo/styles.css +28 -0
- package/demo/styles.css.map +1 -1
- package/demo/styles.min.css +1 -1
- package/demo/styles.min.css.map +1 -1
- package/demo/tsconfig.tsbuildinfo +38 -37
- package/interfaces/axis-scales.d.ts +4 -16
- package/interfaces/axis-scales.js.map +1 -1
- package/interfaces/charts.d.ts +23 -1
- package/interfaces/charts.js.map +1 -1
- package/interfaces/enums.d.ts +0 -4
- package/interfaces/enums.js +0 -5
- package/interfaces/enums.js.map +1 -1
- package/interfaces/events.d.ts +29 -0
- package/interfaces/events.js +33 -0
- package/interfaces/events.js.map +1 -1
- package/model-pie.d.ts +1 -7
- package/model-pie.js +2 -107
- package/model-pie.js.map +1 -1
- package/model.d.ts +31 -13
- package/model.js +204 -75
- package/model.js.map +1 -1
- package/package.json +3 -1
- package/services/essentials/dom-utils.js +3 -2
- package/services/essentials/dom-utils.js.map +1 -1
- package/services/scales-cartesian.d.ts +11 -3
- package/services/scales-cartesian.js +104 -122
- package/services/scales-cartesian.js.map +1 -1
- package/tools.d.ts +2 -2
- package/tools.js +23 -2
- package/tools.js.map +1 -1
- package/tsconfig.tsbuildinfo +93 -93
- package/build/src/model-simple-bar.d.ts +0 -11
- package/model-simple-bar.d.ts +0 -11
- package/model-simple-bar.js +0 -88
- package/model-simple-bar.js.map +0 -1
|
@@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
// Internal Imports
|
|
15
15
|
import { Component } from "../component";
|
|
16
16
|
import { DOMUtils } from "../../services";
|
|
17
|
-
import { TooltipTypes } from "./../../interfaces";
|
|
17
|
+
import { TooltipTypes, Events } from "./../../interfaces";
|
|
18
18
|
var Title = /** @class */ (function (_super) {
|
|
19
19
|
__extends(Title, _super);
|
|
20
20
|
function Title() {
|
|
@@ -53,14 +53,14 @@ var Title = /** @class */ (function (_super) {
|
|
|
53
53
|
var self_1 = this;
|
|
54
54
|
title
|
|
55
55
|
.on("mouseenter", function () {
|
|
56
|
-
self_1.services.events.dispatchEvent(
|
|
56
|
+
self_1.services.events.dispatchEvent(Events.Tooltip.SHOW, {
|
|
57
57
|
hoveredElement: title,
|
|
58
58
|
type: TooltipTypes.TITLE
|
|
59
59
|
});
|
|
60
60
|
})
|
|
61
61
|
.on("mouseout", function () {
|
|
62
|
-
self_1.services.events.dispatchEvent(
|
|
63
|
-
hoveredElement: title
|
|
62
|
+
self_1.services.events.dispatchEvent(Events.Tooltip.HIDE, {
|
|
63
|
+
hoveredElement: title
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -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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,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,AArFD,CAA2B,SAAS,GAqFnC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipTypes, Events } from \"./../../interfaces\";\n\nexport class Title extends Component {\n\ttype = \"title\";\n\n\t/**\n\t * Truncates title creating ellipses and attaching tooltip for exposing full title.\n\t */\n\ttruncateTitle() {\n\t\t// get a reference to the title elements to calculate the size the title can be\n\t\tconst containerWidth = DOMUtils.getSVGElementSize(this.services.domUtils.getMainSVG(), { useAttr: true }).width;\n\t\tconst title = DOMUtils.appendOrSelect(this.parent, \"text.title\");\n\n\t\t// sanity check to prevent stack overflow on binary search\n\t\tif (containerWidth <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// check if the title is too big for the containing svg\n\t\tif (title.node().getComputedTextLength() > containerWidth) {\n\t\t\t// append the ellipses to their own tspan to calculate the text length\n\t\t\ttitle.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// get the bounding width including the elipses '...'\n\t\t\tconst tspanLength = DOMUtils.appendOrSelect(title, \"tspan\").node().getComputedTextLength();\n\t\t\tconst truncatedSize = Math.floor(containerWidth - tspanLength);\n\t\t\tconst titleString = this.model.getOptions().title;\n\n\t\t\t// get the index for creating the max length substring that fit within the svg\n\t\t\t// use one less than the index to avoid crowding (the elipsis)\n\t\t\tconst substringIndex = this.getSubstringIndex(title.node(), 0, titleString.length - 1, truncatedSize);\n\n\t\t\t// use the substring as the title\n\t\t\ttitle.text(titleString.substring(0, substringIndex - 1))\n\t\t\t\t.append(\"tspan\")\n\t\t\t\t.text(\"...\");\n\n\t\t\t// add events for displaying the tooltip with the title\n\t\t\tconst self = this;\n\t\t\ttitle\n\t\t\t\t.on(\"mouseenter\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\t\t\thoveredElement: title,\n\t\t\t\t\t\ttype: TooltipTypes.TITLE\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.on(\"mouseout\", function() {\n\t\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE, {\n\t\t\t\t\t\thoveredElement: title\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t}\n\t}\n\n\trender() {\n\t\tconst svg = this.getContainerSVG();\n\n\t\tconst text = DOMUtils.appendOrSelect(svg, \"text.title\");\n\t\ttext.attr(\"x\", 0)\n\t\t\t.attr(\"y\", 20)\n\t\t\t.text(this.model.getOptions().title);\n\n\t\t// title needs to first render so that we can check for overflow\n\t\tthis.truncateTitle();\n\t}\n\n\t/**\n\t * Returns the index for a maximum length substring that is less than the width parameter.\n\t * @param title the title node used for getting the text lengths of substrings\n\t * @param start the start index for the binary search\n\t * @param end the end index for the binary search\n\t * @param width the width of the svg container that holds the title\n\t */\n\tprotected getSubstringIndex(title, start, end, width) {\n\t\tconst mid = Math.floor((end + start) / 2);\n\t\tif (title.getSubStringLength(0, mid) > width) {\n\t\t\treturn this.getSubstringIndex(title, start, mid, width);\n\t\t} else if (title.getSubStringLength(0, mid) < width) {\n\t\t\tif (title.getSubStringLength(0, mid + 1) > width) {\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t\treturn this.getSubstringIndex(title, mid, end, width);\n\t\t} else {\n\t\t\treturn mid;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export declare class TooltipBar extends Tooltip {
|
|
|
7
7
|
* positive valued data and below negative value data.
|
|
8
8
|
* @param hoveredElement
|
|
9
9
|
*/
|
|
10
|
-
getTooltipPosition(hoveredElement: any): {
|
|
10
|
+
getTooltipPosition(hoveredElement: any, data?: any): {
|
|
11
11
|
placement: TooltipPosition;
|
|
12
12
|
position: {
|
|
13
13
|
left: number;
|
|
@@ -16,7 +16,7 @@ import { Tools } from "../../tools";
|
|
|
16
16
|
import { DOMUtils } from "../../services";
|
|
17
17
|
import { TooltipPosition, TooltipTypes, CartesianOrientations } from "./../../interfaces/enums";
|
|
18
18
|
// import the settings for the css prefix
|
|
19
|
-
import settings from "carbon-components/
|
|
19
|
+
import settings from "carbon-components/es/globals/js/settings";
|
|
20
20
|
// D3 Imports
|
|
21
21
|
import { select } from "d3-selection";
|
|
22
22
|
var TooltipBar = /** @class */ (function (_super) {
|
|
@@ -47,7 +47,13 @@ var TooltipBar = /** @class */ (function (_super) {
|
|
|
47
47
|
defaultHTML = _this.getMultilineTooltipHTML(data);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
|
|
50
|
+
if (e.detail.data) {
|
|
51
|
+
data = e.detail.data;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
data = e.detail.hoveredElement.datum();
|
|
55
|
+
}
|
|
56
|
+
defaultHTML = _this.getTooltipHTML(data);
|
|
51
57
|
}
|
|
52
58
|
// if there is a provided tooltip HTML function call it and pass the defaultHTML
|
|
53
59
|
if (Tools.getProperty(_this.model.getOptions(), "tooltip", "customHTML")) {
|
|
@@ -57,7 +63,7 @@ var TooltipBar = /** @class */ (function (_super) {
|
|
|
57
63
|
// default tooltip
|
|
58
64
|
tooltipTextContainer.html(defaultHTML);
|
|
59
65
|
}
|
|
60
|
-
var position = _this.getTooltipPosition(hoveredElement);
|
|
66
|
+
var position = _this.getTooltipPosition(hoveredElement, data);
|
|
61
67
|
// Position the tooltip relative to the bars
|
|
62
68
|
_this.positionTooltip(e.detail.multidata ? undefined : position);
|
|
63
69
|
}
|
|
@@ -86,8 +92,10 @@ var TooltipBar = /** @class */ (function (_super) {
|
|
|
86
92
|
* positive valued data and below negative value data.
|
|
87
93
|
* @param hoveredElement
|
|
88
94
|
*/
|
|
89
|
-
TooltipBar.prototype.getTooltipPosition = function (hoveredElement) {
|
|
90
|
-
|
|
95
|
+
TooltipBar.prototype.getTooltipPosition = function (hoveredElement, data) {
|
|
96
|
+
if (data === undefined) {
|
|
97
|
+
data = select(hoveredElement).datum();
|
|
98
|
+
}
|
|
91
99
|
var holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();
|
|
92
100
|
var barPosition = hoveredElement.getBoundingClientRect();
|
|
93
101
|
var verticalOffset = this.model.getOptions().tooltip.datapoint.verticalOffset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-bar.js","sourceRoot":"","sources":["tooltip-bar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,yCAAyC;AACzC,OAAO,QAAQ,M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S,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AA3JD,CAAgC,OAAO,GA2JtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/src/globals/js/settings\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class TooltipBar extends Tooltip {\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\n\t\t\t\tlet data = e.detail.hoveredElement.datum() as any;\n\t\t\t\tconst hoveredElement = e.detail.hoveredElement.node();\n\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(e.detail.hoveredElement.datum());\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it and pass the defaultHTML\n\t\t\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\n\t\t\t\t} else {\n\t\t\t\t\t// default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\tconst position = this.getTooltipPosition(hoveredElement);\n\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position );\n\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\t// use the chart size to enforce a max width on the tooltip\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\t\t\t\tthis.tooltip.style(\"max-width\", tooltipMax);\n\n\t\t\t\t// use tooltip.ts to get the tooltip html for titles\n\t\t\t\ttooltipTextContainer.html(super.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(\"hide-tooltip\", () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\t/**\n\t * Get the position of the tooltip relative to the active hovered bar. Tooltip should appear above\n\t * positive valued data and below negative value data.\n\t * @param hoveredElement\n\t */\n\tgetTooltipPosition(hoveredElement) {\n\t\tconst data = select(hoveredElement).datum() as any;\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst barPosition = hoveredElement.getBoundingClientRect();\n\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t// if there is a negative value bar chart, need to place the tooltip below the bar\n\t\tif (data.value <= 0) {\n\t\t\t// negative bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.bottom - holderPosition.top) + verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.BOTTOM, position: tooltipPos};\n\t\t} else {\n\t\t\t// positive bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.top - holderPosition.top) - verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.TOP, position: tooltipPos};\n\t\t}\n\t}\n\n\t/**\n\t * Returns the html for the bar single point tooltip\n\t * @param data associated values for the hovered bar\n\t */\n\tgetTooltipHTML(data: any) {\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : data.value.toLocaleString(\"en\");\n\n\t\treturn `<div class=\"datapoint-tooltip\"><p class=\"value\">${formattedValue}</p></div>`;\n\t}\n\n\t/**\n\t * Multip tooltips for bar charts include totals for each stack\n\t * @param data\n\t */\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\tpoints.reverse();\n\t\t// in a vertical bar chart the tooltip should display in order of the drawn bars\n\t\t// in horizontal stacked bar, the order of the segments from Left to Right are displayed top down in tooltip\n\t\tif (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\n\t\t\tpoints.reverse();\n\t\t}\n\n\t\t// get the total for the stacked tooltip\n\t\tlet total = points.reduce((sum, item) => sum + item.value, 0);\n\n\t\t// format the total value\n\t\ttotal = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(total) : total.toLocaleString(\"en\");\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapoint.value) : datapoint.value.toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t}).join(\"\") +\n\t\t\t\t`<li>\n\t\t\t\t\t<div class='total-val'>\n\t\t\t\t\t\t<p class='label'>Total</p>\n\t\t\t\t\t\t<p class='value'>${total}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t</ul>`;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tooltip-bar.js","sourceRoot":"","sources":["tooltip-bar.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C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KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAEvG,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1F,OAAO,0GAGwB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AAnKD,CAAgC,OAAO,GAmKtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class TooltipBar extends Tooltip {\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\n\t\t\t\tlet data = e.detail.hoveredElement.datum() as any;\n\t\t\t\tconst hoveredElement = e.detail.hoveredElement.node();\n\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tif (e.detail.data) {\n\t\t\t\t\t\tdata = e.detail.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdata = e.detail.hoveredElement.datum();\n\t\t\t\t\t}\n\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it and pass the defaultHTML\n\t\t\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\n\t\t\t\t} else {\n\t\t\t\t\t// default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\tconst position = this.getTooltipPosition(hoveredElement, data);\n\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position );\n\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\t// use the chart size to enforce a max width on the tooltip\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\t\t\t\tthis.tooltip.style(\"max-width\", tooltipMax);\n\n\t\t\t\t// use tooltip.ts to get the tooltip html for titles\n\t\t\t\ttooltipTextContainer.html(super.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(\"hide-tooltip\", () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\t/**\n\t * Get the position of the tooltip relative to the active hovered bar. Tooltip should appear above\n\t * positive valued data and below negative value data.\n\t * @param hoveredElement\n\t */\n\tgetTooltipPosition(hoveredElement, data?: any) {\n\t\tif (data === undefined) {\n\t\t\tdata = select(hoveredElement).datum() as any;\n\t\t}\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst barPosition = hoveredElement.getBoundingClientRect();\n\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t// if there is a negative value bar chart, need to place the tooltip below the bar\n\t\tif (data.value <= 0) {\n\t\t\t// negative bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.bottom - holderPosition.top) + verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.BOTTOM, position: tooltipPos};\n\t\t} else {\n\t\t\t// positive bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.top - holderPosition.top) - verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.TOP, position: tooltipPos};\n\t\t}\n\t}\n\n\t/**\n\t * Returns the html for the bar single point tooltip\n\t * @param data associated values for the hovered bar\n\t */\n\tgetTooltipHTML(data: any) {\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : data.value.toLocaleString(\"en\");\n\n\t\treturn `<div class=\"datapoint-tooltip\"><p class=\"value\">${formattedValue}</p></div>`;\n\t}\n\n\t/**\n\t * Multip tooltips for bar charts include totals for each stack\n\t * @param data\n\t */\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\tpoints.reverse();\n\t\t// in a vertical bar chart the tooltip should display in order of the drawn bars\n\t\t// in horizontal stacked bar, the order of the segments from Left to Right are displayed top down in tooltip\n\t\tif (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\n\t\t\tpoints.reverse();\n\t\t}\n\n\t\t// get the total for the stacked tooltip\n\t\tlet total = points.reduce((sum, item) => sum + item.value, 0);\n\n\t\t// format the total value\n\t\ttotal = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(total) : total.toLocaleString(\"en\");\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapoint.value) : datapoint.value.toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t}).join(\"\") +\n\t\t\t\t`<li>\n\t\t\t\t\t<div class='total-val'>\n\t\t\t\t\t\t<p class='label'>Total</p>\n\t\t\t\t\t\t<p class='value'>${total}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t</ul>`;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { Tooltip } from "./tooltip";
|
|
15
|
+
import { Tools } from "../../tools";
|
|
16
|
+
import { TooltipTypes } from "../../interfaces";
|
|
17
|
+
var TooltipPie = /** @class */ (function (_super) {
|
|
18
|
+
__extends(TooltipPie, _super);
|
|
19
|
+
function TooltipPie() {
|
|
20
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
}
|
|
22
|
+
TooltipPie.prototype.getTooltipHTML = function (d, type) {
|
|
23
|
+
// check if it is getting styles for a tooltip type
|
|
24
|
+
if (type === TooltipTypes.TITLE) {
|
|
25
|
+
var title = this.model.getOptions().title;
|
|
26
|
+
return "<div class=\"title-tooltip\"><text>" + title + "</text></div>";
|
|
27
|
+
}
|
|
28
|
+
var dataVal = d.data;
|
|
29
|
+
var groupMapsTo = this.model.getOptions().data.groupMapsTo;
|
|
30
|
+
// format the value if needed
|
|
31
|
+
var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter") ?
|
|
32
|
+
this.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString("en");
|
|
33
|
+
// pie charts don't have a dataset label since they only support one dataset
|
|
34
|
+
var label = dataVal[groupMapsTo];
|
|
35
|
+
return ("<div class=\"datapoint-tooltip\">\n\t\t\t\t<p class=\"label\">" + label + "</p>\n\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t</div>");
|
|
36
|
+
};
|
|
37
|
+
return TooltipPie;
|
|
38
|
+
}(Tooltip));
|
|
39
|
+
export { TooltipPie };
|
|
40
|
+
//# sourceMappingURL=../../../src/components/essentials/tooltip-pie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-pie.js","sourceRoot":"","sources":["tooltip-pie.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;IAAgC,8BAAO;IAAvC;;IAyBA,CAAC;IAxBA,mCAAc,GAAd,UAAe,CAAM,EAAE,IAAkB;QACxC,mDAAmD;QACnD,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC;YAC5C,OAAO,wCAAoC,KAAK,kBAAe,CAAC;SAChE;QAED,IAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC;QACf,IAAA,sDAAW,CAAkC;QAErD,6BAA6B;QAC7B,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;YAChG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEnG,4EAA4E;QAC5E,IAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QAEnC,OAAO,CACN,mEACoB,KAAK,yCACL,cAAc,uBAC3B,CACP,CAAC;IACH,CAAC;IACF,iBAAC;AAAD,CAAC,AAzBD,CAAgC,OAAO,GAyBtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"../../interfaces\";\n\nexport class TooltipPie extends Tooltip {\n\tgetTooltipHTML(d: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t}\n\n\t\tconst dataVal = d.data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn (\n\t\t\t`<div class=\"datapoint-tooltip\">\n\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`\n\t\t);\n\t}\n}\n"]}
|
|
@@ -19,16 +19,18 @@ var TooltipScatter = /** @class */ (function (_super) {
|
|
|
19
19
|
function TooltipScatter() {
|
|
20
20
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
21
|
}
|
|
22
|
-
TooltipScatter.prototype.getTooltipHTML = function (
|
|
22
|
+
TooltipScatter.prototype.getTooltipHTML = function (datum, type) {
|
|
23
23
|
if (type === TooltipTypes.TITLE) {
|
|
24
24
|
// the main tooltip component handles title styles
|
|
25
|
-
return _super.prototype.getTooltipHTML.call(this,
|
|
25
|
+
return _super.prototype.getTooltipHTML.call(this, datum, type);
|
|
26
26
|
}
|
|
27
|
-
var
|
|
28
|
-
|
|
27
|
+
var groupMapsTo = this.model.getOptions().data.groupMapsTo;
|
|
28
|
+
var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
|
|
29
|
+
var userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter");
|
|
30
|
+
var formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString("en");
|
|
29
31
|
// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.
|
|
30
|
-
var indicatorColor = this.model.getStrokeColor(
|
|
31
|
-
return "\n\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t<a style=\"background-color:" + indicatorColor + "\" class=\"tooltip-color\"></a>\n\t\t\t\t<p class=\"label\">" +
|
|
32
|
+
var indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);
|
|
33
|
+
return "\n\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t<a style=\"background-color:" + indicatorColor + "\" class=\"tooltip-color\"></a>\n\t\t\t\t<p class=\"label\">" + datum[groupMapsTo] + "</p>\n\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t</div>";
|
|
32
34
|
};
|
|
33
35
|
return TooltipScatter;
|
|
34
36
|
}(Tooltip));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-scatter.js","sourceRoot":"","sources":["tooltip-scatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"tooltip-scatter.js","sourceRoot":"","sources":["tooltip-scatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;IAAoC,kCAAO;IAA3C;;IAuBA,CAAC;IAtBA,uCAAc,GAAd,UAAe,KAAU,EAAE,IAAkB;QAC5C,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE;YAChC,kDAAkD;YAClD,OAAO,iBAAM,cAAc,YAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACzC;QAEO,IAAA,sDAAW,CAAkC;QACrD,IAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,kBAAkB,EAAE,CAAC;QAE3E,IAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;QAC3G,IAAM,cAAc,GAAG,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAErJ,2GAA2G;QAC3G,IAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QAErE,OAAO,oFAEwB,cAAc,oEACxB,KAAK,CAAC,WAAW,CAAC,yCAClB,cAAc,uBAC3B,CAAC;IACV,CAAC;IACF,qBAAC;AAAD,CAAC,AAvBD,CAAoC,OAAO,GAuB1C","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { TooltipTypes } from \"./../../interfaces\";\n\nexport class TooltipScatter extends Tooltip {\n\tgetTooltipHTML(datum: any, type: TooltipTypes) {\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\t// the main tooltip component handles title styles\n\t\t\treturn super.getTooltipHTML(datum, type);\n\t\t}\n\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\tconst userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\");\n\t\tconst formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\tconst indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);\n\n\t\treturn `\n\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t</div>`;\n\t}\n}\n"]}
|
|
@@ -17,10 +17,10 @@ import { DOMUtils } from "../../services";
|
|
|
17
17
|
// Carbon position service
|
|
18
18
|
import Position, { PLACEMENTS } from "@carbon/utils-position";
|
|
19
19
|
// import the settings for the css prefix
|
|
20
|
-
import settings from "carbon-components/
|
|
20
|
+
import settings from "carbon-components/es/globals/js/settings";
|
|
21
21
|
// D3 Imports
|
|
22
22
|
import { select, mouse, event } from "d3-selection";
|
|
23
|
-
import { TooltipTypes,
|
|
23
|
+
import { TooltipTypes, TooltipPosition } from "../../interfaces";
|
|
24
24
|
var Tooltip = /** @class */ (function (_super) {
|
|
25
25
|
__extends(Tooltip, _super);
|
|
26
26
|
function Tooltip(model, services, configs) {
|
|
@@ -91,33 +91,30 @@ var Tooltip = /** @class */ (function (_super) {
|
|
|
91
91
|
}
|
|
92
92
|
// this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data
|
|
93
93
|
var dataVal = Tools.getProperty(data, "data") ? data.data : data;
|
|
94
|
+
var groupMapsTo = this.model.getOptions().data.groupMapsTo;
|
|
95
|
+
var rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();
|
|
94
96
|
// format the value if needed
|
|
95
97
|
var formattedValue = Tools.getProperty(this.model.getOptions(), "tooltip", "valueFormatter") ?
|
|
96
|
-
this.model.getOptions().tooltip.valueFormatter(dataVal
|
|
98
|
+
this.model.getOptions().tooltip.valueFormatter(dataVal[rangeIdentifier]) : dataVal[rangeIdentifier].toLocaleString("en");
|
|
97
99
|
// pie charts don't have a dataset label since they only support one dataset
|
|
98
|
-
var label = dataVal
|
|
100
|
+
var label = dataVal[groupMapsTo];
|
|
99
101
|
return "<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">" + label + "</p>\n\t\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t\t</div>";
|
|
100
102
|
};
|
|
101
103
|
Tooltip.prototype.getMultilineTooltipHTML = function (data) {
|
|
102
104
|
var _this = this;
|
|
103
|
-
var points = data;
|
|
104
105
|
// sort them so they are in the same order as the graph
|
|
105
|
-
|
|
106
|
+
data.sort(function (a, b) { return b.value - a.value; });
|
|
106
107
|
// tells us which value to use
|
|
107
108
|
var scaleType = this.services.cartesianScales.getDomainScale().scaleType;
|
|
108
109
|
return "<ul class='multi-tooltip'>" +
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
datapointValue = scaleType === ScaleTypes.TIME ? datapoint.value.date : datapoint.value.value;
|
|
115
|
-
}
|
|
116
|
-
var formattedValue = Tools.getProperty(_this.model.getOptions(), "tooltip", "valueFormatter") ?
|
|
117
|
-
_this.model.getOptions().tooltip.valueFormatter(datapointValue) : datapointValue.toLocaleString("en");
|
|
110
|
+
data.map(function (datum) {
|
|
111
|
+
var groupMapsTo = _this.model.getOptions().data.groupMapsTo;
|
|
112
|
+
var rangeIdentifier = _this.services.cartesianScales.getRangeIdentifier();
|
|
113
|
+
var userProvidedValueFormatter = Tools.getProperty(_this.model.getOptions(), "tooltip", "valueFormatter");
|
|
114
|
+
var formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString("en");
|
|
118
115
|
// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.
|
|
119
|
-
var indicatorColor = _this.model.getStrokeColor(
|
|
120
|
-
return "\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:" + indicatorColor + "\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">" +
|
|
116
|
+
var indicatorColor = _this.model.getStrokeColor(datum[groupMapsTo]);
|
|
117
|
+
return "\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:" + indicatorColor + "\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">" + datum[groupMapsTo] + "</p>\n\t\t\t\t\t\t<p class=\"value\">" + formattedValue + "</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>";
|
|
121
118
|
}).join("") + "</ul>";
|
|
122
119
|
};
|
|
123
120
|
Tooltip.prototype.render = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["tooltip.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO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BAAgB,IAAI,CAAC,CAAC,CAAC;aACvB;YAED,wDAAwD;YACxD,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,AA9MD,CAA6B,SAAS,GA8MrC","sourcesContent":["import * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/src/globals/js/settings\";\n\n// D3 Imports\nimport { select, mouse, event } from \"d3-selection\";\nimport { TooltipTypes, ScaleTypes, TooltipPosition } from \"../../interfaces\";\n\nexport class Tooltip extends Component {\n\ttype = \"tooltip\";\n\n\ttooltip: any;\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tsuper(model, services, configs);\n\n\t\tthis.init();\n\t}\n\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\n\t\t\t\tlet data = select(event.target).datum() as any;\n\n\t\t\t\t// Generate default tooltip\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data, TooltipTypes.DATAPOINT);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it\n\t\t\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\n\t\t\t\t} else {\n\t\t\t\t\t// Use default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\t// Position the tooltip\n\t\t\t\tthis.positionTooltip();\n\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\tconst chartWidth = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\n\t\t\t\ttooltipTextContainer.html(this.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(\"hide-tooltip\", () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\tgetTooltipHTML(data: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t}\n\t\t// this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data\n\t\tconst dataVal = Tools.getProperty(data, \"data\") ? data.data : data;\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal.datasetLabel ? dataVal.datasetLabel : dataVal.label;\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t</div>`;\n\t}\n\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\t// sort them so they are in the same order as the graph\n\t\tpoints.sort((a, b) => b.value - a.value);\n\n\t\t// tells us which value to use\n\t\tconst scaleType = this.services.cartesianScales.getDomainScale().scaleType;\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\t// check if the datapoint has multiple values associates (multiple axes)\n\t\t\t\tlet datapointValue = datapoint.value;\n\t\t\t\tif (datapointValue instanceof Object) {\n\t\t\t\t\t// scale type determines which value we care about since it should align with the scale data\n\t\t\t\t\tdatapointValue = scaleType === ScaleTypes.TIME ? datapoint.value.date : datapoint.value.value;\n\t\t\t\t}\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapointValue) : datapointValue.toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t}).join(\"\") + \"</ul>\";\n\t}\n\n\trender() {\n\t\tthis.tooltip.classed(\"hidden\", true);\n\t}\n\n\t// returns static position based on the element\n\tgetTooltipPosition(hoveredElement) {\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst elementPosition = hoveredElement.getBoundingClientRect();\n\n\t\t// get the vertical offset\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.title;\n\n\t\tconst tooltipPos = {\n\t\t\tleft: (elementPosition.left - holderPosition.left) + elementPosition.width / 2,\n\t\t\ttop: (elementPosition.top - holderPosition.top - verticalOffset)\n\t\t};\n\n\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t}\n\n\tpositionTooltip(positionOverride?: any) {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.tooltip.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\t\tlet pos;\n\n\t\t// override position to place tooltip at {placement:.., position:{top:.. , left:..}}\n\t\tif (positionOverride) {\n\t\t\t// placement determines whether the tooltip is centered above or below the position provided\n\t\t\tconst placement = positionOverride.placement === TooltipPosition.TOP ? PLACEMENTS.TOP : PLACEMENTS.BOTTOM;\n\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\tpositionOverride.position,\n\t\t\t\ttarget,\n\t\t\t\tplacement\n\t\t\t);\n\t\t} else {\n\t\t\t// Find out whether tooltip should be shown on the left or right side\n\t\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\t[\n\t\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\t\tPLACEMENTS.BOTTOM\n\t\t\t\t],\n\t\t\t\t() => ({\n\t\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\t\theight: holder.offsetHeight\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tlet { horizontalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t\tif (bestPlacementOption === PLACEMENTS.LEFT) {\n\t\t\t\thorizontalOffset *= -1;\n\t\t\t}\n\n\t\t\t// Get coordinates to where tooltip should be positioned\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0] + horizontalOffset,\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\tbestPlacementOption\n\t\t\t);\n\t\t}\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["tooltip.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,0BAA0B;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,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,AA5MD,CAA6B,SAAS,GA4MrC","sourcesContent":["import * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select, mouse, event } from \"d3-selection\";\nimport { TooltipTypes, ScaleTypes, TooltipPosition } from \"../../interfaces\";\n\nexport class Tooltip extends Component {\n\ttype = \"tooltip\";\n\n\ttooltip: any;\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tsuper(model, services, configs);\n\n\t\tthis.init();\n\t}\n\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\n\t\t\t\tlet data = select(event.target).datum() as any;\n\n\t\t\t\t// Generate default tooltip\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data, TooltipTypes.DATAPOINT);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it\n\t\t\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\n\t\t\t\t} else {\n\t\t\t\t\t// Use default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\t// Position the tooltip\n\t\t\t\tthis.positionTooltip();\n\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\tconst chartWidth = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\n\t\t\t\tthis.tooltip.style(\"max-width\", chartWidth);\n\n\n\t\t\t\ttooltipTextContainer.html(this.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = this.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(\"hide-tooltip\", () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\tgetTooltipHTML(data: any, type: TooltipTypes) {\n\t\t// check if it is getting styles for a tooltip type\n\t\tif (type === TooltipTypes.TITLE) {\n\t\t\tconst title = this.model.getOptions().title;\n\t\t\treturn `<div class=\"title-tooltip\"><text>${title}</text></div>`;\n\t\t}\n\t\t// this cleans up the data item, pie slices have the data within the data.data but other datapoints are self contained within data\n\t\tconst dataVal = Tools.getProperty(data, \"data\") ? data.data : data;\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal[rangeIdentifier]) : dataVal[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal[groupMapsTo];\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t</div>`;\n\t}\n\n\tgetMultilineTooltipHTML(data: any) {\n\n\t\t// sort them so they are in the same order as the graph\n\t\tdata.sort((a, b) => b.value - a.value);\n\n\t\t// tells us which value to use\n\t\tconst scaleType = this.services.cartesianScales.getDomainScale().scaleType;\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tdata.map(datum => {\n\t\t\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\t\t\t\tconst rangeIdentifier = this.services.cartesianScales.getRangeIdentifier();\n\n\t\t\t\tconst userProvidedValueFormatter = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\");\n\t\t\t\tconst formattedValue = userProvidedValueFormatter ? userProvidedValueFormatter(datum[rangeIdentifier]) : datum[rangeIdentifier].toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datum[groupMapsTo]);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datum[groupMapsTo]}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t}).join(\"\") + \"</ul>\";\n\t}\n\n\trender() {\n\t\tthis.tooltip.classed(\"hidden\", true);\n\t}\n\n\t// returns static position based on the element\n\tgetTooltipPosition(hoveredElement) {\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst elementPosition = hoveredElement.getBoundingClientRect();\n\n\t\t// get the vertical offset\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.title;\n\n\t\tconst tooltipPos = {\n\t\t\tleft: (elementPosition.left - holderPosition.left) + elementPosition.width / 2,\n\t\t\ttop: (elementPosition.top - holderPosition.top - verticalOffset)\n\t\t};\n\n\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t}\n\n\tpositionTooltip(positionOverride?: any) {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.tooltip.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\t\tlet pos;\n\n\t\t// override position to place tooltip at {placement:.., position:{top:.. , left:..}}\n\t\tif (positionOverride) {\n\t\t\t// placement determines whether the tooltip is centered above or below the position provided\n\t\t\tconst placement = positionOverride.placement === TooltipPosition.TOP ? PLACEMENTS.TOP : PLACEMENTS.BOTTOM;\n\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\tpositionOverride.position,\n\t\t\t\ttarget,\n\t\t\t\tplacement\n\t\t\t);\n\t\t} else {\n\t\t\t// Find out whether tooltip should be shown on the left or right side\n\t\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\t[\n\t\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\t\tPLACEMENTS.BOTTOM\n\t\t\t\t],\n\t\t\t\t() => ({\n\t\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\t\theight: holder.offsetHeight\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tlet { horizontalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t\tif (bestPlacementOption === PLACEMENTS.LEFT) {\n\t\t\t\thorizontalOffset *= -1;\n\t\t\t}\n\n\t\t\t// Get coordinates to where tooltip should be positioned\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0] + horizontalOffset,\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\tbestPlacementOption\n\t\t\t);\n\t\t}\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n}\n"]}
|
|
@@ -3,12 +3,14 @@ import { ScaleBand } from "d3-scale";
|
|
|
3
3
|
export declare class GroupedBar extends Bar {
|
|
4
4
|
type: string;
|
|
5
5
|
groupScale: ScaleBand<any>;
|
|
6
|
+
padding: number;
|
|
6
7
|
init(): void;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
protected getDataCorrespondingToLabel(label: string): any;
|
|
9
|
+
protected getGroupWidth(): number;
|
|
10
|
+
protected getTotalGroupPadding(): number;
|
|
11
|
+
protected getBarWidth(): any;
|
|
12
|
+
protected setGroupScale(): void;
|
|
10
13
|
render(animate: boolean): void;
|
|
11
|
-
addLabelsToDataPoints(d: any, index: any): any;
|
|
12
14
|
handleLegendOnHover: (event: CustomEvent<any>) => void;
|
|
13
15
|
handleLegendMouseOut: (event: CustomEvent<any>) => void;
|
|
14
16
|
addEventListeners(): void;
|