-
Notifications
You must be signed in to change notification settings - Fork 2
/
chartControls.js
107 lines (94 loc) · 2.46 KB
/
chartControls.js
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
107
import { update } from "./update.js";
import { html } from "./html.js";
import {
defaultByDate,
defaultFromPatient,
LabelStrategies,
ValueStrategies
} from "./state.js";
import { targetValue } from "./web_modules/@hyperapp/events.js";
export const RemoveFromSelector = state =>
update({
...state,
labelStrategy: [state.labelStrategy[0], ""]
});
export const ChangeLabelStrategy = by => state =>
update({ ...state, labelStrategy: by });
export const SetFromPatient = (state, patient) => {
if (!Array.isArray(state.labelStrategy[0])) {
return state;
}
const newState = {
...state
};
const within = (min, max) => n =>
Math.min(max, Math.max(min, Number(patient)));
newState.labelStrategy[0][1] = within(0, 99999)(Number(patient));
return update(newState);
};
const staticChip = (label, action) => () => html`
<span class="chip c-hand" onclick=${action}>
${label}
<span class="btn btn-clear" href="#" role="button"></span>
</span>
`;
const fromChip = value =>
value
? html`
<span class="chip c-hand" onclick=${RemoveFromSelector}>
From Day ${value}
<span
class="btn btn-clear"
href="#"
aria-label="Remove Date"
role="button"
></span>
</span>
`
: "";
const fromPatient = n =>
html`
${staticChip("From Patient", ChangeLabelStrategy(defaultByDate))()}
${patientNumber(n)}
`;
const patientNumber = n =>
html`
<span class="chip">
<input
class="chip-input"
onchange=${[SetFromPatient, targetValue]}
type="number"
min="0"
max="99999"
value=${n}
/>
</span>
`;
const byDate = staticChip("By Date", ChangeLabelStrategy(defaultFromPatient));
export const labelStrategyChip = ({ labelStrategy: [name, from] }) => {
const strategy = name === LabelStrategies.BY_DATE ? byDate : fromPatient;
return html`
<span>
${strategy(name[1])} ${fromChip(from)}
</span>
`;
};
export const ChangeValueStrategy = valueStrategy => state =>
update({ ...state, valueStrategy });
const total = staticChip(
"Total",
ChangeValueStrategy(ValueStrategies.INCREASE)
);
const increase = staticChip(
"Increase",
ChangeValueStrategy(ValueStrategies.TOTAL)
);
export const valueStrategyChip = ({ valueStrategy }) => {
const strategy =
valueStrategy === ValueStrategies.INCREASE ? increase : total;
return html`
<span>
${strategy()}
</span>
`;
};