Skip to content

Commit

Permalink
Merge pull request #6276 from orionlee/tweak_eclipsing-binary_yscale
Browse files Browse the repository at this point in the history
Tweak Eclipsing Binary simulation y-scale to better see shallow (< 10% depth) eclipses
  • Loading branch information
nikolas authored Nov 1, 2024
2 parents 98f70a8 + bbdd3dd commit 3176a78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions eclipsing-binary-simulator/src/d3/Axes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export default class Axes extends Component {
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9
]);
const xAxis = d3.axisBottom(this.props.xScale || 1).ticks(10);
const yAxis = d3.axisLeft(this.props.yScale).tickValues([
0, 0.25, 0.5, 0.75, 1
]).tickFormat(d3.format('.2r'));
const yAxis = d3.axisLeft(this.props.yScale).ticks(4)
.tickFormat(d3.format('.3r'));

const node1 = this.xAxis.current;
d3.select(node1).call(xAxis);
Expand Down
16 changes: 14 additions & 2 deletions eclipsing-binary-simulator/src/d3/Plot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ const xScale = props => {
// Returns a function that "scales" Y coordinates from the data to fit
// the chart.
const yScale = props => {
const domain = d3.extent(props.lightcurveData, d => d[1]);
// Convert flux in lightcurveData to normalized flux (what's visually presented)
// so as to scale the y-axis accordingly
const flux = props.lightcurveData.map(d => d[1]);
flux.sort();
const halfIdx = Math.floor(flux.length / 2);
const fluxMedian = flux[halfIdx];
const fluxNorm = flux.map(d => d / fluxMedian);

const yExtent = d3.extent(fluxNorm);
const diff = yExtent[1] - yExtent[0];
// Add 10% space above and below the lightcurve.
const dataPad = diff / 10;

return d3
.scaleLinear()
.domain([0, 1.1])
.domain([yExtent[0] - dataPad, yExtent[1] + dataPad])
.range([props.height - props.padding, props.padding]);
};

Expand Down

0 comments on commit 3176a78

Please sign in to comment.