@carbon/charts 0.41.20 → 0.41.24
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 +28 -46
- package/axis-chart.d.ts +4 -4
- package/axis-chart.js +46 -46
- package/axis-chart.js.map +1 -1
- package/build/demo/create-codesandbox.d.ts +42 -42
- package/build/demo/data/bar.d.ts +2 -2
- package/build/demo/data/index.d.ts +13 -13
- package/build/demo/data/line.d.ts +4 -4
- package/build/demo/data/meter.d.ts +1 -1
- package/build/src/axis-chart.d.ts +4 -4
- package/build/src/chart.d.ts +3 -3
- package/build/src/charts/area-stacked.d.ts +2 -2
- package/build/src/charts/area.d.ts +2 -2
- package/build/src/charts/bar-grouped.d.ts +2 -2
- package/build/src/charts/bar-simple.d.ts +2 -2
- package/build/src/charts/bar-stacked.d.ts +2 -2
- package/build/src/charts/bubble.d.ts +2 -2
- package/build/src/charts/combo.d.ts +2 -2
- package/build/src/charts/donut.d.ts +2 -2
- package/build/src/charts/gauge.d.ts +3 -3
- package/build/src/charts/index.d.ts +16 -16
- package/build/src/charts/line.d.ts +2 -2
- package/build/src/charts/lollipop.d.ts +2 -2
- package/build/src/charts/meter.d.ts +3 -3
- package/build/src/charts/pie.d.ts +3 -3
- package/build/src/charts/radar.d.ts +2 -2
- package/build/src/charts/scatter.d.ts +2 -2
- package/build/src/charts/treemap.d.ts +2 -2
- package/build/src/components/axes/axis.d.ts +3 -3
- package/build/src/components/axes/chart-clip.d.ts +2 -2
- package/build/src/components/axes/grid-brush.d.ts +1 -1
- package/build/src/components/axes/grid.d.ts +1 -1
- package/build/src/components/axes/ruler-stacked.d.ts +1 -1
- package/build/src/components/axes/ruler.d.ts +2 -2
- package/build/src/components/axes/toolbar.d.ts +2 -2
- package/build/src/components/axes/two-dimensional-axes.d.ts +2 -2
- package/build/src/components/axes/zero-line.d.ts +1 -1
- package/build/src/components/axes/zoom-bar.d.ts +2 -2
- package/build/src/components/component.d.ts +1 -1
- package/build/src/components/essentials/legend.d.ts +1 -1
- package/build/src/components/essentials/threshold.d.ts +3 -3
- package/build/src/components/essentials/title-meter.d.ts +1 -1
- package/build/src/components/essentials/title.d.ts +1 -1
- package/build/src/components/essentials/tooltip-axis.d.ts +1 -1
- package/build/src/components/essentials/tooltip.d.ts +3 -3
- package/build/src/components/graphs/area-stacked.d.ts +1 -1
- package/build/src/components/graphs/area.d.ts +1 -1
- package/build/src/components/graphs/bar-grouped.d.ts +2 -2
- package/build/src/components/graphs/bar-simple.d.ts +1 -1
- package/build/src/components/graphs/bar-stacked.d.ts +1 -1
- package/build/src/components/graphs/bar.d.ts +1 -1
- package/build/src/components/graphs/bubble.d.ts +2 -2
- package/build/src/components/graphs/donut.d.ts +1 -1
- package/build/src/components/graphs/gauge.d.ts +1 -1
- package/build/src/components/graphs/line.d.ts +1 -1
- package/build/src/components/graphs/lollipop.d.ts +1 -1
- package/build/src/components/graphs/meter.d.ts +1 -1
- package/build/src/components/graphs/pie.d.ts +1 -1
- package/build/src/components/graphs/radar.d.ts +1 -1
- package/build/src/components/graphs/scatter-stacked.d.ts +1 -1
- package/build/src/components/graphs/scatter.d.ts +2 -2
- package/build/src/components/graphs/skeleton-lines.d.ts +1 -1
- package/build/src/components/graphs/skeleton.d.ts +1 -1
- package/build/src/components/graphs/treemap.d.ts +1 -1
- package/build/src/components/index.d.ts +36 -36
- package/build/src/components/layout/layout.d.ts +3 -3
- package/build/src/components/layout/spacer.d.ts +1 -1
- package/build/src/configuration-non-customizable.d.ts +7 -7
- package/build/src/configuration.d.ts +2 -2
- package/build/src/interfaces/axis-scales.d.ts +7 -7
- package/build/src/interfaces/charts.d.ts +11 -4
- package/build/src/interfaces/components.d.ts +3 -3
- package/build/src/interfaces/enums.d.ts +1 -1
- package/build/src/interfaces/index.d.ts +7 -7
- package/build/src/interfaces/layout.d.ts +1 -1
- package/build/src/interfaces/model.d.ts +1 -1
- package/build/src/model-cartesian-charts.d.ts +1 -1
- package/build/src/model-gauge.d.ts +1 -1
- package/build/src/model-meter.d.ts +1 -1
- package/build/src/model-pie.d.ts +1 -1
- package/build/src/model.d.ts +1 -9
- package/build/src/services/angle-utils.d.ts +1 -1
- package/build/src/services/curves.d.ts +2 -2
- package/build/src/services/essentials/dom-utils.d.ts +2 -2
- package/build/src/services/essentials/events.d.ts +1 -1
- package/build/src/services/essentials/gradient-utils.d.ts +1 -1
- package/build/src/services/essentials/transitions.d.ts +2 -2
- package/build/src/services/index.d.ts +7 -7
- package/build/src/services/scales-cartesian.d.ts +2 -2
- package/build/src/services/service.d.ts +1 -1
- package/build/src/services/time-series.d.ts +1 -1
- package/build/src/services/zoom.d.ts +2 -2
- package/build/src/tools.d.ts +2 -2
- package/build/stories/all.stories.d.ts +1 -1
- package/build/stories/tutorials/index.d.ts +11 -11
- package/build/stories/tutorials.stories.d.ts +1 -1
- package/bundle.js +1 -1
- package/chart.d.ts +3 -3
- package/chart.js +35 -35
- package/chart.js.map +1 -1
- package/charts/area-stacked.d.ts +2 -2
- package/charts/area-stacked.js +8 -8
- package/charts/area-stacked.js.map +1 -1
- package/charts/area.d.ts +2 -2
- package/charts/area.js +8 -8
- package/charts/area.js.map +1 -1
- package/charts/bar-grouped.d.ts +2 -2
- package/charts/bar-grouped.js +7 -7
- package/charts/bar-grouped.js.map +1 -1
- package/charts/bar-simple.d.ts +2 -2
- package/charts/bar-simple.js +7 -7
- package/charts/bar-simple.js.map +1 -1
- package/charts/bar-stacked.d.ts +2 -2
- package/charts/bar-stacked.js +7 -7
- package/charts/bar-stacked.js.map +1 -1
- package/charts/bubble.d.ts +2 -2
- package/charts/bubble.js +7 -7
- package/charts/bubble.js.map +1 -1
- package/charts/combo.d.ts +2 -2
- package/charts/combo.js +12 -12
- package/charts/combo.js.map +1 -1
- package/charts/donut.d.ts +2 -2
- package/charts/donut.js +7 -7
- package/charts/donut.js.map +1 -1
- package/charts/gauge.d.ts +3 -3
- package/charts/gauge.js +5 -5
- package/charts/gauge.js.map +1 -1
- package/charts/index.d.ts +16 -16
- package/charts/index.js +16 -16
- package/charts/index.js.map +1 -1
- package/charts/line.d.ts +2 -2
- package/charts/line.js +5 -5
- package/charts/line.js.map +1 -1
- package/charts/lollipop.d.ts +2 -2
- package/charts/lollipop.js +7 -7
- package/charts/lollipop.js.map +1 -1
- package/charts/meter.d.ts +3 -3
- package/charts/meter.js +18 -18
- package/charts/meter.js.map +1 -1
- package/charts/pie.d.ts +3 -3
- package/charts/pie.js +8 -8
- package/charts/pie.js.map +1 -1
- package/charts/radar.d.ts +2 -2
- package/charts/radar.js +5 -5
- package/charts/radar.js.map +1 -1
- package/charts/scatter.d.ts +2 -2
- package/charts/scatter.js +7 -7
- package/charts/scatter.js.map +1 -1
- package/charts/treemap.d.ts +2 -2
- package/charts/treemap.js +4 -4
- package/charts/treemap.js.map +1 -1
- package/components/axes/axis.d.ts +3 -3
- package/components/axes/axis.js +98 -98
- package/components/axes/axis.js.map +1 -1
- package/components/axes/chart-clip.d.ts +2 -2
- package/components/axes/chart-clip.js +9 -9
- package/components/axes/chart-clip.js.map +1 -1
- package/components/axes/grid-brush.d.ts +1 -1
- package/components/axes/grid-brush.js +32 -32
- package/components/axes/grid-brush.js.map +1 -1
- package/components/axes/grid.d.ts +1 -1
- package/components/axes/grid.js +34 -34
- package/components/axes/grid.js.map +1 -1
- package/components/axes/ruler-stacked.d.ts +1 -1
- package/components/axes/ruler-stacked.js +5 -5
- package/components/axes/ruler-stacked.js.map +1 -1
- package/components/axes/ruler.d.ts +2 -2
- package/components/axes/ruler.js +36 -36
- package/components/axes/ruler.js.map +1 -1
- package/components/axes/toolbar.d.ts +2 -2
- package/components/axes/toolbar.js +85 -85
- package/components/axes/toolbar.js.map +1 -1
- package/components/axes/two-dimensional-axes.d.ts +2 -2
- package/components/axes/two-dimensional-axes.js +13 -13
- package/components/axes/two-dimensional-axes.js.map +1 -1
- package/components/axes/zero-line.d.ts +1 -1
- package/components/axes/zero-line.js +12 -12
- package/components/axes/zero-line.js.map +1 -1
- package/components/axes/zoom-bar.d.ts +2 -2
- package/components/axes/zoom-bar.js +114 -114
- package/components/axes/zoom-bar.js.map +1 -1
- package/components/component.d.ts +1 -1
- package/components/component.js +13 -13
- package/components/component.js.map +1 -1
- package/components/essentials/legend.d.ts +1 -1
- package/components/essentials/legend.js +95 -92
- package/components/essentials/legend.js.map +1 -1
- package/components/essentials/threshold.d.ts +3 -3
- package/components/essentials/threshold.js +39 -39
- package/components/essentials/threshold.js.map +1 -1
- package/components/essentials/title-meter.d.ts +1 -1
- package/components/essentials/title-meter.js +42 -42
- package/components/essentials/title-meter.js.map +1 -1
- package/components/essentials/title.d.ts +1 -1
- package/components/essentials/title.js +19 -19
- package/components/essentials/title.js.map +1 -1
- package/components/essentials/tooltip-axis.d.ts +1 -1
- package/components/essentials/tooltip-axis.js +23 -23
- package/components/essentials/tooltip-axis.js.map +1 -1
- package/components/essentials/tooltip.d.ts +3 -3
- package/components/essentials/tooltip.js +31 -31
- package/components/essentials/tooltip.js.map +1 -1
- package/components/graphs/area-stacked.d.ts +1 -1
- package/components/graphs/area-stacked.js +28 -29
- package/components/graphs/area-stacked.js.map +1 -1
- package/components/graphs/area.d.ts +1 -1
- package/components/graphs/area.js +62 -57
- package/components/graphs/area.js.map +1 -1
- package/components/graphs/bar-grouped.d.ts +2 -2
- package/components/graphs/bar-grouped.js +56 -56
- package/components/graphs/bar-grouped.js.map +1 -1
- package/components/graphs/bar-simple.d.ts +1 -1
- package/components/graphs/bar-simple.js +45 -45
- package/components/graphs/bar-simple.js.map +1 -1
- package/components/graphs/bar-stacked.d.ts +1 -1
- package/components/graphs/bar-stacked.js +50 -51
- package/components/graphs/bar-stacked.js.map +1 -1
- package/components/graphs/bar.d.ts +1 -1
- package/components/graphs/bar.js +4 -4
- package/components/graphs/bar.js.map +1 -1
- package/components/graphs/bubble.d.ts +2 -2
- package/components/graphs/bubble.js +19 -19
- package/components/graphs/bubble.js.map +1 -1
- package/components/graphs/donut.d.ts +1 -1
- package/components/graphs/donut.js +20 -20
- package/components/graphs/donut.js.map +1 -1
- package/components/graphs/gauge.d.ts +1 -1
- package/components/graphs/gauge.js +89 -87
- package/components/graphs/gauge.js.map +1 -1
- package/components/graphs/line.d.ts +1 -1
- package/components/graphs/line.js +33 -33
- package/components/graphs/line.js.map +1 -1
- package/components/graphs/lollipop.d.ts +1 -1
- package/components/graphs/lollipop.js +32 -32
- package/components/graphs/lollipop.js.map +1 -1
- package/components/graphs/meter.d.ts +1 -1
- package/components/graphs/meter.js +39 -39
- package/components/graphs/meter.js.map +1 -1
- package/components/graphs/pie.d.ts +1 -1
- package/components/graphs/pie.js +102 -100
- package/components/graphs/pie.js.map +1 -1
- package/components/graphs/radar.d.ts +1 -1
- package/components/graphs/radar.js +180 -180
- package/components/graphs/radar.js.map +1 -1
- package/components/graphs/scatter-stacked.d.ts +1 -1
- package/components/graphs/scatter-stacked.js +22 -22
- package/components/graphs/scatter-stacked.js.map +1 -1
- package/components/graphs/scatter.d.ts +2 -2
- package/components/graphs/scatter.js +67 -66
- package/components/graphs/scatter.js.map +1 -1
- package/components/graphs/skeleton-lines.d.ts +1 -1
- package/components/graphs/skeleton-lines.js +27 -27
- package/components/graphs/skeleton-lines.js.map +1 -1
- package/components/graphs/skeleton.d.ts +1 -1
- package/components/graphs/skeleton.js +85 -85
- package/components/graphs/skeleton.js.map +1 -1
- package/components/graphs/treemap.d.ts +1 -1
- package/components/graphs/treemap.js +82 -82
- package/components/graphs/treemap.js.map +1 -1
- package/components/index.d.ts +36 -36
- package/components/index.js +36 -36
- package/components/index.js.map +1 -1
- package/components/layout/layout.d.ts +3 -3
- package/components/layout/layout.js +28 -28
- package/components/layout/layout.js.map +1 -1
- package/components/layout/spacer.d.ts +1 -1
- package/components/layout/spacer.js +10 -10
- package/components/layout/spacer.js.map +1 -1
- package/configuration-non-customizable.d.ts +7 -7
- package/configuration-non-customizable.js +37 -37
- package/configuration-non-customizable.js.map +1 -1
- package/configuration.d.ts +2 -2
- package/configuration.js +81 -78
- package/configuration.js.map +1 -1
- package/demo/create-codesandbox.d.ts +42 -42
- package/demo/create-codesandbox.js +100 -100
- package/demo/create-codesandbox.js.map +1 -1
- package/demo/data/area.js +220 -190
- package/demo/data/area.js.map +1 -1
- package/demo/data/bar.d.ts +2 -2
- package/demo/data/bar.js +302 -302
- package/demo/data/bar.js.map +1 -1
- package/demo/data/bubble.js +108 -108
- package/demo/data/bubble.js.map +1 -1
- package/demo/data/combo.js +323 -323
- package/demo/data/combo.js.map +1 -1
- package/demo/data/donut.js +19 -19
- package/demo/data/donut.js.map +1 -1
- package/demo/data/gauge.js +20 -20
- package/demo/data/gauge.js.map +1 -1
- package/demo/data/high-scale.js +3 -3
- package/demo/data/high-scale.js.map +1 -1
- package/demo/data/index.d.ts +13 -13
- package/demo/data/index.js +299 -299
- package/demo/data/index.js.map +1 -1
- package/demo/data/line.d.ts +4 -4
- package/demo/data/line.js +332 -332
- package/demo/data/line.js.map +1 -1
- package/demo/data/lollipop.js +19 -19
- package/demo/data/lollipop.js.map +1 -1
- package/demo/data/meter.d.ts +1 -1
- package/demo/data/meter.js +22 -22
- package/demo/data/meter.js.map +1 -1
- package/demo/data/pie.js +17 -17
- package/demo/data/pie.js.map +1 -1
- package/demo/data/radar.js +84 -84
- package/demo/data/radar.js.map +1 -1
- package/demo/data/scatter.js +125 -125
- package/demo/data/scatter.js.map +1 -1
- package/demo/data/step.js +11 -11
- package/demo/data/step.js.map +1 -1
- package/demo/data/time-series-axis.js +164 -164
- package/demo/data/time-series-axis.js.map +1 -1
- package/demo/data/toolbar.js +15 -15
- package/demo/data/toolbar.js.map +1 -1
- package/demo/data/treemap.js +63 -63
- package/demo/data/treemap.js.map +1 -1
- package/demo/data/zoom-bar.js +65 -65
- package/demo/data/zoom-bar.js.map +1 -1
- package/demo/styles.css +1 -1
- package/demo/styles.min.css +1 -1
- package/demo/tsconfig.tsbuildinfo +45 -45
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/interfaces/a11y.js.map +1 -1
- package/interfaces/axis-scales.d.ts +7 -7
- package/interfaces/axis-scales.js.map +1 -1
- package/interfaces/charts.d.ts +11 -4
- package/interfaces/charts.js.map +1 -1
- package/interfaces/components.d.ts +3 -3
- package/interfaces/components.js.map +1 -1
- package/interfaces/enums.d.ts +1 -1
- package/interfaces/enums.js +1 -1
- package/interfaces/enums.js.map +1 -1
- package/interfaces/events.js.map +1 -1
- package/interfaces/index.d.ts +7 -7
- package/interfaces/index.js +2 -2
- package/interfaces/index.js.map +1 -1
- package/interfaces/layout.d.ts +1 -1
- package/interfaces/layout.js.map +1 -1
- package/interfaces/model.d.ts +1 -1
- package/interfaces/model.js.map +1 -1
- package/model-cartesian-charts.d.ts +1 -1
- package/model-cartesian-charts.js +7 -7
- package/model-cartesian-charts.js.map +1 -1
- package/model-gauge.d.ts +1 -1
- package/model-gauge.js +2 -2
- package/model-gauge.js.map +1 -1
- package/model-meter.d.ts +1 -1
- package/model-meter.js +7 -7
- package/model-meter.js.map +1 -1
- package/model-pie.d.ts +1 -1
- package/model-pie.js +1 -1
- package/model-pie.js.map +1 -1
- package/model.d.ts +1 -9
- package/model.js +31 -42
- package/model.js.map +1 -1
- package/package.json +2 -3
- package/polyfills.js +9 -9
- package/polyfills.js.map +1 -1
- package/services/angle-utils.d.ts +1 -1
- package/services/angle-utils.js +9 -9
- package/services/angle-utils.js.map +1 -1
- package/services/curves.d.ts +2 -2
- package/services/curves.js +6 -6
- package/services/curves.js.map +1 -1
- package/services/essentials/dom-utils.d.ts +2 -2
- package/services/essentials/dom-utils.js +37 -37
- package/services/essentials/dom-utils.js.map +1 -1
- package/services/essentials/events.d.ts +1 -1
- package/services/essentials/events.js +3 -3
- package/services/essentials/events.js.map +1 -1
- package/services/essentials/gradient-utils.d.ts +1 -1
- package/services/essentials/gradient-utils.js +25 -25
- package/services/essentials/gradient-utils.js.map +1 -1
- package/services/essentials/transitions.d.ts +2 -2
- package/services/essentials/transitions.js +8 -8
- package/services/essentials/transitions.js.map +1 -1
- package/services/index.d.ts +7 -7
- package/services/index.js +7 -7
- package/services/index.js.map +1 -1
- package/services/scales-cartesian.d.ts +2 -2
- package/services/scales-cartesian.js +57 -60
- package/services/scales-cartesian.js.map +1 -1
- package/services/service.d.ts +1 -1
- package/services/service.js.map +1 -1
- package/services/time-series.d.ts +1 -1
- package/services/time-series.js +27 -27
- package/services/time-series.js.map +1 -1
- package/services/zoom.d.ts +2 -2
- package/services/zoom.js +20 -20
- package/services/zoom.js.map +1 -1
- package/styles/_type.scss +7 -7
- package/styles/color-palatte.scss +218 -218
- package/styles/colors.scss +3 -3
- package/styles/components/_axis.scss +5 -5
- package/styles/components/_ruler.scss +2 -2
- package/styles/components/_threshold.scss +1 -1
- package/styles/components/_title.scss +3 -3
- package/styles/components/_toolbar.scss +1 -1
- package/styles/components/_tooltip.scss +6 -6
- package/styles/components/index.scss +16 -16
- package/styles/graphs/_bubble.scss +1 -1
- package/styles/graphs/_radar.scss +2 -2
- package/styles/graphs/_scatter.scss +1 -1
- package/styles/graphs/_treemap.scss +1 -1
- package/styles/graphs/index.scss +9 -9
- package/styles/styles-g10.scss +2 -2
- package/styles/styles-g100.scss +2 -2
- package/styles/styles-g90.scss +2 -2
- package/styles/styles-white.scss +2 -2
- package/styles/styles.scss +10 -10
- package/tools.d.ts +2 -2
- package/tools.js +26 -26
- package/tools.js.map +1 -1
- package/tsconfig.tsbuildinfo +173 -173
|
@@ -11,21 +11,21 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
11
11
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
12
|
};
|
|
13
13
|
})();
|
|
14
|
-
import { Component } from
|
|
15
|
-
import { Tools } from
|
|
16
|
-
import { DOMUtils } from
|
|
17
|
-
import { AxisPositions, Events, ScaleTypes } from
|
|
18
|
-
import { select, mouse } from
|
|
14
|
+
import { Component } from '../component';
|
|
15
|
+
import { Tools } from '../../tools';
|
|
16
|
+
import { DOMUtils } from '../../services';
|
|
17
|
+
import { AxisPositions, Events, ScaleTypes, } from '../../interfaces';
|
|
18
|
+
import { select, mouse } from 'd3-selection';
|
|
19
19
|
// Carbon position service
|
|
20
|
-
import Position, { PLACEMENTS } from
|
|
20
|
+
import Position, { PLACEMENTS } from '@carbon/utils-position';
|
|
21
21
|
// import the settings for the css prefix
|
|
22
|
-
import settings from
|
|
23
|
-
import { formatTick, computeTimeIntervalName } from
|
|
22
|
+
import settings from 'carbon-components/es/globals/js/settings';
|
|
23
|
+
import { formatTick, computeTimeIntervalName, } from '../../services/time-series';
|
|
24
24
|
var Threshold = /** @class */ (function (_super) {
|
|
25
25
|
__extends(Threshold, _super);
|
|
26
26
|
function Threshold(model, services, configs) {
|
|
27
27
|
var _this = _super.call(this, model, services, configs) || this;
|
|
28
|
-
_this.type =
|
|
28
|
+
_this.type = 'threshold';
|
|
29
29
|
_this.positionService = new Position();
|
|
30
30
|
return _this;
|
|
31
31
|
}
|
|
@@ -33,7 +33,7 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
33
33
|
var _this = this;
|
|
34
34
|
if (animate === void 0) { animate = false; }
|
|
35
35
|
var _a = this.configs, value = _a.value, fillColor = _a.fillColor, axisPosition = _a.axisPosition, index = _a.index;
|
|
36
|
-
var chartprefix = Tools.getProperty(this.getOptions(),
|
|
36
|
+
var chartprefix = Tools.getProperty(this.getOptions(), 'style', 'prefix');
|
|
37
37
|
this.thresholdClass = settings.prefix + "--" + chartprefix + "--threshold";
|
|
38
38
|
// We can have multiple thresholds, set an unique identifier
|
|
39
39
|
this.thresholdIdentifierClass = axisPosition + "-" + index;
|
|
@@ -44,7 +44,7 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
44
44
|
var thresholdLine = DOMUtils.appendOrSelect(this.threshold, "line.threshold-line");
|
|
45
45
|
// Set threshold line color from configs options
|
|
46
46
|
// If not defined, the line takes the defined CSS color
|
|
47
|
-
thresholdLine.style(
|
|
47
|
+
thresholdLine.style('stroke', fillColor);
|
|
48
48
|
var scale = this.services.cartesianScales.getScaleByPosition(axisPosition);
|
|
49
49
|
var scaleType = this.services.cartesianScales.getScaleTypeByPosition(axisPosition);
|
|
50
50
|
var mainXScale = this.services.cartesianScales.getMainXScale();
|
|
@@ -62,25 +62,25 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
62
62
|
var position = getXValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);
|
|
63
63
|
// Position the threshold on the x scale value
|
|
64
64
|
this.threshold
|
|
65
|
-
.transition(this.services.transitions.getTransition(
|
|
66
|
-
.attr(
|
|
65
|
+
.transition(this.services.transitions.getTransition('threshold-update', animate))
|
|
66
|
+
.attr('transform', "translate(" + position + ", " + yScaleStart + ")");
|
|
67
67
|
// Set line end point on the y-axis
|
|
68
|
-
thresholdLine.attr(
|
|
68
|
+
thresholdLine.attr('y2', yScaleEnd - yScaleStart);
|
|
69
69
|
// Set hoverable area width and rotate it
|
|
70
70
|
thresholdRect
|
|
71
|
-
.attr(
|
|
72
|
-
.classed(
|
|
71
|
+
.attr('width', Math.abs(yScaleEnd - yScaleStart))
|
|
72
|
+
.classed('rotate', true);
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
75
|
var position = getYValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);
|
|
76
76
|
// Position the threshold on the y scale value
|
|
77
77
|
this.threshold
|
|
78
|
-
.transition(this.services.transitions.getTransition(
|
|
79
|
-
.attr(
|
|
78
|
+
.transition(this.services.transitions.getTransition('threshold-update', animate))
|
|
79
|
+
.attr('transform', "translate(" + xScaleStart + ", " + position + ")");
|
|
80
80
|
// Set line end point on the x-axis
|
|
81
|
-
thresholdLine.attr(
|
|
81
|
+
thresholdLine.attr('x2', xScaleEnd - xScaleStart);
|
|
82
82
|
// Set hoverable area width
|
|
83
|
-
thresholdRect.attr(
|
|
83
|
+
thresholdRect.attr('width', Math.abs(xScaleEnd - xScaleStart));
|
|
84
84
|
}
|
|
85
85
|
var self = this;
|
|
86
86
|
this.services.events.addEventListener(Events.Threshold.SHOW, function (e) {
|
|
@@ -89,11 +89,11 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
89
89
|
if (hovered === self.threshold) {
|
|
90
90
|
// Set label position and show it
|
|
91
91
|
_this.setThresholdLabelPosition();
|
|
92
|
-
_this.label.classed(
|
|
92
|
+
_this.label.classed('hidden', false);
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
this.services.events.addEventListener(Events.Threshold.HIDE, function (e) {
|
|
96
|
-
_this.label.classed(
|
|
96
|
+
_this.label.classed('hidden', true);
|
|
97
97
|
});
|
|
98
98
|
this.appendThresholdLabel();
|
|
99
99
|
this.addEventListeners();
|
|
@@ -106,19 +106,19 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
106
106
|
if (scaleType === ScaleTypes.TIME) {
|
|
107
107
|
var isVertical = [
|
|
108
108
|
AxisPositions.LEFT,
|
|
109
|
-
AxisPositions.RIGHT
|
|
109
|
+
AxisPositions.RIGHT,
|
|
110
110
|
].includes(axisPosition);
|
|
111
111
|
var mainXScale = this.services.cartesianScales.getMainXScale();
|
|
112
112
|
var mainYScale = this.services.cartesianScales.getMainYScale();
|
|
113
113
|
var scale = isVertical ? mainYScale : mainXScale;
|
|
114
|
-
var timeScaleOptions = Tools.getProperty(options,
|
|
114
|
+
var timeScaleOptions = Tools.getProperty(options, 'timeScale');
|
|
115
115
|
var timeInterval = computeTimeIntervalName(scale.ticks());
|
|
116
116
|
return formatTick(value, 0, timeInterval, timeScaleOptions);
|
|
117
117
|
}
|
|
118
|
-
return value.toLocaleString(
|
|
118
|
+
return value.toLocaleString('en');
|
|
119
119
|
};
|
|
120
120
|
Threshold.prototype.appendThresholdLabel = function () {
|
|
121
|
-
var _a = this.configs, value = _a.value, valueFormatter = _a.valueFormatter, fillColor = _a.fillColor, _b = _a.label, label = _b === void 0 ?
|
|
121
|
+
var _a = this.configs, value = _a.value, valueFormatter = _a.valueFormatter, fillColor = _a.fillColor, _b = _a.label, label = _b === void 0 ? 'Threshold' : _b;
|
|
122
122
|
var holder = select(this.services.domUtils.getHolder());
|
|
123
123
|
// Format the threshold value using valueFormatter if defined in user-provided options
|
|
124
124
|
var formattedValue = valueFormatter
|
|
@@ -127,8 +127,8 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
127
127
|
this.label = DOMUtils.appendOrSelect(holder, "div." + this.thresholdClass + "--label." + this.thresholdIdentifierClass);
|
|
128
128
|
this.label
|
|
129
129
|
.html(label + ": " + formattedValue)
|
|
130
|
-
.classed(
|
|
131
|
-
.style(
|
|
130
|
+
.classed('hidden', true)
|
|
131
|
+
.style('background-color', fillColor);
|
|
132
132
|
};
|
|
133
133
|
Threshold.prototype.setThresholdLabelPosition = function () {
|
|
134
134
|
var holder = this.services.domUtils.getHolder();
|
|
@@ -137,37 +137,37 @@ var Threshold = /** @class */ (function (_super) {
|
|
|
137
137
|
// Find out whether threshold label should be shown on the left or right side
|
|
138
138
|
var bestPlacementOption = this.positionService.findBestPlacementAt({
|
|
139
139
|
left: mouseRelativePos[0],
|
|
140
|
-
top: mouseRelativePos[1]
|
|
140
|
+
top: mouseRelativePos[1],
|
|
141
141
|
}, target, [
|
|
142
142
|
PLACEMENTS.RIGHT,
|
|
143
143
|
PLACEMENTS.LEFT,
|
|
144
144
|
PLACEMENTS.TOP,
|
|
145
|
-
PLACEMENTS.BOTTOM
|
|
145
|
+
PLACEMENTS.BOTTOM,
|
|
146
146
|
], function () { return ({
|
|
147
147
|
width: holder.offsetWidth,
|
|
148
|
-
height: holder.offsetHeight
|
|
148
|
+
height: holder.offsetHeight,
|
|
149
149
|
}); });
|
|
150
150
|
// Get coordinates to where label should be positioned
|
|
151
151
|
var pos = this.positionService.findPositionAt({
|
|
152
152
|
left: mouseRelativePos[0],
|
|
153
|
-
top: mouseRelativePos[1]
|
|
153
|
+
top: mouseRelativePos[1],
|
|
154
154
|
}, target, bestPlacementOption);
|
|
155
155
|
this.positionService.setElement(target, pos);
|
|
156
156
|
};
|
|
157
157
|
Threshold.prototype.addEventListeners = function () {
|
|
158
158
|
var self = this;
|
|
159
159
|
// Add events to the threshold hoverable area
|
|
160
|
-
DOMUtils.appendOrSelect(this.threshold,
|
|
161
|
-
.on(
|
|
162
|
-
self.threshold.classed(
|
|
160
|
+
DOMUtils.appendOrSelect(this.threshold, 'rect')
|
|
161
|
+
.on('mouseover mousemove', function () {
|
|
162
|
+
self.threshold.classed('active', true);
|
|
163
163
|
self.services.events.dispatchEvent(Events.Threshold.SHOW, {
|
|
164
|
-
hoveredElement: select(self.threshold)
|
|
164
|
+
hoveredElement: select(self.threshold),
|
|
165
165
|
});
|
|
166
166
|
})
|
|
167
|
-
.on(
|
|
168
|
-
self.threshold.classed(
|
|
167
|
+
.on('mouseout', function () {
|
|
168
|
+
self.threshold.classed('active', false);
|
|
169
169
|
self.services.events.dispatchEvent(Events.Threshold.HIDE, {
|
|
170
|
-
hoveredElement: select(self.threshold)
|
|
170
|
+
hoveredElement: select(self.threshold),
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
173
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threshold.js","sourceRoot":"","sources":["threshold.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACN,aAAa,EACb,MAAM,EACN,UAAU,EAEV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAChE,OAAO,EACN,UAAU,EACV,uBAAuB,EACvB,MAAM,4BAA4B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,CAAC,WAAW;YACzB,MAAM,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC,EAHI,CAGJ,CACF,CAAC;QAEF,sDAAsD;QACtD,IAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAC9C;YACC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACzB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;SACxB,EACD,MAAM,EACN,mBAAmB,CACnB,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,qCAAiB,GAAjB;QACC,IAAM,IAAI,GAAG,IAAI,CAAC;QAElB,6CAA6C;QAC7C,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC;aAC7C,EAAE,CAAC,qBAAqB,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACF,gBAAC;AAAD,CAAC,AAxOD,CAA+B,SAAS,GAwOvC","sourcesContent":["import { Component } from \"../component\";\nimport { Tools } from \"../../tools\";\nimport { DOMUtils } from \"../../services\";\nimport { ChartModel } from \"../../model\";\nimport {\n\tAxisPositions,\n\tEvents,\n\tScaleTypes,\n\tCartesianOrientations\n} from \"../../interfaces\";\nimport { select, mouse } from \"d3-selection\";\n\n// Carbon position service\nimport Position, { PLACEMENTS } from \"@carbon/utils-position\";\n\n// import the settings for the css prefix\nimport settings from \"carbon-components/es/globals/js/settings\";\nimport {\n\tformatTick,\n\tcomputeTimeIntervalName\n} from \"../../services/time-series\";\n\nexport class Threshold extends Component {\n\ttype = \"threshold\";\n\n\tthreshold: any;\n\tthresholdClass: string;\n\tthresholdIdentifierClass: string;\n\n\tlabel: any;\n\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs: any) {\n\t\tsuper(model, services, configs);\n\t}\n\n\trender(animate = false) {\n\t\tconst { value, fillColor, axisPosition, index } = this.configs;\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t\"style\",\n\t\t\t\"prefix\"\n\t\t);\n\t\tthis.thresholdClass = `${settings.prefix}--${chartprefix}--threshold`;\n\t\t// We can have multiple thresholds, set an unique identifier\n\t\tthis.thresholdIdentifierClass = `${axisPosition}-${index}`;\n\n\t\tthis.threshold = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t`g.${this.thresholdClass}.${this.thresholdIdentifierClass}`\n\t\t).raise();\n\t\t// Append threshold hoverable area\n\t\tconst thresholdRect = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`rect.threshold-hoverable-area`\n\t\t);\n\t\t// Append threshold line\n\t\tconst thresholdLine = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`line.threshold-line`\n\t\t);\n\n\t\t// Set threshold line color from configs options\n\t\t// If not defined, the line takes the defined CSS color\n\t\tthresholdLine.style(\"stroke\", fillColor);\n\n\t\tconst scale = this.services.cartesianScales.getScaleByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst isScaleTypeLabels = scaleType === ScaleTypes.LABELS;\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\tconst { cartesianScales } = this.services;\n\t\tconst orientation = cartesianScales.getOrientation();\n\t\tconst getDomainValue = (d) => cartesianScales.getDomainValue(d);\n\t\tconst getRangeValue = (d) => cartesianScales.getRangeValue(d);\n\t\tconst [\n\t\t\tgetXValue,\n\t\t\tgetYValue\n\t\t] = Tools.flipDomainAndRangeBasedOnOrientation(\n\t\t\tgetDomainValue,\n\t\t\tgetRangeValue,\n\t\t\torientation\n\t\t);\n\n\t\tif (\n\t\t\taxisPosition === AxisPositions.TOP ||\n\t\t\taxisPosition === AxisPositions.BOTTOM\n\t\t) {\n\t\t\tconst position =\n\t\t\t\tgetXValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the x scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${position}, ${yScaleStart})`);\n\t\t\t// Set line end point on the y-axis\n\t\t\tthresholdLine.attr(\"y2\", yScaleEnd - yScaleStart);\n\t\t\t// Set hoverable area width and rotate it\n\t\t\tthresholdRect\n\t\t\t\t.attr(\"width\", Math.abs(yScaleEnd - yScaleStart))\n\t\t\t\t.classed(\"rotate\", true);\n\t\t} else {\n\t\t\tconst position =\n\t\t\t\tgetYValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the y scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t\"threshold-update\",\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr(\"transform\", `translate(${xScaleStart}, ${position})`);\n\t\t\t// Set line end point on the x-axis\n\t\t\tthresholdLine.attr(\"x2\", xScaleEnd - xScaleStart);\n\t\t\t// Set hoverable area width\n\t\t\tthresholdRect.attr(\"width\", Math.abs(xScaleEnd - xScaleStart));\n\t\t}\n\n\t\tconst self = this;\n\t\tthis.services.events.addEventListener(Events.Threshold.SHOW, (e) => {\n\t\t\tconst hovered = e.detail.hoveredElement.node();\n\t\t\t// If is this threshold\n\t\t\tif (hovered === self.threshold) {\n\t\t\t\t// Set label position and show it\n\t\t\t\tthis.setThresholdLabelPosition();\n\t\t\t\tthis.label.classed(\"hidden\", false);\n\t\t\t}\n\t\t});\n\n\t\tthis.services.events.addEventListener(Events.Threshold.HIDE, (e) => {\n\t\t\tthis.label.classed(\"hidden\", true);\n\t\t});\n\n\t\tthis.appendThresholdLabel();\n\n\t\tthis.addEventListeners();\n\t}\n\n\tgetFormattedValue() {\n\t\tconst { value, axisPosition } = this.configs;\n\t\tconst options = this.getOptions();\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\n\t\t// If scale is time, format the threshold date as the ticks format\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst isVertical = [\n\t\t\t\tAxisPositions.LEFT,\n\t\t\t\tAxisPositions.RIGHT\n\t\t\t].includes(axisPosition);\n\t\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\t\tconst scale = isVertical ? mainYScale : mainXScale;\n\n\t\t\tconst timeScaleOptions = Tools.getProperty(options, \"timeScale\");\n\t\t\tconst timeInterval = computeTimeIntervalName(scale.ticks());\n\t\t\treturn formatTick(value, 0, timeInterval, timeScaleOptions);\n\t\t}\n\n\t\treturn value.toLocaleString(\"en\");\n\t}\n\n\tappendThresholdLabel() {\n\t\tconst {\n\t\t\tvalue,\n\t\t\tvalueFormatter,\n\t\t\tfillColor,\n\t\t\tlabel = \"Threshold\"\n\t\t} = this.configs;\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\t// Format the threshold value using valueFormatter if defined in user-provided options\n\t\tconst formattedValue = valueFormatter\n\t\t\t? valueFormatter(value)\n\t\t\t: this.getFormattedValue();\n\n\t\tthis.label = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${this.thresholdClass}--label.${this.thresholdIdentifierClass}`\n\t\t);\n\t\tthis.label\n\t\t\t.html(`${label}: ${formattedValue}`)\n\t\t\t.classed(\"hidden\", true)\n\t\t\t.style(\"background-color\", fillColor);\n\t}\n\n\tsetThresholdLabelPosition() {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.label.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\n\t\t// Find out whether threshold label should be shown on the left or right side\n\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t},\n\t\t\ttarget,\n\t\t\t[\n\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\tPLACEMENTS.BOTTOM\n\t\t\t],\n\t\t\t() => ({\n\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\theight: holder.offsetHeight\n\t\t\t})\n\t\t);\n\n\t\t// Get coordinates to where label should be positioned\n\t\tconst pos = this.positionService.findPositionAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1]\n\t\t\t},\n\t\t\ttarget,\n\t\t\tbestPlacementOption\n\t\t);\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\n\t\t// Add events to the threshold hoverable area\n\t\tDOMUtils.appendOrSelect(this.threshold, \"rect\")\n\t\t\t.on(\"mouseover mousemove\", function () {\n\t\t\t\tself.threshold.classed(\"active\", true);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.SHOW, {\n\t\t\t\t\thoveredElement: select(self.threshold)\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"mouseout\", function () {\n\t\t\t\tself.threshold.classed(\"active\", false);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.HIDE, {\n\t\t\t\t\thoveredElement: select(self.threshold)\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"threshold.js","sourceRoot":"","sources":["threshold.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACN,aAAa,EACb,MAAM,EACN,UAAU,GAEV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,0BAA0B;AAC1B,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE9D,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAChE,OAAO,EACN,UAAU,EACV,uBAAuB,GACvB,MAAM,4BAA4B,CAAC;AAEpC;IAA+B,6BAAS;IAWvC,mBAAY,KAAiB,EAAE,QAAa,EAAE,OAAY;QAA1D,YACC,kBAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,SAC/B;QAZD,UAAI,GAAG,WAAW,CAAC;QAQnB,qBAAe,GAAG,IAAI,QAAQ,EAAE,CAAC;;IAIjC,CAAC;IAED,0BAAM,GAAN,UAAO,OAAe;QAAtB,iBAgHC;QAhHM,wBAA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CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,qCAAiB,GAAjB;QACC,IAAM,IAAI,GAAG,IAAI,CAAC;QAElB,6CAA6C;QAC7C,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC;aAC7C,EAAE,CAAC,qBAAqB,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC;aACD,EAAE,CAAC,UAAU,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;gBACzD,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;aACtC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACF,gBAAC;AAAD,CAAC,AAxOD,CAA+B,SAAS,GAwOvC","sourcesContent":["import { Component } from '../component';\nimport { Tools } from '../../tools';\nimport { DOMUtils } from '../../services';\nimport { ChartModel } from '../../model';\nimport {\n\tAxisPositions,\n\tEvents,\n\tScaleTypes,\n\tCartesianOrientations,\n} from '../../interfaces';\nimport { select, mouse } from 'd3-selection';\n\n// Carbon position service\nimport Position, { PLACEMENTS } from '@carbon/utils-position';\n\n// import the settings for the css prefix\nimport settings from 'carbon-components/es/globals/js/settings';\nimport {\n\tformatTick,\n\tcomputeTimeIntervalName,\n} from '../../services/time-series';\n\nexport class Threshold extends Component {\n\ttype = 'threshold';\n\n\tthreshold: any;\n\tthresholdClass: string;\n\tthresholdIdentifierClass: string;\n\n\tlabel: any;\n\n\tpositionService = new Position();\n\n\tconstructor(model: ChartModel, services: any, configs: any) {\n\t\tsuper(model, services, configs);\n\t}\n\n\trender(animate = false) {\n\t\tconst { value, fillColor, axisPosition, index } = this.configs;\n\t\tconst chartprefix = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'style',\n\t\t\t'prefix'\n\t\t);\n\t\tthis.thresholdClass = `${settings.prefix}--${chartprefix}--threshold`;\n\t\t// We can have multiple thresholds, set an unique identifier\n\t\tthis.thresholdIdentifierClass = `${axisPosition}-${index}`;\n\n\t\tthis.threshold = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t`g.${this.thresholdClass}.${this.thresholdIdentifierClass}`\n\t\t).raise();\n\t\t// Append threshold hoverable area\n\t\tconst thresholdRect = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`rect.threshold-hoverable-area`\n\t\t);\n\t\t// Append threshold line\n\t\tconst thresholdLine = DOMUtils.appendOrSelect(\n\t\t\tthis.threshold,\n\t\t\t`line.threshold-line`\n\t\t);\n\n\t\t// Set threshold line color from configs options\n\t\t// If not defined, the line takes the defined CSS color\n\t\tthresholdLine.style('stroke', fillColor);\n\n\t\tconst scale = this.services.cartesianScales.getScaleByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\tconst isScaleTypeLabels = scaleType === ScaleTypes.LABELS;\n\t\tconst [xScaleStart, xScaleEnd] = mainXScale.range();\n\t\tconst [yScaleEnd, yScaleStart] = mainYScale.range();\n\n\t\tconst { cartesianScales } = this.services;\n\t\tconst orientation = cartesianScales.getOrientation();\n\t\tconst getDomainValue = (d) => cartesianScales.getDomainValue(d);\n\t\tconst getRangeValue = (d) => cartesianScales.getRangeValue(d);\n\t\tconst [\n\t\t\tgetXValue,\n\t\t\tgetYValue,\n\t\t] = Tools.flipDomainAndRangeBasedOnOrientation(\n\t\t\tgetDomainValue,\n\t\t\tgetRangeValue,\n\t\t\torientation\n\t\t);\n\n\t\tif (\n\t\t\taxisPosition === AxisPositions.TOP ||\n\t\t\taxisPosition === AxisPositions.BOTTOM\n\t\t) {\n\t\t\tconst position =\n\t\t\t\tgetXValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the x scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t'threshold-update',\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr('transform', `translate(${position}, ${yScaleStart})`);\n\t\t\t// Set line end point on the y-axis\n\t\t\tthresholdLine.attr('y2', yScaleEnd - yScaleStart);\n\t\t\t// Set hoverable area width and rotate it\n\t\t\tthresholdRect\n\t\t\t\t.attr('width', Math.abs(yScaleEnd - yScaleStart))\n\t\t\t\t.classed('rotate', true);\n\t\t} else {\n\t\t\tconst position =\n\t\t\t\tgetYValue(value) + (isScaleTypeLabels ? scale.step() / 2 : 0);\n\t\t\t// Position the threshold on the y scale value\n\t\t\tthis.threshold\n\t\t\t\t.transition(\n\t\t\t\t\tthis.services.transitions.getTransition(\n\t\t\t\t\t\t'threshold-update',\n\t\t\t\t\t\tanimate\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.attr('transform', `translate(${xScaleStart}, ${position})`);\n\t\t\t// Set line end point on the x-axis\n\t\t\tthresholdLine.attr('x2', xScaleEnd - xScaleStart);\n\t\t\t// Set hoverable area width\n\t\t\tthresholdRect.attr('width', Math.abs(xScaleEnd - xScaleStart));\n\t\t}\n\n\t\tconst self = this;\n\t\tthis.services.events.addEventListener(Events.Threshold.SHOW, (e) => {\n\t\t\tconst hovered = e.detail.hoveredElement.node();\n\t\t\t// If is this threshold\n\t\t\tif (hovered === self.threshold) {\n\t\t\t\t// Set label position and show it\n\t\t\t\tthis.setThresholdLabelPosition();\n\t\t\t\tthis.label.classed('hidden', false);\n\t\t\t}\n\t\t});\n\n\t\tthis.services.events.addEventListener(Events.Threshold.HIDE, (e) => {\n\t\t\tthis.label.classed('hidden', true);\n\t\t});\n\n\t\tthis.appendThresholdLabel();\n\n\t\tthis.addEventListeners();\n\t}\n\n\tgetFormattedValue() {\n\t\tconst { value, axisPosition } = this.configs;\n\t\tconst options = this.getOptions();\n\t\tconst scaleType = this.services.cartesianScales.getScaleTypeByPosition(\n\t\t\taxisPosition\n\t\t);\n\n\t\t// If scale is time, format the threshold date as the ticks format\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst isVertical = [\n\t\t\t\tAxisPositions.LEFT,\n\t\t\t\tAxisPositions.RIGHT,\n\t\t\t].includes(axisPosition);\n\t\t\tconst mainXScale = this.services.cartesianScales.getMainXScale();\n\t\t\tconst mainYScale = this.services.cartesianScales.getMainYScale();\n\t\t\tconst scale = isVertical ? mainYScale : mainXScale;\n\n\t\t\tconst timeScaleOptions = Tools.getProperty(options, 'timeScale');\n\t\t\tconst timeInterval = computeTimeIntervalName(scale.ticks());\n\t\t\treturn formatTick(value, 0, timeInterval, timeScaleOptions);\n\t\t}\n\n\t\treturn value.toLocaleString('en');\n\t}\n\n\tappendThresholdLabel() {\n\t\tconst {\n\t\t\tvalue,\n\t\t\tvalueFormatter,\n\t\t\tfillColor,\n\t\t\tlabel = 'Threshold',\n\t\t} = this.configs;\n\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\t// Format the threshold value using valueFormatter if defined in user-provided options\n\t\tconst formattedValue = valueFormatter\n\t\t\t? valueFormatter(value)\n\t\t\t: this.getFormattedValue();\n\n\t\tthis.label = DOMUtils.appendOrSelect(\n\t\t\tholder,\n\t\t\t`div.${this.thresholdClass}--label.${this.thresholdIdentifierClass}`\n\t\t);\n\t\tthis.label\n\t\t\t.html(`${label}: ${formattedValue}`)\n\t\t\t.classed('hidden', true)\n\t\t\t.style('background-color', fillColor);\n\t}\n\n\tsetThresholdLabelPosition() {\n\t\tconst holder = this.services.domUtils.getHolder();\n\t\tconst target = this.label.node();\n\t\tconst mouseRelativePos = mouse(holder);\n\n\t\t// Find out whether threshold label should be shown on the left or right side\n\t\tconst bestPlacementOption = this.positionService.findBestPlacementAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t},\n\t\t\ttarget,\n\t\t\t[\n\t\t\t\tPLACEMENTS.RIGHT,\n\t\t\t\tPLACEMENTS.LEFT,\n\t\t\t\tPLACEMENTS.TOP,\n\t\t\t\tPLACEMENTS.BOTTOM,\n\t\t\t],\n\t\t\t() => ({\n\t\t\t\twidth: holder.offsetWidth,\n\t\t\t\theight: holder.offsetHeight,\n\t\t\t})\n\t\t);\n\n\t\t// Get coordinates to where label should be positioned\n\t\tconst pos = this.positionService.findPositionAt(\n\t\t\t{\n\t\t\t\tleft: mouseRelativePos[0],\n\t\t\t\ttop: mouseRelativePos[1],\n\t\t\t},\n\t\t\ttarget,\n\t\t\tbestPlacementOption\n\t\t);\n\n\t\tthis.positionService.setElement(target, pos);\n\t}\n\n\taddEventListeners() {\n\t\tconst self = this;\n\n\t\t// Add events to the threshold hoverable area\n\t\tDOMUtils.appendOrSelect(this.threshold, 'rect')\n\t\t\t.on('mouseover mousemove', function () {\n\t\t\t\tself.threshold.classed('active', true);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.SHOW, {\n\t\t\t\t\thoveredElement: select(self.threshold),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on('mouseout', function () {\n\t\t\t\tself.threshold.classed('active', false);\n\t\t\t\tself.services.events.dispatchEvent(Events.Threshold.HIDE, {\n\t\t\t\t\thoveredElement: select(self.threshold),\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n"]}
|
|
@@ -12,16 +12,16 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
};
|
|
13
13
|
})();
|
|
14
14
|
// Internal Imports
|
|
15
|
-
import { Title } from
|
|
16
|
-
import { DOMUtils } from
|
|
17
|
-
import { Tools } from
|
|
18
|
-
import { Statuses } from
|
|
19
|
-
import * as Configuration from
|
|
15
|
+
import { Title } from './title';
|
|
16
|
+
import { DOMUtils } from '../../services';
|
|
17
|
+
import { Tools } from '../../tools';
|
|
18
|
+
import { Statuses } from './../../interfaces/enums';
|
|
19
|
+
import * as Configuration from '../../configuration';
|
|
20
20
|
var MeterTitle = /** @class */ (function (_super) {
|
|
21
21
|
__extends(MeterTitle, _super);
|
|
22
22
|
function MeterTitle() {
|
|
23
23
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
-
_this.type =
|
|
24
|
+
_this.type = 'meter-title';
|
|
25
25
|
return _this;
|
|
26
26
|
}
|
|
27
27
|
MeterTitle.prototype.render = function () {
|
|
@@ -31,15 +31,15 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
31
31
|
var groupMapsTo = options.data.groupMapsTo;
|
|
32
32
|
// the title for a meter, is the label for that dataset
|
|
33
33
|
var title = svg
|
|
34
|
-
.selectAll(
|
|
34
|
+
.selectAll('text.meter-title')
|
|
35
35
|
.data([dataset[groupMapsTo]]);
|
|
36
36
|
title
|
|
37
37
|
.enter()
|
|
38
|
-
.append(
|
|
39
|
-
.classed(
|
|
38
|
+
.append('text')
|
|
39
|
+
.classed('meter-title', true)
|
|
40
40
|
.merge(title)
|
|
41
|
-
.attr(
|
|
42
|
-
.attr(
|
|
41
|
+
.attr('x', 0)
|
|
42
|
+
.attr('y', '1em')
|
|
43
43
|
.text(function (d) { return d; });
|
|
44
44
|
title.exit().remove();
|
|
45
45
|
// appends the associated percentage after title
|
|
@@ -48,7 +48,7 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
48
48
|
this.displayStatus();
|
|
49
49
|
// get the max width of a title (with consideration for the status/percentage)
|
|
50
50
|
var maxWidth = this.getMaxTitleWidth();
|
|
51
|
-
var titleElement = DOMUtils.appendOrSelect(svg,
|
|
51
|
+
var titleElement = DOMUtils.appendOrSelect(svg, 'text.meter-title');
|
|
52
52
|
if (maxWidth > 0 &&
|
|
53
53
|
titleElement.node().getComputedTextLength() > maxWidth) {
|
|
54
54
|
this.truncateTitle(titleElement, maxWidth);
|
|
@@ -66,31 +66,31 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
66
66
|
// this can happen if the chart is toggled on/off and the height is 0 for the parent, it wont validateDimensions
|
|
67
67
|
var containerWidth = containerBounds.width
|
|
68
68
|
? containerBounds.width
|
|
69
|
-
: this.parent.node().getAttribute(
|
|
69
|
+
: this.parent.node().getAttribute('width');
|
|
70
70
|
// get the status from the model
|
|
71
71
|
var status = this.model.getStatus();
|
|
72
72
|
var radius = Configuration.meter.status.indicatorSize / 2;
|
|
73
73
|
// create a group for the icon/inner path
|
|
74
74
|
var statusGroup = DOMUtils.appendOrSelect(svg, "g.status-indicator")
|
|
75
|
-
.attr(
|
|
76
|
-
.attr(
|
|
75
|
+
.attr('class', status !== null ? "status-indicator status--" + status : '')
|
|
76
|
+
.attr('transform', "translate(" + (containerWidth - radius) + ", 0)");
|
|
77
77
|
var data = status ? [status] : [];
|
|
78
|
-
var icon = statusGroup.selectAll(
|
|
78
|
+
var icon = statusGroup.selectAll('circle.status').data(data);
|
|
79
79
|
icon.enter()
|
|
80
|
-
.append(
|
|
80
|
+
.append('circle')
|
|
81
81
|
.merge(icon)
|
|
82
|
-
.attr(
|
|
83
|
-
.attr(
|
|
84
|
-
.attr(
|
|
85
|
-
.attr(
|
|
86
|
-
var innerIcon = statusGroup.selectAll(
|
|
82
|
+
.attr('class', 'status')
|
|
83
|
+
.attr('r', radius)
|
|
84
|
+
.attr('cx', 0)
|
|
85
|
+
.attr('cy', "calc(1em / 2)");
|
|
86
|
+
var innerIcon = statusGroup.selectAll('path.innerFill').data(data);
|
|
87
87
|
innerIcon
|
|
88
88
|
.enter()
|
|
89
|
-
.append(
|
|
89
|
+
.append('path')
|
|
90
90
|
.merge(innerIcon)
|
|
91
|
-
.attr(
|
|
92
|
-
.attr(
|
|
93
|
-
.attr(
|
|
91
|
+
.attr('d', self.getStatusIconPathString(status))
|
|
92
|
+
.attr('transform', "translate(-" + radius + ", 0)")
|
|
93
|
+
.attr('class', 'innerFill');
|
|
94
94
|
innerIcon.exit().remove();
|
|
95
95
|
icon.exit().remove();
|
|
96
96
|
};
|
|
@@ -101,23 +101,23 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
101
101
|
var dataValue = this.model.getDisplayData().value;
|
|
102
102
|
// use the title's position to append the percentage to the end
|
|
103
103
|
var svg = this.getContainerSVG();
|
|
104
|
-
var title = DOMUtils.appendOrSelect(svg,
|
|
104
|
+
var title = DOMUtils.appendOrSelect(svg, 'text.meter-title');
|
|
105
105
|
// check if it is enabled
|
|
106
|
-
var data = Tools.getProperty(this.getOptions(),
|
|
106
|
+
var data = Tools.getProperty(this.getOptions(), 'meter', 'statusBar', 'percentageIndicator', 'enabled') === true
|
|
107
107
|
? [dataValue]
|
|
108
108
|
: [];
|
|
109
109
|
// append a percentage if it is enabled, update it
|
|
110
|
-
var percentage = svg.selectAll(
|
|
110
|
+
var percentage = svg.selectAll('text.percent-value').data(data);
|
|
111
111
|
// the horizontal offset of the percentage value from the title
|
|
112
112
|
var offset = Configuration.meter.statusBar.paddingRight;
|
|
113
113
|
percentage
|
|
114
114
|
.enter()
|
|
115
|
-
.append(
|
|
116
|
-
.classed(
|
|
115
|
+
.append('text')
|
|
116
|
+
.classed('percent-value', true)
|
|
117
117
|
.merge(percentage)
|
|
118
118
|
.text(function (d) { return d + "%"; })
|
|
119
|
-
.attr(
|
|
120
|
-
.attr(
|
|
119
|
+
.attr('x', +title.attr('x') + title.node().getComputedTextLength() + offset) // set the position to after the title
|
|
120
|
+
.attr('y', title.attr('y'));
|
|
121
121
|
percentage.exit().remove();
|
|
122
122
|
};
|
|
123
123
|
/**
|
|
@@ -129,11 +129,11 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
129
129
|
MeterTitle.prototype.truncateTitle = function (title, maxWidth) {
|
|
130
130
|
_super.prototype.truncateTitle.call(this, title, maxWidth);
|
|
131
131
|
// update the position on the percentage to be inline with the title
|
|
132
|
-
var tspan = DOMUtils.appendOrSelect(this.parent,
|
|
132
|
+
var tspan = DOMUtils.appendOrSelect(this.parent, 'tspan');
|
|
133
133
|
var offset = Configuration.meter.statusBar.paddingRight;
|
|
134
134
|
var tspanLength = Math.ceil(tspan.node().getComputedTextLength());
|
|
135
|
-
var percentage = DOMUtils.appendOrSelect(this.parent,
|
|
136
|
-
percentage.attr(
|
|
135
|
+
var percentage = DOMUtils.appendOrSelect(this.parent, 'text.percent-value');
|
|
136
|
+
percentage.attr('x', +title.attr('x') +
|
|
137
137
|
title.node().getComputedTextLength() +
|
|
138
138
|
tspanLength +
|
|
139
139
|
offset);
|
|
@@ -145,12 +145,12 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
145
145
|
// need to check if the width is 0, and try to use the parent attribute
|
|
146
146
|
var containerWidth = containerBounds.width
|
|
147
147
|
? containerBounds.width
|
|
148
|
-
: this.parent.node().getAttribute(
|
|
149
|
-
var percentage = DOMUtils.appendOrSelect(this.parent,
|
|
148
|
+
: this.parent.node().getAttribute('width');
|
|
149
|
+
var percentage = DOMUtils.appendOrSelect(this.parent, 'text.percent-value');
|
|
150
150
|
// the title needs to fit the width of the container without crowding the status, and percentage value
|
|
151
151
|
var offset = Configuration.meter.statusBar.paddingRight;
|
|
152
152
|
var percentageWidth = percentage.node().getComputedTextLength();
|
|
153
|
-
var statusGroup = DOMUtils.appendOrSelect(this.parent,
|
|
153
|
+
var statusGroup = DOMUtils.appendOrSelect(this.parent, 'g.status-indicator').node();
|
|
154
154
|
var statusWidth = DOMUtils.getSVGElementSize(statusGroup, { useBBox: true }).width +
|
|
155
155
|
Configuration.meter.status.paddingLeft;
|
|
156
156
|
return containerWidth - percentageWidth - offset - statusWidth;
|
|
@@ -162,11 +162,11 @@ var MeterTitle = /** @class */ (function (_super) {
|
|
|
162
162
|
MeterTitle.prototype.getStatusIconPathString = function (status) {
|
|
163
163
|
switch (status) {
|
|
164
164
|
case Statuses.SUCCESS:
|
|
165
|
-
return
|
|
165
|
+
return 'M6.875 11.3125 3.75 8.1875 4.74375 7.25 6.875 9.34375 11.50625 4.75 12.5 5.7375 Z';
|
|
166
166
|
case Statuses.DANGER:
|
|
167
|
-
return
|
|
167
|
+
return 'M10.7 11.5 4.5 5.3 5.3 4.5 11.5 10.7 Z';
|
|
168
168
|
case Statuses.WARNING:
|
|
169
|
-
return
|
|
169
|
+
return 'M7.9375,11.125 C7.41973305,11.125 7,11.544733 7,12.0625 C7,12.580267 7.41973305,13 7.9375,13 C8.45526695,13 8.875,12.580267 8.875,12.0625 C8.875,11.544733 8.45526695,11.125 7.9375,11.125 M7.3125, 3 8.5625, 3 8.5625, 9.875 7.3125, 9.875, 7.3125, 3 Z';
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
172
|
return MeterTitle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title-meter.js","sourceRoot":"","sources":["title-meter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAErD;IAAgC,8BAAK;IAArC;QAAA,qEAuNC;QAtNA,UAAI,GAAG,aAAa,CAAC;;IAsNtB,CAAC;IApNA,2BAAM,GAAN;QACC,IAAM,OAAO,GAAG,IAAI,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,GAuNpC","sourcesContent":["// Internal Imports\nimport { Title } from \"./title\";\nimport { DOMUtils } from \"../../services\";\nimport { Tools } from \"../../tools\";\nimport { Statuses } from \"./../../interfaces/enums\";\nimport * as Configuration from \"../../configuration\";\n\nexport class MeterTitle extends Title {\n\ttype = \"meter-title\";\n\n\trender() {\n\t\tconst dataset = this.model.getDisplayData();\n\t\tconst options = this.getOptions();\n\t\tconst svg = this.getContainerSVG();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\t// the title for a meter, is the label for that dataset\n\t\tconst title = svg\n\t\t\t.selectAll(\"text.meter-title\")\n\t\t\t.data([dataset[groupMapsTo]]);\n\n\t\ttitle\n\t\t\t.enter()\n\t\t\t.append(\"text\")\n\t\t\t.classed(\"meter-title\", true)\n\t\t\t.merge(title)\n\t\t\t.attr(\"x\", 0)\n\t\t\t.attr(\"y\", \"1em\")\n\t\t\t.text((d) => d);\n\n\t\ttitle.exit().remove();\n\n\t\t// appends the associated percentage after title\n\t\tthis.appendPercentage();\n\n\t\t// if status ranges are provided (custom or default), display indicator\n\t\tthis.displayStatus();\n\n\t\t// get the max width of a title (with consideration for the status/percentage)\n\t\tconst maxWidth = this.getMaxTitleWidth();\n\t\tconst titleElement = DOMUtils.appendOrSelect(svg, \"text.meter-title\");\n\n\t\tif (\n\t\t\tmaxWidth > 0 &&\n\t\t\ttitleElement.node().getComputedTextLength() > maxWidth\n\t\t) {\n\t\t\tthis.truncateTitle(titleElement, maxWidth);\n\t\t}\n\t}\n\n\t/**\n\t * Appends the corresponding status based on the value and the peak.\n\t */\n\tdisplayStatus() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.getOptions();\n\n\t\tconst containerBounds = DOMUtils.getSVGElementSize(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t);\n\n\t\t// need to check if the width is 0, and try to use the parent attribute\n\t\t// this can happen if the chart is toggled on/off and the height is 0 for the parent, it wont validateDimensions\n\t\tconst containerWidth = containerBounds.width\n\t\t\t? containerBounds.width\n\t\t\t: this.parent.node().getAttribute(\"width\");\n\n\t\t// get the status from the model\n\t\tconst status = this.model.getStatus();\n\t\tconst radius = Configuration.meter.status.indicatorSize / 2;\n\n\t\t// create a group for the icon/inner path\n\t\tconst statusGroup = DOMUtils.appendOrSelect(svg, `g.status-indicator`)\n\t\t\t.attr(\n\t\t\t\t\"class\",\n\t\t\t\tstatus !== null ? `status-indicator status--${status}` : \"\"\n\t\t\t)\n\t\t\t.attr(\"transform\", `translate(${containerWidth - radius}, 0)`);\n\n\t\tconst data = status ? [status] : [];\n\t\tconst icon = statusGroup.selectAll(\"circle.status\").data(data);\n\n\t\ticon.enter()\n\t\t\t.append(\"circle\")\n\t\t\t.merge(icon)\n\t\t\t.attr(\"class\", \"status\")\n\t\t\t.attr(\"r\", radius)\n\t\t\t.attr(\"cx\", 0)\n\t\t\t.attr(\"cy\", `calc(1em / 2)`);\n\n\t\tconst innerIcon = statusGroup.selectAll(\"path.innerFill\").data(data);\n\n\t\tinnerIcon\n\t\t\t.enter()\n\t\t\t.append(\"path\")\n\t\t\t.merge(innerIcon)\n\t\t\t.attr(\"d\", self.getStatusIconPathString(status))\n\t\t\t.attr(\"transform\", `translate(-${radius}, 0)`)\n\t\t\t.attr(\"class\", \"innerFill\");\n\n\t\tinnerIcon.exit().remove();\n\t\ticon.exit().remove();\n\t}\n\n\t/**\n\t * Appends the associated percentage to the end of the title\n\t */\n\tappendPercentage() {\n\t\tconst dataValue = this.model.getDisplayData().value;\n\n\t\t// use the title's position to append the percentage to the end\n\t\tconst svg = this.getContainerSVG();\n\t\tconst title = DOMUtils.appendOrSelect(svg, \"text.meter-title\");\n\n\t\t// check if it is enabled\n\t\tconst data =\n\t\t\tTools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t\"meter\",\n\t\t\t\t\"statusBar\",\n\t\t\t\t\"percentageIndicator\",\n\t\t\t\t\"enabled\"\n\t\t\t) === true\n\t\t\t\t? [dataValue]\n\t\t\t\t: [];\n\n\t\t// append a percentage if it is enabled, update it\n\t\tconst percentage = svg.selectAll(\"text.percent-value\").data(data);\n\n\t\t// the horizontal offset of the percentage value from the title\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\n\t\tpercentage\n\t\t\t.enter()\n\t\t\t.append(\"text\")\n\t\t\t.classed(\"percent-value\", true)\n\t\t\t.merge(percentage)\n\t\t\t.text((d) => `${d}%`)\n\t\t\t.attr(\n\t\t\t\t\"x\",\n\t\t\t\t+title.attr(\"x\") + title.node().getComputedTextLength() + offset\n\t\t\t) // set the position to after the title\n\t\t\t.attr(\"y\", title.attr(\"y\"));\n\n\t\tpercentage.exit().remove();\n\t}\n\n\t/**\n\t * Uses the parent class truncate logic\n\t * @param title d3 selection of title element that will be truncated\n\t * @param titlestring the original string that needs truncation\n\t * @param maxWidth the max width the title can take\n\t */\n\ttruncateTitle(title, maxWidth) {\n\t\tsuper.truncateTitle(title, maxWidth);\n\n\t\t// update the position on the percentage to be inline with the title\n\t\tconst tspan = DOMUtils.appendOrSelect(this.parent, \"tspan\");\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\t\tconst tspanLength = Math.ceil(tspan.node().getComputedTextLength());\n\n\t\tconst percentage = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t\"text.percent-value\"\n\t\t);\n\t\tpercentage.attr(\n\t\t\t\"x\",\n\t\t\t+title.attr(\"x\") +\n\t\t\t\ttitle.node().getComputedTextLength() +\n\t\t\t\ttspanLength +\n\t\t\t\toffset\n\t\t);\n\t}\n\n\t// computes the maximum space a title can take\n\tprotected getMaxTitleWidth() {\n\t\t// get a reference to the title elements to calculate the size the title can be\n\t\tconst containerBounds = DOMUtils.getSVGElementSize(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t);\n\n\t\t// need to check if the width is 0, and try to use the parent attribute\n\t\tconst containerWidth = containerBounds.width\n\t\t\t? containerBounds.width\n\t\t\t: this.parent.node().getAttribute(\"width\");\n\n\t\tconst percentage = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t\"text.percent-value\"\n\t\t);\n\t\t// the title needs to fit the width of the container without crowding the status, and percentage value\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\t\tconst percentageWidth = percentage.node().getComputedTextLength();\n\n\t\tconst statusGroup = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t\"g.status-indicator\"\n\t\t).node();\n\t\tconst statusWidth =\n\t\t\tDOMUtils.getSVGElementSize(statusGroup, { useBBox: true }).width +\n\t\t\tConfiguration.meter.status.paddingLeft;\n\n\t\treturn containerWidth - percentageWidth - offset - statusWidth;\n\t}\n\n\t/**\n\t * Get the associated status icon for the data\n\t * @param status the active status for the meter chart\n\t */\n\tprotected getStatusIconPathString(status) {\n\t\tswitch (status) {\n\t\t\tcase Statuses.SUCCESS:\n\t\t\t\treturn \"M6.875 11.3125 3.75 8.1875 4.74375 7.25 6.875 9.34375 11.50625 4.75 12.5 5.7375 Z\";\n\t\t\tcase Statuses.DANGER:\n\t\t\t\treturn \"M10.7 11.5 4.5 5.3 5.3 4.5 11.5 10.7 Z\";\n\t\t\tcase Statuses.WARNING:\n\t\t\t\treturn \"M7.9375,11.125 C7.41973305,11.125 7,11.544733 7,12.0625 C7,12.580267 7.41973305,13 7.9375,13 C8.45526695,13 8.875,12.580267 8.875,12.0625 C8.875,11.544733 8.45526695,11.125 7.9375,11.125 M7.3125, 3 8.5625, 3 8.5625, 9.875 7.3125, 9.875, 7.3125, 3 Z\";\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"title-meter.js","sourceRoot":"","sources":["title-meter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE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;QACvC,QAAQ,MAAM,EAAE;YACf,KAAK,QAAQ,CAAC,OAAO;gBACpB,OAAO,mFAAmF,CAAC;YAC5F,KAAK,QAAQ,CAAC,MAAM;gBACnB,OAAO,wCAAwC,CAAC;YACjD,KAAK,QAAQ,CAAC,OAAO;gBACpB,OAAO,0PAA0P,CAAC;SACnQ;IACF,CAAC;IACF,iBAAC;AAAD,CAAC,AAvND,CAAgC,KAAK,GAuNpC","sourcesContent":["// Internal Imports\nimport { Title } from './title';\nimport { DOMUtils } from '../../services';\nimport { Tools } from '../../tools';\nimport { Statuses } from './../../interfaces/enums';\nimport * as Configuration from '../../configuration';\n\nexport class MeterTitle extends Title {\n\ttype = 'meter-title';\n\n\trender() {\n\t\tconst dataset = this.model.getDisplayData();\n\t\tconst options = this.getOptions();\n\t\tconst svg = this.getContainerSVG();\n\t\tconst { groupMapsTo } = options.data;\n\n\t\t// the title for a meter, is the label for that dataset\n\t\tconst title = svg\n\t\t\t.selectAll('text.meter-title')\n\t\t\t.data([dataset[groupMapsTo]]);\n\n\t\ttitle\n\t\t\t.enter()\n\t\t\t.append('text')\n\t\t\t.classed('meter-title', true)\n\t\t\t.merge(title)\n\t\t\t.attr('x', 0)\n\t\t\t.attr('y', '1em')\n\t\t\t.text((d) => d);\n\n\t\ttitle.exit().remove();\n\n\t\t// appends the associated percentage after title\n\t\tthis.appendPercentage();\n\n\t\t// if status ranges are provided (custom or default), display indicator\n\t\tthis.displayStatus();\n\n\t\t// get the max width of a title (with consideration for the status/percentage)\n\t\tconst maxWidth = this.getMaxTitleWidth();\n\t\tconst titleElement = DOMUtils.appendOrSelect(svg, 'text.meter-title');\n\n\t\tif (\n\t\t\tmaxWidth > 0 &&\n\t\t\ttitleElement.node().getComputedTextLength() > maxWidth\n\t\t) {\n\t\t\tthis.truncateTitle(titleElement, maxWidth);\n\t\t}\n\t}\n\n\t/**\n\t * Appends the corresponding status based on the value and the peak.\n\t */\n\tdisplayStatus() {\n\t\tconst self = this;\n\t\tconst svg = this.getContainerSVG();\n\t\tconst options = this.getOptions();\n\n\t\tconst containerBounds = DOMUtils.getSVGElementSize(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t);\n\n\t\t// need to check if the width is 0, and try to use the parent attribute\n\t\t// this can happen if the chart is toggled on/off and the height is 0 for the parent, it wont validateDimensions\n\t\tconst containerWidth = containerBounds.width\n\t\t\t? containerBounds.width\n\t\t\t: this.parent.node().getAttribute('width');\n\n\t\t// get the status from the model\n\t\tconst status = this.model.getStatus();\n\t\tconst radius = Configuration.meter.status.indicatorSize / 2;\n\n\t\t// create a group for the icon/inner path\n\t\tconst statusGroup = DOMUtils.appendOrSelect(svg, `g.status-indicator`)\n\t\t\t.attr(\n\t\t\t\t'class',\n\t\t\t\tstatus !== null ? `status-indicator status--${status}` : ''\n\t\t\t)\n\t\t\t.attr('transform', `translate(${containerWidth - radius}, 0)`);\n\n\t\tconst data = status ? [status] : [];\n\t\tconst icon = statusGroup.selectAll('circle.status').data(data);\n\n\t\ticon.enter()\n\t\t\t.append('circle')\n\t\t\t.merge(icon)\n\t\t\t.attr('class', 'status')\n\t\t\t.attr('r', radius)\n\t\t\t.attr('cx', 0)\n\t\t\t.attr('cy', `calc(1em / 2)`);\n\n\t\tconst innerIcon = statusGroup.selectAll('path.innerFill').data(data);\n\n\t\tinnerIcon\n\t\t\t.enter()\n\t\t\t.append('path')\n\t\t\t.merge(innerIcon)\n\t\t\t.attr('d', self.getStatusIconPathString(status))\n\t\t\t.attr('transform', `translate(-${radius}, 0)`)\n\t\t\t.attr('class', 'innerFill');\n\n\t\tinnerIcon.exit().remove();\n\t\ticon.exit().remove();\n\t}\n\n\t/**\n\t * Appends the associated percentage to the end of the title\n\t */\n\tappendPercentage() {\n\t\tconst dataValue = this.model.getDisplayData().value;\n\n\t\t// use the title's position to append the percentage to the end\n\t\tconst svg = this.getContainerSVG();\n\t\tconst title = DOMUtils.appendOrSelect(svg, 'text.meter-title');\n\n\t\t// check if it is enabled\n\t\tconst data =\n\t\t\tTools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t'meter',\n\t\t\t\t'statusBar',\n\t\t\t\t'percentageIndicator',\n\t\t\t\t'enabled'\n\t\t\t) === true\n\t\t\t\t? [dataValue]\n\t\t\t\t: [];\n\n\t\t// append a percentage if it is enabled, update it\n\t\tconst percentage = svg.selectAll('text.percent-value').data(data);\n\n\t\t// the horizontal offset of the percentage value from the title\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\n\t\tpercentage\n\t\t\t.enter()\n\t\t\t.append('text')\n\t\t\t.classed('percent-value', true)\n\t\t\t.merge(percentage)\n\t\t\t.text((d) => `${d}%`)\n\t\t\t.attr(\n\t\t\t\t'x',\n\t\t\t\t+title.attr('x') + title.node().getComputedTextLength() + offset\n\t\t\t) // set the position to after the title\n\t\t\t.attr('y', title.attr('y'));\n\n\t\tpercentage.exit().remove();\n\t}\n\n\t/**\n\t * Uses the parent class truncate logic\n\t * @param title d3 selection of title element that will be truncated\n\t * @param titlestring the original string that needs truncation\n\t * @param maxWidth the max width the title can take\n\t */\n\ttruncateTitle(title, maxWidth) {\n\t\tsuper.truncateTitle(title, maxWidth);\n\n\t\t// update the position on the percentage to be inline with the title\n\t\tconst tspan = DOMUtils.appendOrSelect(this.parent, 'tspan');\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\t\tconst tspanLength = Math.ceil(tspan.node().getComputedTextLength());\n\n\t\tconst percentage = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t'text.percent-value'\n\t\t);\n\t\tpercentage.attr(\n\t\t\t'x',\n\t\t\t+title.attr('x') +\n\t\t\t\ttitle.node().getComputedTextLength() +\n\t\t\t\ttspanLength +\n\t\t\t\toffset\n\t\t);\n\t}\n\n\t// computes the maximum space a title can take\n\tprotected getMaxTitleWidth() {\n\t\t// get a reference to the title elements to calculate the size the title can be\n\t\tconst containerBounds = DOMUtils.getSVGElementSize(\n\t\t\tthis.services.domUtils.getMainSVG(),\n\t\t\t{ useAttr: true }\n\t\t);\n\n\t\t// need to check if the width is 0, and try to use the parent attribute\n\t\tconst containerWidth = containerBounds.width\n\t\t\t? containerBounds.width\n\t\t\t: this.parent.node().getAttribute('width');\n\n\t\tconst percentage = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t'text.percent-value'\n\t\t);\n\t\t// the title needs to fit the width of the container without crowding the status, and percentage value\n\t\tconst offset = Configuration.meter.statusBar.paddingRight;\n\t\tconst percentageWidth = percentage.node().getComputedTextLength();\n\n\t\tconst statusGroup = DOMUtils.appendOrSelect(\n\t\t\tthis.parent,\n\t\t\t'g.status-indicator'\n\t\t).node();\n\t\tconst statusWidth =\n\t\t\tDOMUtils.getSVGElementSize(statusGroup, { useBBox: true }).width +\n\t\t\tConfiguration.meter.status.paddingLeft;\n\n\t\treturn containerWidth - percentageWidth - offset - statusWidth;\n\t}\n\n\t/**\n\t * Get the associated status icon for the data\n\t * @param status the active status for the meter chart\n\t */\n\tprotected getStatusIconPathString(status) {\n\t\tswitch (status) {\n\t\t\tcase Statuses.SUCCESS:\n\t\t\t\treturn 'M6.875 11.3125 3.75 8.1875 4.74375 7.25 6.875 9.34375 11.50625 4.75 12.5 5.7375 Z';\n\t\t\tcase Statuses.DANGER:\n\t\t\t\treturn 'M10.7 11.5 4.5 5.3 5.3 4.5 11.5 10.7 Z';\n\t\t\tcase Statuses.WARNING:\n\t\t\t\treturn 'M7.9375,11.125 C7.41973305,11.125 7,11.544733 7,12.0625 C7,12.580267 7.41973305,13 7.9375,13 C8.45526695,13 8.875,12.580267 8.875,12.0625 C8.875,11.544733 8.45526695,11.125 7.9375,11.125 M7.3125, 3 8.5625, 3 8.5625, 9.875 7.3125, 9.875, 7.3125, 3 Z';\n\t\t}\n\t}\n}\n"]}
|
|
@@ -12,31 +12,31 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
};
|
|
13
13
|
})();
|
|
14
14
|
// Internal Imports
|
|
15
|
-
import { Component } from
|
|
16
|
-
import { DOMUtils } from
|
|
17
|
-
import { Events } from
|
|
15
|
+
import { Component } from '../component';
|
|
16
|
+
import { DOMUtils } from '../../services';
|
|
17
|
+
import { Events } from './../../interfaces';
|
|
18
18
|
var Title = /** @class */ (function (_super) {
|
|
19
19
|
__extends(Title, _super);
|
|
20
20
|
function Title() {
|
|
21
21
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
22
|
-
_this.type =
|
|
22
|
+
_this.type = 'title';
|
|
23
23
|
return _this;
|
|
24
24
|
}
|
|
25
25
|
Title.prototype.render = function () {
|
|
26
26
|
var svg = this.getContainerSVG();
|
|
27
27
|
var text = svg
|
|
28
|
-
.selectAll(
|
|
28
|
+
.selectAll('text.title')
|
|
29
29
|
.data([this.getOptions().title]);
|
|
30
30
|
text.enter()
|
|
31
|
-
.append(
|
|
32
|
-
.classed(
|
|
31
|
+
.append('text')
|
|
32
|
+
.classed('title', true)
|
|
33
33
|
.merge(text)
|
|
34
|
-
.attr(
|
|
35
|
-
.attr(
|
|
34
|
+
.attr('x', 0)
|
|
35
|
+
.attr('y', '1em')
|
|
36
36
|
.html(function (d) { return d; });
|
|
37
37
|
// check the max space the title has to render
|
|
38
38
|
var maxWidth = this.getMaxTitleWidth();
|
|
39
|
-
var title = DOMUtils.appendOrSelect(svg,
|
|
39
|
+
var title = DOMUtils.appendOrSelect(svg, 'text.title');
|
|
40
40
|
// check if title needs truncation (and tooltip support)
|
|
41
41
|
if (title.node().getComputedTextLength() > maxWidth && maxWidth > 0) {
|
|
42
42
|
this.truncateTitle(title, maxWidth);
|
|
@@ -55,9 +55,9 @@ var Title = /** @class */ (function (_super) {
|
|
|
55
55
|
// check if the title is too big for the containing svg
|
|
56
56
|
if (title.node().getComputedTextLength() > maxWidth) {
|
|
57
57
|
// append the ellipses to their own tspan to calculate the text length
|
|
58
|
-
title.append(
|
|
58
|
+
title.append('tspan').text('...');
|
|
59
59
|
// get the bounding width including the elipses '...'
|
|
60
|
-
var tspanLength = DOMUtils.appendOrSelect(title,
|
|
60
|
+
var tspanLength = DOMUtils.appendOrSelect(title, 'tspan')
|
|
61
61
|
.node()
|
|
62
62
|
.getComputedTextLength();
|
|
63
63
|
// with elipses
|
|
@@ -68,21 +68,21 @@ var Title = /** @class */ (function (_super) {
|
|
|
68
68
|
// use the substring as the title
|
|
69
69
|
title
|
|
70
70
|
.html(titleString.substring(0, substringIndex - 1))
|
|
71
|
-
.append(
|
|
72
|
-
.text(
|
|
71
|
+
.append('tspan')
|
|
72
|
+
.text('...');
|
|
73
73
|
// add events for displaying the tooltip with the title
|
|
74
74
|
var self_1 = this;
|
|
75
75
|
title
|
|
76
|
-
.on(
|
|
76
|
+
.on('mouseover', function () {
|
|
77
77
|
self_1.services.events.dispatchEvent(Events.Tooltip.SHOW, {
|
|
78
78
|
hoveredElement: title,
|
|
79
|
-
content: untruncatedTitle
|
|
79
|
+
content: untruncatedTitle,
|
|
80
80
|
});
|
|
81
81
|
})
|
|
82
|
-
.on(
|
|
82
|
+
.on('mousemove', function () {
|
|
83
83
|
self_1.services.events.dispatchEvent(Events.Tooltip.MOVE);
|
|
84
84
|
})
|
|
85
|
-
.on(
|
|
85
|
+
.on('mouseout', function () {
|
|
86
86
|
self_1.services.events.dispatchEvent(Events.Tooltip.HIDE);
|
|
87
87
|
});
|
|
88
88
|
}
|
|
@@ -90,7 +90,7 @@ var Title = /** @class */ (function (_super) {
|
|
|
90
90
|
// computes the maximum space a title can take
|
|
91
91
|
Title.prototype.getMaxTitleWidth = function () {
|
|
92
92
|
return DOMUtils.getSVGElementSize(this.parent.node(), {
|
|
93
|
-
useAttr: true
|
|
93
|
+
useAttr: true,
|
|
94
94
|
}).width;
|
|
95
95
|
};
|
|
96
96
|
/**
|