Skip to content

Commit

Permalink
Bring hidden scatter point in mid to remove extra space
Browse files Browse the repository at this point in the history
  • Loading branch information
jaladh-singhal committed Sep 14, 2020
1 parent 1c01462 commit b54358b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tardis/widgets/line_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,25 @@ def get_middle_half_edges(arr):
(arr[-1] - arr[0]) * 3 / 4 + arr[1],
]

@staticmethod
def get_mid_point_idx(arr):
"""
Get index of the middle point of a sorted array (ascending or descending).
The values in array may not be evenly distributed so it picks the middle
point not by index but by their values.
Parameters
----------
arr : np.array
Returns
-------
int
"""
mid_value = (arr[0] + arr[-1]) / 2
return np.abs(arr - mid_value).argmin()

def plot_spectrum(
self,
wavelength,
Expand Down Expand Up @@ -473,8 +492,13 @@ def plot_spectrum(
-------
plotly.graph_objects.FigureWidget
"""
# Initially zoomed range in rangeslider should be middle half of spectrum
initial_zoomed_range = self.get_middle_half_edges(wavelength.value)

# The scatter point should be a middle point in spectrum otherwise
# the extra padding around it will be oddly visible when near the edge
scatter_point_idx = self.get_mid_point_idx(wavelength.value)

return go.FigureWidget(
[
go.Scatter(
Expand All @@ -489,8 +513,8 @@ def plot_spectrum(
),
# Hide a one point scatter trace, to bring boxselect in modebar
go.Scatter(
x=wavelength[0],
y=luminosity_density_lambda[0],
x=wavelength[scatter_point_idx],
y=luminosity_density_lambda[scatter_point_idx],
mode="markers",
marker=dict(opacity=0),
showlegend=False,
Expand Down

0 comments on commit b54358b

Please sign in to comment.