@cashub/ui 0.48.0 → 0.48.2
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/chart/LineChart.js
CHANGED
|
@@ -8,6 +8,7 @@ var _react = require("react");
|
|
|
8
8
|
var _styledComponents = require("styled-components");
|
|
9
9
|
var _reactChartjs = require("react-chartjs-2");
|
|
10
10
|
var _customTooltip = _interopRequireDefault(require("./utils/customTooltip"));
|
|
11
|
+
var _yAxisTopTitlePlugin = _interopRequireDefault(require("./utils/yAxisTopTitlePlugin"));
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
const LineChart = _ref => {
|
|
@@ -25,17 +26,23 @@ const LineChart = _ref => {
|
|
|
25
26
|
_reactChartjs.defaults.color = theme.fontOnBg;
|
|
26
27
|
_reactChartjs.defaults.plugins.tooltip.external = (0, _customTooltip.default)(theme);
|
|
27
28
|
const customOptions = (0, _react.useMemo)(() => {
|
|
29
|
+
const {
|
|
30
|
+
yAxisTopTitle
|
|
31
|
+
} = options;
|
|
28
32
|
return {
|
|
29
33
|
suggestedMax: options.suggestedMax ? options.suggestedMax : 10,
|
|
30
34
|
tooltipTitlePrefix: '',
|
|
31
35
|
tooltipLabelPrefix: '',
|
|
32
|
-
|
|
36
|
+
tooltipLabelPostfix: '',
|
|
37
|
+
showLegend: options.showLegend === undefined ? false : options.showLegend,
|
|
38
|
+
yAxisTopTitle: yAxisTopTitle ? yAxisTopTitle : ''
|
|
33
39
|
};
|
|
34
40
|
}, [options]);
|
|
35
41
|
if (options.tooltips) {
|
|
36
42
|
const tooltipsOptions = options.tooltips;
|
|
37
43
|
customOptions.tooltipTitlePrefix = tooltipsOptions.titlePrefix || '';
|
|
38
44
|
customOptions.tooltipLabelPrefix = tooltipsOptions.labelPrefix || '';
|
|
45
|
+
customOptions.tooltipLabelPostfix = tooltipsOptions.labelPostfix || '';
|
|
39
46
|
}
|
|
40
47
|
const defaultOptions = (0, _react.useMemo)(() => {
|
|
41
48
|
return {
|
|
@@ -59,7 +66,7 @@ const LineChart = _ref => {
|
|
|
59
66
|
},
|
|
60
67
|
label(context) {
|
|
61
68
|
const content = context.dataset.data[context.dataIndex].toString();
|
|
62
|
-
return `${customOptions.tooltipLabelPrefix}${content}`;
|
|
69
|
+
return `${customOptions.tooltipLabelPrefix}${content}${customOptions.tooltipLabelPostfix}`;
|
|
63
70
|
},
|
|
64
71
|
labelColor(context) {
|
|
65
72
|
const {
|
|
@@ -83,6 +90,9 @@ const LineChart = _ref => {
|
|
|
83
90
|
return color;
|
|
84
91
|
}
|
|
85
92
|
}
|
|
93
|
+
},
|
|
94
|
+
yAxisTopTitle: {
|
|
95
|
+
title: customOptions.yAxisTopTitle
|
|
86
96
|
}
|
|
87
97
|
},
|
|
88
98
|
scales: {
|
|
@@ -108,6 +118,11 @@ const LineChart = _ref => {
|
|
|
108
118
|
}
|
|
109
119
|
}
|
|
110
120
|
}
|
|
121
|
+
},
|
|
122
|
+
layout: {
|
|
123
|
+
padding: {
|
|
124
|
+
top: 32
|
|
125
|
+
}
|
|
111
126
|
}
|
|
112
127
|
};
|
|
113
128
|
}, [customOptions, theme.fontOnPrimary]);
|
|
@@ -115,6 +130,7 @@ const LineChart = _ref => {
|
|
|
115
130
|
height: height,
|
|
116
131
|
data: data,
|
|
117
132
|
options: defaultOptions,
|
|
133
|
+
plugins: [_yAxisTopTitlePlugin.default],
|
|
118
134
|
...props
|
|
119
135
|
});
|
|
120
136
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactChartjs = require("react-chartjs-2");
|
|
8
|
+
const yAxisTopTitlePlugin = {
|
|
9
|
+
id: 'yAxisTopTitle',
|
|
10
|
+
afterDraw(chart) {
|
|
11
|
+
const {
|
|
12
|
+
options
|
|
13
|
+
} = chart.config;
|
|
14
|
+
const config = options.plugins.yAxisTopTitle;
|
|
15
|
+
if (!config || !config.title) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const {
|
|
19
|
+
title
|
|
20
|
+
} = config;
|
|
21
|
+
const {
|
|
22
|
+
ctx,
|
|
23
|
+
chartArea,
|
|
24
|
+
scales
|
|
25
|
+
} = chart;
|
|
26
|
+
const yScale = scales.y;
|
|
27
|
+
if (!yScale) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
ctx.save();
|
|
31
|
+
const {
|
|
32
|
+
font,
|
|
33
|
+
color
|
|
34
|
+
} = _reactChartjs.defaults;
|
|
35
|
+
const {
|
|
36
|
+
family,
|
|
37
|
+
size
|
|
38
|
+
} = font;
|
|
39
|
+
ctx.font = `bold ${size}px ${family}`;
|
|
40
|
+
ctx.fillStyle = color;
|
|
41
|
+
ctx.textAlign = 'left';
|
|
42
|
+
ctx.textBaseline = 'middle';
|
|
43
|
+
const x = yScale.left;
|
|
44
|
+
const y = chartArea.top - 24;
|
|
45
|
+
ctx.fillText(title, x, y);
|
|
46
|
+
ctx.restore();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var _default = exports.default = yAxisTopTitlePlugin;
|
package/package.json
CHANGED