diff --git a/lib/plox.ex b/lib/plox.ex index 6a92b12..800dd4f 100644 --- a/lib/plox.ex +++ b/lib/plox.ex @@ -314,23 +314,39 @@ defmodule Plox do slot :inner_block, required: true def tooltip(assigns) do + height = assigns.dataset.dimensions.height point = GraphDataset.to_graph_point(assigns.dataset, assigns.x, assigns.y, assigns.point_id) - assigns = - assign(assigns, point: point) + {container_classes, pointer_classes} = + if point.y < height / 2 do + # top half of the graph: draw tooltip BELOW the clicked point + {"top: #{point.y + 12}px;", "top: -0.5rem;"} + else + # bottom half of the graph: draw tooltip ABOVE the clicked point + {"bottom: #{height - point.y + 12}px;", "bottom: -0.5rem;"} + end + + assigns = assign(assigns, point: point, container_classes: container_classes, pointer_classes: pointer_classes) ~H""" -
- <%= render_slot(@inner_block, @point.data_point.original) %> -
+
+
+ <%= render_slot(@inner_block, @point.data_point.original) %> +
+
""" end