-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflourish_sentence.html
877 lines (745 loc) · 30.8 KB
/
flourish_sentence.html
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Pro Life or Pro Strife?</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="dropdown.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
</style>
</head>
<body>
<div class="body">
<div class="header">
<div class="container">
<img src="./Images/header_v2_mobile.svg" width="auto" height="auto">
<h1> <span class="highlight2-container"><span class="highlight2">Pro-life</span></span>
or <span class="highlight-container"><span class="highlight">pro-strife</span></span>?</h1>
<h3>Pro-life states with strict abortion laws are spending less money to support families and children.
<br>
<br>
The Supreme Court overturned Roe v. Wade in June 2022, giving states the power to decide whether a
woman can
access an abortion. Now, <strong>states with some of the nation’s strictest abortion laws are also
some of the
hardest places to raise a healthy child.</strong> </h3>
<br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<div class="imageContainer">
<h2>28 states curently ban or seriously restrict access to abortion. </h2>
<div class="image">
<img src="./Images/HighResFilesForScroll2-01.svg" width="100%" height="auto"></div>
<div>
<p>In <span class="proLife">pro-life</span> sates abortion access is not protected or it is severely
restricted. <br> In <span class="proChoice">pro-choice</span> states abortion access is
protected or has
been
expanded </p>
</div>
<div class="container">
<br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<div>
<h2><strong>Where do you live?</strong> Select your state below to see how it ranks in spending on
children
and access to abortion. Do you see a connection? </h2>
</div>
</div>
<div id="controls">
<div id="sentence">
<span class="sentence">
<strong>I live in</strong>
<span id="hide-np">State</span>
</span>
<div class="menuContainer active onLoadClass" id="topicContainer">
<select id="stateMenu" style="display: none" ;>
<option value="">State</option>
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">The District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option>
</select>
</div>
<span class="sentence">
<span id="statename1">My state</span> ranks <span id="categoryRank">#</span> in spending on
</span>
<div class="menuContainer active onLoadClass" id="categoryContainer">
<select id="categoryMenu" style="display:none" ;>
<option value="">Category </option>
<option value="total">Total Spending</option>
<option value="health">Health + Nutrition</option>
<option value="financial">Financial Support</option>
<option value="housing">Housing</option>
<option value="education">Education</option>
<option value="resources">Financial Resources</option>
</select>
<span class="sentence">
<strong>Abortion access</strong> in <span id="statename2">My State</span> is <span
id="abortionRank">status</span>.
</span>
</div>
</div>
</div>
</div>
<div class="container">
<br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<div id="my-wrapper">
<div class="headlines.life">
<h2>“Our state’s historic case before the United States Supreme Court was the catalyst for overturning
Roe v.
Wade and has made the nation safer for children than it was just a few short hours ago." --
Mississippi
Governor </h2>
</div>
<h4>Carrying an unwanted pregnancy <span style="font-weight:bold;"> quadruples the odds </span> that a woman
and
her child will live below the federal poverty line, according to The Turnaway Study, a University of
California
San Francisco research project that tracked women who got access to abortions versus those who’d been
denied
them over a 10-year period. It triples the chances of the woman being unemployed.
</h4>
<img src="./Images/children_1_7_poverty.png" width="350px"><br><br>
<div class="container">
<br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<h2>Child poverty rates are higher in states that restrict abortion access.</h2>
<h4>Keep scrolling to learn more. Click on your state at any time for the specific data. </h4>
<div class="container">
<br><br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<div class="flourish-embed" data-src="story/1766936" width="80%">
<script src="https://public.flourish.studio/resources/embed.js"></script>
</div>
<p class="invisible"><a href="#story/1766936/slide-1"></a></p>
<p class="invisible"><a href="#story/1766936/slide-2"></a></p>
<p>The red cluster represents <span class="proLife">pro-life</span> states that spend less on
children,*and?* yet
have higher poverty rates.<a href="#story/1766936/slide-3"></a></p>
<p>While the blue cluster represents <span class="proChoice">pro-choice</span> states that spend more on
children
with lower poverty rates<a href="#story/1766936/slide-4"></a></p>
<p>The District of Columbia looks to be an outlier, spending the most per child at almost $64k<a
href="#story/1766936/slide-5"></a></p>
</div>
<div class="container">
<br>
<hr width="50%">
<img src="./Images/Down-Arrow.png" width="20x">
<br>
</div>
<h2>States that limit abortion access spend 20% less on children than pro-choice states.</h2>
<div class="flourish-embed flourish-map" data-src="visualisation/11864887" width="80%">
<script src="https://public.flourish.studio/resources/embed.js"></script>
</div>
<h2>Where does state spending for families go? How states spend their budgets also differs. For our evaluation
we
broke the data into 5 buckets.</h2>
<div style='display: flex; justify-content: center;' class="rollover">
</div>
<img src="./Images/spending_categories.png" width=100% height="100%">
<div class="flourish-embed" data-src="story/1769151" width="80%">
<script src="https://public.flourish.studio/resources/embed.js"></script>
</div>
<p>There is a 26% decrease in spending on education in <span class="proLife">pro-life states.</span><a
href="#story/1769151/slide-1"></a></p>
<p><span class="proLife">Pro-life</span> states spend 23% less on financial payments to families than <span
class="proChoice">pro-choice</span> states<a href="#story/1769151/slide-2"></a></p>
<p><span class="proLife">Pro-life</span> states spend on average, 16% less than <span
class="proChoice">pro-choice</span> states on health and nutrition services.<a
href="#story/1769151/slide-3"></a></p>
<p><span class="proLife">Pro-life</span> states spend on average, $200 less than <span
class="proChoice">pro-choice</span> states on public resources such as libraries and parks.<a
href="#story/1769151/slide-4"></a></p>
<p>Housing is by far the category with the biggest difference, with <span class="proLife">pro-life</span> states
spending 61% less than <span class="proChoice">pro-choice</span> states .<a
href="#story/1769151/slide-5"></a></p>
<h2>We need to look more broadly at the relationship between reproductive rights and spending.</h2>
<h4>The Institute for Women’s Policy Research developed a comprehensive reproductive rights index score weighted
across eight key indicators. These include factors such as public insurance coverage, high quality sex
education
in schools, and access to infertility treatments. What is the relationship between the reproductive rights
score
of the state and financial support of chidlren and families? </h4>
<div class="flourish-embed" data-src="story/1762540">
<script src="https://public.flourish.studio/resources/embed.js"></script>
</div>
<!-- Here is where you add your captions, linking them to specific slides in the story -->
<p>What to say about this <a href="#story/1762540/slide-1"></a></p>
<p>Several <span class="proLife">Pro-life</span> states have banned abortion or significantly weakened abortion
access. <br> These same pro-life states have the weakest maternal and child health outcomes, and they spend
significantly less money than <span class="proChoice">pro-choice</span> states taking care of families<a
href="#story/1762540/slide-1"></a></p>
<br><br><br>
<h2>As access to reproductive rights fall, so does state financial support for families and chidren.</h2>
<h4>Scroll to see how state rankings match up against all spending categories. Darker colored indicate higher
ranks.
States are ordered by reproductive rights scores.</h4>
<div class="background">
<div class="flourish-embed flourish-heatmap" data-src="visualisation/12012702" width="80%">
<script src="https://public.flourish.studio/resources/embed.js"></script>
</div>
</div>
<h2>"One upside of Dobbs is that it makes possible broad coalitions of people of goodwill who, despite their
disagreement on the fundamental question of abortion, agree that we must all work to provide for the needs
of
mothers, children and families in crisis."</h2>
<br>
<div class="text">
<h3><strong>So, what can you do next?</strong>
<ul>
<li>Share this story with others</li>
<li> Get involved. Support planned parenthood</li>
<li>Advocate for changes to your state budget</li>
</ul>
</h3>
</div>
<br>
<h2>Social Share</h2>
<div class="text">
<h3><strong>Methodology</strong></h3>
<h4>Here is where we put our how </h4>
<h3><strong>Notes</strong></h3>
<h4>Here is where we put any caveats </h4>
<h3><strong>Sources and Thanks</strong></h3>
<h4>Here is where we put links, project description? What else could be useful? </h4>
</body>
<!-- Add the Flourish Scrolly library -->
<script src="https://cdn.flourish.rocks/flourish-scrolly-v3.1.0.min.js" type="text/javascript"></script>
<!-- Initialize the library to turn your story into scrolly magic! -->
<script>
initFlourishScrolly({
trigger_point: "50%",
offset_top: "100px",
step_styles: {
background: "white",
color: "darkgrey",
fontSize: "16px",
opacity: 0.9,
}
});
</script>
</div>
</div>
</div>
</body>
</html>
<style>
.body {
background-color: #ffffff;
max-width: 760px;
margin: 0 auto;
align-content: center;
}
.paragraph {
display: flex;
}
.text {
align-self: flex-end;
}
.header {
margin: -10 0 0 -20;
padding: 40 30;
}
.margins {
width: 80%;
padding: 40;
margin: 0 auto;
}
p {
font-family: 'Roboto';
font-size: 14px;
line-height: 1.8em;
}
h1 {
font-family: 'Roboto Slab';
font-size: 60px;
font-weight: 100;
padding: 10 10 10 10;
line-height: 1.45em;
}
h2 {
font-family: 'Roboto Slab';
font-size: 25px;
line-height: 1.4em;
font-weight: 300;
text-align: center;
background-color: #ffffff;
color: #990612;
}
h3 {
font-family: 'Roboto';
font-size: 18px;
font-weight: 400;
padding-left: 10;
margin: auto;
font-weight: 100;
line-height: 1.55em;
text-align: left;
}
h4 {
font-family: 'Roboto';
font-size: 16px;
font-weight: 200;
line-height: 1.45em;
padding-top: 10px;
margin-left: 20px;
margin-right: 0px
}
.proLife {
color: #990612;
font-weight: 900;
}
.proChoice {
color: #003F5C;
font-weight: 900;
}
.highlight2 {
color: #990612;
}
.highlight-container,
.highlight {
position: relative;
}
.background {
background-image: url ("./Images/test_background.png");
}
.container {
line-height: 1.4;
text-align: center;
padding: 44px;
color: #333;
margin: 0 auto;
}
.imageContainer {
margin-left: auto;
margin-right: auto;
flex-wrap: wrap;
/* or inline-flex */
}
image {
margin-left: auto;
margin-right: auto;
object-fit: contain;
}
.highlight-container,
.highlight {
position: relative;
text-decoration: underline #990612;
text-decoration-skip-ink: none;
text-decoration-thickness: 1px;
text-underline-offset: 0.2rem;
}
.highlight-container {
display: inline-block;
}
.highlight-container:before {
content: " ";
display: block;
height: 90%;
margin-left: -3px;
margin-right: -3px;
position: absolute;
opacity: 0.5;
top: -1px;
left: -1px;
color: #990612;
padding: 3px 3px 3px 3px;
}
.highlight2-container,
.highlight2 {
position: relative;
}
.highlight2-container {
display: inline-block;
}
.highlight2-container:before {
content: " ";
display: block;
height: 90%;
width: 100%;
margin-left: -3px;
margin-right: -3px;
position: absolute;
color: #990612;
opacity: 0.9;
top: -1px;
left: -1px;
padding: 10px 3px 3px 10px;
}
.fl-scrolly-step {
color: #6e6969 !important;
font-family: Roboto Condensed;
font-weight: 100;
}
.flourish-embed {
align-content: center;
}
/* To hide a caption, add class="invisible" to the <p> tag of that caption */
.invisible {
opacity: 0 !important;
}
.rollover {
display: block;
width: 436px;
height: 730px;
background: url("./Images/direct_rollover-03-small.png") no-repeat;
-webkit-transition: all .7s ease-in-out;
-moz-transition: all .7s ease-in-out;
-o-transition: all .7s ease-in-out;
transition: all .7s ease-in-out;
}
.rollover:hover {
background: url(./Images/direct_rollover-04-small.png)
}
#controls {
width: 100%;
}
#sentence {
font-family: 'Roboto Condensed', sans-serif;
top: 160px;
position: relative;
margin: 0 auto;
width: 80%;
text-align: center;
line-height: 68px;
margin-bottom: 160px;
}
span.sentence {
font-size: 43px;
font-weight: 100;
}
#locationContainer,
#categoryContainer {
margin-top: 20px;
}
.menuContainer {
display: inline;
margin-right: 10px;
margin-left: 10px;
top: -15px;
position: relative;
}
.menuContainer,
.menuContainerYears {
display: inline;
margin-right: 10px;
margin-left: 10px;
top: -15px;
position: relative;
}
.menuContainer.active.onLoadClass .ui-selectmenu-button {
/* color: white !important; */
background: url(../../Images/urban-select-2x.png) no-repeat right #a5a5a0;
;
background-size: 53px 53px !important;
}
.menuContainer.active .ui-selectmenu-button {
/* color: white !important; */
background: url(/Images/urban-select-active.png) no-repeat right #094c6a;
background-size: 53px 53px;
}
.menuContainer.active .ui-selectmenu-button {
/* color: white !important; */
background: url(./Images/urban-select-active.png) no-repeat right #094c6a;
background-size: 53px 53px;
}
option {
font-weight: normal;
display: block;
white-space: nowrap;
min-height: 1.2em;
padding: 0px 2px 1px;
}
select {
writing-mode: horizontal-tb !important;
text-rendering: auto;
color: fieldtext;
letter-spacing: normal;
word-spacing: normal;
line-height: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
text-align: start;
white-space: pre;
-webkit-rtl-ordering: logical;
cursor: default;
}
select:not(:-internal-list-box) {
overflow: visible !important;
}
ul {
list-style: none;
}
.ui-selectmenu-button.ui-button {
text-align: left;
white-space: nowrap;
height: 53px;
background: url ("./Images/urban-select-2x.png") no-repeat right #16d27a;
background-size: 53px 53px;
border: none;
color: white;
margin-right: 12px;
width: auto;
}
.ui-corner-all,
.ui-corner-bottom,
.ui-corner-right,
.ui-corner-br {
border-bottom-right-radius: 0px;
}
.ui-corner-all,
.ui-corner-bottom,
.ui-corner-left,
.ui-corner-bl {
border-bottom-left-radius: 0px;
}
.ui-button {
padding: 0.4em 1em;
display: inline-block;
position: relative;
line-height: normal;
margin-right: 0.1em;
cursor: pointer;
vertical-align: middle;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
overflow: visible;
}
.ui-selectmenu-text {
display: block;
position: relative;
margin-right: 31px;
overflow: hidden;
text-overflow: ellipsis;
font-family: 'Roboto Condensed';
font-weight: 100;
margin-top: -5px;
font-size: 43px;
}
.ui-widget-content {
background: #ffffff;
color: #003F5C;
}
#hide-np {
display: none;
}
.locationMenu.disabled {
opacity: .3;
}
</style>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<!--
jQuery, a library that does a variety things, including DOM manipulation.
Note: jQuery refers to itself as `$`, so in the same way you might call `d3.method()`
for d3 functions you call `$.method()` for jQuery functions). If you want to use Svelte,
then JS might get confused about also using `$` for `$:` declarations. Here's a
stackoverflow thread of resolving this!
https://stackoverflow.com/questions/58219453/how-do-i-use-jquery-in-svelte
-->
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<!--
jQuery-UI is a separate plugin to jQuery, which we're using to create `selectmenu`
elements. Check out the docs for selectmenu, here:
https://jqueryui.com/selectmenu/
Lots of other cool elements available here as well!
-->
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<!--
Some dummy data. If you have a CSV document with column headers `state`,
`incomeRank`, and `educationRank`, then d3 will read it in to this format.
Check out the d3 docs for more info
https://github.com/d3/d3-dsv
Note: some front end developers will tell you that it's not a best practice
to include both jQuery and d3 in a single project, since they do similar things
(DOM manipulation). While that's true for production-level sites, I think it's
100% fine to use both here.
-->
<script>
let csvData = {};
d3.csv("./State_wide.csv", function (data) {
for (var i = 0; i < data.length; i++) {
csvData[data[i].State] = data[i];
}
});
</script>
<!--
This code does two things:
1. the call to `selectmenu` creates the UI element (i.e. hides the `select`
element and creates the styled divs/spans which work like a dropdown)
2. the `change` event handler does something when the value of the menu changes
(see the docs linked above for more useful methods)
-->
<script>
$("#stateMenu").selectmenu({
change: function (event, ui) {
showRankInfo();
if (ui.item.value !== '') {
document.getElementById('statename1').innerText = ui.item.value;
document.getElementById('statename2').innerText = ui.item.value;
} else {
document.getElementById('statename1').innerText = 'My state';
document.getElementById('statename2').innerText = 'My state';
}
displayRank(getRank(ui.item.value, getCategory()))
}
});
$("#categoryMenu").selectmenu({
change: function (event, ui) {
showRankInfo();
displayRank(getRank(getState(), ui.item.value))
}
});
function ordinal(n) {
const s = ["th", "st", "nd", "rd"];
const v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
}
function showRankInfo() {
const state = getState(),
category = getCategory(),
categoryRankSpan = document.getElementById('categoryRank');
abortionRankSpan = document.getElementById('abortionRank');
if (state !== '') {
const stateData = csvData[state];
const abortionData = stateData['abortionRank'] || 'status';
abortionRankSpan.innerText = abortionData;
} else {
abortionRankSpan.innerText = 'status';
}
if (state !== '' && category !== '') {
const stateData = csvData[state];
const categoryData = stateData[category + 'Rank'],
categoryDataNum = Number(categoryData);
categoryRankSpan.innerText = ordinal(categoryDataNum);
} else {
categoryRankSpan.innerText = '#';
}
}
function getRank(State, Category) {}
// let stateDatum = data.filter(s => s.State == State)[0]
/* <!--
I wrote this in one line, but to break it down:
1. data.filter is a JS built in function which takes an array and returns
a filtered copy of it, based on certain criteria.
See more info here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Note that MDN is a great resource for JS, HTML, and CSS documentation (for vanilla JS)
2. Filter works by looking at every element in an array, and seeing if it matches your criteria.
So an identical way to write this would be:
let stateDatum = data.filter(function(s){
return s.state == State
})[0]
We're checking if the `state` property of each datum in the array is equal to the `state`
variable that was passed as a parameter to `getRank()`
3. Since `filter` returns an array (in this case an array of length 1), we need to grab the first
element of the array, hence the `[0]`
-->
/*
Once we've grabbed the datum, use the `category` variable which was passed in
as a string to get the relevant rank. So if category is "health", we return
stateDatum["healthRank"].
Could have this whole function in one line as
`return data.filter(s => s.state == state)[0][category + "Rank"]`
but I thought that wasn't the nicest looking
*/
/*
Two `getter` functions. When you call `getRank`, you need two values
(`state` and `category`). One of those two values will be provided
within the event handler for the related dropdown menu, but you'll
need to grab the other value from the current status of the other dropdown
*/
function getCategory() {
return $("#categoryMenu").val()
}
function getState() {
return $("#stateMenu").val()
}
/*
Use jQuery to change the text inside the `rankLabel` span
I believe your prototype had "1st" "2nd" "3rd" etc text, which
you can handle the logic for in this function if you'd like
*/
function displayRank(rank) {
$("#rankLabel").text(rank)
}
</script>
</html>