1
1
import React from 'react' ;
2
2
import DorlingCartogram from '../src/DorlingCartogram' ;
3
+ import ResponsiveDorlingCartogram from '../src/ResponsiveDorlingCartogram' ;
3
4
import geoNaturalEarth1 from 'd3-geo/src/projection/naturalEarth1' ;
4
5
import geodata from './world.json' ;
6
+ import { pie , arc } from 'd3-shape' ;
7
+
8
+ const customMark = ( d ) => {
9
+ if ( ( ! d . bbhouseholds && ! d . watchers ) || d . r < 4 ) {
10
+ return < circle fill = "gray" cx = { d . x } cy = { d . y } r = { d . r } /> ;
11
+ }
12
+ const pieLayout = pie ( ) ;
13
+ const piePieces = pieLayout ( [ d . bbhouseholds , d . watchers ] ) ;
14
+
15
+ const arcGenerator = arc ( )
16
+ . outerRadius ( d . r - 4 )
17
+ . innerRadius ( d . r > 10 ? 5 : 0 ) ;
18
+
19
+ return (
20
+ < g transform = { `translate(${ d . x } ,${ d . y } )` } >
21
+ < circle r = { d . r } fill = "purple" />
22
+ < path d = { arcGenerator ( piePieces [ 0 ] ) } fill = "gold" stroke = "white" />
23
+ < path d = { arcGenerator ( piePieces [ 1 ] ) } fill = "brown" stroke = "white" />
24
+ </ g >
25
+ ) ;
26
+ } ;
5
27
6
28
const dynamicSize = ( d , i ) => ( d . watchers && d . watchers / 10 ) || i / 20 + 1 ;
7
29
const staticSize = d => ( d . bbhouseholds && d . bbhouseholds / 10 ) || 0 ;
@@ -78,7 +100,7 @@ class SimpleDorling extends React.Component {
78
100
super ( props ) ;
79
101
this . state = {
80
102
carto : false ,
81
- sizeByBasic : true
103
+ sizeByBasic : false
82
104
} ;
83
105
}
84
106
@@ -95,15 +117,19 @@ class SimpleDorling extends React.Component {
95
117
>
96
118
Change SizeBy
97
119
</ button >
98
- < DorlingCartogram
99
- zoomToFit = { false }
120
+
121
+ < ResponsiveDorlingCartogram
122
+ responsiveWidth
100
123
// showBorders
101
124
cartogram = { this . state . carto }
102
125
// circleStyle={{ fill: 'red' }}
126
+ customMark = { customMark }
103
127
geoStyle = { d =>
104
- ( d . bbhouseholds ? { fill : 'purple' } : { fill : 'orange' } )
128
+ ( d . bbhouseholds
129
+ ? { fill : 'purple' , stroke : 'none' }
130
+ : { fill : 'orange' , stroke : 'none' } )
105
131
}
106
- transitionSeconds = { 0.5 }
132
+ transitionSeconds = { 2 }
107
133
size = { [ 800 , 600 ] }
108
134
sizeBy = { this . state . sizeByBasic ? dynamicSize : staticSize }
109
135
projectionType = { geoNaturalEarth1 }
@@ -112,7 +138,7 @@ class SimpleDorling extends React.Component {
112
138
onHover = { ( d ) => {
113
139
console . info ( 'hover d' , d ) ;
114
140
} }
115
- label = { d =>
141
+ /* label={d =>
116
142
(d.id ? (
117
143
<text
118
144
fill="white"
@@ -126,7 +152,7 @@ class SimpleDorling extends React.Component {
126
152
) : (
127
153
''
128
154
))
129
- }
155
+ } */
130
156
/>
131
157
< pre >
132
158
{ `import React from 'react';
0 commit comments