Skip to content

Commit

Permalink
measurements/createXScale: Add paddingProportion param
Browse files Browse the repository at this point in the history
Based on feedback from @huddlej
<87b4446#r1720389378>

I added as optional param here with a default value of 0.1
In the future, we can potentially feed in a user defined value from
the measurements JSON.
  • Loading branch information
joverlee521 committed Aug 16, 2024
1 parent 87b4446 commit c302939
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/measurements/measurementsD3.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ const getSubplotDOMId = (groupingValueIndex) => `measurement_subplot_${groupingV
/**
* Creates the D3 linear scale for the x-axis with the provided measurements'
* values as the domain and the panelWidth with hard-coded padding values as
* the range. Expected to be shared across all subplots.
* the range. The optional paddingProportion can be provided to include additional
* padding for the domain. Expected to be shared across all subplots.
* @param {number} panelWidth
* @param {Array<Object>} measurements
* @param {number} [paddingProportion=0.1]
* @returns {function}
*/
export const createXScale = (panelWidth, measurements) => {
export const createXScale = (panelWidth, measurements, paddingProportion = 0.1) => {
// Padding the xScale based on proportion
// Copied from https://github.com/d3/d3-scale/issues/150#issuecomment-561304239
function padLinear([x0, x1], k) {
Expand All @@ -73,7 +75,7 @@ export const createXScale = (panelWidth, measurements) => {

return (
scaleLinear()
.domain(padLinear(extent(measurements, (m) => m.value), 0.1))
.domain(padLinear(extent(measurements, (m) => m.value), paddingProportion))
.range([layout.leftPadding, panelWidth - layout.rightPadding])
.nice()
);
Expand Down

0 comments on commit c302939

Please sign in to comment.