File tree 1 file changed +28
-31
lines changed
1 file changed +28
-31
lines changed Original file line number Diff line number Diff line change 7
7
<!-- Load plotly.js into the DOM -->
8
8
< script src ="https://cdn.plot.ly/plotly-2.16.1.min.js "> </ script >
9
9
10
- < script
11
- src ="https://code.jquery.com/jquery-3.6.3.min.js "
12
- integrity ="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU= "
13
- crossorigin ="anonymous "
14
- > </ script >
10
+ < script src ="https://code.jquery.com/jquery-3.6.3.min.js "
11
+ integrity ="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU= " crossorigin ="anonymous "> </ script >
15
12
16
13
< body >
17
14
< label > Election Type:</ label >
121
118
//compatible with president and legialator-at-large
122
119
let candidates = ! candidateData . columns . includes ( "candidate" )
123
120
? Array . from (
124
- new Set (
125
- candidateData . map ( ( d ) => [
126
- d [ "candidate_party" ] ,
127
- d [ "candidate_party" ] ,
128
- ] )
129
- )
130
- )
121
+ new Set (
122
+ candidateData . map ( ( d ) => [
123
+ d [ "candidate_party" ] ,
124
+ d [ "candidate_party" ] ,
125
+ ] )
126
+ )
127
+ )
131
128
: Array . from (
132
- new Set (
133
- candidateData . map ( ( d ) => [ d [ "candidate" ] , d [ "candidate_party" ] ] )
134
- )
135
- ) ;
129
+ new Set (
130
+ candidateData . map ( ( d ) => [ d [ "candidate" ] , d [ "candidate_party" ] ] )
131
+ )
132
+ ) ;
136
133
for ( let c of candidates ) {
137
134
candidateInfo [ c [ 0 ] ] = {
138
135
party : c [ 1 ] ,
173
170
width : 800 ,
174
171
height : 800 ,
175
172
title : title ,
176
- colorway : [
177
- "#f3cec9" ,
178
- "#e7a4b6" ,
179
- "#cd7eaf" ,
180
-
181
- ] ,
182
173
} ;
183
174
184
175
var config = {
185
176
mapboxAccessToken :
186
177
"pk.eyJ1IjoiYTA1MTI4IiwiYSI6ImNsY2JybmJyYTIyZzEzb2w3dGl3cXpkdXYifQ.aIV8apormocbhm8GpqbySg" ,
187
178
} ;
188
179
189
- //todo: draw legeng in map ?
180
+ //legends by adding dummy traces
181
+ let data = candidates . map ( ( c ) => {
182
+ return {
183
+ type : "scattermapbox" ,
184
+ lat : [ 46 ] ,
185
+ lon : [ - 74 ] ,
186
+ z : [ 0 ] ,
187
+ name : c [ 0 ] == c [ 1 ] ?c [ 0 ] :c [ 0 ] + " (" + c [ 1 ] + ")" ,
188
+ showlegend : true ,
189
+ color : partyColor ( c [ 1 ] ) ,
190
+ }
191
+ } ) ;
192
+
190
193
Plotly . newPlot (
191
194
"map" ,
192
- [
193
- {
194
- type : "scattermapbox" ,
195
- lat : [ 46 ] ,
196
- lon : [ - 74 ] ,
197
- } ,
198
- ] ,
195
+ data ,
199
196
layout ,
200
197
config
201
198
) ;
248
245
}
249
246
250
247
presidentPlot ( files [ "president" ] , 2016 ) ;
251
- </ script >
248
+ </ script >
You can’t perform that action at this time.
0 commit comments