@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
package/charts/bar-grouped.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxisChart } from "../axis-chart";
|
|
2
|
-
import {
|
|
2
|
+
import { BarChartOptions, ChartConfig } from "../interfaces/index";
|
|
3
3
|
export declare class GroupedBarChart extends AxisChart {
|
|
4
|
-
constructor(holder: Element, chartConfigs: ChartConfig<
|
|
4
|
+
constructor(holder: Element, chartConfigs: ChartConfig<BarChartOptions>);
|
|
5
5
|
getComponents(): any[];
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-grouped.js","sourceRoot":"","sources":["bar-grouped.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,IAAI,EACJ,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,UAAU,EAKV,MAAM,qBAAqB,CAAC;AAE7B;IAAqC,mCAAS;IAC7C,yBAAY,MAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"bar-grouped.js","sourceRoot":"","sources":["bar-grouped.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,IAAI,EACJ,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,UAAU,EAKV,MAAM,qBAAqB,CAAC;AAE7B;IAAqC,mCAAS;IAC7C,yBAAY,MAAe,EAAE,YAA0C;QAAvE,YACC,kBAAM,MAAM,EAAE,YAAY,CAAC,SAa3B;QAXA,2CAA2C;QAC3C,iCAAiC;QACjC,KAAI,CAAC,KAAK,CAAC,UAAU,CACpB,KAAK,CAAC,wBAAwB,CAC7B,aAAa,CAAC,OAAO,CAAC,eAAe,EACrC,YAAY,CAAC,OAAO,CACpB,CACD,CAAC;QAEF,6CAA6C;QAC7C,KAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;;IACjC,CAAC;IAED,uCAAa,GAAb;QACC,gDAAgD;QAChD,IAAM,oBAAoB,GAAG;YAC5B,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACjD,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACnC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACzC,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;SACvC,CAAC;QAEF,IAAM,UAAU,GAAU,IAAI,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;QAC5E,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3D,OAAO,UAAU,CAAC;IACnB,CAAC;IACF,sBAAC;AAAD,CAAC,AA9BD,CAAqC,SAAS,GA8B7C","sourcesContent":["// Internal Imports\nimport { AxisChart } from \"../axis-chart\";\nimport * as Configuration from \"../configuration\";\nimport {\n\tBarChartOptions,\n\tChartConfig\n} from \"../interfaces/index\";\nimport { Tools } from \"../tools\";\n\n// Components\nimport {\n\tGrid,\n\tGroupedBar,\n\tTwoDimensionalAxes,\n\tZeroLine,\n\tTooltipBar,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tTooltip,\n\tLegend,\n\tLayoutComponent\n} from \"../components/index\";\n\nexport class GroupedBarChart extends AxisChart {\n\tconstructor(holder: Element, chartConfigs: ChartConfig<BarChartOptions>) {\n\t\tsuper(holder, chartConfigs);\n\n\t\t// Merge the default options for this chart\n\t\t// With the user provided options\n\t\tthis.model.setOptions(\n\t\t\tTools.mergeDefaultChartOptions(\n\t\t\t\tConfiguration.options.groupedBarChart,\n\t\t\t\tchartConfigs.options\n\t\t\t)\n\t\t);\n\n\t\t// Initialize data, services, components etc.\n\t\tthis.init(holder, chartConfigs);\n\t}\n\n\tgetComponents() {\n\t\t// Specify what to render inside the graph-frame\n\t\tconst graphFrameComponents = [\n\t\t\tnew TwoDimensionalAxes(this.model, this.services),\n\t\t\tnew Grid(this.model, this.services),\n\t\t\tnew GroupedBar(this.model, this.services),\n\t\t\tnew ZeroLine(this.model, this.services)\n\t\t];\n\n\t\tconst components: any[] = this.getAxisChartComponents(graphFrameComponents);\n\t\tcomponents.push(new TooltipBar(this.model, this.services));\n\t\treturn components;\n\t}\n}\n"]}
|
package/charts/bar-simple.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AxisChart } from "../axis-chart";
|
|
2
|
-
import {
|
|
3
|
-
import { SimpleBarChartModel } from "../model-simple-bar";
|
|
2
|
+
import { BarChartOptions, ChartConfig } from "../interfaces/index";
|
|
4
3
|
export declare class SimpleBarChart extends AxisChart {
|
|
5
|
-
|
|
6
|
-
constructor(holder: Element, chartConfigs: ChartConfig<ScatterChartOptions>);
|
|
4
|
+
constructor(holder: Element, chartConfigs: ChartConfig<BarChartOptions>);
|
|
7
5
|
getComponents(): any[];
|
|
8
6
|
}
|
package/charts/bar-simple.js
CHANGED
|
@@ -15,14 +15,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
import { AxisChart } from "../axis-chart";
|
|
16
16
|
import * as Configuration from "../configuration";
|
|
17
17
|
import { Tools } from "../tools";
|
|
18
|
-
import { SimpleBarChartModel } from "../model-simple-bar";
|
|
19
18
|
// Components
|
|
20
19
|
import { Grid, SimpleBar, TwoDimensionalAxes, ZeroLine, TooltipBar } from "../components/index";
|
|
21
20
|
var SimpleBarChart = /** @class */ (function (_super) {
|
|
22
21
|
__extends(SimpleBarChart, _super);
|
|
23
22
|
function SimpleBarChart(holder, chartConfigs) {
|
|
24
23
|
var _this = _super.call(this, holder, chartConfigs) || this;
|
|
25
|
-
_this.model = new SimpleBarChartModel(_this.services);
|
|
26
24
|
// Merge the default options for this chart
|
|
27
25
|
// With the user provided options
|
|
28
26
|
_this.model.setOptions(Tools.mergeDefaultChartOptions(Configuration.options.simpleBarChart, chartConfigs.options));
|
package/charts/bar-simple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-simple.js","sourceRoot":"","sources":["bar-simple.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"bar-simple.js","sourceRoot":"","sources":["bar-simple.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,IAAI,EACJ,SAAS,EACT,kBAAkB,EAClB,QAAQ,EACR,UAAU,EAKV,MAAM,qBAAqB,CAAC;AAE7B;IAAoC,kCAAS;IAC5C,wBAAY,MAAe,EAAE,YAA0C;QAAvE,YACC,kBAAM,MAAM,EAAE,YAAY,CAAC,SAa3B;QAXA,2CAA2C;QAC3C,iCAAiC;QACjC,KAAI,CAAC,KAAK,CAAC,UAAU,CACpB,KAAK,CAAC,wBAAwB,CAC7B,aAAa,CAAC,OAAO,CAAC,cAAc,EACpC,YAAY,CAAC,OAAO,CACpB,CACD,CAAC;QAEF,6CAA6C;QAC7C,KAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;;IACjC,CAAC;IAED,sCAAa,GAAb;QACC,gDAAgD;QAChD,IAAM,oBAAoB,GAAG;YAC5B,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACjD,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACnC,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;YACxC,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;SACvC,CAAC;QAEF,IAAM,UAAU,GAAU,IAAI,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;QAC5E,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3D,OAAO,UAAU,CAAC;IACnB,CAAC;IACF,qBAAC;AAAD,CAAC,AA9BD,CAAoC,SAAS,GA8B5C","sourcesContent":["// Internal Imports\nimport { AxisChart } from \"../axis-chart\";\nimport * as Configuration from \"../configuration\";\nimport {\n\tBarChartOptions,\n\tChartConfig\n} from \"../interfaces/index\";\nimport { Tools } from \"../tools\";\n\n// Components\nimport {\n\tGrid,\n\tSimpleBar,\n\tTwoDimensionalAxes,\n\tZeroLine,\n\tTooltipBar,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tTooltip,\n\tLegend,\n\tLayoutComponent\n} from \"../components/index\";\n\nexport class SimpleBarChart extends AxisChart {\n\tconstructor(holder: Element, chartConfigs: ChartConfig<BarChartOptions>) {\n\t\tsuper(holder, chartConfigs);\n\n\t\t// Merge the default options for this chart\n\t\t// With the user provided options\n\t\tthis.model.setOptions(\n\t\t\tTools.mergeDefaultChartOptions(\n\t\t\t\tConfiguration.options.simpleBarChart,\n\t\t\t\tchartConfigs.options\n\t\t\t)\n\t\t);\n\n\t\t// Initialize data, services, components etc.\n\t\tthis.init(holder, chartConfigs);\n\t}\n\n\tgetComponents() {\n\t\t// Specify what to render inside the graph-frame\n\t\tconst graphFrameComponents = [\n\t\t\tnew TwoDimensionalAxes(this.model, this.services),\n\t\t\tnew Grid(this.model, this.services),\n\t\t\tnew SimpleBar(this.model, this.services),\n\t\t\tnew ZeroLine(this.model, this.services)\n\t\t];\n\n\t\tconst components: any[] = this.getAxisChartComponents(graphFrameComponents);\n\t\tcomponents.push(new TooltipBar(this.model, this.services));\n\t\treturn components;\n\t}\n}\n"]}
|
package/charts/donut.js
CHANGED
|
@@ -16,7 +16,7 @@ import { PieChart } from "./pie";
|
|
|
16
16
|
import * as Configuration from "../configuration";
|
|
17
17
|
import { Tools } from "../tools";
|
|
18
18
|
// Components
|
|
19
|
-
import { Donut,
|
|
19
|
+
import { Donut, TooltipPie } from "../components/index";
|
|
20
20
|
var DonutChart = /** @class */ (function (_super) {
|
|
21
21
|
__extends(DonutChart, _super);
|
|
22
22
|
function DonutChart(holder, chartConfigs) {
|
|
@@ -34,7 +34,7 @@ var DonutChart = /** @class */ (function (_super) {
|
|
|
34
34
|
new Donut(this.model, this.services)
|
|
35
35
|
];
|
|
36
36
|
var components = this.getChartComponents(graphFrameComponents);
|
|
37
|
-
components.push(new
|
|
37
|
+
components.push(new TooltipPie(this.model, this.services));
|
|
38
38
|
return components;
|
|
39
39
|
};
|
|
40
40
|
return DonutChart;
|
package/charts/donut.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"donut.js","sourceRoot":"","sources":["donut.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,KAAK,EAIL,
|
|
1
|
+
{"version":3,"file":"donut.js","sourceRoot":"","sources":["donut.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,KAAK,EAIL,UAAU,EACV,MAAM,qBAAqB,CAAC;AAE7B;IAAgC,8BAAQ;IACvC,oBAAY,MAAe,EAAE,YAA0C;QAAvE,YACC,kBAAM,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,SAajC;QAXA,2CAA2C;QAC3C,iCAAiC;QACjC,KAAI,CAAC,KAAK,CAAC,UAAU,CACpB,KAAK,CAAC,wBAAwB,CAC7B,aAAa,CAAC,OAAO,CAAC,UAAU,EAChC,YAAY,CAAC,OAAO,CACpB,CACD,CAAC;QAEF,6CAA6C;QAC7C,KAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;;IACjC,CAAC;IAED,kCAAa,GAAb;QACC,gDAAgD;QAChD,IAAM,oBAAoB,GAAG;YAC5B,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;SACpC,CAAC;QAEF,IAAM,UAAU,GAAU,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;QACxE,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3D,OAAO,UAAU,CAAC;IACnB,CAAC;IACF,iBAAC;AAAD,CAAC,AA3BD,CAAgC,QAAQ,GA2BvC","sourcesContent":["// Internal Imports\nimport { PieChart } from \"./pie\";\nimport * as Configuration from \"../configuration\";\nimport {\n\tChartConfig,\n\tPieChartOptions\n} from \"../interfaces/index\";\nimport { Tools } from \"../tools\";\n\n// Components\nimport {\n\tDonut,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tLegend,\n\tLayoutComponent,\n\tTooltipPie\n} from \"../components/index\";\n\nexport class DonutChart extends PieChart {\n\tconstructor(holder: Element, chartConfigs: ChartConfig<PieChartOptions>) {\n\t\tsuper(holder, chartConfigs, true);\n\n\t\t// Merge the default options for this chart\n\t\t// With the user provided options\n\t\tthis.model.setOptions(\n\t\t\tTools.mergeDefaultChartOptions(\n\t\t\t\tConfiguration.options.donutChart,\n\t\t\t\tchartConfigs.options\n\t\t\t)\n\t\t);\n\n\t\t// Initialize data, services, components etc.\n\t\tthis.init(holder, chartConfigs);\n\t}\n\n\tgetComponents() {\n\t\t// Specify what to render inside the graph-frame\n\t\tconst graphFrameComponents = [\n\t\t\tnew Donut(this.model, this.services)\n\t\t];\n\n\t\tconst components: any[] = this.getChartComponents(graphFrameComponents);\n\t\tcomponents.push(new TooltipPie(this.model, this.services));\n\t\treturn components;\n\t}\n}\n"]}
|
package/charts/pie.js
CHANGED
|
@@ -19,7 +19,7 @@ import { Tools } from "../tools";
|
|
|
19
19
|
// Components
|
|
20
20
|
import { Pie,
|
|
21
21
|
// the imports below are needed because of typescript bug (error TS4029)
|
|
22
|
-
|
|
22
|
+
TooltipPie } from "../components/index";
|
|
23
23
|
var PieChart = /** @class */ (function (_super) {
|
|
24
24
|
__extends(PieChart, _super);
|
|
25
25
|
// TODO - Optimize the use of "extending"
|
|
@@ -45,7 +45,7 @@ var PieChart = /** @class */ (function (_super) {
|
|
|
45
45
|
];
|
|
46
46
|
// get the base chart components and export with tooltip
|
|
47
47
|
var components = this.getChartComponents(graphFrameComponents);
|
|
48
|
-
components.push(new
|
|
48
|
+
components.push(new TooltipPie(this.model, this.services));
|
|
49
49
|
return components;
|
|
50
50
|
};
|
|
51
51
|
return PieChart;
|
package/charts/pie.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie.js","sourceRoot":"","sources":["pie.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,GAAG;AACH,wEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"pie.js","sourceRoot":"","sources":["pie.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,GAAG;AACH,wEAAwE;AACxE,UAAU,EAGV,MAAM,qBAAqB,CAAC;AAE7B;IAA8B,4BAAK;IAGlC,yCAAyC;IACzC,kBAAY,MAAe,EAAE,YAA0C,EAAE,SAAiB;QAAjB,0BAAA,EAAA,iBAAiB;QAA1F,YACC,kBAAM,MAAM,EAAE,YAAY,CAAC,SAkB3B;QAtBD,WAAK,GAAG,IAAI,aAAa,CAAC,KAAI,CAAC,QAAQ,CAAC,CAAC;QAMxC,yCAAyC;QACzC,IAAI,SAAS,EAAE;;SAEd;QAED,2CAA2C;QAC3C,iCAAiC;QACjC,KAAI,CAAC,KAAK,CAAC,UAAU,CACpB,KAAK,CAAC,wBAAwB,CAC7B,aAAa,CAAC,OAAO,CAAC,QAAQ,EAC9B,YAAY,CAAC,OAAO,CACpB,CACD,CAAC;QAEF,6CAA6C;QAC7C,KAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;;IACjC,CAAC;IAED,gCAAa,GAAb;QACC,gDAAgD;QAChD,IAAM,oBAAoB,GAAG;YAC5B,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;SAClC,CAAC;QAEF,wDAAwD;QACxD,IAAM,UAAU,GAAU,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;QACxE,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3D,OAAO,UAAU,CAAC;IACnB,CAAC;IACF,eAAC;AAAD,CAAC,AApCD,CAA8B,KAAK,GAoClC","sourcesContent":["// Internal Imports\nimport { PieChartModel } from \"../model-pie\";\nimport { Chart } from \"../chart\";\nimport * as Configuration from \"../configuration\";\nimport {\n\tChartConfig,\n\tPieChartOptions\n} from \"../interfaces/index\";\nimport { Tools } from \"../tools\";\n\n// Components\nimport {\n\tPie,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tTooltipPie,\n\tLegend,\n\tLayoutComponent\n} from \"../components/index\";\n\nexport class PieChart extends Chart {\n\tmodel = new PieChartModel(this.services);\n\n\t// TODO - Optimize the use of \"extending\"\n\tconstructor(holder: Element, chartConfigs: ChartConfig<PieChartOptions>, extending = false) {\n\t\tsuper(holder, chartConfigs);\n\n\t\t// TODO - Optimize the use of \"extending\"\n\t\tif (extending) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Merge the default options for this chart\n\t\t// With the user provided options\n\t\tthis.model.setOptions(\n\t\t\tTools.mergeDefaultChartOptions(\n\t\t\t\tConfiguration.options.pieChart,\n\t\t\t\tchartConfigs.options\n\t\t\t)\n\t\t);\n\n\t\t// Initialize data, services, components etc.\n\t\tthis.init(holder, chartConfigs);\n\t}\n\n\tgetComponents() {\n\t\t// Specify what to render inside the graph-frame\n\t\tconst graphFrameComponents = [\n\t\t\tnew Pie(this.model, this.services)\n\t\t];\n\n\t\t// get the base chart components and export with tooltip\n\t\tconst components: any[] = this.getChartComponents(graphFrameComponents);\n\t\tcomponents.push(new TooltipPie(this.model, this.services));\n\t\treturn components;\n\t}\n}\n"]}
|
package/components/axes/grid.js
CHANGED
|
@@ -117,10 +117,10 @@ var Grid = /** @class */ (function (_super) {
|
|
|
117
117
|
* @param position mouse positon
|
|
118
118
|
*/
|
|
119
119
|
Grid.prototype.getActiveGridline = function (position) {
|
|
120
|
-
var
|
|
121
|
-
|
|
120
|
+
var userSpecifiedThreshold = Tools.getProperty(this.model.getOptions, "tooltip", "gridline", "threshold");
|
|
121
|
+
var threshold = userSpecifiedThreshold ? userSpecifiedThreshold : this.getGridlineThreshold(position);
|
|
122
122
|
var svg = this.parent;
|
|
123
|
-
var
|
|
123
|
+
var xGridlines = svg.selectAll(".x.grid .tick")
|
|
124
124
|
.filter(function () {
|
|
125
125
|
var translations = Tools.getTranslationValues(this);
|
|
126
126
|
// threshold for when to display a gridline tooltip
|
|
@@ -130,7 +130,7 @@ var Grid = /** @class */ (function (_super) {
|
|
|
130
130
|
};
|
|
131
131
|
return bounds.min <= position[0] && position[0] <= bounds.max;
|
|
132
132
|
});
|
|
133
|
-
return
|
|
133
|
+
return xGridlines;
|
|
134
134
|
};
|
|
135
135
|
/**
|
|
136
136
|
* Adds the listener on the X grid to trigger multiple point tooltips along the x axis.
|
|
@@ -139,8 +139,7 @@ var Grid = /** @class */ (function (_super) {
|
|
|
139
139
|
var self = this;
|
|
140
140
|
var svg = this.parent;
|
|
141
141
|
var grid = DOMUtils.appendOrSelect(svg, "rect.chart-grid-backdrop");
|
|
142
|
-
grid
|
|
143
|
-
.on("mousemove mouseover", function () {
|
|
142
|
+
grid.on("mousemove mouseover", function () {
|
|
144
143
|
var chartContainer = self.services.domUtils.getMainSVG();
|
|
145
144
|
var pos = mouse(chartContainer);
|
|
146
145
|
var hoveredElement = select(this);
|
|
@@ -149,28 +148,22 @@ var Grid = /** @class */ (function (_super) {
|
|
|
149
148
|
allgridlines.classed("active", false);
|
|
150
149
|
var activeGridline = self.getActiveGridline(pos);
|
|
151
150
|
if (activeGridline.empty()) {
|
|
152
|
-
self.services.events.dispatchEvent(Events.Tooltip.HIDE);
|
|
153
|
-
return;
|
|
151
|
+
return self.services.events.dispatchEvent(Events.Tooltip.HIDE);
|
|
154
152
|
}
|
|
155
153
|
// set active class to control dasharray and theme colors
|
|
156
|
-
activeGridline
|
|
157
|
-
.classed("active", true);
|
|
154
|
+
activeGridline.classed("active", true);
|
|
158
155
|
// get the items that should be highlighted
|
|
159
|
-
var
|
|
160
|
-
// use the selected gridline to get the data with associated domain
|
|
161
|
-
activeGridline.each(function (d) {
|
|
162
|
-
highlightItems = self.services.cartesianScales.getDataFromDomain(d);
|
|
163
|
-
});
|
|
156
|
+
var itemsToHighlight = self.services.cartesianScales.getDataFromDomain(activeGridline.datum());
|
|
164
157
|
self.services.events.dispatchEvent(Events.Tooltip.SHOW, {
|
|
165
158
|
hoveredElement: hoveredElement,
|
|
166
|
-
multidata:
|
|
159
|
+
multidata: itemsToHighlight,
|
|
167
160
|
type: TooltipTypes.GRIDLINE
|
|
168
161
|
});
|
|
169
162
|
})
|
|
170
163
|
.on("mouseout", function () {
|
|
171
164
|
svg.selectAll(".x.grid .tick")
|
|
172
165
|
.classed("active", false);
|
|
173
|
-
self.services.events.dispatchEvent(Events.Tooltip.HIDE
|
|
166
|
+
self.services.events.dispatchEvent(Events.Tooltip.HIDE);
|
|
174
167
|
});
|
|
175
168
|
};
|
|
176
169
|
Grid.prototype.drawBackdrop = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.js","sourceRoot":"","sources":["grid.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM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CAAC,QAAQ,EAAE,SAAS,GAAG,WAAW,CAAC;aACvC,KAAK,EAAE,CAAC;QAEV,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;aAChC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,wBAAS,GAAT,UAAU,CAAC;QACV,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;aACjB,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE3C,wBAAwB;QACxB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC7B,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IACF,WAAC;AAAD,CAAC,AAvND,CAA0B,SAAS,GAuNlC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { axisBottom, axisLeft } from \"d3-axis\";\nimport { mouse, select } from \"d3-selection\";\nimport { TooltipTypes, Events } from \"../../interfaces\";\n\nexport class Grid extends Component {\n\ttype = \"grid\";\n\n\tbackdrop: any;\n\n\trender() {\n\t\t// Draw the backdrop\n\t\tthis.drawBackdrop();\n\t\tDOMUtils.appendOrSelect(this.backdrop, \"g.x.grid\");\n\t\tDOMUtils.appendOrSelect(this.backdrop, \"g.y.grid\");\n\n\t\tthis.drawXGrid();\n\t\tthis.drawYGrid();\n\n\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) {\n\t\t\tthis.addGridEventListeners();\n\t\t}\n\t}\n\n\tdrawXGrid() {\n\t\tconst svg = this.parent;\n\n\t\tconst height = this.backdrop.attr(\"height\");\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst xGrid = axisBottom(mainXScale)\n\t\t\t.tickSizeInner(-height)\n\t\t\t.tickSizeOuter(0);\n\n\t\t// Determine number of ticks\n\t\tconst numberOfTicks = Tools.getProperty(this.model.getOptions(), \"grid\", \"x\", \"numberOfTicks\");\n\t\txGrid.ticks(numberOfTicks);\n\n\t\tconst g = svg.select(\".x.grid\")\n\t\t\t.attr(\"transform\", `translate(${-this.backdrop.attr(\"x\")}, ${height})`)\n\t\t\t.call(xGrid);\n\n\t\tthis.cleanGrid(g);\n\t}\n\n\tdrawYGrid() {\n\t\tconst svg = this.parent;\n\t\tconst width = this.backdrop.attr(\"width\");\n\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst yGrid = axisLeft(mainYScale)\n\t\t\t.tickSizeInner(-width)\n\t\t\t.tickSizeOuter(0);\n\n\t\t// Determine number of ticks\n\t\tconst numberOfTicks = Tools.getProperty(this.model.getOptions(), \"grid\", \"y\", \"numberOfTicks\");\n\t\tyGrid.ticks(numberOfTicks);\n\n\t\tconst g = svg.select(\".y.grid\")\n\t\t\t.attr(\"transform\", `translate(0, ${-this.backdrop.attr(\"y\")})`)\n\t\t\t.call(yGrid);\n\n\t\tthis.cleanGrid(g);\n\t}\n\n\t/**\n\t * Returns the threshold for the gridline tooltips based on the mouse location.\n\t * Calculated based on the mouse position between the two closest gridlines or edges of chart.\n\t */\n\tgetGridlineThreshold(mousePos) {\n\t\t// use the space between axis grid ticks to adjust the threshold for the tooltips\n\t\tconst svg = this.parent;\n\n\t\t// sort in ascending x translation value order\n\t\tconst gridlinesX = svg.selectAll(\".x.grid .tick\").nodes()\n\t\t.sort((a, b) => {\n\t\t\treturn Number(Tools.getTranslationValues(a).tx) - Number(Tools.getTranslationValues(b).tx);\n\t\t});\n\n\t\t// find the 2 gridlines on either side of the mouse\n\t\tlet floor = -1; let ceiling;\n\t\tgridlinesX.forEach((line: HTMLElement, i: any) => {\n\t\t\tif (mousePos[0] >= +Tools.getTranslationValues(line).tx) {\n\t\t\t\tfloor ++;\n\t\t\t}\n\t\t});\n\t\tceiling = (floor + 1 < gridlinesX.length) ? floor + 1 : gridlinesX.length;\n\n\t\t// get the 'step' between chart gridlines\n\t\tconst line1 = gridlinesX[floor];\n\t\tconst line2 = gridlinesX[ceiling];\n\t\tlet lineSpacing;\n\n\t\t// if the mouse is on edge of charts (mouseX < first gridline || mouseX > last gridline)\n\t\t// we can use the chart edge to determind the threshold for the gridlines\n\t\tif (!line1) {\n\t\t\t// we are between the first gridline and the chart edge\n\t\t\tlineSpacing = +Tools.getTranslationValues(line2).tx;\n\t\t} else if (!line2) {\n\t\t\t// we need to use the chart right bounds in case there isnt a domain axis\n\t\t\tconst gridElement = svg.select(\"rect.chart-grid-backdrop\").node();\n\t\t\tconst width = DOMUtils.getSVGElementSize(gridElement).width;\n\n\t\t\tlineSpacing = width - +Tools.getTranslationValues(line1).tx;\n\t\t} else {\n\t\t\t// there are two gridlines to use\n\t\t\tlineSpacing = +Tools.getTranslationValues(line2).tx - +Tools.getTranslationValues(line1).tx;\n\t\t}\n\t\tconst { threshold } = this.model.getOptions().tooltip.gridline;\n\t\t// return the threshold\n\t\treturn lineSpacing * threshold;\n\t}\n\n\t/**\n\t * Returns the active gridlines based on the gridline threshold and mouse position.\n\t * @param position mouse positon\n\t */\n\tgetActiveGridline(position) {\n\t\tconst threshold = Tools.getProperty(this.model.getOptions, \"tooltip\", \"gridline\", \"threshold\") ?\n\t\t\tTools.getProperty(this.model.getOptions, \"tooltip\", \"gridline\", \"threshold\") : this.getGridlineThreshold(position);\n\t\tconst svg = this.parent;\n\n\t\tconst gridlinesX = svg.selectAll(\".x.grid .tick\")\n\t\t.filter(function() {\n\t\t\tconst translations = Tools.getTranslationValues(this);\n\n\t\t\t// threshold for when to display a gridline tooltip\n\t\t\tconst bounds = {\n\t\t\t\tmin: Number(translations.tx) - threshold,\n\t\t\t\tmax: Number(translations.tx) + threshold };\n\n\t\t\treturn bounds.min <= position[0] && position[0] <= bounds.max;\n\t\t});\n\n\t\treturn gridlinesX;\n\t}\n\n\t/**\n\t * Adds the listener on the X grid to trigger multiple point tooltips along the x axis.\n\t */\n\taddGridEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.parent;\n\t\tconst grid = DOMUtils.appendOrSelect(svg, \"rect.chart-grid-backdrop\");\n\n\t\tgrid\n\t\t.on(\"mousemove mouseover\", function() {\n\t\t\tconst chartContainer = self.services.domUtils.getMainSVG();\n\t\t\tconst pos = mouse(chartContainer);\n\t\t\tconst hoveredElement = select(this);\n\n\t\t\t// remove the styling on the lines\n\t\t\tconst allgridlines = svg.selectAll(\".x.grid .tick\");\n\t\t\tallgridlines.classed(\"active\", false);\n\n\t\t\tconst activeGridline = self.getActiveGridline(pos);\n\t\t\tif (activeGridline.empty()) {\n\t\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// set active class to control dasharray and theme colors\n\t\t\tactiveGridline\n\t\t\t.classed(\"active\", true);\n\n\t\t\t// get the items that should be highlighted\n\t\t\tlet highlightItems;\n\n\t\t\t// use the selected gridline to get the data with associated domain\n\t\t\tactiveGridline.each(function(d) {\n\t\t\t\thighlightItems = self.services.cartesianScales.getDataFromDomain(d);\n\t\t\t});\n\n\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\thoveredElement,\n\t\t\t\tmultidata: highlightItems,\n\t\t\t\ttype: TooltipTypes.GRIDLINE\n\t\t\t});\n\t\t})\n\t\t.on(\"mouseout\", function() {\n\t\t\tsvg.selectAll(\".x.grid .tick\")\n\t\t\t.classed(\"active\", false);\n\n\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE, {});\n\t\t});\n\t}\n\n\tdrawBackdrop() {\n\t\tconst svg = this.parent;\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\t// Get height from the grid\n\t\tthis.backdrop = DOMUtils.appendOrSelect(svg, \"svg.chart-grid-backdrop\");\n\t\tconst backdropRect = DOMUtils.appendOrSelect(this.backdrop, \"rect.chart-grid-backdrop\");\n\n\t\tthis.backdrop.merge(backdropRect)\n\t\t\t.attr(\"x\", xScaleStart)\n\t\t\t.attr(\"y\", yScaleStart)\n\t\t\t.attr(\"width\", xScaleEnd - xScaleStart)\n\t\t\t.attr(\"height\", yScaleEnd - yScaleStart)\n\t\t\t.lower();\n\n\t\tbackdropRect.attr(\"width\", \"100%\")\n\t\t\t.attr(\"height\", \"100%\");\n\t}\n\n\tcleanGrid(g) {\n\t\tconst options = this.model.getOptions();\n\t\tg.selectAll(\"line\")\n\t\t\t.attr(\"stroke\", options.grid.strokeColor);\n\n\t\t// Remove extra elements\n\t\tg.selectAll(\"text\").remove();\n\t\tg.select(\".domain\").remove();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"grid.js","sourceRoot":"","sources":["grid.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,aAAa;AACb,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAExD;IAA0B,wBAAS;IAAnC;QAAA,qEAgNC;QA/MA,UAAI,GAAG,MAAM,CAAC;;IA+Mf,CAAC;IA3MA,qBAAM,GAAN;QACC,oBAAoB;QACpB,IAAI,CAAC,YAAY,EAAE,CAAC;Q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AAC,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IACF,WAAC;AAAD,CAAC,AAhND,CAA0B,SAAS,GAgNlC","sourcesContent":["// Internal Imports\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { axisBottom, axisLeft } from \"d3-axis\";\nimport { mouse, select } from \"d3-selection\";\nimport { TooltipTypes, Events } from \"../../interfaces\";\n\nexport class Grid extends Component {\n\ttype = \"grid\";\n\n\tbackdrop: any;\n\n\trender() {\n\t\t// Draw the backdrop\n\t\tthis.drawBackdrop();\n\t\tDOMUtils.appendOrSelect(this.backdrop, \"g.x.grid\");\n\t\tDOMUtils.appendOrSelect(this.backdrop, \"g.y.grid\");\n\n\t\tthis.drawXGrid();\n\t\tthis.drawYGrid();\n\n\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) {\n\t\t\tthis.addGridEventListeners();\n\t\t}\n\t}\n\n\tdrawXGrid() {\n\t\tconst svg = this.parent;\n\n\t\tconst height = this.backdrop.attr(\"height\");\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst xGrid = axisBottom(mainXScale)\n\t\t\t.tickSizeInner(-height)\n\t\t\t.tickSizeOuter(0);\n\n\t\t// Determine number of ticks\n\t\tconst numberOfTicks = Tools.getProperty(this.model.getOptions(), \"grid\", \"x\", \"numberOfTicks\");\n\t\txGrid.ticks(numberOfTicks);\n\n\t\tconst g = svg.select(\".x.grid\")\n\t\t\t.attr(\"transform\", `translate(${-this.backdrop.attr(\"x\")}, ${height})`)\n\t\t\t.call(xGrid);\n\n\t\tthis.cleanGrid(g);\n\t}\n\n\tdrawYGrid() {\n\t\tconst svg = this.parent;\n\t\tconst width = this.backdrop.attr(\"width\");\n\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst yGrid = axisLeft(mainYScale)\n\t\t\t.tickSizeInner(-width)\n\t\t\t.tickSizeOuter(0);\n\n\t\t// Determine number of ticks\n\t\tconst numberOfTicks = Tools.getProperty(this.model.getOptions(), \"grid\", \"y\", \"numberOfTicks\");\n\t\tyGrid.ticks(numberOfTicks);\n\n\t\tconst g = svg.select(\".y.grid\")\n\t\t\t.attr(\"transform\", `translate(0, ${-this.backdrop.attr(\"y\")})`)\n\t\t\t.call(yGrid);\n\n\t\tthis.cleanGrid(g);\n\t}\n\n\t/**\n\t * Returns the threshold for the gridline tooltips based on the mouse location.\n\t * Calculated based on the mouse position between the two closest gridlines or edges of chart.\n\t */\n\tgetGridlineThreshold(mousePos) {\n\t\t// use the space between axis grid ticks to adjust the threshold for the tooltips\n\t\tconst svg = this.parent;\n\n\t\t// sort in ascending x translation value order\n\t\tconst gridlinesX = svg.selectAll(\".x.grid .tick\").nodes()\n\t\t.sort((a, b) => {\n\t\t\treturn Number(Tools.getTranslationValues(a).tx) - Number(Tools.getTranslationValues(b).tx);\n\t\t});\n\n\t\t// find the 2 gridlines on either side of the mouse\n\t\tlet floor = -1; let ceiling;\n\t\tgridlinesX.forEach((line: HTMLElement, i: any) => {\n\t\t\tif (mousePos[0] >= +Tools.getTranslationValues(line).tx) {\n\t\t\t\tfloor ++;\n\t\t\t}\n\t\t});\n\t\tceiling = (floor + 1 < gridlinesX.length) ? floor + 1 : gridlinesX.length;\n\n\t\t// get the 'step' between chart gridlines\n\t\tconst line1 = gridlinesX[floor];\n\t\tconst line2 = gridlinesX[ceiling];\n\t\tlet lineSpacing;\n\n\t\t// if the mouse is on edge of charts (mouseX < first gridline || mouseX > last gridline)\n\t\t// we can use the chart edge to determind the threshold for the gridlines\n\t\tif (!line1) {\n\t\t\t// we are between the first gridline and the chart edge\n\t\t\tlineSpacing = +Tools.getTranslationValues(line2).tx;\n\t\t} else if (!line2) {\n\t\t\t// we need to use the chart right bounds in case there isnt a domain axis\n\t\t\tconst gridElement = svg.select(\"rect.chart-grid-backdrop\").node();\n\t\t\tconst width = DOMUtils.getSVGElementSize(gridElement).width;\n\n\t\t\tlineSpacing = width - +Tools.getTranslationValues(line1).tx;\n\t\t} else {\n\t\t\t// there are two gridlines to use\n\t\t\tlineSpacing = +Tools.getTranslationValues(line2).tx - +Tools.getTranslationValues(line1).tx;\n\t\t}\n\t\tconst { threshold } = this.model.getOptions().tooltip.gridline;\n\t\t// return the threshold\n\t\treturn lineSpacing * threshold;\n\t}\n\n\t/**\n\t * Returns the active gridlines based on the gridline threshold and mouse position.\n\t * @param position mouse positon\n\t */\n\tgetActiveGridline(position) {\n\t\tconst userSpecifiedThreshold = Tools.getProperty(this.model.getOptions, \"tooltip\", \"gridline\", \"threshold\");\n\t\tconst threshold = userSpecifiedThreshold ? userSpecifiedThreshold : this.getGridlineThreshold(position);\n\t\tconst svg = this.parent;\n\n\t\tconst xGridlines = svg.selectAll(\".x.grid .tick\")\n\t\t.filter(function() {\n\t\t\tconst translations = Tools.getTranslationValues(this);\n\n\t\t\t// threshold for when to display a gridline tooltip\n\t\t\tconst bounds = {\n\t\t\t\tmin: Number(translations.tx) - threshold,\n\t\t\t\tmax: Number(translations.tx) + threshold\n\t\t\t};\n\n\t\t\treturn bounds.min <= position[0] && position[0] <= bounds.max;\n\t\t});\n\n\t\treturn xGridlines;\n\t}\n\n\t/**\n\t * Adds the listener on the X grid to trigger multiple point tooltips along the x axis.\n\t */\n\taddGridEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.parent;\n\t\tconst grid = DOMUtils.appendOrSelect(svg, \"rect.chart-grid-backdrop\");\n\n\t\tgrid.on(\"mousemove mouseover\", function() {\n\t\t\tconst chartContainer = self.services.domUtils.getMainSVG();\n\t\t\tconst pos = mouse(chartContainer);\n\t\t\tconst hoveredElement = select(this);\n\n\t\t\t// remove the styling on the lines\n\t\t\tconst allgridlines = svg.selectAll(\".x.grid .tick\");\n\t\t\tallgridlines.classed(\"active\", false);\n\n\t\t\tconst activeGridline = self.getActiveGridline(pos);\n\t\t\tif (activeGridline.empty()) {\n\t\t\t\treturn self.services.events.dispatchEvent(Events.Tooltip.HIDE);\n\t\t\t}\n\n\t\t\t// set active class to control dasharray and theme colors\n\t\t\tactiveGridline.classed(\"active\", true);\n\n\t\t\t// get the items that should be highlighted\n\t\t\tconst itemsToHighlight = self.services.cartesianScales.getDataFromDomain(activeGridline.datum());\n\n\t\t\tself.services.events.dispatchEvent(Events.Tooltip.SHOW, {\n\t\t\t\thoveredElement,\n\t\t\t\tmultidata: itemsToHighlight,\n\t\t\t\ttype: TooltipTypes.GRIDLINE\n\t\t\t});\n\t\t})\n\t\t.on(\"mouseout\", function() {\n\t\t\tsvg.selectAll(\".x.grid .tick\")\n\t\t\t\t.classed(\"active\", false);\n\n\t\t\tself.services.events.dispatchEvent(Events.Tooltip.HIDE);\n\t\t});\n\t}\n\n\tdrawBackdrop() {\n\t\tconst svg = this.parent;\n\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\t// Get height from the grid\n\t\tthis.backdrop = DOMUtils.appendOrSelect(svg, \"svg.chart-grid-backdrop\");\n\t\tconst backdropRect = DOMUtils.appendOrSelect(this.backdrop, \"rect.chart-grid-backdrop\");\n\n\t\tthis.backdrop.merge(backdropRect)\n\t\t\t.attr(\"x\", xScaleStart)\n\t\t\t.attr(\"y\", yScaleStart)\n\t\t\t.attr(\"width\", xScaleEnd - xScaleStart)\n\t\t\t.attr(\"height\", yScaleEnd - yScaleStart)\n\t\t\t.lower();\n\n\t\tbackdropRect.attr(\"width\", \"100%\")\n\t\t\t.attr(\"height\", \"100%\");\n\t}\n\n\tcleanGrid(g) {\n\t\tconst options = this.model.getOptions();\n\t\tg.selectAll(\"line\")\n\t\t\t.attr(\"stroke\", options.grid.strokeColor);\n\n\t\t// Remove extra elements\n\t\tg.selectAll(\"text\").remove();\n\t\tg.select(\".domain\").remove();\n\t}\n}\n"]}
|
|
@@ -29,7 +29,8 @@ var Legend = /** @class */ (function (_super) {
|
|
|
29
29
|
var svg = this.getContainerSVG().attr("role", Roles.GRAPHICS_DOCUMENT);
|
|
30
30
|
var options = this.model.getOptions();
|
|
31
31
|
var legendItems = svg.selectAll("g.legend-item")
|
|
32
|
-
.data(this.
|
|
32
|
+
.data(this.model.getDataGroups(), function (dataGroup) { return dataGroup.name; });
|
|
33
|
+
// this.getLegendItemArray()
|
|
33
34
|
var addedLegendItems = legendItems.enter()
|
|
34
35
|
.append("g")
|
|
35
36
|
.classed("legend-item", true);
|
|
@@ -43,13 +44,13 @@ var Legend = /** @class */ (function (_super) {
|
|
|
43
44
|
.attr("rx", 1)
|
|
44
45
|
.attr("ry", 1)
|
|
45
46
|
.style("fill", function (d) {
|
|
46
|
-
return d.
|
|
47
|
+
return d.status === options.legend.items.status.ACTIVE ? _this.model.getStrokeColor(d.name) : null;
|
|
47
48
|
}).classed("active", function (d, i) {
|
|
48
|
-
return d.
|
|
49
|
+
return d.status === options.legend.items.status.ACTIVE;
|
|
49
50
|
});
|
|
50
51
|
addedLegendItems.append("text")
|
|
51
52
|
.merge(legendItems.select("text"))
|
|
52
|
-
.text(function (d) { return d.
|
|
53
|
+
.text(function (d) { return d.name; })
|
|
53
54
|
.attr("alignment-baseline", "middle");
|
|
54
55
|
this.breakItemsIntoLines(addedLegendItems);
|
|
55
56
|
// Remove old elements as needed.
|
|
@@ -76,8 +77,8 @@ var Legend = /** @class */ (function (_super) {
|
|
|
76
77
|
var spaceNeededForCheckbox = (checkboxRadius * 2) + options.legend.checkbox.spaceAfter;
|
|
77
78
|
// Check if there are disabled legend items
|
|
78
79
|
var DISABLED = options.legend.items.status.DISABLED;
|
|
79
|
-
var
|
|
80
|
-
var hasDeactivatedItems =
|
|
80
|
+
var dataGroups = this.model.getDataGroups();
|
|
81
|
+
var hasDeactivatedItems = dataGroups.some(function (dataGroup) { return dataGroup.status === DISABLED; });
|
|
81
82
|
var legendOrientation = Tools.getProperty(options, "legend", "orientation");
|
|
82
83
|
// Keep track of line numbers and positions
|
|
83
84
|
var startingPoint = 0;
|
|
@@ -133,21 +134,6 @@ var Legend = /** @class */ (function (_super) {
|
|
|
133
134
|
}
|
|
134
135
|
itemIndexInLine++;
|
|
135
136
|
});
|
|
136
|
-
// TODO - Replace with layout component margins
|
|
137
|
-
DOMUtils.appendOrSelect(svg, "rect.spacer")
|
|
138
|
-
.attr("x", 0)
|
|
139
|
-
.attr("y", lastYPosition)
|
|
140
|
-
.attr("width", 16)
|
|
141
|
-
.attr("height", 16)
|
|
142
|
-
.attr("fill", "none");
|
|
143
|
-
};
|
|
144
|
-
Legend.prototype.getLegendItemArray = function () {
|
|
145
|
-
var legendItems = this.model.get("dataLabels");
|
|
146
|
-
var legendItemKeys = Object.keys(legendItems);
|
|
147
|
-
return legendItemKeys.map(function (key) { return ({
|
|
148
|
-
key: key,
|
|
149
|
-
value: legendItems[key]
|
|
150
|
-
}); });
|
|
151
137
|
};
|
|
152
138
|
Legend.prototype.addEventListeners = function () {
|
|
153
139
|
var self = this;
|
|
@@ -177,7 +163,7 @@ var Legend = /** @class */ (function (_super) {
|
|
|
177
163
|
});
|
|
178
164
|
var clickedItem = select(this);
|
|
179
165
|
var clickedItemData = clickedItem.datum();
|
|
180
|
-
self.model.toggleDataLabel(clickedItemData.
|
|
166
|
+
self.model.toggleDataLabel(clickedItemData.name);
|
|
181
167
|
})
|
|
182
168
|
.on("mouseout", function () {
|
|
183
169
|
var hoveredItem = select(this);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.js","sourceRoot":"","sources":["legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACN,kBAAkB,EAClB,KAAK,EACL,MAAM,EACN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,E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ACL,CAAC;IACF,aAAC;AAAD,CAAC,AA7MD,CAA4B,SAAS,GA6MpC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport {\n\tLegendOrientations,\n\tRoles,\n\tEvents\n} from \"../../interfaces\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class Legend extends Component {\n\ttype = \"legend\";\n\n\trender() {\n\t\tconst svg = this.getContainerSVG().attr(\"role\", Roles.GRAPHICS_DOCUMENT);\n\t\tconst options = this.model.getOptions();\n\n\t\tconst legendItems = svg.selectAll(\"g.legend-item\")\n\t\t\t.data(this.getLegendItemArray());\n\n\t\tconst addedLegendItems = legendItems.enter()\n\t\t\t.append(\"g\")\n\t\t\t.classed(\"legend-item\", true);\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\taddedLegendItems.append(\"rect\")\n\t\t\t.classed(\"checkbox\", true)\n\t\t\t.merge(legendItems.select(\"rect.checkbox\"))\n\t\t\t.attr(\"width\", checkboxRadius * 2)\n\t\t\t.attr(\"height\", checkboxRadius * 2)\n\t\t\t.attr(\"rx\", 1)\n\t\t\t.attr(\"ry\", 1)\n\t\t\t.style(\"fill\", d => {\n\t\t\t\treturn d.value === options.legend.items.status.ACTIVE ? this.model.getStrokeColor(d.key) : null;\n\t\t\t}).classed(\"active\", function (d, i) {\n\t\t\t\treturn d.value === options.legend.items.status.ACTIVE;\n\t\t\t});\n\n\t\taddedLegendItems.append(\"text\")\n\t\t\t.merge(legendItems.select(\"text\"))\n\t\t\t.text(d => d.key)\n\t\t\t.attr(\"alignment-baseline\", \"middle\");\n\n\t\tthis.breakItemsIntoLines(addedLegendItems);\n\n\t\t// Remove old elements as needed.\n\t\tlegendItems.exit()\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"click\", null)\n\t\t\t.on(\"mouseout\", null)\n\t\t\t.remove();\n\n\t\tconst legendClickable = Tools.getProperty(this.model.getOptions(), \"legend\", \"clickable\");\n\t\tsvg.classed(\"clickable\", legendClickable);\n\n\t\tif (legendClickable && addedLegendItems.size() > 0) {\n\t\t\tthis.addEventListeners();\n\t\t}\n\t}\n\n\tbreakItemsIntoLines(addedLegendItems) {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\t\tconst legendItemsHorizontalSpacing = options.legend.items.horizontalSpace;\n\t\tconst legendItemsVerticalSpacing = options.legend.items.verticalSpace;\n\t\tconst legendTextYOffset = options.legend.items.textYOffset;\n\t\tconst spaceNeededForCheckbox = (checkboxRadius * 2) + options.legend.checkbox.spaceAfter;\n\n\t\t// Check if there are disabled legend items\n\t\tconst { DISABLED } = options.legend.items.status;\n\t\tconst dataLabels = this.model.get(\"dataLabels\");\n\t\tconst hasDeactivatedItems = Object.keys(dataLabels).some(label => dataLabels[label] === DISABLED);\n\n\t\tconst legendOrientation = Tools.getProperty(options, \"legend\", \"orientation\");\n\n\t\t// Keep track of line numbers and positions\n\t\tlet startingPoint = 0;\n\t\tlet lineNumber = 0;\n\t\tlet itemIndexInLine = 0;\n\t\tlet lastYPosition;\n\t\taddedLegendItems.merge(svg.selectAll(\"g.legend-item\"))\n\t\t\t.each(function (d, i) {\n\t\t\t\tconst legendItem = select(this);\n\t\t\t\tconst previousLegendItem = select(svg.selectAll(\"g.legend-item\").nodes()[i - 1]);\n\n\t\t\t\tif (itemIndexInLine === 0 || previousLegendItem.empty() || legendOrientation === LegendOrientations.VERTICAL) {\n\t\t\t\t\tif (legendOrientation === LegendOrientations.VERTICAL && i !== 0) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst svgDimensions = DOMUtils.getSVGElementSize(self.parent, { useAttr: true });\n\t\t\t\t\tconst legendItemTextDimensions = DOMUtils.getSVGElementSize(select(this).select(\"text\"), { useBBox: true });\n\t\t\t\t\tconst lastLegendItemTextDimensions = DOMUtils.getSVGElementSize(previousLegendItem.select(\"text\"), { useBBox: true });\n\t\t\t\t\tstartingPoint = startingPoint + lastLegendItemTextDimensions.width + spaceNeededForCheckbox + legendItemsHorizontalSpacing;\n\n\t\t\t\t\tif (startingPoint + spaceNeededForCheckbox + legendItemTextDimensions.width > svgDimensions.width) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t\tstartingPoint = 0;\n\t\t\t\t\t\titemIndexInLine = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst yOffset = 0;\n\n\t\t\t\t// Position checkbox\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tlegendItem.select(\"rect.checkbox\")\n\t\t\t\t\t.attr(\"x\", startingPoint)\n\t\t\t\t\t.attr(\"y\", yOffset + lineNumber * legendItemsVerticalSpacing);\n\n\t\t\t\t// Position text\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tconst yPosition = legendTextYOffset + (lineNumber * legendItemsVerticalSpacing);\n\t\t\t\tlegendItem.select(\"text\")\n\t\t\t\t\t.attr(\"x\", startingPoint + spaceNeededForCheckbox)\n\t\t\t\t\t.attr(\"y\", yOffset + yPosition);\n\n\t\t\t\tlastYPosition = yPosition;\n\n\t\t\t\t// Render checkbox check icon\n\t\t\t\tif (hasDeactivatedItems && legendItem.select(\"g.check\").empty()) {\n\t\t\t\t\tlegendItem.append(\"g\")\n\t\t\t\t\t\t.classed(\"check\", true)\n\t\t\t\t\t\t.html(`\n\t\t\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 32 32\" aria-hidden=\"true\"\n\t\t\t\t\t\t\t\tstyle=\"will-change: transform;\">\n\t\t\t\t\t\t\t\t<path d=\"M13 21.2l-7.1-7.1-1.4 1.4 7.1 7.1L13 24 27.1 9.9l-1.4-1.5z\"></path>\n\t\t\t\t\t\t\t\t<title>Checkmark</title>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t`);\n\n\t\t\t\t\tlegendItem.select(\"g.check svg\")\n\t\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"x\", parseFloat(legendItem.select(\"rect.checkbox\").attr(\"x\")) + 0.5)\n\t\t\t\t\t\t.attr(\"y\", parseFloat(legendItem.select(\"rect.checkbox\").attr(\"y\")) + 0.5);\n\n\t\t\t\t} else if (!hasDeactivatedItems && !legendItem.select(\"g.check\").empty()) {\n\t\t\t\t\tlegendItem.select(\"g.check\").remove();\n\t\t\t\t}\n\n\t\t\t\titemIndexInLine++;\n\t\t\t});\n\n\t\t// TODO - Replace with layout component margins\n\t\tDOMUtils.appendOrSelect(svg, \"rect.spacer\")\n\t\t\t.attr(\"x\", 0)\n\t\t\t.attr(\"y\", lastYPosition)\n\t\t\t.attr(\"width\", 16)\n\t\t\t.attr(\"height\", 16)\n\t\t\t.attr(\"fill\", \"none\");\n\t}\n\n\tgetLegendItemArray() {\n\t\tconst legendItems = this.model.get(\"dataLabels\");\n\t\tconst legendItemKeys = Object.keys(legendItems);\n\n\t\treturn legendItemKeys.map(key => ({\n\t\t\tkey,\n\t\t\tvalue: legendItems[key]\n\t\t}));\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\tsvg.selectAll(\"g.legend-item\")\n\t\t\t.on(\"mouseover\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_HOVER, {\n\t\t\t\t\thoveredElement: select(this)\n\t\t\t\t});\n\n\t\t\t\t// Configs\n\t\t\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.append(\"rect\")\n\t\t\t\t\t.classed(\"hover-stroke\", true)\n\t\t\t\t\t.attr(\"x\", parseFloat(hoveredItem.select(\"rect.checkbox\").attr(\"x\")) - 2)\n\t\t\t\t\t.attr(\"y\", parseFloat(hoveredItem.select(\"rect.checkbox\").attr(\"y\")) - 2)\n\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"rx\", 3)\n\t\t\t\t\t.attr(\"ry\", 3)\n\t\t\t\t\t.lower();\n\t\t\t})\n\t\t\t.on(\"click\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_CLICK, {\n\t\t\t\t\tclickedElement: select(this)\n\t\t\t\t});\n\n\t\t\t\tconst clickedItem = select(this);\n\t\t\t\tconst clickedItemData = clickedItem.datum() as any;\n\n\t\t\t\tself.model.toggleDataLabel(clickedItemData.key);\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.select(\"rect.hover-stroke\").remove();\n\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_MOUSEOUT, {\n\t\t\t\t\thoveredElement: hoveredItem\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"legend.js","sourceRoot":"","sources":["legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACN,kBAAkB,EAClB,KAAK,EACL,MAAM,EACN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AA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,CAAC;aAC5B,CAAC,CAAC;YAEH,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,IAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAS,CAAC;YAEnD,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;YAEjD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;gBAC/D,cAAc,EAAE,WAAW;aAC3B,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACF,aAAC;AAAD,CAAC,AA5LD,CAA4B,SAAS,GA4LpC","sourcesContent":["// Internal Imports\nimport * as Configuration from \"../../configuration\";\nimport { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport {\n\tLegendOrientations,\n\tRoles,\n\tEvents\n} from \"../../interfaces\";\nimport { DOMUtils } from \"../../services\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class Legend extends Component {\n\ttype = \"legend\";\n\n\trender() {\n\t\tconst svg = this.getContainerSVG().attr(\"role\", Roles.GRAPHICS_DOCUMENT);\n\t\tconst options = this.model.getOptions();\n\t\tconst legendItems = svg.selectAll(\"g.legend-item\")\n\t\t\t.data(this.model.getDataGroups(), dataGroup => dataGroup.name);\n\n\t\t\t// this.getLegendItemArray()\n\n\t\tconst addedLegendItems = legendItems.enter()\n\t\t\t.append(\"g\")\n\t\t\t.classed(\"legend-item\", true);\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\taddedLegendItems.append(\"rect\")\n\t\t\t.classed(\"checkbox\", true)\n\t\t\t.merge(legendItems.select(\"rect.checkbox\"))\n\t\t\t.attr(\"width\", checkboxRadius * 2)\n\t\t\t.attr(\"height\", checkboxRadius * 2)\n\t\t\t.attr(\"rx\", 1)\n\t\t\t.attr(\"ry\", 1)\n\t\t\t.style(\"fill\", d => {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE ? this.model.getStrokeColor(d.name) : null;\n\t\t\t}).classed(\"active\", function (d, i) {\n\t\t\t\treturn d.status === options.legend.items.status.ACTIVE;\n\t\t\t});\n\n\t\taddedLegendItems.append(\"text\")\n\t\t\t.merge(legendItems.select(\"text\"))\n\t\t\t.text(d => d.name)\n\t\t\t.attr(\"alignment-baseline\", \"middle\");\n\n\t\tthis.breakItemsIntoLines(addedLegendItems);\n\n\t\t// Remove old elements as needed.\n\t\tlegendItems.exit()\n\t\t\t.on(\"mouseover\", null)\n\t\t\t.on(\"click\", null)\n\t\t\t.on(\"mouseout\", null)\n\t\t\t.remove();\n\n\t\tconst legendClickable = Tools.getProperty(this.model.getOptions(), \"legend\", \"clickable\");\n\t\tsvg.classed(\"clickable\", legendClickable);\n\n\t\tif (legendClickable && addedLegendItems.size() > 0) {\n\t\t\tthis.addEventListeners();\n\t\t}\n\t}\n\n\tbreakItemsIntoLines(addedLegendItems) {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\t// Configs\n\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\t\tconst legendItemsHorizontalSpacing = options.legend.items.horizontalSpace;\n\t\tconst legendItemsVerticalSpacing = options.legend.items.verticalSpace;\n\t\tconst legendTextYOffset = options.legend.items.textYOffset;\n\t\tconst spaceNeededForCheckbox = (checkboxRadius * 2) + options.legend.checkbox.spaceAfter;\n\n\t\t// Check if there are disabled legend items\n\t\tconst { DISABLED } = options.legend.items.status;\n\t\tconst dataGroups = this.model.getDataGroups();\n\t\tconst hasDeactivatedItems = dataGroups.some(dataGroup => dataGroup.status === DISABLED);\n\n\t\tconst legendOrientation = Tools.getProperty(options, \"legend\", \"orientation\");\n\n\t\t// Keep track of line numbers and positions\n\t\tlet startingPoint = 0;\n\t\tlet lineNumber = 0;\n\t\tlet itemIndexInLine = 0;\n\t\tlet lastYPosition;\n\t\taddedLegendItems.merge(svg.selectAll(\"g.legend-item\"))\n\t\t\t.each(function (d, i) {\n\t\t\t\tconst legendItem = select(this);\n\t\t\t\tconst previousLegendItem = select(svg.selectAll(\"g.legend-item\").nodes()[i - 1]);\n\n\t\t\t\tif (itemIndexInLine === 0 || previousLegendItem.empty() || legendOrientation === LegendOrientations.VERTICAL) {\n\t\t\t\t\tif (legendOrientation === LegendOrientations.VERTICAL && i !== 0) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst svgDimensions = DOMUtils.getSVGElementSize(self.parent, { useAttr: true });\n\t\t\t\t\tconst legendItemTextDimensions = DOMUtils.getSVGElementSize(select(this).select(\"text\"), { useBBox: true });\n\t\t\t\t\tconst lastLegendItemTextDimensions = DOMUtils.getSVGElementSize(previousLegendItem.select(\"text\"), { useBBox: true });\n\t\t\t\t\tstartingPoint = startingPoint + lastLegendItemTextDimensions.width + spaceNeededForCheckbox + legendItemsHorizontalSpacing;\n\n\t\t\t\t\tif (startingPoint + spaceNeededForCheckbox + legendItemTextDimensions.width > svgDimensions.width) {\n\t\t\t\t\t\tlineNumber++;\n\t\t\t\t\t\tstartingPoint = 0;\n\t\t\t\t\t\titemIndexInLine = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst yOffset = 0;\n\n\t\t\t\t// Position checkbox\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tlegendItem.select(\"rect.checkbox\")\n\t\t\t\t\t.attr(\"x\", startingPoint)\n\t\t\t\t\t.attr(\"y\", yOffset + lineNumber * legendItemsVerticalSpacing);\n\n\t\t\t\t// Position text\n\t\t\t\t// TODO - Replace with layout component margins\n\t\t\t\tconst yPosition = legendTextYOffset + (lineNumber * legendItemsVerticalSpacing);\n\t\t\t\tlegendItem.select(\"text\")\n\t\t\t\t\t.attr(\"x\", startingPoint + spaceNeededForCheckbox)\n\t\t\t\t\t.attr(\"y\", yOffset + yPosition);\n\n\t\t\t\tlastYPosition = yPosition;\n\n\t\t\t\t// Render checkbox check icon\n\t\t\t\tif (hasDeactivatedItems && legendItem.select(\"g.check\").empty()) {\n\t\t\t\t\tlegendItem.append(\"g\")\n\t\t\t\t\t\t.classed(\"check\", true)\n\t\t\t\t\t\t.html(`\n\t\t\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 32 32\" aria-hidden=\"true\"\n\t\t\t\t\t\t\t\tstyle=\"will-change: transform;\">\n\t\t\t\t\t\t\t\t<path d=\"M13 21.2l-7.1-7.1-1.4 1.4 7.1 7.1L13 24 27.1 9.9l-1.4-1.5z\"></path>\n\t\t\t\t\t\t\t\t<title>Checkmark</title>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t`);\n\n\t\t\t\t\tlegendItem.select(\"g.check svg\")\n\t\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 - 1)\n\t\t\t\t\t\t.attr(\"x\", parseFloat(legendItem.select(\"rect.checkbox\").attr(\"x\")) + 0.5)\n\t\t\t\t\t\t.attr(\"y\", parseFloat(legendItem.select(\"rect.checkbox\").attr(\"y\")) + 0.5);\n\n\t\t\t\t} else if (!hasDeactivatedItems && !legendItem.select(\"g.check\").empty()) {\n\t\t\t\t\tlegendItem.select(\"g.check\").remove();\n\t\t\t\t}\n\n\t\t\t\titemIndexInLine++;\n\t\t\t});\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.model.getOptions();\n\n\t\tsvg.selectAll(\"g.legend-item\")\n\t\t\t.on(\"mouseover\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_HOVER, {\n\t\t\t\t\thoveredElement: select(this)\n\t\t\t\t});\n\n\t\t\t\t// Configs\n\t\t\t\tconst checkboxRadius = options.legend.checkbox.radius;\n\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.append(\"rect\")\n\t\t\t\t\t.classed(\"hover-stroke\", true)\n\t\t\t\t\t.attr(\"x\", parseFloat(hoveredItem.select(\"rect.checkbox\").attr(\"x\")) - 2)\n\t\t\t\t\t.attr(\"y\", parseFloat(hoveredItem.select(\"rect.checkbox\").attr(\"y\")) - 2)\n\t\t\t\t\t.attr(\"width\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"height\", checkboxRadius * 2 + 4)\n\t\t\t\t\t.attr(\"rx\", 3)\n\t\t\t\t\t.attr(\"ry\", 3)\n\t\t\t\t\t.lower();\n\t\t\t})\n\t\t\t.on(\"click\", function () {\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_CLICK, {\n\t\t\t\t\tclickedElement: select(this)\n\t\t\t\t});\n\n\t\t\t\tconst clickedItem = select(this);\n\t\t\t\tconst clickedItemData = clickedItem.datum() as any;\n\n\t\t\t\tself.model.toggleDataLabel(clickedItemData.name);\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tconst hoveredItem = select(this);\n\t\t\t\thoveredItem.select(\"rect.hover-stroke\").remove();\n\n\t\t\t\tself.services.events.dispatchEvent(Events.Legend.ITEM_MOUSEOUT, {\n\t\t\t\t\thoveredElement: hoveredItem\n\t\t\t\t});\n\t\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;
|
|
@@ -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 ver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CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;oBAChG,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAEvG,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1F,OAAO,0GAGwB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AA3JD,CAAgC,OAAO,GA2JtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/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\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\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C,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACjF,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEnF,OAAQ,4BAA4B;YACnC,MAAM,CAAC,GAAG,CAAC,UAAA,SAAS;gBACnB,IAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;oBAChG,KAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAEvG,2GAA2G;gBAC3G,IAAM,cAAc,GAAG,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1F,OAAO,0GAGwB,cAAc,wEACxB,SAAS,CAAC,YAAY,6CACtB,cAAc,0CAE7B,CAAC;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;aACV,mHAGqB,KAAK,uDAGrB,CAAA,CAAC;IACT,CAAC;IACF,iBAAC;AAAD,CAAC,AAnKD,CAAgC,OAAO,GAmKtC","sourcesContent":["import { Tooltip } from \"./tooltip\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { TooltipPosition, TooltipTypes, CartesianOrientations } from \"./../../interfaces/enums\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\n\n// D3 Imports\nimport { select } from \"d3-selection\";\n\nexport class TooltipBar extends Tooltip {\n\tinit() {\n\t\t// Grab the tooltip element\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\tconst chartprefix = Tools.getProperty(this.model.getOptions(), \"style\", \"prefix\");\n\t\tthis.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);\n\n\t\t// Apply html content to the tooltip\n\t\tconst tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, \"div.content-box\");\n\t\tthis.tooltip.style(\"max-width\", null);\n\n\t\t// listen to show-tooltip Custom Events to render the tooltip\n\t\tthis.services.events.addEventListener(\"show-tooltip\", e => {\n\t\t\t// check the type of tooltip and that it is enabled\n\t\t\tif ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"datapoint\", \"enabled\"))\n\t\t\t\t|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), \"tooltip\", \"gridline\", \"enabled\")) ) {\n\n\t\t\t\tlet data = e.detail.hoveredElement.datum() as any;\n\t\t\t\tconst hoveredElement = e.detail.hoveredElement.node();\n\n\t\t\t\tlet defaultHTML;\n\t\t\t\tif (e.detail.multidata) {\n\t\t\t\t\t// multi tooltip\n\t\t\t\t\tdata = e.detail.multidata;\n\t\t\t\t\tdefaultHTML = this.getMultilineTooltipHTML(data);\n\t\t\t\t} else {\n\t\t\t\t\tif (e.detail.data) {\n\t\t\t\t\t\tdata = e.detail.data;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdata = e.detail.hoveredElement.datum();\n\t\t\t\t\t}\n\n\t\t\t\t\tdefaultHTML = this.getTooltipHTML(data);\n\t\t\t\t}\n\n\t\t\t\t// if there is a provided tooltip HTML function call it and pass the defaultHTML\n\t\t\t\tif (Tools.getProperty(this.model.getOptions(), \"tooltip\", \"customHTML\")) {\n\t\t\t\t\ttooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data, defaultHTML));\n\t\t\t\t} else {\n\t\t\t\t\t// default tooltip\n\t\t\t\t\ttooltipTextContainer.html(defaultHTML);\n\t\t\t\t}\n\n\t\t\t\tconst position = this.getTooltipPosition(hoveredElement, data);\n\t\t\t\t// Position the tooltip relative to the bars\n\t\t\t\tthis.positionTooltip(e.detail.multidata ? undefined : position );\n\n\t\t\t} else if (e.detail.type === TooltipTypes.TITLE) {\n\t\t\t\t// use the chart size to enforce a max width on the tooltip\n\t\t\t\tconst chart = DOMUtils.appendOrSelect(holder, `svg.${settings.prefix}--${chartprefix}--chart-svg`);\n\t\t\t\t// use the configs to determine how large the tooltip should be\n\t\t\t\tconst tooltipMax = DOMUtils.getSVGElementSize(chart).width * Tools.getProperty(this.model.getOptions(), \"tooltip\", \"title\", \"width\");\n\t\t\t\tthis.tooltip.style(\"max-width\", tooltipMax);\n\n\t\t\t\t// use tooltip.ts to get the tooltip html for titles\n\t\t\t\ttooltipTextContainer.html(super.getTooltipHTML(e.detail.hoveredElement, TooltipTypes.TITLE));\n\n\t\t\t\t// get the position based on the title positioning (static)\n\t\t\t\tconst position = super.getTooltipPosition(e.detail.hoveredElement.node());\n\t\t\t\tthis.positionTooltip(position);\n\t\t\t}\n\n\t\t\t// Fade in\n\t\t\tthis.tooltip.classed(\"hidden\", false);\n\t\t});\n\n\t\t// listen to hide-tooltip Custom Events to hide the tooltip\n\t\tthis.services.events.addEventListener(\"hide-tooltip\", () => {\n\t\t\tthis.tooltip.classed(\"hidden\", true);\n\t\t});\n\t}\n\n\t/**\n\t * Get the position of the tooltip relative to the active hovered bar. Tooltip should appear above\n\t * positive valued data and below negative value data.\n\t * @param hoveredElement\n\t */\n\tgetTooltipPosition(hoveredElement, data?: any) {\n\t\tif (data === undefined) {\n\t\t\tdata = select(hoveredElement).datum() as any;\n\t\t}\n\n\t\tconst holderPosition = select(this.services.domUtils.getHolder()).node().getBoundingClientRect();\n\t\tconst barPosition = hoveredElement.getBoundingClientRect();\n\n\t\tconst { verticalOffset } = this.model.getOptions().tooltip.datapoint;\n\t\t// if there is a negative value bar chart, need to place the tooltip below the bar\n\t\tif (data.value <= 0) {\n\t\t\t// negative bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.bottom - holderPosition.top) + verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.BOTTOM, position: tooltipPos};\n\t\t} else {\n\t\t\t// positive bars\n\t\t\tconst tooltipPos = {\n\t\t\t\tleft: (barPosition.left - holderPosition.left) + barPosition.width / 2,\n\t\t\t\ttop: (barPosition.top - holderPosition.top) - verticalOffset\n\t\t\t};\n\n\t\t\treturn {placement: TooltipPosition.TOP, position: tooltipPos};\n\t\t}\n\t}\n\n\t/**\n\t * Returns the html for the bar single point tooltip\n\t * @param data associated values for the hovered bar\n\t */\n\tgetTooltipHTML(data: any) {\n\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(data.value) : data.value.toLocaleString(\"en\");\n\n\t\treturn `<div class=\"datapoint-tooltip\"><p class=\"value\">${formattedValue}</p></div>`;\n\t}\n\n\t/**\n\t * Multip tooltips for bar charts include totals for each stack\n\t * @param data\n\t */\n\tgetMultilineTooltipHTML(data: any) {\n\t\tconst points = data;\n\n\t\tpoints.reverse();\n\t\t// in a vertical bar chart the tooltip should display in order of the drawn bars\n\t\t// in horizontal stacked bar, the order of the segments from Left to Right are displayed top down in tooltip\n\t\tif (this.services.cartesianScales.getOrientation() === CartesianOrientations.VERTICAL) {\n\t\t\tpoints.reverse();\n\t\t}\n\n\t\t// get the total for the stacked tooltip\n\t\tlet total = points.reduce((sum, item) => sum + item.value, 0);\n\n\t\t// format the total value\n\t\ttotal = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\tthis.model.getOptions().tooltip.valueFormatter(total) : total.toLocaleString(\"en\");\n\n\t\treturn \"<ul class='multi-tooltip'>\" +\n\t\t\tpoints.map(datapoint => {\n\t\t\t\tconst formattedValue = Tools.getProperty(this.model.getOptions(), \"tooltip\", \"valueFormatter\") ?\n\t\t\t\tthis.model.getOptions().tooltip.valueFormatter(datapoint.value) : datapoint.value.toLocaleString(\"en\");\n\n\t\t\t\t// For the tooltip color, we always want the normal stroke color, not dynamically determined by data value.\n\t\t\t\tconst indicatorColor = this.model.getStrokeColor(datapoint.datasetLabel, datapoint.label);\n\n\t\t\t\treturn `\n\t\t\t\t<li>\n\t\t\t\t\t<div class=\"datapoint-tooltip\">\n\t\t\t\t\t\t<a style=\"background-color:${indicatorColor}\" class=\"tooltip-color\"></a>\n\t\t\t\t\t\t<p class=\"label\">${datapoint.datasetLabel}</p>\n\t\t\t\t\t\t<p class=\"value\">${formattedValue}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>`;\n\t\t\t}).join(\"\") +\n\t\t\t\t`<li>\n\t\t\t\t\t<div class='total-val'>\n\t\t\t\t\t\t<p class='label'>Total</p>\n\t\t\t\t\t\t<p class='value'>${total}</p>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t</ul>`;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,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
|