@@ -83,7 +83,7 @@ export function removeTooltip() {
83
83
}
84
84
85
85
/**
86
- * Calculates the x-coordinate of the lower left-hand side of the tooltip rectangle (obviously without
86
+ * Calculates the x-coordinate of the upper left-hand side of the tooltip rectangle (obviously without
87
87
* "rounded corners"). Adjusts the x-coordinate so that tooltip is visible on the edges of the plot.
88
88
* @param x The current x-coordinate of the mouse
89
89
* @param textWidth The width of the tooltip text
@@ -93,38 +93,39 @@ export function removeTooltip() {
93
93
* @return The x-coordinate of the lower left-hand side of the tooltip rectangle
94
94
*/
95
95
export function tooltipX ( x : number , textWidth : number , plotDimensions : Dimensions , tooltipStyle : TooltipStyle , margin : Margin ) : number {
96
- if ( x + textWidth + tooltipStyle . paddingLeft + 10 > plotDimensions . width + margin . left ) {
96
+ if ( x > plotDimensions . width + margin . left - ( textWidth + tooltipStyle . paddingLeft + tooltipStyle . paddingRight ) ) {
97
97
return x - textWidth - margin . right + tooltipStyle . paddingRight + tooltipStyle . paddingLeft
98
98
}
99
99
return x + tooltipStyle . paddingLeft
100
100
}
101
101
102
102
/**
103
- * Calculates the y-coordinate of the lower -left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
103
+ * Calculates the y-coordinate of the upper -left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
104
104
* so that the tooltip is visible on the upper edge of the plot
105
- * @param y The y-coordinate of the series
105
+ * @param y The y-coordinate of the mouse
106
106
* @param textHeight The height of the header and neuron ID text
107
107
* @param plotDimensions The dimensions of the plot
108
108
* @param tooltipStyle The tooltip style information
109
109
* @param margin The plot margin
110
110
* @return The y-coordinate of the lower-left-hand corner of the tooltip rectangle
111
111
*/
112
112
export function tooltipY ( y : number , textHeight : number , plotDimensions : Dimensions , tooltipStyle : TooltipStyle , margin : Margin ) : number {
113
- return Math . min (
114
- y + margin . top - textHeight ,
115
- plotDimensions . height - margin . top + tooltipStyle . paddingTop + tooltipStyle . paddingBottom
116
- )
113
+ if ( y > plotDimensions . height + margin . top - ( textHeight + tooltipStyle . paddingTop + tooltipStyle . paddingBottom ) ) {
114
+ return plotDimensions . height + margin . top - ( textHeight + tooltipStyle . paddingTop + tooltipStyle . paddingBottom )
115
+ }
116
+ return y + tooltipStyle . paddingTop
117
117
}
118
118
119
119
/**
120
- * Calculates the y-coordinate of the lower -left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
121
- * so that the tooltip is visible on the upper edge of the plot
120
+ * Calculates the y-coordinate for the upper -left-hand the tooltip rectangle. Adjusts the y-coordinate so
121
+ * that the tooltip is visible on the upper and lower edges of the plot
122
122
* @param seriesName The name of the series
123
123
* @param textHeight The height of the header and neuron ID text
124
124
* @param axis The category axis for determining the y-value of the tooltip
125
125
* @param tooltipStyle The tooltip style
126
126
* @param margin The plot margin
127
127
* @param categoryHeight The height (in pixels) of the category
128
+ * @param plotDimensions The dimensions of the plot
128
129
* @return The y-coordinate of the lower-left-hand corner of the tooltip rectangle
129
130
*/
130
131
export function categoryTooltipY (
@@ -133,10 +134,18 @@ export function categoryTooltipY(
133
134
axis : CategoryAxis ,
134
135
tooltipStyle : TooltipStyle ,
135
136
margin : Margin ,
136
- categoryHeight : number
137
+ categoryHeight : number ,
138
+ plotDimensions : Dimensions
137
139
) : number {
138
- const y = ( axis . scale ( seriesName ) || 0 ) + margin . top - tooltipStyle . paddingBottom
139
- return y > 0 ? y : y + tooltipStyle . paddingBottom + textHeight + tooltipStyle . paddingTop + categoryHeight
140
+ const y = axis . scale ( seriesName ) || 0
141
+ const halfHeight = ( tooltipStyle . paddingBottom + textHeight + tooltipStyle . paddingTop ) / 2
142
+ if ( y < halfHeight ) {
143
+ return margin . top
144
+ }
145
+ if ( y > plotDimensions . height + margin . top - halfHeight ) {
146
+ return plotDimensions . height + margin . top - textHeight
147
+ }
148
+ return y + margin . top - halfHeight + categoryHeight / 2
140
149
}
141
150
142
151
0 commit comments