@@ -413,6 +413,7 @@ function mouseoverPath(d) {
413
413
414
414
// Label
415
415
var gd = d . parcatsViewModel . graphDiv ;
416
+ var trace = d . parcatsViewModel . trace ;
416
417
var fullLayout = gd . _fullLayout ;
417
418
var rootBBox = fullLayout . _paperdiv . node ( ) . getBoundingClientRect ( ) ;
418
419
var graphDivBBox = d . parcatsViewModel . graphDiv . getBoundingClientRect ( ) ;
@@ -438,19 +439,27 @@ function mouseoverPath(d) {
438
439
439
440
var textColor = tinycolor . mostReadable ( d . model . color , [ 'black' , 'white' ] ) ;
440
441
442
+ var count = d . model . count ;
443
+ var prob = count / d . parcatsViewModel . model . count ;
444
+ var labels = {
445
+ countLabel : count ,
446
+ probabilityLabel : prob . toFixed ( 3 )
447
+ } ;
448
+
441
449
// Build hover text
442
450
var hovertextParts = [ ] ;
443
451
if ( d . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
444
- hovertextParts . push ( [ 'Count:' , d . model . count ] . join ( ' ' ) ) ;
452
+ hovertextParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
445
453
}
446
454
if ( d . parcatsViewModel . hoverinfoItems . indexOf ( 'probability' ) !== - 1 ) {
447
- hovertextParts . push ( [ 'P:' , ( d . model . count / d . parcatsViewModel . model . count ) . toFixed ( 3 ) ] . join ( ' ' ) ) ;
455
+ hovertextParts . push ( [ 'P:' , labels . probabilityLabel ] . join ( ' ' ) ) ;
448
456
}
449
457
450
458
var hovertext = hovertextParts . join ( '<br>' ) ;
451
459
var mouseX = d3 . mouse ( gd ) [ 0 ] ;
452
460
453
461
Fx . loneHover ( {
462
+ trace : trace ,
454
463
x : hoverCenterX - rootBBox . left + graphDivBBox . left ,
455
464
y : hoverCenterY - rootBBox . top + graphDivBBox . top ,
456
465
text : hovertext ,
@@ -459,7 +468,15 @@ function mouseoverPath(d) {
459
468
fontFamily : 'Monaco, "Courier New", monospace' ,
460
469
fontSize : 10 ,
461
470
fontColor : textColor ,
462
- idealAlign : mouseX < hoverCenterX ? 'right' : 'left'
471
+ idealAlign : mouseX < hoverCenterX ? 'right' : 'left' ,
472
+ hovertemplate : ( trace . line || { } ) . hovertemplate ,
473
+ hovertemplateLabels : labels ,
474
+ eventData : [ {
475
+ data : trace . _input ,
476
+ fullData : trace ,
477
+ count : count ,
478
+ probability : prob
479
+ } ]
463
480
} , {
464
481
container : fullLayout . _hoverlayer . node ( ) ,
465
482
outerContainer : fullLayout . _paper . node ( ) ,
@@ -715,6 +732,7 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
715
732
var catViewModel = rectSelection . datum ( ) ;
716
733
var parcatsViewModel = catViewModel . parcatsViewModel ;
717
734
var dimensionModel = parcatsViewModel . model . dimensions [ catViewModel . model . dimensionInd ] ;
735
+ var trace = parcatsViewModel . trace ;
718
736
719
737
// Positions
720
738
var hoverCenterY = rectBoundingBox . top + rectBoundingBox . height / 2 ;
@@ -732,19 +750,27 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
732
750
hoverLabelIdealAlign = 'right' ;
733
751
}
734
752
753
+ var count = catViewModel . model . count ;
754
+ var catLabel = catViewModel . model . categoryLabel ;
755
+ var prob = count / catViewModel . parcatsViewModel . model . count ;
756
+ var labels = {
757
+ countLabel : count ,
758
+ categoryLabel : catLabel ,
759
+ probabilityLabel : prob . toFixed ( 3 )
760
+ } ;
761
+
735
762
// Hover label text
736
763
var hoverinfoParts = [ ] ;
737
764
if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
738
- hoverinfoParts . push ( [ 'Count:' , catViewModel . model . count ] . join ( ' ' ) ) ;
765
+ hoverinfoParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
739
766
}
740
767
if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'probability' ) !== - 1 ) {
741
- hoverinfoParts . push ( [
742
- 'P(' + catViewModel . model . categoryLabel + '):' ,
743
- ( catViewModel . model . count / catViewModel . parcatsViewModel . model . count ) . toFixed ( 3 ) ] . join ( ' ' ) ) ;
768
+ hoverinfoParts . push ( [ 'P(' + labels . categoryLabel + '):' , labels . probabilityLabel ] . join ( ' ' ) ) ;
744
769
}
745
770
746
771
var hovertext = hoverinfoParts . join ( '<br>' ) ;
747
772
return {
773
+ trace : trace ,
748
774
x : hoverCenterX - rootBBox . left ,
749
775
y : hoverCenterY - rootBBox . top ,
750
776
text : hovertext ,
@@ -753,7 +779,16 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
753
779
fontFamily : 'Monaco, "Courier New", monospace' ,
754
780
fontSize : 12 ,
755
781
fontColor : 'black' ,
756
- idealAlign : hoverLabelIdealAlign
782
+ idealAlign : hoverLabelIdealAlign ,
783
+ hovertemplate : trace . hovertemplate ,
784
+ hovertemplateLabels : labels ,
785
+ eventData : [ {
786
+ data : trace . _input ,
787
+ fullData : trace ,
788
+ count : count ,
789
+ category : catLabel ,
790
+ probability : prob
791
+ } ]
757
792
} ;
758
793
}
759
794
@@ -800,6 +835,7 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
800
835
var catViewModel = bandViewModel . categoryViewModel ;
801
836
var parcatsViewModel = catViewModel . parcatsViewModel ;
802
837
var dimensionModel = parcatsViewModel . model . dimensions [ catViewModel . model . dimensionInd ] ;
838
+ var trace = parcatsViewModel . trace ;
803
839
804
840
// positions
805
841
var hoverCenterY = bandBoundingBox . y + bandBoundingBox . height / 2 ;
@@ -840,26 +876,25 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
840
876
}
841
877
} ) ;
842
878
879
+ var pColorAndCat = bandColorCount / totalCount ;
880
+ var pCatGivenColor = bandColorCount / colorCount ;
881
+ var pColorGivenCat = bandColorCount / catCount ;
882
+
883
+ var labels = {
884
+ countLabel : totalCount ,
885
+ categoryLabel : catLabel ,
886
+ probabilityLabel : pColorAndCat . toFixed ( 3 )
887
+ } ;
888
+
843
889
// Hover label text
844
890
var hoverinfoParts = [ ] ;
845
891
if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
846
- hoverinfoParts . push ( [ 'Count:' , bandColorCount ] . join ( ' ' ) ) ;
892
+ hoverinfoParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
847
893
}
848
894
if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'probability' ) !== - 1 ) {
849
- var pColorAndCatLable = 'P(color ∩ ' + catLabel + '): ' ;
850
- var pColorAndCatValue = ( bandColorCount / totalCount ) . toFixed ( 3 ) ;
851
- var pColorAndCatRow = pColorAndCatLable + pColorAndCatValue ;
852
- hoverinfoParts . push ( pColorAndCatRow ) ;
853
-
854
- var pCatGivenColorLabel = 'P(' + catLabel + ' | color): ' ;
855
- var pCatGivenColorValue = ( bandColorCount / colorCount ) . toFixed ( 3 ) ;
856
- var pCatGivenColorRow = pCatGivenColorLabel + pCatGivenColorValue ;
857
- hoverinfoParts . push ( pCatGivenColorRow ) ;
858
-
859
- var pColorGivenCatLabel = 'P(color | ' + catLabel + '): ' ;
860
- var pColorGivenCatValue = ( bandColorCount / catCount ) . toFixed ( 3 ) ;
861
- var pColorGivenCatRow = pColorGivenCatLabel + pColorGivenCatValue ;
862
- hoverinfoParts . push ( pColorGivenCatRow ) ;
895
+ hoverinfoParts . push ( 'P(color ∩ ' + catLabel + '): ' + labels . probabilityLabel ) ;
896
+ hoverinfoParts . push ( 'P(' + catLabel + ' | color): ' + pCatGivenColor . toFixed ( 3 ) ) ;
897
+ hoverinfoParts . push ( 'P(color | ' + catLabel + '): ' + pColorGivenCat . toFixed ( 3 ) ) ;
863
898
}
864
899
865
900
var hovertext = hoverinfoParts . join ( '<br>' ) ;
@@ -868,6 +903,7 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
868
903
var textColor = tinycolor . mostReadable ( bandViewModel . color , [ 'black' , 'white' ] ) ;
869
904
870
905
return {
906
+ trace : trace ,
871
907
x : hoverCenterX - rootBBox . left ,
872
908
y : hoverCenterY - rootBBox . top ,
873
909
// name: 'NAME',
@@ -877,7 +913,19 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
877
913
fontFamily : 'Monaco, "Courier New", monospace' ,
878
914
fontColor : textColor ,
879
915
fontSize : 10 ,
880
- idealAlign : hoverLabelIdealAlign
916
+ idealAlign : hoverLabelIdealAlign ,
917
+ hovertemplate : trace . hovertemplate ,
918
+ hovertemplateLabels : labels ,
919
+ eventData : [ {
920
+ data : trace . _input ,
921
+ fullData : trace ,
922
+ category : catLabel ,
923
+ count : totalCount ,
924
+ probability : pColorAndCat ,
925
+ categorycount : catCount ,
926
+ colorcount : colorCount ,
927
+ bandcolorcount : bandColorCount
928
+ } ]
881
929
} ;
882
930
}
883
931
@@ -1475,12 +1523,13 @@ function createParcatsViewModel(graphDiv, layout, wrappedParcatsModel) {
1475
1523
if ( trace . hoverinfo === 'all' ) {
1476
1524
hoverinfoItems = [ 'count' , 'probability' ] ;
1477
1525
} else {
1478
- hoverinfoItems = trace . hoverinfo . split ( '+' ) ;
1526
+ hoverinfoItems = ( trace . hoverinfo || '' ) . split ( '+' ) ;
1479
1527
}
1480
1528
1481
1529
// Construct parcatsViewModel
1482
1530
// --------------------------
1483
1531
var parcatsViewModel = {
1532
+ trace : trace ,
1484
1533
key : trace . uid ,
1485
1534
model : parcatsModel ,
1486
1535
x : traceX ,
0 commit comments