iph-chart 0.1.0 → 1.1.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/package.json +3 -2
- package/src/index.js +59 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iph-chart",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "creates charts and transforms user data into visual components",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"src"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "npm run test"
|
|
14
|
+
"test": "npm run test",
|
|
15
|
+
"build": "echo \"No build step needed for now\""
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
package/src/index.js
CHANGED
|
@@ -1,29 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Line } from 'react-chartjs-2';
|
|
3
|
+
import { Chart as ChartJS, registerables } from 'chart.js';
|
|
4
|
+
|
|
5
|
+
ChartJS.register(...registerables);
|
|
6
|
+
|
|
7
|
+
export const IphLineChart = ({
|
|
8
|
+
jsonData,
|
|
9
|
+
labelKey,
|
|
10
|
+
dataKey,
|
|
11
|
+
title = "Dataset",
|
|
12
|
+
color = "#3b82f6",
|
|
13
|
+
showCrosshair = true,
|
|
14
|
+
showTooltip = true
|
|
15
|
+
}) => {
|
|
16
|
+
if (!jsonData || jsonData.length === 0) return <div>No data found</div>;
|
|
17
|
+
|
|
18
|
+
const data = {
|
|
19
|
+
labels: jsonData.map(item => item[labelKey]),
|
|
20
|
+
datasets: [{
|
|
21
|
+
label: title,
|
|
22
|
+
data: jsonData.map(item => item[dataKey]),
|
|
23
|
+
borderColor: color,
|
|
24
|
+
backgroundColor: color + '33',
|
|
25
|
+
fill: true,
|
|
26
|
+
pointRadius: 4,
|
|
27
|
+
pointHoverRadius: 6,
|
|
28
|
+
borderWidth: 2,
|
|
29
|
+
tension: 0.4,
|
|
30
|
+
}]
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const options = {
|
|
34
|
+
responsive: true,
|
|
35
|
+
maintainAspectRatio: false,
|
|
36
|
+
plugins: {
|
|
37
|
+
legend: { display: true, position: 'top' },
|
|
38
|
+
tooltip: {
|
|
39
|
+
enabled: showTooltip,
|
|
40
|
+
intersect: false,
|
|
41
|
+
mode: 'index',
|
|
23
42
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
},
|
|
44
|
+
scales: {
|
|
45
|
+
x: { grid: { display: false } },
|
|
46
|
+
y: { beginAtZero: true }
|
|
47
|
+
},
|
|
48
|
+
interaction: {
|
|
49
|
+
mode: 'index',
|
|
50
|
+
intersect: false,
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
hover: {
|
|
54
|
+
mode: 'index',
|
|
55
|
+
intersect: false
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return <Line data={data} options={options} />;
|
|
60
|
+
};
|