@servicetitan/marketing-ui 5.8.1 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ads/ads-stat.js +21 -10
- package/dist/components/ads/ads-stat.js.map +1 -1
- package/dist/components/charts/funnel-chart/components/funnel-chart.js +118 -6
- package/dist/components/charts/funnel-chart/components/funnel-chart.js.map +1 -1
- package/dist/components/charts/funnel-chart/components/funnel-chart.module.less.d.ts +9 -0
- package/dist/components/charts/funnel-chart/components/funnel-svg.js +62 -12
- package/dist/components/charts/funnel-chart/components/funnel-svg.js.map +1 -1
- package/dist/components/charts/funnel-chart/funnel-chart.stories.d.ts +0 -1
- package/dist/components/charts/funnel-chart/funnel-chart.stories.d.ts.map +1 -1
- package/dist/components/charts/funnel-chart/index.js +1 -0
- package/dist/components/charts/funnel-chart/index.js.map +1 -1
- package/dist/components/charts/funnel-chart/utils/const.js +1 -0
- package/dist/components/charts/funnel-chart/utils/const.js.map +1 -1
- package/dist/components/charts/funnel-chart/utils/interface.js +2 -1
- package/dist/components/charts/funnel-chart/utils/interface.js.map +1 -1
- package/dist/components/charts/line-chart/components/body.js +105 -16
- package/dist/components/charts/line-chart/components/body.js.map +1 -1
- package/dist/components/charts/line-chart/components/body.module.less.d.ts +4 -0
- package/dist/components/charts/line-chart/components/container.js +12 -4
- package/dist/components/charts/line-chart/components/container.js.map +1 -1
- package/dist/components/charts/line-chart/components/hover-popover.js +56 -13
- package/dist/components/charts/line-chart/components/hover-popover.js.map +1 -1
- package/dist/components/charts/line-chart/components/hover-popover.module.less.d.ts +5 -0
- package/dist/components/charts/line-chart/components/sidebar.js +35 -5
- package/dist/components/charts/line-chart/components/sidebar.js.map +1 -1
- package/dist/components/charts/line-chart/components/sidebar.module.less.d.ts +13 -0
- package/dist/components/charts/line-chart/components/stuff.js +73 -32
- package/dist/components/charts/line-chart/components/stuff.js.map +1 -1
- package/dist/components/charts/line-chart/components/stuff.module.less.d.ts +6 -0
- package/dist/components/charts/line-chart/components/svg-bars.d.ts.map +1 -1
- package/dist/components/charts/line-chart/components/svg-bars.js +60 -26
- package/dist/components/charts/line-chart/components/svg-bars.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg-body.js +52 -11
- package/dist/components/charts/line-chart/components/svg-body.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg-lines.js +46 -27
- package/dist/components/charts/line-chart/components/svg-lines.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg.module.less.d.ts +5 -0
- package/dist/components/charts/line-chart/index.js +1 -0
- package/dist/components/charts/line-chart/index.js.map +1 -1
- package/dist/components/charts/line-chart/stores/line-chart.store.d.ts.map +1 -1
- package/dist/components/charts/line-chart/stores/line-chart.store.js +98 -127
- package/dist/components/charts/line-chart/stores/line-chart.store.js.map +1 -1
- package/dist/components/charts/line-chart/stores/svg.store.d.ts.map +1 -1
- package/dist/components/charts/line-chart/stores/svg.store.js +66 -108
- package/dist/components/charts/line-chart/stores/svg.store.js.map +1 -1
- package/dist/components/charts/line-chart/utils/const.js +8 -7
- package/dist/components/charts/line-chart/utils/const.js.map +1 -1
- package/dist/components/charts/line-chart/utils/formatters.d.ts.map +1 -1
- package/dist/components/charts/line-chart/utils/formatters.js +13 -11
- package/dist/components/charts/line-chart/utils/formatters.js.map +1 -1
- package/dist/components/charts/line-chart/utils/interfaces.js +2 -1
- package/dist/components/charts/line-chart/utils/interfaces.js.map +1 -1
- package/dist/components/charts/line-chart/utils/internal-interfaces.js +2 -1
- package/dist/components/charts/line-chart/utils/internal-interfaces.js.map +1 -1
- package/dist/components/charts/line-chart/utils/key.d.ts.map +1 -1
- package/dist/components/charts/line-chart/utils/key.js +2 -1
- package/dist/components/charts/line-chart/utils/key.js.map +1 -1
- package/dist/components/charts/line-chart/utils/labels.d.ts.map +1 -1
- package/dist/components/charts/line-chart/utils/labels.js +50 -46
- package/dist/components/charts/line-chart/utils/labels.js.map +1 -1
- package/dist/components/charts/pie-chart/components/pie-chart.js +60 -6
- package/dist/components/charts/pie-chart/components/pie-chart.js.map +1 -1
- package/dist/components/charts/pie-chart/components/pie-chart.module.less.d.ts +3 -0
- package/dist/components/charts/pie-chart/components/pie.js +176 -39
- package/dist/components/charts/pie-chart/components/pie.js.map +1 -1
- package/dist/components/charts/pie-chart/index.js +2 -0
- package/dist/components/charts/pie-chart/index.js.map +1 -1
- package/dist/components/charts/pie-chart/pie-chart.stories.d.ts +0 -1
- package/dist/components/charts/pie-chart/pie-chart.stories.d.ts.map +1 -1
- package/dist/components/charts/pie-chart/utils/const.d.ts.map +1 -1
- package/dist/components/charts/pie-chart/utils/const.js +55 -39
- package/dist/components/charts/pie-chart/utils/const.js.map +1 -1
- package/dist/components/charts/pie-chart/utils/interface.js +2 -1
- package/dist/components/charts/pie-chart/utils/interface.js.map +1 -1
- package/dist/components/image-cropper/image-cropper.d.ts.map +1 -1
- package/dist/components/image-cropper/image-cropper.js +74 -88
- package/dist/components/image-cropper/image-cropper.js.map +1 -1
- package/dist/components/stat/stat-card.js +68 -22
- package/dist/components/stat/stat-card.js.map +1 -1
- package/dist/components/stat/stat-card.module.less.d.ts +5 -0
- package/dist/components/stat/stat-cards.stories.d.ts +0 -1
- package/dist/components/stat/stat-cards.stories.d.ts.map +1 -1
- package/dist/components/stat/stat-extended-card.js +76 -4
- package/dist/components/stat/stat-extended-card.js.map +1 -1
- package/dist/components/stat/stat-extended-card.stories.d.ts +0 -1
- package/dist/components/stat/stat-extended-card.stories.d.ts.map +1 -1
- package/dist/components/ui/action-button/action-button.js +33 -7
- package/dist/components/ui/action-button/action-button.js.map +1 -1
- package/dist/components/ui/action-button/action-button.module.less.d.ts +9 -0
- package/dist/components/ui/action-button/action-button.stories.d.ts +0 -1
- package/dist/components/ui/action-button/action-button.stories.d.ts.map +1 -1
- package/dist/components/ui/action-button/index.js +1 -0
- package/dist/components/ui/action-button/index.js.map +1 -1
- package/dist/components/ui/centered-spinner/centered-spinner.js +20 -2
- package/dist/components/ui/centered-spinner/centered-spinner.js.map +1 -1
- package/dist/components/ui/centered-spinner/centered-spinner.stories.d.ts +0 -1
- package/dist/components/ui/centered-spinner/centered-spinner.stories.d.ts.map +1 -1
- package/dist/components/ui/date-range-picker/date-range-picker.d.ts.map +1 -1
- package/dist/components/ui/date-range-picker/date-range-picker.js +71 -35
- package/dist/components/ui/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/ui/date-range-picker/date-range-picker.module.less.d.ts +4 -0
- package/dist/components/ui/date-range-picker/date-range-picker.stories.d.ts.map +1 -1
- package/dist/components/ui/disabled-button.js +12 -3
- package/dist/components/ui/disabled-button.js.map +1 -1
- package/dist/components/ui/label-with-hint/label-with-hint.js +23 -1
- package/dist/components/ui/label-with-hint/label-with-hint.js.map +1 -1
- package/dist/components/ui/label-with-hint/label-with-hint.stories.d.ts +0 -1
- package/dist/components/ui/label-with-hint/label-with-hint.stories.d.ts.map +1 -1
- package/dist/components/ui/line-text/index.js +1 -0
- package/dist/components/ui/line-text/index.js.map +1 -1
- package/dist/components/ui/line-text/line-text-body.stories.d.ts +0 -1
- package/dist/components/ui/line-text/line-text-body.stories.d.ts.map +1 -1
- package/dist/components/ui/line-text/line-text-head.stories.d.ts +0 -1
- package/dist/components/ui/line-text/line-text-head.stories.d.ts.map +1 -1
- package/dist/components/ui/line-text/line-text.js +71 -25
- package/dist/components/ui/line-text/line-text.js.map +1 -1
- package/dist/components/ui/line-text/line-text.module.less.d.ts +6 -0
- package/dist/components/ui/title-popover/index.js +1 -0
- package/dist/components/ui/title-popover/index.js.map +1 -1
- package/dist/components/ui/title-popover/title-popover.d.ts.map +1 -1
- package/dist/components/ui/title-popover/title-popover.js +78 -69
- package/dist/components/ui/title-popover/title-popover.js.map +1 -1
- package/dist/components/ui/title-popover/title-popover.module.less.d.ts +3 -0
- package/dist/components/ui/title-popover/title-popover.stories.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/__tests__/format-big-numbers.test.d.ts +2 -0
- package/dist/utils/__tests__/format-big-numbers.test.d.ts.map +1 -0
- package/dist/utils/__tests__/formatters.test.d.ts +2 -0
- package/dist/utils/__tests__/formatters.test.d.ts.map +1 -0
- package/dist/utils/__tests__/helpers.test.d.ts +2 -0
- package/dist/utils/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/utils/__tests__/string-case.test.d.ts +2 -0
- package/dist/utils/__tests__/string-case.test.d.ts.map +1 -0
- package/dist/utils/ads-texts.js +2 -1
- package/dist/utils/ads-texts.js.map +1 -1
- package/dist/utils/date/__tests__/date-range-picker.test.d.ts +2 -0
- package/dist/utils/date/__tests__/date-range-picker.test.d.ts.map +1 -0
- package/dist/utils/date/__tests__/date-tenant.test.d.ts +2 -0
- package/dist/utils/date/__tests__/date-tenant.test.d.ts.map +1 -0
- package/dist/utils/date/date-range-picker-options.d.ts.map +1 -1
- package/dist/utils/date/date-range-picker-options.js +90 -68
- package/dist/utils/date/date-range-picker-options.js.map +1 -1
- package/dist/utils/date/date-range-picker-state.d.ts.map +1 -1
- package/dist/utils/date/date-range-picker-state.js +42 -43
- package/dist/utils/date/date-range-picker-state.js.map +1 -1
- package/dist/utils/date/date-tenant.js +4 -6
- package/dist/utils/date/date-tenant.js.map +1 -1
- package/dist/utils/date/date.d.ts.map +1 -1
- package/dist/utils/date/date.js +5 -9
- package/dist/utils/date/date.js.map +1 -1
- package/dist/utils/date/index.js +1 -0
- package/dist/utils/date/index.js.map +1 -1
- package/dist/utils/format-big-numbers.d.ts.map +1 -1
- package/dist/utils/format-big-numbers.js +11 -6
- package/dist/utils/format-big-numbers.js.map +1 -1
- package/dist/utils/formatters.d.ts.map +1 -1
- package/dist/utils/formatters.js +8 -7
- package/dist/utils/formatters.js.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +9 -12
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/marketing-parner-handlers.js +9 -12
- package/dist/utils/marketing-parner-handlers.js.map +1 -1
- package/dist/utils/string-case.js +1 -0
- package/dist/utils/string-case.js.map +1 -1
- package/dist/utils/use-client-rect.d.ts +1 -5
- package/dist/utils/use-client-rect.d.ts.map +1 -1
- package/dist/utils/use-client-rect.js +19 -19
- package/dist/utils/use-client-rect.js.map +1 -1
- package/dist/utils/use-target-range-store.js +7 -6
- package/dist/utils/use-target-range-store.js.map +1 -1
- package/package.json +11 -11
- package/src/components/charts/funnel-chart/funnel-chart.stories.tsx +3 -2
- package/src/components/charts/line-chart/components/svg-bars.tsx +2 -0
- package/src/components/ui/action-button/action-button.stories.tsx +3 -2
- package/src/components/ui/centered-spinner/centered-spinner.stories.tsx +3 -2
- package/src/components/ui/date-range-picker/date-range-picker.stories.tsx +5 -6
- package/src/components/ui/date-range-picker/date-range-picker.tsx +2 -2
- package/src/components/ui/line-text/line-text-body.stories.tsx +3 -2
- package/src/components/ui/line-text/line-text-head.stories.tsx +3 -2
- package/src/components/ui/line-text/line-text.tsx +1 -1
- package/src/components/ui/title-popover/title-popover.stories.tsx +3 -2
- package/src/utils/date/__tests__/date-range-picker.test.ts +1 -1
- package/src/utils/use-client-rect.ts +1 -1
- package/dist/components/charts/funnel-chart/funnel-chart.stories.js +0 -76
- package/dist/components/charts/funnel-chart/funnel-chart.stories.js.map +0 -1
- package/dist/components/charts/line-chart/line-chart.stories.js +0 -225
- package/dist/components/charts/line-chart/line-chart.stories.js.map +0 -1
- package/dist/components/charts/pie-chart/pie-chart.stories.js +0 -22
- package/dist/components/charts/pie-chart/pie-chart.stories.js.map +0 -1
- package/dist/components/image-cropper/image-cropper.stories.js +0 -48
- package/dist/components/image-cropper/image-cropper.stories.js.map +0 -1
- package/dist/components/stat/stat-cards.stories.js +0 -16
- package/dist/components/stat/stat-cards.stories.js.map +0 -1
- package/dist/components/stat/stat-extended-card.stories.js +0 -12
- package/dist/components/stat/stat-extended-card.stories.js.map +0 -1
- package/dist/components/ui/action-button/action-button.stories.js +0 -11
- package/dist/components/ui/action-button/action-button.stories.js.map +0 -1
- package/dist/components/ui/centered-spinner/centered-spinner.stories.js +0 -12
- package/dist/components/ui/centered-spinner/centered-spinner.stories.js.map +0 -1
- package/dist/components/ui/date-range-picker/date-range-picker.stories.js +0 -18
- package/dist/components/ui/date-range-picker/date-range-picker.stories.js.map +0 -1
- package/dist/components/ui/label-with-hint/label-with-hint.stories.js +0 -12
- package/dist/components/ui/label-with-hint/label-with-hint.stories.js.map +0 -1
- package/dist/components/ui/line-text/line-text-body.stories.js +0 -11
- package/dist/components/ui/line-text/line-text-body.stories.js.map +0 -1
- package/dist/components/ui/line-text/line-text-head.stories.js +0 -11
- package/dist/components/ui/line-text/line-text-head.stories.js.map +0 -1
- package/dist/components/ui/title-popover/title-popover.stories.js +0 -17
- package/dist/components/ui/title-popover/title-popover.stories.js.map +0 -1
- package/dist/utils/date/__mocks__/date-mock.js +0 -19
- package/dist/utils/date/__mocks__/date-mock.js.map +0 -1
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
22
|
+
}
|
|
10
23
|
import { injectable } from '@servicetitan/react-ioc';
|
|
11
24
|
import { action, observable, makeObservable } from 'mobx';
|
|
25
|
+
import { LineChartDisplay, LineChartResolution } from '../utils/interfaces';
|
|
12
26
|
import { defaultDisplay } from '../utils/const';
|
|
27
|
+
import { SideMetricsSettings } from '../utils/internal-interfaces';
|
|
13
28
|
import { getFormatter } from '../utils/formatters';
|
|
14
|
-
const getSideMetricsSettings = (metrics, values, range, title, format)
|
|
15
|
-
var _a;
|
|
29
|
+
const getSideMetricsSettings = (metrics, values, range, title, format)=>{
|
|
16
30
|
let maxRange = range !== null && range !== void 0 ? range : 0;
|
|
17
|
-
const lineBarMetricIDs = metrics
|
|
18
|
-
|
|
19
|
-
.map(m => m.id);
|
|
20
|
-
const stackedBarMetricIDs = metrics.filter(m => m.type === 'stacked-bar').map(m => m.id);
|
|
31
|
+
const lineBarMetricIDs = metrics.filter((m)=>m.type === 'line' || m.type === 'bar' || m.type === 'grouped-bar').map((m)=>m.id);
|
|
32
|
+
const stackedBarMetricIDs = metrics.filter((m)=>m.type === 'stacked-bar').map((m)=>m.id);
|
|
21
33
|
if (!maxRange) {
|
|
22
|
-
maxRange = values.reduce((sum, metricValues)
|
|
23
|
-
? Math.max(sum, metricValues.values.reduce((acc, v) => Math.max(acc, v), 0))
|
|
24
|
-
: sum, 0);
|
|
34
|
+
maxRange = values.reduce((sum, metricValues)=>lineBarMetricIDs.includes(metricValues.metricId) ? Math.max(sum, metricValues.values.reduce((acc, v)=>Math.max(acc, v), 0)) : sum, 0);
|
|
25
35
|
}
|
|
26
36
|
if (stackedBarMetricIDs.length) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const summedStackedMetrics = (_a = stackChartMetricValues[0]) === null || _a === void 0 ? void 0 : _a.map((value, i) => stackChartMetricValues.reduce((sum, metricValues) => sum + metricValues[i], 0));
|
|
37
|
+
var _stackChartMetricValues_;
|
|
38
|
+
const stackChartMetricValues = values.filter((metricValues)=>stackedBarMetricIDs.includes(metricValues.metricId)).map((metric)=>metric.values);
|
|
39
|
+
const summedStackedMetrics = (_stackChartMetricValues_ = stackChartMetricValues[0]) === null || _stackChartMetricValues_ === void 0 ? void 0 : _stackChartMetricValues_.map((value, i)=>stackChartMetricValues.reduce((sum, metricValues)=>sum + metricValues[i], 0));
|
|
31
40
|
if (summedStackedMetrics === null || summedStackedMetrics === void 0 ? void 0 : summedStackedMetrics.length) {
|
|
32
41
|
maxRange = Math.max(...summedStackedMetrics, maxRange);
|
|
33
42
|
}
|
|
@@ -45,141 +54,103 @@ const getSideMetricsSettings = (metrics, values, range, title, format) => {
|
|
|
45
54
|
const sums = [];
|
|
46
55
|
const step = maxRange / 10;
|
|
47
56
|
const formatter = getFormatter(format);
|
|
48
|
-
for
|
|
57
|
+
for(let i = 0; i < 10; i++){
|
|
49
58
|
sums.push(formatter(maxRange - i * step));
|
|
50
59
|
}
|
|
51
60
|
const width = title ? 64 : 48;
|
|
52
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
maxRange,
|
|
63
|
+
maxValue: 1.1 * maxRange,
|
|
64
|
+
title: title !== null && title !== void 0 ? title : '',
|
|
65
|
+
values: sums,
|
|
66
|
+
width
|
|
67
|
+
};
|
|
53
68
|
};
|
|
54
|
-
|
|
55
|
-
constructor()
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: void 0
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(this, "right", {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
configurable: true,
|
|
95
|
-
writable: true,
|
|
96
|
-
value: void 0
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(this, "hoveredIndex", {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true,
|
|
101
|
-
writable: true,
|
|
102
|
-
value: -1
|
|
69
|
+
export class LineChartStore {
|
|
70
|
+
constructor(){
|
|
71
|
+
_define_property(this, "isInit", false);
|
|
72
|
+
_define_property(this, "display", defaultDisplay());
|
|
73
|
+
_define_property(this, "metrics", []);
|
|
74
|
+
_define_property(this, "periods", []);
|
|
75
|
+
_define_property(this, "resolution", 'day');
|
|
76
|
+
_define_property(this, "left", void 0);
|
|
77
|
+
_define_property(this, "right", void 0);
|
|
78
|
+
_define_property(this, "hoveredIndex", -1);
|
|
79
|
+
_define_property(this, "init", (props)=>{
|
|
80
|
+
var _props_display;
|
|
81
|
+
this.display = {
|
|
82
|
+
...defaultDisplay(),
|
|
83
|
+
...(_props_display = props.display) !== null && _props_display !== void 0 ? _props_display : {}
|
|
84
|
+
};
|
|
85
|
+
this.metrics = props.metrics.map((m)=>{
|
|
86
|
+
const mv = props.metricValues.find((mv)=>mv.metricId === m.id);
|
|
87
|
+
var _m_type, _m_opts, _mv_values;
|
|
88
|
+
return {
|
|
89
|
+
...m,
|
|
90
|
+
isRight: !!m.isRight,
|
|
91
|
+
type: (_m_type = m.type) !== null && _m_type !== void 0 ? _m_type : 'line',
|
|
92
|
+
opts: (_m_opts = m.opts) !== null && _m_opts !== void 0 ? _m_opts : {},
|
|
93
|
+
values: (_mv_values = mv === null || mv === void 0 ? void 0 : mv.values) !== null && _mv_values !== void 0 ? _mv_values : [],
|
|
94
|
+
valuesOpts: mv === null || mv === void 0 ? void 0 : mv.opts
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
this.left = getSideMetricsSettings(this.metrics.filter((m)=>!m.isRight), props.metricValues, props.maxRange, props.titleY, this.display.yLeftFormat);
|
|
98
|
+
this.right = getSideMetricsSettings(this.metrics.filter((m)=>m.isRight), props.metricValues, props.maxRangeRight, props.titleYRight, this.display.yRightFormat);
|
|
99
|
+
this.resolution = props.resolution;
|
|
100
|
+
this.periods = props.periods || [];
|
|
101
|
+
this.hoveredIndex = -1;
|
|
102
|
+
this.isInit = true;
|
|
103
103
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
value: (props) => {
|
|
109
|
-
var _a;
|
|
110
|
-
this.display = Object.assign(Object.assign({}, defaultDisplay()), ((_a = props.display) !== null && _a !== void 0 ? _a : {}));
|
|
111
|
-
this.metrics = props.metrics.map(m => {
|
|
112
|
-
var _a, _b, _c;
|
|
113
|
-
const mv = props.metricValues.find(mv => mv.metricId === m.id);
|
|
114
|
-
return Object.assign(Object.assign({}, m), { isRight: !!m.isRight, type: (_a = m.type) !== null && _a !== void 0 ? _a : 'line', opts: (_b = m.opts) !== null && _b !== void 0 ? _b : {}, values: (_c = mv === null || mv === void 0 ? void 0 : mv.values) !== null && _c !== void 0 ? _c : [], valuesOpts: mv === null || mv === void 0 ? void 0 : mv.opts });
|
|
115
|
-
});
|
|
116
|
-
this.left = getSideMetricsSettings(this.metrics.filter(m => !m.isRight), props.metricValues, props.maxRange, props.titleY, this.display.yLeftFormat);
|
|
117
|
-
this.right = getSideMetricsSettings(this.metrics.filter(m => m.isRight), props.metricValues, props.maxRangeRight, props.titleYRight, this.display.yRightFormat);
|
|
118
|
-
this.resolution = props.resolution;
|
|
119
|
-
this.periods = props.periods || [];
|
|
104
|
+
_define_property(this, "setHoveredIndex", (index, isHovered)=>{
|
|
105
|
+
if (isHovered) {
|
|
106
|
+
this.hoveredIndex = index;
|
|
107
|
+
} else if (index === this.hoveredIndex) {
|
|
120
108
|
this.hoveredIndex = -1;
|
|
121
|
-
this.isInit = true;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
Object.defineProperty(this, "setHoveredIndex", {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
configurable: true,
|
|
127
|
-
writable: true,
|
|
128
|
-
value: (index, isHovered) => {
|
|
129
|
-
if (isHovered) {
|
|
130
|
-
this.hoveredIndex = index;
|
|
131
|
-
}
|
|
132
|
-
else if (index === this.hoveredIndex) {
|
|
133
|
-
this.hoveredIndex = -1;
|
|
134
|
-
}
|
|
135
109
|
}
|
|
136
110
|
});
|
|
137
111
|
makeObservable(this);
|
|
138
112
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
observable
|
|
142
|
-
__metadata("design:type", Object)
|
|
113
|
+
}
|
|
114
|
+
_ts_decorate([
|
|
115
|
+
observable
|
|
143
116
|
], LineChartStore.prototype, "isInit", void 0);
|
|
144
|
-
|
|
117
|
+
_ts_decorate([
|
|
145
118
|
observable,
|
|
146
|
-
|
|
119
|
+
_ts_metadata("design:type", typeof LineChartDisplay === "undefined" ? Object : LineChartDisplay)
|
|
147
120
|
], LineChartStore.prototype, "display", void 0);
|
|
148
|
-
|
|
121
|
+
_ts_decorate([
|
|
149
122
|
observable,
|
|
150
|
-
|
|
123
|
+
_ts_metadata("design:type", Array)
|
|
151
124
|
], LineChartStore.prototype, "metrics", void 0);
|
|
152
|
-
|
|
125
|
+
_ts_decorate([
|
|
153
126
|
observable,
|
|
154
|
-
|
|
127
|
+
_ts_metadata("design:type", Array)
|
|
155
128
|
], LineChartStore.prototype, "periods", void 0);
|
|
156
|
-
|
|
129
|
+
_ts_decorate([
|
|
157
130
|
observable,
|
|
158
|
-
|
|
131
|
+
_ts_metadata("design:type", typeof LineChartResolution === "undefined" ? Object : LineChartResolution)
|
|
159
132
|
], LineChartStore.prototype, "resolution", void 0);
|
|
160
|
-
|
|
133
|
+
_ts_decorate([
|
|
161
134
|
observable,
|
|
162
|
-
|
|
135
|
+
_ts_metadata("design:type", typeof SideMetricsSettings === "undefined" ? Object : SideMetricsSettings)
|
|
163
136
|
], LineChartStore.prototype, "left", void 0);
|
|
164
|
-
|
|
137
|
+
_ts_decorate([
|
|
165
138
|
observable,
|
|
166
|
-
|
|
139
|
+
_ts_metadata("design:type", typeof SideMetricsSettings === "undefined" ? Object : SideMetricsSettings)
|
|
167
140
|
], LineChartStore.prototype, "right", void 0);
|
|
168
|
-
|
|
169
|
-
observable
|
|
170
|
-
__metadata("design:type", Object)
|
|
141
|
+
_ts_decorate([
|
|
142
|
+
observable
|
|
171
143
|
], LineChartStore.prototype, "hoveredIndex", void 0);
|
|
172
|
-
|
|
173
|
-
action
|
|
174
|
-
__metadata("design:type", Object)
|
|
144
|
+
_ts_decorate([
|
|
145
|
+
action
|
|
175
146
|
], LineChartStore.prototype, "init", void 0);
|
|
176
|
-
|
|
177
|
-
action
|
|
178
|
-
__metadata("design:type", Object)
|
|
147
|
+
_ts_decorate([
|
|
148
|
+
action
|
|
179
149
|
], LineChartStore.prototype, "setHoveredIndex", void 0);
|
|
180
|
-
LineChartStore =
|
|
150
|
+
LineChartStore = _ts_decorate([
|
|
181
151
|
injectable(),
|
|
182
|
-
|
|
152
|
+
_ts_metadata("design:type", Function),
|
|
153
|
+
_ts_metadata("design:paramtypes", [])
|
|
183
154
|
], LineChartStore);
|
|
184
|
-
|
|
155
|
+
|
|
185
156
|
//# sourceMappingURL=line-chart.store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/line-chart/stores/line-chart.store.ts"],"sourcesContent":["import { injectable } from '@servicetitan/react-ioc';\nimport { action, observable, makeObservable } from 'mobx';\nimport {\n LineChartDisplay,\n LineChartDisplayValueFormat,\n LineChartMetricValues,\n LineChartPeriod,\n LineChartProps,\n LineChartResolution,\n} from '../utils/interfaces';\nimport { defaultDisplay } from '../utils/const';\nimport { ChartMetric, SideMetricsSettings } from '../utils/internal-interfaces';\nimport { getFormatter } from '../utils/formatters';\n\nconst getSideMetricsSettings = (\n metrics: ChartMetric[],\n values: LineChartMetricValues[],\n range?: number,\n title?: string,\n format?: LineChartDisplayValueFormat\n): SideMetricsSettings | undefined => {\n let maxRange = range ?? 0;\n const lineBarMetricIDs = metrics\n .filter(m => m.type === 'line' || m.type === 'bar' || m.type === 'grouped-bar')\n .map(m => m.id);\n const stackedBarMetricIDs = metrics.filter(m => m.type === 'stacked-bar').map(m => m.id);\n\n if (!maxRange) {\n maxRange = values.reduce(\n (sum, metricValues) =>\n lineBarMetricIDs.includes(metricValues.metricId)\n ? Math.max(\n sum,\n metricValues.values.reduce((acc, v) => Math.max(acc, v), 0)\n )\n : sum,\n 0\n );\n }\n\n if (stackedBarMetricIDs.length) {\n const stackChartMetricValues = values\n .filter(metricValues => stackedBarMetricIDs.includes(metricValues.metricId))\n .map(metric => metric.values);\n\n const summedStackedMetrics = stackChartMetricValues[0]?.map((value, i) =>\n stackChartMetricValues.reduce((sum, metricValues) => sum + metricValues[i], 0)\n );\n\n if (summedStackedMetrics?.length) {\n maxRange = Math.max(...summedStackedMetrics, maxRange);\n }\n }\n\n if (!maxRange) {\n if (!lineBarMetricIDs.length && !stackedBarMetricIDs.length) {\n return undefined;\n }\n\n maxRange = 10;\n }\n\n maxRange = Math.max(maxRange, 10);\n\n if (format === 'moneyShort' && maxRange > 1000 && maxRange < 10000) {\n maxRange = 10000;\n }\n\n const sums = [];\n const step = maxRange / 10;\n const formatter = getFormatter(format);\n\n for (let i = 0; i < 10; i++) {\n sums.push(formatter(maxRange - i * step));\n }\n\n const width = title ? 64 : 48;\n\n return { maxRange, maxValue: 1.1 * maxRange, title: title ?? '', values: sums, width };\n};\n\n@injectable()\nexport class LineChartStore {\n @observable isInit = false;\n @observable display: LineChartDisplay = defaultDisplay();\n @observable metrics: ChartMetric[] = [];\n @observable periods: LineChartPeriod[] = [];\n @observable resolution: LineChartResolution = 'day';\n\n @observable left?: SideMetricsSettings;\n @observable right?: SideMetricsSettings;\n\n @observable hoveredIndex = -1;\n\n constructor() {\n makeObservable(this);\n }\n\n @action init = (props: LineChartProps) => {\n this.display = {\n ...defaultDisplay(),\n ...(props.display ?? {}),\n };\n\n this.metrics = props.metrics.map(m => {\n const mv = props.metricValues.find(mv => mv.metricId === m.id);\n\n return {\n ...m,\n isRight: !!m.isRight,\n type: m.type ?? 'line',\n opts: m.opts ?? {},\n values: mv?.values ?? [],\n valuesOpts: mv?.opts,\n };\n });\n\n this.left = getSideMetricsSettings(\n this.metrics.filter(m => !m.isRight),\n props.metricValues,\n props.maxRange,\n props.titleY,\n this.display.yLeftFormat\n );\n this.right = getSideMetricsSettings(\n this.metrics.filter(m => m.isRight),\n props.metricValues,\n props.maxRangeRight,\n props.titleYRight,\n this.display.yRightFormat\n );\n\n this.resolution = props.resolution;\n this.periods = props.periods || [];\n this.hoveredIndex = -1;\n this.isInit = true;\n };\n\n @action setHoveredIndex = (index: number, isHovered: boolean) => {\n if (isHovered) {\n this.hoveredIndex = index;\n } else if (index === this.hoveredIndex) {\n this.hoveredIndex = -1;\n }\n };\n}\n"],"names":["injectable","action","observable","makeObservable","LineChartDisplay","LineChartResolution","defaultDisplay","SideMetricsSettings","getFormatter","getSideMetricsSettings","metrics","values","range","title","format","maxRange","lineBarMetricIDs","filter","m","type","map","id","stackedBarMetricIDs","reduce","sum","metricValues","includes","metricId","Math","max","acc","v","length","stackChartMetricValues","metric","summedStackedMetrics","value","i","undefined","sums","step","formatter","push","width","maxValue","LineChartStore","constructor","isInit","display","periods","resolution","left","right","hoveredIndex","init","props","mv","find","isRight","opts","valuesOpts","titleY","yLeftFormat","maxRangeRight","titleYRight","yRightFormat","setHoveredIndex","index","isHovered"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,QAAQ,0BAA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GAAG,CAAC;YACzB;QACJ;QAjDIlD,eAAe,IAAI;IACvB;AAiDJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svg.store.d.ts","sourceRoot":"","sources":["../../../../../src/components/charts/line-chart/stores/svg.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAK3D,qBACa,QAAQ;IACL,GAAG,SAAK;IACR,MAAM,SAAK;IACX,OAAO,SAAK;IACZ,QAAQ,SAAK;IAEzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,aAAa,CAAK;;IAMlB,IAAI,
|
|
1
|
+
{"version":3,"file":"svg.store.d.ts","sourceRoot":"","sources":["../../../../../src/components/charts/line-chart/stores/svg.store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAK3D,qBACa,QAAQ;IACL,GAAG,SAAK;IACR,MAAM,SAAK;IACX,OAAO,SAAK;IACZ,QAAQ,SAAK;IAEzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,aAAa,CAAK;;IAMlB,IAAI,GACR,QAAQ,MAAM,EACd,SAAS,WAAW,EAAE,EACtB,cAAc,MAAM,EACpB,eAAe,MAAM,UAoBvB;IAEF,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI9B,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAO5C,GAAG,GAAI,KAAK,MAAM,KAAG,MAAM,CAEzB;IAEF,GAAG,GAAI,KAAK,MAAM,KAAG,MAAM,CAEzB;CACL"}
|
|
@@ -1,131 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
22
|
+
}
|
|
10
23
|
import { injectable } from '@servicetitan/react-ioc';
|
|
11
24
|
import { action, observable, makeObservable } from 'mobx';
|
|
12
25
|
const barRelativeWidth = 0.8;
|
|
13
26
|
const maxBarWidth = 7;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
Object.defineProperty(this, "key", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: 0
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(this, "length", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: 1
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(this, "xOffset", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: 0
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(this, "barWidth", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: 0
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, "fullBarWidth", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: 0
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(this, "maxValueLeft", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: 0
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "maxValueRight", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: 0
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(this, "init", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: (length, metrics, maxValueLeft, maxValueRight) => {
|
|
63
|
-
this.length = length || 1;
|
|
64
|
-
this.key = Date.now();
|
|
65
|
-
const hasBars = !!metrics.filter(m => m.type === 'bar' || m.type === 'stacked-bar' || m.type === 'grouped-bar').length;
|
|
66
|
-
if (hasBars) {
|
|
67
|
-
this.fullBarWidth = 100 / this.length;
|
|
68
|
-
this.xOffset = this.fullBarWidth / 2;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.fullBarWidth = 100 / (this.length - 1);
|
|
72
|
-
this.xOffset = 0;
|
|
73
|
-
}
|
|
74
|
-
this.barWidth = Math.min(barRelativeWidth * this.fullBarWidth, maxBarWidth);
|
|
75
|
-
this.maxValueLeft = maxValueLeft;
|
|
76
|
-
this.maxValueRight = maxValueRight;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, "fpx", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: (val) => {
|
|
84
|
-
return val.toFixed(1);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(this, "fpy", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: true,
|
|
91
|
-
value: (val) => {
|
|
92
|
-
return (100 - val).toFixed(1);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
makeObservable(this);
|
|
96
|
-
}
|
|
27
|
+
export class SvgStore {
|
|
97
28
|
periodX(index) {
|
|
98
29
|
return this.xOffset + this.fullBarWidth * index;
|
|
99
30
|
}
|
|
100
31
|
periodY(m, ind) {
|
|
101
32
|
const value = ind < 0 || ind >= m.values.length ? 0 : m.values[ind];
|
|
102
33
|
const maxValue = m.isRight ? this.maxValueRight : this.maxValueLeft;
|
|
103
|
-
return value && maxValue ?
|
|
34
|
+
return value && maxValue ? 100 * value / maxValue : 0;
|
|
35
|
+
}
|
|
36
|
+
constructor(){
|
|
37
|
+
_define_property(this, "key", 0);
|
|
38
|
+
_define_property(this, "length", 1);
|
|
39
|
+
_define_property(this, "xOffset", 0);
|
|
40
|
+
_define_property(this, "barWidth", 0);
|
|
41
|
+
_define_property(this, "fullBarWidth", 0);
|
|
42
|
+
_define_property(this, "maxValueLeft", 0);
|
|
43
|
+
_define_property(this, "maxValueRight", 0);
|
|
44
|
+
_define_property(this, "init", (length, metrics, maxValueLeft, maxValueRight)=>{
|
|
45
|
+
this.length = length || 1;
|
|
46
|
+
this.key = Date.now();
|
|
47
|
+
const hasBars = !!metrics.filter((m)=>m.type === 'bar' || m.type === 'stacked-bar' || m.type === 'grouped-bar').length;
|
|
48
|
+
if (hasBars) {
|
|
49
|
+
this.fullBarWidth = 100 / this.length;
|
|
50
|
+
this.xOffset = this.fullBarWidth / 2;
|
|
51
|
+
} else {
|
|
52
|
+
this.fullBarWidth = 100 / (this.length - 1);
|
|
53
|
+
this.xOffset = 0;
|
|
54
|
+
}
|
|
55
|
+
this.barWidth = Math.min(barRelativeWidth * this.fullBarWidth, maxBarWidth);
|
|
56
|
+
this.maxValueLeft = maxValueLeft;
|
|
57
|
+
this.maxValueRight = maxValueRight;
|
|
58
|
+
});
|
|
59
|
+
_define_property(this, "fpx", (val)=>{
|
|
60
|
+
return val.toFixed(1);
|
|
61
|
+
});
|
|
62
|
+
_define_property(this, "fpy", (val)=>{
|
|
63
|
+
return (100 - val).toFixed(1);
|
|
64
|
+
});
|
|
65
|
+
makeObservable(this);
|
|
104
66
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
observable
|
|
108
|
-
__metadata("design:type", Object)
|
|
67
|
+
}
|
|
68
|
+
_ts_decorate([
|
|
69
|
+
observable
|
|
109
70
|
], SvgStore.prototype, "key", void 0);
|
|
110
|
-
|
|
111
|
-
observable
|
|
112
|
-
__metadata("design:type", Object)
|
|
71
|
+
_ts_decorate([
|
|
72
|
+
observable
|
|
113
73
|
], SvgStore.prototype, "length", void 0);
|
|
114
|
-
|
|
115
|
-
observable
|
|
116
|
-
__metadata("design:type", Object)
|
|
74
|
+
_ts_decorate([
|
|
75
|
+
observable
|
|
117
76
|
], SvgStore.prototype, "xOffset", void 0);
|
|
118
|
-
|
|
119
|
-
observable
|
|
120
|
-
__metadata("design:type", Object)
|
|
77
|
+
_ts_decorate([
|
|
78
|
+
observable
|
|
121
79
|
], SvgStore.prototype, "barWidth", void 0);
|
|
122
|
-
|
|
123
|
-
action
|
|
124
|
-
__metadata("design:type", Object)
|
|
80
|
+
_ts_decorate([
|
|
81
|
+
action
|
|
125
82
|
], SvgStore.prototype, "init", void 0);
|
|
126
|
-
SvgStore =
|
|
83
|
+
SvgStore = _ts_decorate([
|
|
127
84
|
injectable(),
|
|
128
|
-
|
|
85
|
+
_ts_metadata("design:type", Function),
|
|
86
|
+
_ts_metadata("design:paramtypes", [])
|
|
129
87
|
], SvgStore);
|
|
130
|
-
|
|
88
|
+
|
|
131
89
|
//# sourceMappingURL=svg.store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/line-chart/stores/svg.store.ts"],"sourcesContent":["import { injectable } from '@servicetitan/react-ioc';\nimport { action, observable, makeObservable } from 'mobx';\nimport { ChartMetric } from '../utils/internal-interfaces';\n\nconst barRelativeWidth = 0.8;\nconst maxBarWidth = 7;\n\n@injectable()\nexport class SvgStore {\n @observable key = 0;\n @observable length = 1;\n @observable xOffset = 0;\n @observable barWidth = 0;\n\n private fullBarWidth = 0;\n private maxValueLeft = 0;\n private maxValueRight = 0;\n\n constructor() {\n makeObservable(this);\n }\n\n @action init = (\n length: number,\n metrics: ChartMetric[],\n maxValueLeft: number,\n maxValueRight: number\n ) => {\n this.length = length || 1;\n this.key = Date.now();\n\n const hasBars = !!metrics.filter(\n m => m.type === 'bar' || m.type === 'stacked-bar' || m.type === 'grouped-bar'\n ).length;\n\n if (hasBars) {\n this.fullBarWidth = 100 / this.length;\n this.xOffset = this.fullBarWidth / 2;\n } else {\n this.fullBarWidth = 100 / (this.length - 1);\n this.xOffset = 0;\n }\n\n this.barWidth = Math.min(barRelativeWidth * this.fullBarWidth, maxBarWidth);\n this.maxValueLeft = maxValueLeft;\n this.maxValueRight = maxValueRight;\n };\n\n periodX(index: number): number {\n return this.xOffset + this.fullBarWidth * index;\n }\n\n periodY(m: ChartMetric, ind: number): number {\n const value = ind < 0 || ind >= m.values.length ? 0 : m.values[ind];\n const maxValue = m.isRight ? this.maxValueRight : this.maxValueLeft;\n\n return value && maxValue ? (100 * value) / maxValue : 0;\n }\n\n fpx = (val: number): string => {\n return val.toFixed(1);\n };\n\n fpy = (val: number): string => {\n return (100 - val).toFixed(1);\n };\n}\n"],"names":["injectable","action","observable","makeObservable","barRelativeWidth","maxBarWidth","SvgStore","periodX","index","xOffset","fullBarWidth","periodY","m","ind","value","values","length","maxValue","isRight","maxValueRight","maxValueLeft","constructor","key","barWidth","init","metrics","Date","now","h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O,CAAA,IAAI,CAACM,MAAM,GAAG,CAAA;gBACzC,IAAI,CAACP,OAAO,GAAG;YACnB;YAEA,IAAI,CAACc,QAAQ,GAAGQ,KAAKC,GAAG,CAAC5B,mBAAmB,IAAI,CAACM,YAAY,EAAEL;YAC/D,IAAI,CAACe,YAAY,GAAGA;YACpB,IAAI,CAACD,aAAa,GAAGA;QACzB;QAaAc,uBAAAA,OAAM,CAACC;YACH,OAAOA,IAAIC,OAAO,CAAC;QACvB;QAEAC,uBAAAA,OAAM,CAACF;YACH,OAAO,AAAC,CAAA,MAAMA,GAAE,EAAGC,OAAO,CAAC;QAC/B;QA9CIhC,eAAe,IAAI;IACvB;AA8CJ"}
|
|
@@ -2,12 +2,13 @@ export const chartResolutionTitles = {
|
|
|
2
2
|
hour: 'by hour',
|
|
3
3
|
day: 'by day',
|
|
4
4
|
week: 'by week',
|
|
5
|
-
month: 'by month'
|
|
5
|
+
month: 'by month'
|
|
6
6
|
};
|
|
7
|
-
export const defaultDisplay = ()
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
7
|
+
export const defaultDisplay = ()=>({
|
|
8
|
+
xLabels: true,
|
|
9
|
+
yGrid: true,
|
|
10
|
+
yLeft: true,
|
|
11
|
+
yRight: true
|
|
12
|
+
});
|
|
13
|
+
|
|
13
14
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/line-chart/utils/const.ts"],"sourcesContent":["import { LineChartResolution, LineChartDisplay } from './interfaces';\n\nexport const chartResolutionTitles: Record<LineChartResolution, string> = {\n hour: 'by hour',\n day: 'by day',\n week: 'by week',\n month: 'by month',\n};\n\nexport const defaultDisplay = (): LineChartDisplay => ({\n xLabels: true,\n yGrid: true,\n yLeft: true,\n yRight: true,\n});\n"],"names":["chartResolutionTitles","hour","day","week","month","defaultDisplay","xLabels","yGrid","yLeft","yRight"],"mappings":"AAEA,OAAO,MAAMA,wBAA6D;IACtEC,MAAM;IACNC,KAAK;IACLC,MAAM;IACNC,OAAO;AACX,EAAE;AAEF,OAAO,MAAMC,iBAAiB,IAAyB,CAAA;QACnDC,SAAS;QACTC,OAAO;QACPC,OAAO;QACPC,QAAQ;IACZ,CAAA,EAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../src/components/charts/line-chart/utils/formatters.ts"],"names":[],"mappings":"AACA,OAAO,EACH,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,EACrC,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,UAAU,EAAE,MAAM,CAC3B,kCAAkC,EAClC,8BAA8B,CAkBjC,CAAC;AAEF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../src/components/charts/line-chart/utils/formatters.ts"],"names":[],"mappings":"AACA,OAAO,EACH,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,EACrC,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,UAAU,EAAE,MAAM,CAC3B,kCAAkC,EAClC,8BAA8B,CAkBjC,CAAC;AAEF,eAAO,MAAM,YAAY,GACrB,SAAS,2BAA2B,KACrC,8BAKwB,CAAC"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { formatMoney } from 'accounting';
|
|
2
2
|
export const formatters = {
|
|
3
|
-
number: (value)
|
|
4
|
-
money: (value)
|
|
5
|
-
moneyShort: (value)
|
|
6
|
-
const postfixes = [
|
|
3
|
+
number: (value)=>Math.round(value).toLocaleString(),
|
|
4
|
+
money: (value)=>formatMoney(value, undefined, 0),
|
|
5
|
+
moneyShort: (value)=>{
|
|
6
|
+
const postfixes = [
|
|
7
|
+
'',
|
|
8
|
+
'K',
|
|
9
|
+
'M',
|
|
10
|
+
'B'
|
|
11
|
+
];
|
|
7
12
|
let val = value;
|
|
8
|
-
for
|
|
13
|
+
for(let i = 0; i < postfixes.length; i++){
|
|
9
14
|
if (val < 1000 || i === postfixes.length - 1) {
|
|
10
15
|
return formatMoney(Math.round(val), undefined, 0) + postfixes[i];
|
|
11
16
|
}
|
|
12
17
|
val = val / 1000;
|
|
13
18
|
}
|
|
14
19
|
return '';
|
|
15
|
-
}
|
|
20
|
+
}
|
|
16
21
|
};
|
|
17
|
-
export const getFormatter = (format)
|
|
18
|
-
|
|
19
|
-
? formatters[format] || formatters.number
|
|
20
|
-
: format
|
|
21
|
-
: formatters.number;
|
|
22
|
+
export const getFormatter = (format)=>format ? typeof format === 'string' ? formatters[format] || formatters.number : format : formatters.number;
|
|
23
|
+
|
|
22
24
|
//# sourceMappingURL=formatters.js.map
|