@@ -413,6 +413,7 @@ function mouseoverPath(d) {
413413
414414 // Label
415415 var gd = d . parcatsViewModel . graphDiv ;
416+ var trace = d . parcatsViewModel . trace ;
416417 var fullLayout = gd . _fullLayout ;
417418 var rootBBox = fullLayout . _paperdiv . node ( ) . getBoundingClientRect ( ) ;
418419 var graphDivBBox = d . parcatsViewModel . graphDiv . getBoundingClientRect ( ) ;
@@ -438,19 +439,27 @@ function mouseoverPath(d) {
438439
439440 var textColor = tinycolor . mostReadable ( d . model . color , [ 'black' , 'white' ] ) ;
440441
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+
441449 // Build hover text
442450 var hovertextParts = [ ] ;
443451 if ( d . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
444- hovertextParts . push ( [ 'Count:' , d . model . count ] . join ( ' ' ) ) ;
452+ hovertextParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
445453 }
446454 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 ( ' ' ) ) ;
448456 }
449457
450458 var hovertext = hovertextParts . join ( '<br>' ) ;
451459 var mouseX = d3 . mouse ( gd ) [ 0 ] ;
452460
453461 Fx . loneHover ( {
462+ trace : trace ,
454463 x : hoverCenterX - rootBBox . left + graphDivBBox . left ,
455464 y : hoverCenterY - rootBBox . top + graphDivBBox . top ,
456465 text : hovertext ,
@@ -459,7 +468,15 @@ function mouseoverPath(d) {
459468 fontFamily : 'Monaco, "Courier New", monospace' ,
460469 fontSize : 10 ,
461470 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+ } ]
463480 } , {
464481 container : fullLayout . _hoverlayer . node ( ) ,
465482 outerContainer : fullLayout . _paper . node ( ) ,
@@ -715,6 +732,7 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
715732 var catViewModel = rectSelection . datum ( ) ;
716733 var parcatsViewModel = catViewModel . parcatsViewModel ;
717734 var dimensionModel = parcatsViewModel . model . dimensions [ catViewModel . model . dimensionInd ] ;
735+ var trace = parcatsViewModel . trace ;
718736
719737 // Positions
720738 var hoverCenterY = rectBoundingBox . top + rectBoundingBox . height / 2 ;
@@ -732,19 +750,27 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
732750 hoverLabelIdealAlign = 'right' ;
733751 }
734752
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+
735762 // Hover label text
736763 var hoverinfoParts = [ ] ;
737764 if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
738- hoverinfoParts . push ( [ 'Count:' , catViewModel . model . count ] . join ( ' ' ) ) ;
765+ hoverinfoParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
739766 }
740767 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 ( ' ' ) ) ;
744769 }
745770
746771 var hovertext = hoverinfoParts . join ( '<br>' ) ;
747772 return {
773+ trace : trace ,
748774 x : hoverCenterX - rootBBox . left ,
749775 y : hoverCenterY - rootBBox . top ,
750776 text : hovertext ,
@@ -753,7 +779,16 @@ function createHoverLabelForCategoryHovermode(rootBBox, bandElement) {
753779 fontFamily : 'Monaco, "Courier New", monospace' ,
754780 fontSize : 12 ,
755781 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+ } ]
757792 } ;
758793}
759794
@@ -800,6 +835,7 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
800835 var catViewModel = bandViewModel . categoryViewModel ;
801836 var parcatsViewModel = catViewModel . parcatsViewModel ;
802837 var dimensionModel = parcatsViewModel . model . dimensions [ catViewModel . model . dimensionInd ] ;
838+ var trace = parcatsViewModel . trace ;
803839
804840 // positions
805841 var hoverCenterY = bandBoundingBox . y + bandBoundingBox . height / 2 ;
@@ -840,26 +876,25 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
840876 }
841877 } ) ;
842878
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+
843889 // Hover label text
844890 var hoverinfoParts = [ ] ;
845891 if ( catViewModel . parcatsViewModel . hoverinfoItems . indexOf ( 'count' ) !== - 1 ) {
846- hoverinfoParts . push ( [ 'Count:' , bandColorCount ] . join ( ' ' ) ) ;
892+ hoverinfoParts . push ( [ 'Count:' , labels . countLabel ] . join ( ' ' ) ) ;
847893 }
848894 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 ) ) ;
863898 }
864899
865900 var hovertext = hoverinfoParts . join ( '<br>' ) ;
@@ -868,6 +903,7 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
868903 var textColor = tinycolor . mostReadable ( bandViewModel . color , [ 'black' , 'white' ] ) ;
869904
870905 return {
906+ trace : trace ,
871907 x : hoverCenterX - rootBBox . left ,
872908 y : hoverCenterY - rootBBox . top ,
873909 // name: 'NAME',
@@ -877,7 +913,19 @@ function createHoverLabelForColorHovermode(rootBBox, bandElement) {
877913 fontFamily : 'Monaco, "Courier New", monospace' ,
878914 fontColor : textColor ,
879915 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+ } ]
881929 } ;
882930}
883931
@@ -1475,12 +1523,13 @@ function createParcatsViewModel(graphDiv, layout, wrappedParcatsModel) {
14751523 if ( trace . hoverinfo === 'all' ) {
14761524 hoverinfoItems = [ 'count' , 'probability' ] ;
14771525 } else {
1478- hoverinfoItems = trace . hoverinfo . split ( '+' ) ;
1526+ hoverinfoItems = ( trace . hoverinfo || '' ) . split ( '+' ) ;
14791527 }
14801528
14811529 // Construct parcatsViewModel
14821530 // --------------------------
14831531 var parcatsViewModel = {
1532+ trace : trace ,
14841533 key : trace . uid ,
14851534 model : parcatsModel ,
14861535 x : traceX ,
0 commit comments