@@ -417,7 +417,6 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
417
417
}
418
418
419
419
Axes . drawTicks ( gd , ax , {
420
- // TODO right? No need to clip here ever?
421
420
vals : vals ,
422
421
layer : layers [ 'radial-axis' ] ,
423
422
path : Axes . makeTickPath ( ax , 0 , tickSign [ 2 ] ) ,
@@ -428,7 +427,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
428
427
vals : valsClipped ,
429
428
layer : layers [ 'radial-grid' ] ,
430
429
path : gridPathFn ,
431
- transFn : transFn
430
+ transFn : Lib . noop
432
431
} ) ;
433
432
434
433
Axes . drawLabels ( gd , ax , {
@@ -448,23 +447,20 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
448
447
rad2deg ( snapToVertexAngle ( deg2rad ( radialLayout . angle ) , _this . vangles ) ) :
449
448
radialLayout . angle ;
450
449
451
- // TODO no more "draw-and-then-tweak" !!!
452
- var trans = strTranslate ( cx , cy ) + strRotate ( - angle ) ;
450
+ var tLayer = strTranslate ( cx , cy ) ;
451
+ var tLayer2 = tLayer + strRotate ( - angle ) ;
453
452
454
453
updateElement (
455
454
layers [ 'radial-axis' ] ,
456
455
hasRoomForIt && ( radialLayout . showticklabels || radialLayout . ticks ) ,
457
- { transform : trans }
456
+ { transform : tLayer2 }
458
457
) ;
459
458
460
- // TODO !!
461
- // move all grid paths to about circle center,
462
- // undo individual grid lines translations
463
459
updateElement (
464
460
layers [ 'radial-grid' ] ,
465
461
hasRoomForIt && radialLayout . showgrid ,
466
- { transform : strTranslate ( cx , cy ) }
467
- ) . selectAll ( 'path' ) . attr ( 'transform' , null ) ;
462
+ { transform : tLayer }
463
+ ) ;
468
464
469
465
updateElement (
470
466
layers [ 'radial-line' ] . select ( 'line' ) ,
@@ -474,7 +470,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
474
470
y1 : 0 ,
475
471
x2 : radius ,
476
472
y2 : 0 ,
477
- transform : trans
473
+ transform : tLayer2
478
474
}
479
475
)
480
476
. attr ( 'stroke-width' , radialLayout . linewidth )
@@ -531,6 +527,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
531
527
_this . fillViewInitialKey ( 'angularaxis.rotation' , angularLayout . rotation ) ;
532
528
533
529
ax . setGeometry ( ) ;
530
+ ax . setScale ( ) ;
534
531
535
532
// 't'ick to 'g'eometric radians is used all over the place here
536
533
var t2g = function ( d ) { return ax . t2g ( d . x ) ; } ;
@@ -541,23 +538,17 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
541
538
ax . dtick = rad2deg ( ax . dtick ) ;
542
539
}
543
540
544
- // TODO break up into two functions!
545
- var transFn = function ( d ) {
546
- var sel = d3 . select ( this ) ;
547
- var hasElement = sel && sel . node ( ) ;
541
+ var _transFn = function ( rad ) {
542
+ return strTranslate ( cx + radius * Math . cos ( rad ) , cy - radius * Math . sin ( rad ) ) ;
543
+ } ;
548
544
549
- // don't translate grid lines
550
- if ( hasElement && sel . classed ( 'angularaxisgrid' ) ) return '' ;
545
+ var transFn = function ( d ) {
546
+ return _transFn ( t2g ( d ) ) ;
547
+ } ;
551
548
549
+ var transFn2 = function ( d ) {
552
550
var rad = t2g ( d ) ;
553
- var out = strTranslate ( cx + radius * Math . cos ( rad ) , cy - radius * Math . sin ( rad ) ) ;
554
-
555
- // must also rotate ticks, but don't rotate labels
556
- if ( hasElement && sel . classed ( 'ticks' ) ) {
557
- out += strRotate ( - rad2deg ( rad ) ) ;
558
- }
559
-
560
- return out ;
551
+ return _transFn ( rad ) + strRotate ( - rad2deg ( rad ) ) ;
561
552
} ;
562
553
563
554
var gridPathFn = function ( d ) {
@@ -568,13 +559,14 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
568
559
'L' + [ cx + radius * cosRad , cy - radius * sinRad ] ;
569
560
} ;
570
561
571
- Axes . makeLabelFns ( ax , 0 ) ;
562
+ var out = Axes . makeLabelFns ( ax , 0 ) ;
563
+ var labelStandoff = out . labelStandoff ;
564
+ var labelShift = out . labelShift ;
572
565
var offset4fontsize = ( angularLayout . ticks !== 'outside' ? 0.7 : 0.5 ) ;
566
+ var pad = ( ax . linewidth || 1 ) / 2 ;
573
567
574
568
var labelXFn = function ( d ) {
575
569
var rad = t2g ( d ) ;
576
- var labelStandoff = ax . _labelStandoff ;
577
- var pad = ax . _pad ;
578
570
579
571
var offset4tx = signSin ( rad ) === 0 ?
580
572
0 :
@@ -586,9 +578,6 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
586
578
587
579
var labelYFn = function ( d ) {
588
580
var rad = t2g ( d ) ;
589
- var labelStandoff = ax . _labelStandoff ;
590
- var labelShift = ax . _labelShift ;
591
- var pad = ax . _pad ;
592
581
593
582
var offset4tx = d . dy + d . fontSize * MID_SHIFT - labelShift ;
594
583
var offset4tick = - Math . sin ( rad ) * ( labelStandoff + pad + offset4fontsize * d . fontSize ) ;
@@ -610,15 +599,32 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
610
599
_this . angularTickLayout = newTickLayout ;
611
600
}
612
601
613
- ax . setScale ( ) ;
614
-
615
602
var vals = Axes . calcTicks ( ax ) ;
603
+
604
+ // angle of polygon vertices in geometric radians (null means circles)
605
+ // TODO what to do when ax.period > ax._categories ??
606
+ var vangles ;
607
+ if ( polarLayout . gridshape === 'linear' ) {
608
+ vangles = vals . map ( t2g ) ;
609
+
610
+ // ax._vals should be always ordered, make them
611
+ // always turn counterclockwise for convenience here
612
+ if ( Lib . angleDelta ( vangles [ 0 ] , vangles [ 1 ] ) < 0 ) {
613
+ vangles = vangles . slice ( ) . reverse ( ) ;
614
+ }
615
+ } else {
616
+ vangles = null ;
617
+ }
618
+ _this . vangles = vangles ;
619
+
616
620
// Use tickval filter for category axes instead of tweaking
617
621
// the range w.r.t sector, so that sectors that cross 360 can
618
622
// show all their ticks.
619
- var tickVals = ax . type === 'category' ?
620
- vals . filter ( function ( d ) { return Lib . isAngleInsideSector ( t2g ( d ) , _this . sectorInRad ) ; } ) :
621
- vals ;
623
+ if ( ax . type === 'category' ) {
624
+ vals = vals . filter ( function ( d ) {
625
+ return Lib . isAngleInsideSector ( t2g ( d ) , _this . sectorInRad ) ;
626
+ } ) ;
627
+ }
622
628
623
629
if ( ax . visible ) {
624
630
// TODO dry!!
@@ -628,25 +634,22 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
628
634
tickSign = tickSign . map ( function ( v ) { return - v ; } ) ;
629
635
}
630
636
631
- var pad = tickSign [ 2 ] * ( ax . linewidth || 1 ) / 2 ;
632
- var len = tickSign [ 2 ] * ax . ticklen ;
633
-
634
637
Axes . drawTicks ( gd , ax , {
635
- vals : tickVals ,
638
+ vals : vals ,
636
639
layer : layers [ 'angular-axis' ] ,
637
- path : 'M' + pad + ',0h' + len ,
638
- transFn : transFn
640
+ path : 'M' + ( tickSign [ 2 ] * pad ) + ',0h' + ( tickSign [ 2 ] * ax . ticklen ) ,
641
+ transFn : transFn2
639
642
} ) ;
640
643
641
644
Axes . drawGrid ( gd , ax , {
642
- vals : tickVals ,
645
+ vals : vals ,
643
646
layer : layers [ 'angular-grid' ] ,
644
647
path : gridPathFn ,
645
- transFn : transFn
648
+ transFn : Lib . noop
646
649
} ) ;
647
650
648
651
Axes . drawLabels ( gd , ax , {
649
- vals : tickVals ,
652
+ vals : vals ,
650
653
layer : layers [ 'angular-axis' ] ,
651
654
shift : 0 ,
652
655
transFn : transFn ,
@@ -657,22 +660,6 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
657
660
} ) ;
658
661
}
659
662
660
- // angle of polygon vertices in geometric radians (null means circles)
661
- // TODO what to do when ax.period > ax._categories ??
662
- var vangles ;
663
- if ( polarLayout . gridshape === 'linear' ) {
664
- vangles = vals . map ( t2g ) ;
665
-
666
- // ax._vals should be always ordered, make them
667
- // always turn counterclockwise for convenience here
668
- if ( Lib . angleDelta ( vangles [ 0 ] , vangles [ 1 ] ) < 0 ) {
669
- vangles = vangles . slice ( ) . reverse ( ) ;
670
- }
671
- } else {
672
- vangles = null ;
673
- }
674
- _this . vangles = vangles ;
675
-
676
663
// TODO maybe two arcs is better here?
677
664
// maybe split style attributes between inner and outer angular axes?
678
665
0 commit comments