-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path1040.html.m4
319 lines (261 loc) · 8.9 KB
/
1040.html.m4
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
m4_changequote(<|,|>)
<meta charset="utf-8">
<!-- Licensed under GPLv2, with one clarification; see https://github.com/b-k/1040.js . -->
<html>
<title>The tax graph</title>
<script src="d3.v3.min.js" charset="utf-8"></script>
<script src="dagre-d3.min.js" charset="utf-8"></script>
<script>
</script>
<style id="css">
g.u > rect {
fill: #caf2bd;
}
text {
font-weight: 300;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;
font-size: 19px;
}
input[type=checkbox]
{
padding: 10px;
}
.checkboxtext
{
/* Checkbox text */
font-size: 110%;
display: inline;
}
body{
font-size: 25px;
}
.node rect {
stroke: #999;
fill: #fff;
stroke-width: 1.5px;
}
.edgePath path {
stroke: #333;
stroke-width: 1.5px;
}
div.tooltip { /* thx, http://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html */
position: absolute;
text-align: center;
/*width: 60px;
height: 28px; */
padding: 3px;
font: 25px sans-serif;
background: lightsteelblue;
border: 1px;
border-radius: 8px;
pointer-events: none;
}
</style>
<body>
The 2023 U.S. tax graph<br>
Click an avocado box to enter a value.<br>
To see more or less, use your browser's zoom (often <ctrl>-<+> or <ctrl>-<->, or try your mouse wheel).<br>
Hover your mouse over a box to see a little more text and the form the box is from.<br>
Or try <a href="https://github.com/b-k/py1040">the Python version</a>.<br>
<table><tr><td>
<input type="radio" name="spouse" size=3em checked onchange="recalc()"> I am single.<br>
<input type="radio" name="spouse" size=3em onchange="recalc()"> I have a spouse; we file jointly.<br>
<input type="radio" name="spouse" size=3em onchange="recalc()"> I have a spouse; we file separately.<br>
<input text id="kids" size=3em onchange="kidcalc()"> Dependent children<br>
<input text id="nonkid_dependents" size=3em onchange="recalc()"> Dependents over 17<br>
</td><td>
m4_define(BOX, <|<INPUT class=check TYPE=CHECKBOX NAME="$1" id=".$1" onclick="checkbox(id, checked)" checked><span class="checkboxtext"> $2</span><BR>|>)
BOX(over_65, I am over 65.)
BOX(spouse_over_65, My spouse is over 65.)
BOX(s_loans, I have student loans or education expenses.)
BOX(ly_refund, I got a tax refund and itemized last year.)
BOX(mort, I have a mortgage.)
BOX(itemizing, I am itemizing.)
BOX(cap_gains, I have long-term capital gains or associated dividends.)
BOX(self_emp, I have self-employment (Schedule C) income.)
BOX(have_rr, I have rental or royalty (Schedule E) income.)
<INPUT class=check TYPE=CHECKBOX NAME="hide_zeros" id=".hide_zeros" onclick="hidezeros(id, checked)" ><span class="checkboxtext"> I want to hide the inessential zero cells.</span><BR>
<a href="https://github.com/b-k/1040.js">I want to make this tax explorer better.</a>
</td></tr></table>
<svg id="svg-canvas" width=960 height=600></svg>
<script id="js">
<!-- Much of this started at http://cpettitt.github.io/project/dagre-d3/latest/demo/sentence-tokenization.html -->
var itemizing = 0;
var over_65 = 0;
var spouse_over_65 = 0;
m4_include(fns)
// Create the input graph
var g = new dagreD3.graphlib.Graph()
.setGraph({})
.setDefaultEdgeLabel(function() { return {}; });
m4_include(nodes)
var nodestorage=[]
var edgestorage=[]
var fixboxsize= function(node) {
// Round the corners of the nodes
node.rx = node.ry = 5;
size = Math.sqrt(Math.max(node.val, 1000));
//node.width = size*2.5;
node.height = size*.9;
node.label = node.baselabel + ": " + node.val
};
var fb2 = function(v){
fixboxsize(g.node(v));
}
g.nodes().forEach(fb2);
var set_edges = function(from, toset){
if (typeof g._nodes[from] === "undefined") return;
for (i in toset){
if (toset[i]=="") return;
if (typeof g._nodes[toset[i]] === "undefined") return;
g.setEdge(toset[i], from);
}
}
// Set up edges, no special attributes.
var reedge = function(){
m4_include(edges)
}
reedge();
g.graph().rankdir="lr";
// Create the renderer
var render = new dagreD3.render();
// Set up an SVG group so that we can translate the final graph.
var svg = d3.select("svg"),
svgGroup = svg.append("g");
// Run the renderer. This is what draws the final graph.
render(d3.select("svg g"), g);
// Center the graph
svg.attr("width", g.graph().width + 40);
svg.attr("height", g.graph().height + 40);
var xCenterOffset = (svg.attr("width") - g.graph().width) / 2;
svgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");
var val_prompt = function(d){
//var promptval = window.prompt(this.textContent, g._nodes[d].val);
var promptval = window.prompt(this.textContent);
var floated = parseFloat(promptval)
if(isNaN(floated)) return;
g._nodes[d].val = floated;
fixboxsize(g._nodes[d]);
last_eval += 1;
Cv("f1040_refund");
Cv("f1040_tax_owed");
Cv("f8582_carryover_to_next_year");
redrawIt();
}
var redrawIt = function(){
d3.selectAll("div.tooltip").style("opacity", 0);
render(d3.select("svg g"), g);
svg.attr("width", g.graph().width + 40);
svg.attr("height", g.graph().height + 40);
var xCenterOffset = (svg.attr("width") - g.graph().width) / 2;
svgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");
svg.selectAll(".u").on('click', val_prompt);
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
svg.selectAll(".a_node")
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", .9);
div .html(g._nodes[d].fullname + "<br>" + g._nodes[d].form)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}
)
.on("mouseout", function(d){
div.transition()
.duration(500)
.style("opacity", 0);
});
}
svg.selectAll(".u").on('click', val_prompt);
svg.selectAll("arrowhead").style("opacity", false);
var situations = [];
var last_eval = 0;
function Cv(name){
this_cell = g._nodes[name];
if (typeof this_cell === "undefined") this_cell = nodestorage[name];
if (this_cell.eqn==="" || this_cell.last_eval >= last_eval)
return parseFloat(this_cell.val);
var out = parseFloat(eval(this_cell.eqn));
if (g._nodes[name]){
g._nodes[name].last_eval = last_eval;
g._nodes[name].val = out;
fixboxsize(g._nodes[name]);
} else{
nodestorage[name].last_eval = last_eval;
nodestorage[name].val = out;
}
return out;
}
function recalc(){
last_eval +=1
Cv("f1040_refund");
Cv("f1040_tax_owed");
Cv("f8582_carryover_to_next_year");
redrawIt();
}
function checkbox(id, checked){situations[id]=checked;
if (!checked){
svg.selectAll(id).each(function(i){
if (g._nodes[i].class.match("critical")) return;
var n = g._nodes[i];
nodestorage[i] = { label: n.label,
baselabel: n.baselabel,
form: n.form,
fullname: n.fullname,
class: n.class, val:n.val
, eqn: n.eqn, last_eval: n.last_eval
};
g.removeNode(i);
});
redrawIt();
} else {
for (i in nodestorage){
if (nodestorage[i].class.indexOf(id.replace('\.',''))>0){
g.setNode(i, nodestorage[i], { label: nodestorage[i].label,
baselabel: nodestorage[i].baselabel,
form: nodestorage[i].form,
fullname: nodestorage[i].fullname,
class: nodestorage[i].class, val:nodestorage[i].val
, eqn: nodestorage[i].eqn, last_eval: nodestorage[i].last_eval
});
}
}
reedge();
redrawIt();
}
Cv("f1040_refund");
Cv("f1040_tax_owed");
}
function hidezeros(id, checked){
if (!checked){
checkbox(id, !checked);
} else {
for (i in g._nodes) g._nodes[i].class.replace(/hide_zeros/g, "");
for (i in nodestorage) nodestorage[i].class.replace(/hide_zeros/g, "");
for (i in g._nodes) if (g._nodes[i].val==0) g._nodes[i].class += " hide_zeros";
redrawIt();
checkbox(id, !checked);
}
}
var kidcalc = function(){
var kids = parseFloat(document.getElementById("kids").value)
if (isNaN(kids)) kids = 0;
checkbox('.kids', (kids>0 ? true : false)); recalc();
}
document.getElementById(".have_rr").click()
document.getElementById(".cap_gains").click()
document.getElementById(".s_loans").click()
document.getElementById(".ly_refund").click()
document.getElementById(".mort").click()
document.getElementById(".itemizing").click()
document.getElementById(".over_65").click()
document.getElementById(".spouse_over_65").click()
//checkbox(".kids", false)
kidcalc()
redrawIt()
</script>
</body>
</html>