-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathModuleDrag.js
More file actions
106 lines (96 loc) · 2.34 KB
/
Copy pathModuleDrag.js
File metadata and controls
106 lines (96 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React, { useState, useRef } from "react";
import "zingchart/es6";
import ZingChart from "../lib/Zingchart";
import "zingchart/modules-es6/zingchart-dragging.min.js";
/*
* Demonstrate interacting with a chart to change its data
* using the dragging module. Note that the module is imported
* and then passed as a prop to the ZingChart component.
*/
function ModuleDrag() {
const startingValues = [20, 40, 14, 50, 15, 35, 5];
const goals = [25, 43, 30, 40, 21, 59, 35];
// Compare values to goals and return count of goals met
function countGoodDays(vs, gs) {
let n = 0;
for (const i in vs) if (vs[i] >= gs[i]) n++;
return n;
}
const chart = useRef(null);
const [goodDays, setGoodDays] = useState(
countGoodDays(startingValues, goals)
);
const [config] = useState({
type: "vbullet",
title: {
text: "Pushups Per Day",
},
subtitle: {
text: "Bars are draggable",
},
plot: {
valueBox: [
{
type: "all",
text: "[%node-value / %node-goal-value]",
color: "#000",
placement: "goal",
},
],
},
scaleX: {
labels: ["Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun"],
},
tooltip: {
borderRadius: "3px",
borderWidth: "0px",
fontSize: "14px",
shadow: true,
},
series: [
{
values: startingValues,
dataDragging: true,
goal: {
backgroundColor: "#64b5f6",
borderWidth: "0px",
},
goals: goals,
rules: [
{
backgroundColor: "#81c784",
rule: "%v >= %g",
},
{
backgroundColor: "#ef5350",
rule: "%v < %g/2",
},
{
backgroundColor: "#ffca28",
rule: "%v >= %g/2 && %v < %g",
},
],
},
],
});
/*
* Update the number of days the goals have been met
*/
function showData() {
const data = chart.current.getseriesdata();
setGoodDays(countGoodDays(data[0].values, data[0].goals));
}
return (
<div>
<div>Goals met {goodDays} days this week</div>
<ZingChart
ref={chart}
data={config}
height="600px"
modules="dragging"
zingchart_plugins_dragging_complete={showData}
/>
</div>
);
}
export default ModuleDrag;