Skip to content

Commit

Permalink
Fixes GH-194
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveiano committed Oct 22, 2023
1 parent 109bf23 commit 363b252
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ See https://github.com/Daveiano/weewx-wdc/compare/v3.2.0...11eed6b3#diff-ba225fb
- Bugfix: Wind and Gust speed have a space between unit and comma (and added missing apostrophe to Yesterday's and Today's) GH-200
- Bugfix: Division by zero in get_windrose_data GH-192
- Bugfix: Manifest.json does not use base_path GH-197
- Bugfix: Tool Tip out of Scope GH-194
- Added `show_min_max` configuration to gauges config, added ordinal display for windDir gauge min/max
- Only show 3 decimals for the geocode provided by weewx-forecast GH-191
- Make sidebar scrollable (if there are too many items) GH-193
22 changes: 21 additions & 1 deletion skins/weewx-wdc/src/js/diagrams/d3/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ export const D3BarDiagram: FunctionComponent<BarDiagramBaseProps> = (
.on("mousemove", (event: MouseEvent) => {
// @see https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales
const xScaleStep = xScale.step();
const pointerX = d3.pointer(event)[0];
const padingInner = xScale.paddingInner();

let i = Math.floor(d3.pointer(event)[0] / xScaleStep);

Expand All @@ -321,10 +323,28 @@ export const D3BarDiagram: FunctionComponent<BarDiagramBaseProps> = (

d3.select(tooltipRef.current)
.style("display", "block")
.style("left", xScaleStep * i + "px")
// Tooltip over the bars.
.style("top", yScale(d.y) - 45 + "px");

// Is the cursor in the right half or in the left half of the chart?
if (pointerX > width / 2) {
// Right.
d3.select(tooltipRef.current).style(
"left",
margin.left +
padingInner * i +
xScaleStep * i -
(tooltipRef.current?.clientWidth as number) +
"px"
);
} else {
// Left.
d3.select(tooltipRef.current).style(
"left",
margin.left + xScaleStep * i + padingInner * i + 40 + "px"
);
}

if (props.nivoProps.enableCrosshair) {
focus
.select("line.y")
Expand Down
33 changes: 12 additions & 21 deletions skins/weewx-wdc/src/js/diagrams/d3/line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -597,33 +597,24 @@ export const D3LineDiagram: FunctionComponent<LineDiagramBaseProps> = (
setTooltip(values);

// Combined tooltip position left or right from the cursor.
if (props.data.length > 1) {
// Is the cursor in the right half or in the left half of the chart?
if (pointerX > width / 2) {
// Right.
d3.select(tooltipRef.current).style(
"left",
margin.left +
xScale(values[0].x * 1000) -
(tooltipRef.current?.clientWidth as number) -
20 +
"px"
);
} else {
// Left.
d3.select(tooltipRef.current).style(
"left",
margin.left + xScale(values[0].x * 1000) + 20 + "px"
);
}
} else {

// Is the cursor in the right half or in the left half of the chart?
if (pointerX > width / 2) {
// Right.
d3.select(tooltipRef.current).style(
"left",
margin.left +
xScale(values[0].x * 1000) -
(tooltipRef.current?.clientWidth as number) / 2 +
(tooltipRef.current?.clientWidth as number) -
20 +
"px"
);
} else {
// Left.
d3.select(tooltipRef.current).style(
"left",
margin.left + xScale(values[0].x * 1000) + 20 + "px"
);
}

d3.select(tooltipRef.current).style(
Expand Down

0 comments on commit 363b252

Please sign in to comment.