@carbon/charts 0.30.7 → 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 +8 -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/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/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 +10 -17
- package/components/axes/grid.js.map +1 -1
- package/components/essentials/legend.d.ts +0 -4
- package/components/essentials/legend.js +8 -22
- package/components/essentials/legend.js.map +1 -1
- package/components/essentials/tooltip-bar.d.ts +1 -1
- package/components/essentials/tooltip-bar.js +12 -4
- 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 +13 -16
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/bar-grouped.d.ts +6 -4
- package/components/graphs/bar-grouped.js +58 -30
- package/components/graphs/bar-grouped.js.map +1 -1
- package/components/graphs/bar-simple.d.ts +0 -1
- package/components/graphs/bar-simple.js +10 -28
- package/components/graphs/bar-simple.js.map +1 -1
- package/components/graphs/bar-stacked.d.ts +0 -1
- package/components/graphs/bar-stacked.js +27 -108
- package/components/graphs/bar-stacked.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 +41 -30
- package/components/graphs/line.js.map +1 -1
- package/components/graphs/pie.d.ts +0 -1
- package/components/graphs/pie.js +11 -18
- package/components/graphs/pie.js.map +1 -1
- package/components/graphs/scatter.d.ts +0 -1
- package/components/graphs/scatter.js +24 -39
- 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 +36 -35
- 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/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 +199 -75
- package/model.js.map +1 -1
- package/package.json +3 -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 +72 -73
- 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
|
@@ -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"]}
|
|
@@ -20,7 +20,7 @@ import Position, { PLACEMENTS } from "@carbon/utils-position";
|
|
|
20
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,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE7E;IAA6B,2BAAS;IAMrC,iBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QAA3D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAG/B;QATD,UAAI,GAAG,SAAS,CAAC;QAGjB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;QAKhC,KAAI,CAAC,IAAI,EAAE,CAAC;;IACb,CAAC;IAED,sBAAI,GAAJ;QAAA,iBA8DC;QA7DA,2BAA2B;QAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EA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,CAAC,MAAM,CAAC;YAE1G,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC,gBAAgB,CAAC,QAAQ,EACzB,MAAM,EACN,SAAS,CACT,CAAC;SACF;aAAM;YACN,qEAAqE;YACrE,IAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB,CACnE;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;gBACzB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN;gBACC,UAAU,CAAC,KAAK;gBAChB,UAAU,CAAC,IAAI;gBACf,UAAU,CAAC,GAAG;gBACd,UAAU,CAAC,MAAM;aACjB,EACD,cAAM,OAAA,CAAC;gBACN,KAAK,EAAE,MAAM,CAAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;YAEI,IAAA,6EAAgB,CAA+C;YACrE,IAAI,mBAAmB,KAAK,UAAU,CAAC,IAAI,EAAE;gBAC5C,gBAAgB,IAAI,CAAC,CAAC,CAAC;aACvB;YAED,wDAAwD;YACxD,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,AA9MD,CAA6B,SAAS,GA8MrC","sourcesContent":["import * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/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\n\t\t// format the value if needed\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(dataVal.value) : dataVal.value.toLocaleString(\"en\");\n\n\t\t// pie charts don't have a dataset label since they only support one dataset\n\t\tconst label = dataVal.datasetLabel ? dataVal.datasetLabel : dataVal.label;\n\n\t\treturn `<div class=\"datapoint-tooltip\">\n\t\t\t\t\t<p class=\"label\">${label}</p>\n\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t</div>`;\n\t}\n\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\t// sort them so they are in the same order as the graph\n\t\tpoints.sort((a, b) => b.value - a.value);\n\n\t\t// tells us which value to use\n\t\tconst scaleType = this.services.cartesianScales.getDomainScale().scaleType;\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\t// check if the datapoint has multiple values associates (multiple axes)\n\t\t\t\tlet datapointValue = datapoint.value;\n\t\t\t\tif (datapointValue instanceof Object) {\n\t\t\t\t\t// scale type determines which value we care about since it should align with the scale data\n\t\t\t\t\tdatapointValue = scaleType === ScaleTypes.TIME ? datapoint.value.date : datapoint.value.value;\n\t\t\t\t}\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapointValue) : datapointValue.toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t\t}).join(\"\") + \"</ul>\";\n\t}\n\n\trender() {\n\t\tthis.tooltip.classed(\"hidden\", true);\n\t}\n\n\t// returns static position based on the element\n\tgetTooltipPosition(hoveredElement) {\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst elementPosition = hoveredElement.getBoundingClientRect();\n\n\t\t// get the vertical offset\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.title;\n\n\t\tconst tooltipPos = {\n\t\t\tleft: (elementPosition.left - holderPosition.left) + elementPosition.width / 2,\n\t\t\ttop: (elementPosition.top - holderPosition.top - verticalOffset)\n\t\t};\n\n\t\treturn { placement: TooltipPosition.BOTTOM, position: tooltipPos };\n\t}\n\n\tpositionTooltip(positionOverride?: any) {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.tooltip.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\t\tlet pos;\n\n\t\t// override position to place tooltip at {placement:.., position:{top:.. , left:..}}\n\t\tif (positionOverride) {\n\t\t\t// placement determines whether the tooltip is centered above or below the position provided\n\t\t\tconst placement = positionOverride.placement === TooltipPosition.TOP ? PLACEMENTS.TOP : PLACEMENTS.BOTTOM;\n\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\tpositionOverride.position,\n\t\t\t\ttarget,\n\t\t\t\tplacement\n\t\t\t);\n\t\t} else {\n\t\t\t// Find out whether tooltip should be shown on the left or right side\n\t\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\t[\n\t\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\t\tPLACEMENTS.BOTTOM\n\t\t\t\t],\n\t\t\t\t() => ({\n\t\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\t\theight: holder.offsetHeight\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tlet { horizontalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t\tif (bestPlacementOption === PLACEMENTS.LEFT) {\n\t\t\t\thorizontalOffset *= -1;\n\t\t\t}\n\n\t\t\t// Get coordinates to where tooltip should be positioned\n\t\t\tpos = this.positionService.findPositionAt(\n\t\t\t\t{\n\t\t\t\t\tleft: mouseRelativePos[0] + horizontalOffset,\n\t\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t\t},\n\t\t\t\ttarget,\n\t\t\t\tbestPlacementOption\n\t\t\t);\n\t\t}\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["tooltip.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE7E;IAA6B,2BAAS;IAMrC,iBAAY,KAAiB,EAAE,QAAa,EAAE,OAAa;QAA3D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAG/B;QATD,UAAI,GAAG,SAAS,CAAC;QAGjB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;QAKhC,KAAI,CAAC,IAAI,EAAE,CAAC;;IACb,CAAC;IAED,sBAAI,GAAJ;QAAA,iBA8DC;QA7DA,2BAA2B;QAC3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,CAAC,cAAc,CACxC,gBAAgB,CAAC,QAAQ,EACzB,MAAM,EACN,SAAS,CACT,CAAC;SACF;aAAM;YACN,qEAAqE;YACrE,IAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB,CACnE;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;gBACzB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN;gBACC,UAAU,CAAC,KAAK;gBAChB,UAAU,CAAC,IAAI;gBACf,UAAU,CAAC,GAAG;gBACd,UAAU,CAAC,MAAM;aACjB,EACD,cAAM,OAAA,CAAC;gBACN,KAAK,EAAE,MAAM,CAAC,WAAW;gBACzB,MAAM,EAAE,MAAM,CAAC,YAAY;aAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;YAEI,IAAA,6EAAgB,CAA+C;YACrE,IAAI,mBAAmB,KAAK,UAAU,CAAC,IAAI,EAAE;gBAC5C,gBAAgB,IAAI,CAAC,CAAC,CAAC;aACvB;YAED,wDAAwD;YACxD,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CACxC;gBACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB;gBAC5C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;aACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;SACF;QAED,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IACF,cAAC;AAAD,CAAC,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;
|
|
@@ -16,6 +16,7 @@ import { Bar } from "./bar";
|
|
|
16
16
|
import { Tools } from "../../tools";
|
|
17
17
|
import { CartesianOrientations, Events, Roles, TooltipTypes } from "../../interfaces";
|
|
18
18
|
// D3 Imports
|
|
19
|
+
import { map } from "d3-collection";
|
|
19
20
|
import { select } from "d3-selection";
|
|
20
21
|
import { color } from "d3-color";
|
|
21
22
|
import { scaleBand } from "d3-scale";
|
|
@@ -24,12 +25,14 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
24
25
|
function GroupedBar() {
|
|
25
26
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
26
27
|
_this.type = "grouped-bar";
|
|
28
|
+
_this.padding = 5;
|
|
27
29
|
// Highlight elements that match the hovered legend item
|
|
28
30
|
_this.handleLegendOnHover = function (event) {
|
|
29
31
|
var hoveredElement = event.detail.hoveredElement;
|
|
32
|
+
var groupMapsTo = _this.model.getOptions().data.groupMapsTo;
|
|
30
33
|
_this.parent.selectAll("path.bar")
|
|
31
34
|
.transition(_this.services.transitions.getTransition("legend-hover-bar"))
|
|
32
|
-
.attr("opacity", function (d) { return (d
|
|
35
|
+
.attr("opacity", function (d) { return (d[groupMapsTo] !== hoveredElement.datum()["name"]) ? 0.3 : 1; });
|
|
33
36
|
};
|
|
34
37
|
// Un-highlight all elements
|
|
35
38
|
_this.handleLegendMouseOut = function (event) {
|
|
@@ -46,33 +49,65 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
46
49
|
// Un-highlight circles on legend item mouseouts
|
|
47
50
|
eventsFragment.addEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);
|
|
48
51
|
};
|
|
52
|
+
GroupedBar.prototype.getDataCorrespondingToLabel = function (label) {
|
|
53
|
+
var displayData = this.model.getDisplayData();
|
|
54
|
+
var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
|
|
55
|
+
return displayData.filter(function (datum) { return datum[domainIdentifier] === label; });
|
|
56
|
+
};
|
|
49
57
|
GroupedBar.prototype.getGroupWidth = function () {
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
return
|
|
58
|
+
var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
|
|
59
|
+
var totalGroupPadding = this.getTotalGroupPadding();
|
|
60
|
+
return this.getBarWidth() * numOfActiveDataGroups + totalGroupPadding;
|
|
53
61
|
};
|
|
54
|
-
GroupedBar.prototype.
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
GroupedBar.prototype.getTotalGroupPadding = function () {
|
|
63
|
+
var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
|
|
64
|
+
if (numOfActiveDataGroups === 1) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
var domainScale = this.services.cartesianScales.getDomainScale();
|
|
68
|
+
var padding = Math.min(5, 5 * (domainScale.step() / 70));
|
|
69
|
+
return padding * (numOfActiveDataGroups - 1);
|
|
59
70
|
};
|
|
60
71
|
// Gets the correct width for bars based on options & configurations
|
|
61
72
|
GroupedBar.prototype.getBarWidth = function () {
|
|
62
|
-
var
|
|
73
|
+
var options = this.model.getOptions();
|
|
74
|
+
var providedWidth = Tools.getProperty(options, "bars", "width");
|
|
75
|
+
var providedMaxWidth = Tools.getProperty(options, "bars", "maxWidth");
|
|
76
|
+
// If there's a provided width, compare with maxWidth and
|
|
77
|
+
// Determine which to return
|
|
78
|
+
if (providedWidth !== null) {
|
|
79
|
+
if (providedMaxWidth === null) {
|
|
80
|
+
return providedWidth;
|
|
81
|
+
}
|
|
82
|
+
else if (providedWidth <= providedMaxWidth) {
|
|
83
|
+
return providedWidth;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;
|
|
87
|
+
var totalGroupPadding = this.getTotalGroupPadding();
|
|
63
88
|
var domainScale = this.services.cartesianScales.getDomainScale();
|
|
64
|
-
return Math.min(domainScale.step()
|
|
89
|
+
return Math.min(providedMaxWidth, (domainScale.step() - totalGroupPadding) / numOfActiveDataGroups);
|
|
90
|
+
};
|
|
91
|
+
GroupedBar.prototype.setGroupScale = function () {
|
|
92
|
+
this.groupScale = scaleBand()
|
|
93
|
+
.domain(this.model.getActiveDataGroupNames())
|
|
94
|
+
.rangeRound([0, this.getGroupWidth()]);
|
|
65
95
|
};
|
|
66
96
|
GroupedBar.prototype.render = function (animate) {
|
|
67
97
|
var _this = this;
|
|
68
98
|
// Chart options mixed with the internal configurations
|
|
69
99
|
var displayData = this.model.getDisplayData();
|
|
100
|
+
var options = this.model.getOptions();
|
|
101
|
+
var groupMapsTo = options.data.groupMapsTo;
|
|
102
|
+
var domainIdentifier = this.services.cartesianScales.getDomainIdentifier();
|
|
103
|
+
// Get unique labels
|
|
70
104
|
this.setGroupScale();
|
|
71
105
|
// Grab container SVG
|
|
72
106
|
var svg = this.getContainerSVG();
|
|
107
|
+
var allDataLabels = map(displayData, function (datum) { return datum[domainIdentifier]; }).keys();
|
|
73
108
|
// Update data on bar groups
|
|
74
109
|
var barGroups = svg.selectAll("g.bars")
|
|
75
|
-
.data(
|
|
110
|
+
.data(allDataLabels, function (label) { return label; });
|
|
76
111
|
// Remove dot groups that need to be removed
|
|
77
112
|
barGroups.exit()
|
|
78
113
|
.attr("opacity", 0)
|
|
@@ -85,9 +120,10 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
85
120
|
.attr("aria-labelledby", function (d) { return d; });
|
|
86
121
|
// Update data on all bars
|
|
87
122
|
var bars = barGroupsEnter.merge(barGroups)
|
|
88
|
-
.attr("transform", function (
|
|
89
|
-
var scaleValue = _this.services.cartesianScales.getDomainValue(
|
|
90
|
-
var translateBy = scaleValue - _this.getGroupWidth() / 2
|
|
123
|
+
.attr("transform", function (label, i) {
|
|
124
|
+
var scaleValue = _this.services.cartesianScales.getDomainValue(label, i);
|
|
125
|
+
var translateBy = scaleValue - _this.getGroupWidth() / 2;
|
|
126
|
+
// const translateBy = scaleValue - this.getGroupWidth(null) / 2 + this.getBarWidth(null);
|
|
91
127
|
if (_this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {
|
|
92
128
|
return "translate(" + translateBy + ", 0)";
|
|
93
129
|
}
|
|
@@ -97,7 +133,7 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
97
133
|
}
|
|
98
134
|
})
|
|
99
135
|
.selectAll("path.bar")
|
|
100
|
-
.data(function (
|
|
136
|
+
.data(function (label) { return _this.getDataCorrespondingToLabel(label); });
|
|
101
137
|
// Remove bars that are no longer needed
|
|
102
138
|
bars.exit()
|
|
103
139
|
.attr("opacity", 0)
|
|
@@ -110,7 +146,7 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
110
146
|
barsEnter.merge(bars)
|
|
111
147
|
.classed("bar", true)
|
|
112
148
|
.transition(this.services.transitions.getTransition("bar-update-enter", animate))
|
|
113
|
-
.attr("fill", function (d) { return _this.model.
|
|
149
|
+
.attr("fill", function (d) { return _this.model.getFillColor(d[groupMapsTo]); })
|
|
114
150
|
.attr("d", function (d) {
|
|
115
151
|
/*
|
|
116
152
|
* Orientation support for horizontal/vertical bar charts
|
|
@@ -118,10 +154,10 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
118
154
|
* to draw the bars needed, and pass those coordinates down to
|
|
119
155
|
* generateSVGPathString() to decide whether it needs to flip them
|
|
120
156
|
*/
|
|
121
|
-
var
|
|
157
|
+
var startX = _this.groupScale(d[groupMapsTo]);
|
|
122
158
|
var barWidth = _this.getBarWidth();
|
|
123
|
-
var x0 =
|
|
124
|
-
var x1 =
|
|
159
|
+
var x0 = startX;
|
|
160
|
+
var x1 = startX + barWidth;
|
|
125
161
|
var y0 = _this.services.cartesianScales.getRangeValue(0);
|
|
126
162
|
var y1 = _this.services.cartesianScales.getRangeValue(d.value);
|
|
127
163
|
return Tools.generateSVGPathString({ x0: x0, x1: x1, y0: y0, y1: y1 }, _this.services.cartesianScales.getOrientation());
|
|
@@ -134,15 +170,6 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
134
170
|
// Add event listeners to elements drawn
|
|
135
171
|
this.addEventListeners();
|
|
136
172
|
};
|
|
137
|
-
// TODO - This method could be re-used in more graphs
|
|
138
|
-
GroupedBar.prototype.addLabelsToDataPoints = function (d, index) {
|
|
139
|
-
var datasets = this.model.getDisplayData().datasets;
|
|
140
|
-
return datasets.map(function (dataset) { return ({
|
|
141
|
-
label: d,
|
|
142
|
-
datasetLabel: dataset.label,
|
|
143
|
-
value: dataset.data[index].value ? dataset.data[index].value : dataset.data[index]
|
|
144
|
-
}); });
|
|
145
|
-
};
|
|
146
173
|
GroupedBar.prototype.addEventListeners = function () {
|
|
147
174
|
var self = this;
|
|
148
175
|
this.parent.selectAll("path.bar")
|
|
@@ -178,8 +205,9 @@ var GroupedBar = /** @class */ (function (_super) {
|
|
|
178
205
|
.on("mouseout", function (datum) {
|
|
179
206
|
var hoveredElement = select(this);
|
|
180
207
|
hoveredElement.classed("hovered", false);
|
|
208
|
+
var groupMapsTo = self.model.getOptions().data.groupMapsTo;
|
|
181
209
|
hoveredElement.transition(self.services.transitions.getTransition("graph_element_mouseout_fill_update"))
|
|
182
|
-
.attr("fill", function (d) { return self.model.
|
|
210
|
+
.attr("fill", function (d) { return self.model.getFillColor(d[groupMapsTo]); });
|
|
183
211
|
// Dispatch mouse event
|
|
184
212
|
self.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOUT, {
|
|
185
213
|
element: hoveredElement,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-grouped.js","sourceRoot":"","sources":["bar-grouped.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACN,qBAAqB,EACrB,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAE1B,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAa,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD;IAAgC,8BAAG;IAAnC;QAAA,qEA0NC;QAzNA,UAAI,GAAG,aAAa,CAAC;QAwIrB,wDAAwD;QACxD,yBAAmB,GAAG,UAAC,KAAkB;YAChC,IAAA,4CAAc,CAAkB;YAExC,KAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;iBAC/B,UAAU,CAAC,KA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P;QACC,yBAAyB;QACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;aAC/B,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAEvB,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACvF,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC5F,CAAC;IACF,iBAAC;AAAD,CAAC,AA1ND,CAAgC,GAAG,GA0NlC","sourcesContent":["// Internal Imports\nimport { Bar } from \"./bar\";\nimport { Tools } from \"../../tools\";\nimport {\n\tCartesianOrientations,\n\tEvents,\n\tRoles,\n\tTooltipTypes\n} from \"../../interfaces\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\nimport { color } from \"d3-color\";\nimport { ScaleBand, scaleBand } from \"d3-scale\";\n\nexport class GroupedBar extends Bar {\n\ttype = \"grouped-bar\";\n\n\tgroupScale: ScaleBand<any>;\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(Events.Legend.ITEM_HOVER, this.handleLegendOnHover);\n\n\t\t// Un-highlight circles on legend item mouseouts\n\t\teventsFragment.addEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);\n\t}\n\n\tgetGroupWidth() {\n\t\tconst { datasets } = this.model.getDisplayData();\n\t\tconst padding = 5;\n\n\t\treturn datasets.length * this.getBarWidth() + (padding * (datasets.length - 1));\n\t}\n\n\tsetGroupScale() {\n\t\tconst { datasets } = this.model.getDisplayData();\n\n\t\tthis.groupScale = scaleBand()\n\t\t\t.domain(datasets.map(dataset => dataset.label))\n\t\t\t.rangeRound([0, this.getGroupWidth()]);\n\t}\n\n\t// Gets the correct width for bars based on options & configurations\n\tgetBarWidth() {\n\t\tconst { datasets } = this.model.getDisplayData();\n\t\tconst domainScale = this.services.cartesianScales.getDomainScale();\n\n\t\treturn Math.min(\n\t\t\tdomainScale.step() / 2 / datasets.length,\n\t\t\tsuper.getBarWidth()\n\t\t);\n\t}\n\n\trender(animate: boolean) {\n\t\t// Chart options mixed with the internal configurations\n\t\tconst displayData = this.model.getDisplayData();\n\n\t\tthis.setGroupScale();\n\n\t\t// Grab container SVG\n\t\tconst svg = this.getContainerSVG();\n\n\t\t// Update data on bar groups\n\t\tconst barGroups = svg.selectAll(\"g.bars\")\n\t\t\t.data(displayData.labels);\n\n\t\t// Remove dot groups that need to be removed\n\t\tbarGroups.exit()\n\t\t\t.attr(\"opacity\", 0)\n\t\t\t.remove();\n\n\t\t// Add the bar groups that need to be introduced\n\t\tconst barGroupsEnter = barGroups.enter()\n\t\t\t.append(\"g\")\n\t\t\t\t.classed(\"bars\", true)\n\t\t\t\t.attr(\"role\", Roles.GROUP)\n\t\t\t\t.attr(\"aria-labelledby\", d => d);\n\n\t\t// Update data on all bars\n\t\tconst bars = barGroupsEnter.merge(barGroups)\n\t\t\t.attr(\"transform\", (d, i) => {\n\t\t\t\tconst scaleValue = this.services.cartesianScales.getDomainValue(d, i);\n\t\t\t\tconst translateBy = scaleValue - this.getGroupWidth() / 2 + this.getBarWidth();\n\n\t\t\t\tif (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\n\t\t\t\t\treturn `translate(${translateBy}, 0)`;\n\t\t\t\t} else {\n\t\t\t\t\t// translate in the y direction for horizontal groups\n\t\t\t\t\treturn `translate(0, ${translateBy})`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.selectAll(\"path.bar\")\n\t\t\t.data((d, i) => this.addLabelsToDataPoints(d, i));\n\n\t\t// Remove bars that are no longer needed\n\t\tbars.exit()\n\t\t\t.attr(\"opacity\", 0)\n\t\t\t.remove();\n\n\t\t// Add the circles that need to be introduced\n\t\tconst barsEnter = bars.enter()\n\t\t\t.append(\"path\")\n\t\t\t.attr(\"opacity\", 0);\n\n\t\t// code for vertical grouped bar charts\n\t\tbarsEnter.merge(bars)\n\t\t\t.classed(\"bar\", true)\n\t\t\t.transition(this.services.transitions.getTransition(\"bar-update-enter\", animate))\n\t\t\t.attr(\"fill\", d => this.model.getFillScale()[d.datasetLabel](d.label))\n\t\t\t.attr(\"d\", d => {\n\t\t\t\t/*\n\t\t\t\t * Orientation support for horizontal/vertical bar charts\n\t\t\t\t * Determine coordinates needed for a vertical set of paths\n\t\t\t\t * to draw the bars needed, and pass those coordinates down to\n\t\t\t\t * generateSVGPathString() to decide whether it needs to flip them\n\t\t\t\t */\n\t\t\t\tconst centerX = this.groupScale(d.datasetLabel);\n\t\t\t\tconst barWidth = this.getBarWidth();\n\t\t\t\tconst x0 = centerX - barWidth / 2;\n\t\t\t\tconst x1 = centerX + barWidth / 2;\n\t\t\t\tconst y0 = this.services.cartesianScales.getRangeValue(0);\n\t\t\t\tconst y1 = this.services.cartesianScales.getRangeValue(d.value);\n\n\t\t\t\treturn Tools.generateSVGPathString(\n\t\t\t\t\t{ x0, x1, y0, y1 },\n\t\t\t\t\tthis.services.cartesianScales.getOrientation()\n\t\t\t\t);\n\t\t\t})\n\t\t\t.attr(\"opacity\", 1)\n\t\t\t// a11y\n\t\t\t.attr(\"role\", Roles.GRAPHICS_SYMBOL)\n\t\t\t.attr(\"aria-roledescription\", \"bar\")\n\t\t\t.attr(\"aria-label\", d => d.value);\n\n\t\t// Add event listeners to elements drawn\n\t\tthis.addEventListeners();\n\t}\n\n\t// TODO - This method could be re-used in more graphs\n\taddLabelsToDataPoints(d, index) {\n\t\tconst { datasets } = this.model.getDisplayData();\n\n\t\treturn datasets.map(dataset => ({\n\t\t\tlabel: d,\n\t\t\tdatasetLabel: dataset.label,\n\t\t\tvalue: dataset.data[index].value ? dataset.data[index].value : dataset.data[index]\n\t\t}));\n\t}\n\n\t// Highlight elements that match the hovered legend item\n\thandleLegendOnHover = (event: CustomEvent) => {\n\t\tconst { hoveredElement } = event.detail;\n\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.transition(this.services.transitions.getTransition(\"legend-hover-bar\"))\n\t\t\t.attr(\"opacity\", d => (d.datasetLabel !== hoveredElement.datum()[\"key\"]) ? 0.3 : 1);\n\t}\n\n\t// Un-highlight all elements\n\thandleLegendMouseOut = (event: CustomEvent) => {\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.transition(this.services.transitions.getTransition(\"legend-mouseout-bar\"))\n\t\t\t.attr(\"opacity\", 1);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.on(\"mouseover\", function(datum) {\n\t\t\t\tconst hoveredElement = select(this);\n\n\t\t\t\thoveredElement.transition(self.services.transitions.getTransition(\"graph_element_mouseover_fill_update\"))\n\t\t\t\t\t.attr(\"fill\", color(hoveredElement.attr(\"fill\")).darker(0.7).toString());\n\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOVER, {\n\t\t\t\t\telement: hoveredElement,\n\t\t\t\t\tdatum\n\t\t\t\t});\n\n\t\t\t\t// Show tooltip\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\t\thoveredElement,\n\t\t\t\t\ttype: TooltipTypes.DATAPOINT\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mousemove\", function(datum) {\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEMOVE, {\n\t\t\t\t\telement: select(this),\n\t\t\t\t\tdatum\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"click\", function(datum) {\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_CLICK, {\n\t\t\t\t\telement: select(this),\n\t\t\t\t\tdatum\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mouseout\", function(datum) {\n\t\t\t\tconst hoveredElement = select(this);\n\t\t\t\thoveredElement.classed(\"hovered\", false);\n\n\t\t\t\thoveredElement.transition(self.services.transitions.getTransition(\"graph_element_mouseout_fill_update\"))\n\t\t\t\t\t.attr(\"fill\", (d: any) => self.model.getFillScale()[d.datasetLabel](d.label));\n\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOUT, {\n\t\t\t\t\telement: hoveredElement,\n\t\t\t\t\tdatum\n\t\t\t\t});\n\n\t\t\t\t// Hide tooltip\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE, { hoveredElement });\n\t\t\t});\n\t}\n\n\tdestroy() {\n\t\t// Remove event listeners\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"mousemove\", null)\n\t\t\t.on(\"mouseout\", null);\n\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(Events.Legend.ITEM_HOVER, this.handleLegendOnHover);\n\t\teventsFragment.removeEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bar-grouped.js","sourceRoot":"","sources":["bar-grouped.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACN,qBAAqB,EACrB,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAE1B,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,eA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C,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE;gBAC3D,OAAO,EAAE,cAAc;gBACvB,KAAK,OAAA;aACL,CAAC,CAAC;YAEH,eAAe;YACf,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,cAAc,gBAAA,EAAE,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,4BAAO,GAAP;QACC,yBAAyB;QACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;aAC/B,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;aACrB,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAEvB,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACvF,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC5F,CAAC;IACF,iBAAC;AAAD,CAAC,AAlQD,CAAgC,GAAG,GAkQlC","sourcesContent":["// Internal Imports\nimport { Bar } from \"./bar\";\nimport { Tools } from \"../../tools\";\nimport {\n\tCartesianOrientations,\n\tEvents,\n\tRoles,\n\tTooltipTypes\n} from \"../../interfaces\";\n\n// D3 Imports\nimport { map } from \"d3-collection\";\nimport { select } from \"d3-selection\";\nimport { color } from \"d3-color\";\nimport { ScaleBand, scaleBand } from \"d3-scale\";\n\nexport class GroupedBar extends Bar {\n\ttype = \"grouped-bar\";\n\n\tgroupScale: ScaleBand<any>;\n\n\tpadding = 5;\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(Events.Legend.ITEM_HOVER, this.handleLegendOnHover);\n\n\t\t// Un-highlight circles on legend item mouseouts\n\t\teventsFragment.addEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);\n\t}\n\n\tprotected getDataCorrespondingToLabel(label: string) {\n\t\tconst displayData = this.model.getDisplayData();\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\n\t\treturn displayData.filter(datum => datum[domainIdentifier] === label);\n\t}\n\n\tprotected getGroupWidth() {\n\t\tconst numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;\n\t\tconst totalGroupPadding = this.getTotalGroupPadding();\n\n\t\treturn this.getBarWidth() * numOfActiveDataGroups + totalGroupPadding;\n\t}\n\n\n\tprotected getTotalGroupPadding() {\n\t\tconst numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;\n\n\t\tif (numOfActiveDataGroups === 1) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tconst domainScale = this.services.cartesianScales.getDomainScale();\n\t\tconst padding = Math.min(\n\t\t\t5,\n\t\t\t5 * (domainScale.step() / 70)\n\t\t);\n\n\t\treturn padding * (numOfActiveDataGroups - 1);\n\t}\n\n\t// Gets the correct width for bars based on options & configurations\n\tprotected getBarWidth() {\n\t\tconst options = this.model.getOptions();\n\t\tconst providedWidth = Tools.getProperty(options, \"bars\", \"width\");\n\t\tconst providedMaxWidth = Tools.getProperty(options, \"bars\", \"maxWidth\");\n\n\t\t// If there's a provided width, compare with maxWidth and\n\t\t// Determine which to return\n\t\tif (providedWidth !== null) {\n\t\t\tif (providedMaxWidth === null) {\n\t\t\t\treturn providedWidth;\n\t\t\t} else if (providedWidth <= providedMaxWidth) {\n\t\t\t\treturn providedWidth;\n\t\t\t}\n\t\t}\n\n\t\tconst numOfActiveDataGroups = this.model.getActiveDataGroupNames().length;\n\t\tconst totalGroupPadding = this.getTotalGroupPadding();\n\n\t\tconst domainScale = this.services.cartesianScales.getDomainScale();\n\t\treturn Math.min(\n\t\t\tprovidedMaxWidth,\n\t\t\t(domainScale.step() - totalGroupPadding) / numOfActiveDataGroups\n\t\t);\n\t}\n\n\tprotected setGroupScale() {\n\t\tthis.groupScale = scaleBand()\n\t\t\t.domain(this.model.getActiveDataGroupNames())\n\t\t\t.rangeRound([0, this.getGroupWidth()]);\n\t}\n\n\trender(animate: boolean) {\n\t\t// Chart options mixed with the internal configurations\n\t\tconst displayData = this.model.getDisplayData();\n\n\t\tconst options = this.model.getOptions();\n\t\tconst { groupMapsTo } = options.data;\n\t\tconst domainIdentifier = this.services.cartesianScales.getDomainIdentifier();\n\n\t\t// Get unique labels\n\t\tthis.setGroupScale();\n\n\t\t// Grab container SVG\n\t\tconst svg = this.getContainerSVG();\n\n\t\tconst allDataLabels = map(displayData, datum => datum[domainIdentifier]).keys();\n\n\t\t// Update data on bar groups\n\t\tconst barGroups = svg.selectAll(\"g.bars\")\n\t\t\t.data(allDataLabels, label => label);\n\n\t\t// Remove dot groups that need to be removed\n\t\tbarGroups.exit()\n\t\t\t.attr(\"opacity\", 0)\n\t\t\t.remove();\n\n\t\t// Add the bar groups that need to be introduced\n\t\tconst barGroupsEnter = barGroups.enter()\n\t\t\t.append(\"g\")\n\t\t\t\t.classed(\"bars\", true)\n\t\t\t\t.attr(\"role\", Roles.GROUP)\n\t\t\t\t.attr(\"aria-labelledby\", d => d);\n\n\t\t// Update data on all bars\n\t\tconst bars = barGroupsEnter.merge(barGroups)\n\t\t\t.attr(\"transform\", (label, i) => {\n\t\t\t\tconst scaleValue = this.services.cartesianScales.getDomainValue(label, i);\n\t\t\t\tconst translateBy = scaleValue - this.getGroupWidth() / 2;\n\t\t\t\t// const translateBy = scaleValue - this.getGroupWidth(null) / 2 + this.getBarWidth(null);\n\n\t\t\t\tif (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\n\t\t\t\t\treturn `translate(${translateBy}, 0)`;\n\t\t\t\t} else {\n\t\t\t\t\t// translate in the y direction for horizontal groups\n\t\t\t\t\treturn `translate(0, ${translateBy})`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.selectAll(\"path.bar\")\n\t\t\t.data(label => this.getDataCorrespondingToLabel(label));\n\n\t\t// Remove bars that are no longer needed\n\t\tbars.exit()\n\t\t\t.attr(\"opacity\", 0)\n\t\t\t.remove();\n\n\t\t// Add the circles that need to be introduced\n\t\tconst barsEnter = bars.enter()\n\t\t\t.append(\"path\")\n\t\t\t.attr(\"opacity\", 0);\n\n\t\t// code for vertical grouped bar charts\n\t\tbarsEnter.merge(bars)\n\t\t\t.classed(\"bar\", true)\n\t\t\t.transition(this.services.transitions.getTransition(\"bar-update-enter\", animate))\n\t\t\t.attr(\"fill\", d => this.model.getFillColor(d[groupMapsTo]))\n\t\t\t.attr(\"d\", d => {\n\t\t\t\t/*\n\t\t\t\t * Orientation support for horizontal/vertical bar charts\n\t\t\t\t * Determine coordinates needed for a vertical set of paths\n\t\t\t\t * to draw the bars needed, and pass those coordinates down to\n\t\t\t\t * generateSVGPathString() to decide whether it needs to flip them\n\t\t\t\t */\n\t\t\t\tconst startX = this.groupScale(d[groupMapsTo]);\n\t\t\t\tconst barWidth = this.getBarWidth();\n\n\t\t\t\tconst x0 = startX;\n\t\t\t\tconst x1 = startX + barWidth;\n\t\t\t\tconst y0 = this.services.cartesianScales.getRangeValue(0);\n\t\t\t\tconst y1 = this.services.cartesianScales.getRangeValue(d.value);\n\n\t\t\t\treturn Tools.generateSVGPathString(\n\t\t\t\t\t{ x0, x1, y0, y1 },\n\t\t\t\t\tthis.services.cartesianScales.getOrientation()\n\t\t\t\t);\n\t\t\t})\n\t\t\t.attr(\"opacity\", 1)\n\t\t\t// a11y\n\t\t\t.attr(\"role\", Roles.GRAPHICS_SYMBOL)\n\t\t\t.attr(\"aria-roledescription\", \"bar\")\n\t\t\t.attr(\"aria-label\", d => d.value);\n\n\t\t// Add event listeners to elements drawn\n\t\tthis.addEventListeners();\n\t}\n\n\t// Highlight elements that match the hovered legend item\n\thandleLegendOnHover = (event: CustomEvent) => {\n\t\tconst { hoveredElement } = event.detail;\n\n\t\tconst { groupMapsTo } = this.model.getOptions().data;\n\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.transition(this.services.transitions.getTransition(\"legend-hover-bar\"))\n\t\t\t.attr(\"opacity\", d => (d[groupMapsTo] !== hoveredElement.datum()[\"name\"]) ? 0.3 : 1);\n\t}\n\n\t// Un-highlight all elements\n\thandleLegendMouseOut = (event: CustomEvent) => {\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.transition(this.services.transitions.getTransition(\"legend-mouseout-bar\"))\n\t\t\t.attr(\"opacity\", 1);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.on(\"mouseover\", function(datum) {\n\t\t\t\tconst hoveredElement = select(this);\n\n\t\t\t\thoveredElement.transition(self.services.transitions.getTransition(\"graph_element_mouseover_fill_update\"))\n\t\t\t\t\t.attr(\"fill\", color(hoveredElement.attr(\"fill\")).darker(0.7).toString());\n\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOVER, {\n\t\t\t\t\telement: hoveredElement,\n\t\t\t\t\tdatum\n\t\t\t\t});\n\n\t\t\t\t// Show tooltip\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\t\thoveredElement,\n\t\t\t\t\ttype: TooltipTypes.DATAPOINT\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mousemove\", function(datum) {\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEMOVE, {\n\t\t\t\t\telement: select(this),\n\t\t\t\t\tdatum\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"click\", function(datum) {\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_CLICK, {\n\t\t\t\t\telement: select(this),\n\t\t\t\t\tdatum\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mouseout\", function(datum) {\n\t\t\t\tconst hoveredElement = select(this);\n\t\t\t\thoveredElement.classed(\"hovered\", false);\n\n\t\t\t\tconst { groupMapsTo } = self.model.getOptions().data;\n\t\t\t\thoveredElement.transition(self.services.transitions.getTransition(\"graph_element_mouseout_fill_update\"))\n\t\t\t\t\t.attr(\"fill\", (d: any) => self.model.getFillColor(d[groupMapsTo]));\n\n\t\t\t\t// Dispatch mouse event\n\t\t\t\tself.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOUT, {\n\t\t\t\t\telement: hoveredElement,\n\t\t\t\t\tdatum\n\t\t\t\t});\n\n\t\t\t\t// Hide tooltip\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE, { hoveredElement });\n\t\t\t});\n\t}\n\n\tdestroy() {\n\t\t// Remove event listeners\n\t\tthis.parent.selectAll(\"path.bar\")\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"mousemove\", null)\n\t\t\t.on(\"mouseout\", null);\n\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(Events.Legend.ITEM_HOVER, this.handleLegendOnHover);\n\t\teventsFragment.removeEventListener(Events.Legend.ITEM_MOUSEOUT, this.handleLegendMouseOut);\n\t}\n}\n"]}
|
|
@@ -5,7 +5,6 @@ export declare class SimpleBar extends Bar {
|
|
|
5
5
|
render(animate: boolean): void;
|
|
6
6
|
handleLegendOnHover: (event: CustomEvent<any>) => void;
|
|
7
7
|
handleLegendMouseOut: (event: CustomEvent<any>) => void;
|
|
8
|
-
addLabelsToDataPoints(d: any, index: any): any;
|
|
9
8
|
addEventListeners(): void;
|
|
10
9
|
destroy(): void;
|
|
11
10
|
}
|
|
@@ -25,9 +25,10 @@ var SimpleBar = /** @class */ (function (_super) {
|
|
|
25
25
|
_this.type = "simple-bar";
|
|
26
26
|
_this.handleLegendOnHover = function (event) {
|
|
27
27
|
var hoveredElement = event.detail.hoveredElement;
|
|
28
|
+
var groupMapsTo = _this.model.getOptions().data.groupMapsTo;
|
|
28
29
|
_this.parent.selectAll("path.bar")
|
|
29
30
|
.transition(_this.services.transitions.getTransition("legend-hover-simple-bar"))
|
|
30
|
-
.attr("opacity", function (d) { return (d
|
|
31
|
+
.attr("opacity", function (d) { return (d[groupMapsTo] !== hoveredElement.datum()["name"]) ? 0.3 : 1; });
|
|
31
32
|
};
|
|
32
33
|
_this.handleLegendMouseOut = function (event) {
|
|
33
34
|
_this.parent.selectAll("path.bar")
|
|
@@ -45,24 +46,13 @@ var SimpleBar = /** @class */ (function (_super) {
|
|
|
45
46
|
};
|
|
46
47
|
SimpleBar.prototype.render = function (animate) {
|
|
47
48
|
var _this = this;
|
|
49
|
+
var options = this.model.getOptions();
|
|
50
|
+
var groupMapsTo = options.data.groupMapsTo;
|
|
48
51
|
// Grab container SVG
|
|
49
52
|
var svg = this.getContainerSVG();
|
|
50
|
-
// Update data on bar groups
|
|
51
|
-
var barGroups = svg.selectAll("g.bars")
|
|
52
|
-
.data(this.model.getDisplayData().datasets, function (dataset) { return dataset.label; });
|
|
53
|
-
// Remove dot groups that need to be removed
|
|
54
|
-
barGroups.exit()
|
|
55
|
-
.attr("opacity", 0)
|
|
56
|
-
.remove();
|
|
57
|
-
// Add the bar groups that need to be introduced
|
|
58
|
-
var barGroupsEnter = barGroups.enter()
|
|
59
|
-
.append("g")
|
|
60
|
-
.classed("bars", true)
|
|
61
|
-
.attr("role", Roles.GROUP);
|
|
62
53
|
// Update data on all bars
|
|
63
|
-
var bars =
|
|
64
|
-
.
|
|
65
|
-
.data(function (d, i) { return _this.addLabelsToDataPoints(d, i); }, function (d) { return d.label; });
|
|
54
|
+
var bars = svg.selectAll("path.bar")
|
|
55
|
+
.data(this.model.getDisplayData(), function (datum) { return datum[groupMapsTo]; });
|
|
66
56
|
// Remove bars that are no longer needed
|
|
67
57
|
bars.exit()
|
|
68
58
|
.attr("opacity", 0)
|
|
@@ -75,7 +65,7 @@ var SimpleBar = /** @class */ (function (_super) {
|
|
|
75
65
|
.classed("bar", true)
|
|
76
66
|
.attr("width", this.getBarWidth.bind(this))
|
|
77
67
|
.transition(this.services.transitions.getTransition("bar-update-enter", animate))
|
|
78
|
-
.attr("fill", function (d) { return _this.model.
|
|
68
|
+
.attr("fill", function (d) { return _this.model.getFillColor(d[groupMapsTo]); })
|
|
79
69
|
.attr("d", function (d, i) {
|
|
80
70
|
/*
|
|
81
71
|
* Orientation support for horizontal/vertical bar charts
|
|
@@ -98,17 +88,9 @@ var SimpleBar = /** @class */ (function (_super) {
|
|
|
98
88
|
// Add event listeners to elements drawn
|
|
99
89
|
this.addEventListeners();
|
|
100
90
|
};
|
|
101
|
-
// TODO - This method could be re-used in more graphs
|
|
102
|
-
SimpleBar.prototype.addLabelsToDataPoints = function (d, index) {
|
|
103
|
-
var labels = this.model.getDisplayData().labels;
|
|
104
|
-
return d.data.map(function (datum, i) { return ({
|
|
105
|
-
date: datum.date,
|
|
106
|
-
label: labels[i],
|
|
107
|
-
datasetLabel: d.label,
|
|
108
|
-
value: isNaN(datum) ? datum.value : datum
|
|
109
|
-
}); });
|
|
110
|
-
};
|
|
111
91
|
SimpleBar.prototype.addEventListeners = function () {
|
|
92
|
+
var options = this.model.getOptions();
|
|
93
|
+
var groupMapsTo = options.data.groupMapsTo;
|
|
112
94
|
var self = this;
|
|
113
95
|
this.parent.selectAll("path.bar")
|
|
114
96
|
.on("mouseover", function (datum) {
|
|
@@ -144,7 +126,7 @@ var SimpleBar = /** @class */ (function (_super) {
|
|
|
144
126
|
var hoveredElement = select(this);
|
|
145
127
|
hoveredElement.classed("hovered", false);
|
|
146
128
|
hoveredElement.transition(self.services.transitions.getTransition("graph_element_mouseout_fill_update"))
|
|
147
|
-
.attr("fill", function (d) { return self.model.
|
|
129
|
+
.attr("fill", function (d) { return self.model.getFillColor(d[groupMapsTo]); });
|
|
148
130
|
// Dispatch mouse event
|
|
149
131
|
self.services.events.dispatchEvent(Events.Bar.BAR_MOUSEOUT, {
|
|
150
132
|
element: hoveredElement,
|