16
16
* specific language governing permissions and limitations
17
17
* under the License. */
18
18
19
- import { Part , Relation , TextMeasure } from '../types/types' ;
19
+ import { Part , TextMeasure } from '../types/types' ;
20
20
import { linkTextLayout } from './link_text_layout' ;
21
21
import { Config , PartitionLayout } from '../types/config_types' ;
22
22
import { TAU , trueBearingToStandardPositionAngle } from '../utils/math' ;
23
23
import { Distance , Pixels , Radius } from '../types/geometry_types' ;
24
24
import { meanAngle } from '../geometry' ;
25
25
import { treemap } from '../utils/treemap' ;
26
26
import { sunburst } from '../utils/sunburst' ;
27
- import { IndexedAccessorFn } from '../../../../utils/accessor' ;
28
27
import { argsToRGBString , stringToRGB } from '../utils/d3_utils' ;
29
28
import {
30
29
nullShapeViewModel ,
@@ -49,20 +48,16 @@ import {
49
48
} from './fill_text_layout' ;
50
49
import {
51
50
aggregateAccessor ,
52
- aggregateComparator ,
53
- aggregators ,
54
51
ArrayEntry ,
55
- childOrders ,
56
52
depthAccessor ,
57
53
entryKey ,
58
54
entryValue ,
59
- groupByRollup ,
60
55
mapEntryValue ,
61
- mapsToArrays ,
62
56
parentAccessor ,
63
57
sortIndexAccessor ,
58
+ HierarchyOfArrays ,
64
59
} from '../utils/group_by_rollup' ;
65
- import { StrokeStyle , ValueAccessor , ValueFormatter } from '../../../../utils/commons' ;
60
+ import { StrokeStyle , ValueFormatter } from '../../../../utils/commons' ;
66
61
import { percentValueGetter } from '../config/config' ;
67
62
68
63
function paddingAccessor ( n : ArrayEntry ) {
@@ -148,13 +143,11 @@ export function shapeViewModel(
148
143
textMeasure : TextMeasure ,
149
144
config : Config ,
150
145
layers : Layer [ ] ,
151
- rawFacts : Relation ,
152
146
rawTextGetter : RawTextGetter ,
153
- valueAccessor : ValueAccessor ,
154
147
specifiedValueFormatter : ValueFormatter ,
155
148
specifiedPercentFormatter : ValueFormatter ,
156
149
valueGetter : ValueGetterFunction ,
157
- groupByRollupAccessors : IndexedAccessorFn [ ] ,
150
+ tree : HierarchyOfArrays ,
158
151
) : ShapeViewModel {
159
152
const {
160
153
width,
@@ -179,31 +172,11 @@ export function shapeViewModel(
179
172
y : height * margin . top + innerHeight / 2 ,
180
173
} ;
181
174
182
- const aggregator = aggregators . sum ;
183
-
184
- const facts = rawFacts . filter ( ( n ) => {
185
- const value = valueAccessor ( n ) ;
186
- return Number . isFinite ( value ) && value >= 0 ;
187
- } ) ;
188
-
189
175
// don't render anything if the total, the width or height is not positive
190
- if (
191
- facts . reduce ( ( p : number , n ) => aggregator . reducer ( p , valueAccessor ( n ) ) , aggregator . identity ( ) ) <= 0 ||
192
- ! ( width > 0 ) ||
193
- ! ( height > 0 )
194
- ) {
176
+ if ( ! ( width > 0 ) || ! ( height > 0 ) || tree . length === 0 ) {
195
177
return nullShapeViewModel ( config , diskCenter ) ;
196
178
}
197
179
198
- // We can precompute things invariant of how the rectangle is divvied up.
199
- // By introducing `scale`, we no longer need to deal with the dichotomy of
200
- // size as data value vs size as number of pixels in the rectangle
201
-
202
- const tree = mapsToArrays (
203
- groupByRollup ( groupByRollupAccessors , valueAccessor , aggregator , facts ) ,
204
- aggregateComparator ( mapEntryValue , childOrders . descending ) ,
205
- ) ;
206
-
207
180
const totalValue = tree . reduce ( ( p : number , n : ArrayEntry ) : number => p + mapEntryValue ( n ) , 0 ) ;
208
181
209
182
const sunburstValueToAreaScale = TAU / totalValue ;
@@ -332,5 +305,6 @@ export function shapeViewModel(
332
305
linkLabelViewModels,
333
306
outsideLinksViewModel,
334
307
pickQuads,
308
+ outerRadius,
335
309
} ;
336
310
}
0 commit comments