Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[viz] Axis fix for histogram and distribution chart #569

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,12 @@ <h1 class="no-responsive__title">Hold on! :)</h1>
const minY = Math.abs(d3.min(data));
let positiveY = Math.ceil(maxY) % 1 ? maxY + 2*(maxY/(maxY*10)) : maxY + 2*(maxY/(maxY/10)),
negativeY = Math.ceil(minY) % 1 ? minY + 2*(minY/(minY*10)) : minY + 2*(minY/(minY/10));

const yScale = d3.scaleLinear()
.domain([-negativeY, positiveY || 0])
.range([CHART_HEIGHT,0])

.domain([-negativeY*1.2, positiveY*1.2 || 0])
.nice()
const xAxis = d3.axisBottom(xScale).ticks(SVG_WIDTH / 80, xFormat).tickSizeOuter(0);
const yAxis = d3.axisLeft(yScale).ticks(CHART_HEIGHT / 30, yFormat);
yFormat = yScale.tickFormat(100, yFormat);

svgEl.append("g")
.attr("transform", `translate(${MARGIN.LEFT}, 0)`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,19 @@ <h1 class="no-responsive__title">Hold on! :)</h1>

this.xScale = d3
.scaleLinear()
.domain([d3.min(this.charts2, function(d) { return parseFloat(d.axisX); }),(this.maxTargetXValue+this.targetBinWidth >= this.maxReferenceXValue+this.referenceBinWidth) ? this.maxTargetXValue+this.targetBinWidth:this.maxReferenceXValue+this.referenceBinWidth]) // I was too lazy to do basic math of max(bin_start + width for each distribution)
.domain([d3.min(this.charts2, function(d) { return parseFloat(d.axisX); }),(this.maxTargetXValue+this.targetBinWidth >= this.maxReferenceXValue+this.referenceBinWidth) ? this.maxTargetXValue+this.targetBinWidth:this.maxReferenceXValue+this.referenceBinWidth])
.range([0, this.CHART_WIDTH ]);

this.svgEl.append("g")
.attr("transform", "translate("+ this.MARGIN.LEFT +"," + this.SVG_HEIGHT + ")")
.call(d3.axisBottom(this.xScale));
this.yScale = d3.scaleLinear()
.range([this.CHART_HEIGHT , 0])
this.yScale.domain([d3.min(this.charts2, function(d) { return parseFloat(d.axisY); }), d3.max(this.charts2, function(d) { return parseFloat(d.axisY); })]);
.domain([d3.min(this.charts2, function(d) { return parseFloat(d.axisY); }), d3.max(this.charts2, function(d) { return parseFloat(d.axisY); })*1.2])
.nice();
}
}

function chartData(column) {
const data = [];
if (column.numberSummary?.histogram) {
Expand Down Expand Up @@ -300,8 +301,7 @@ <h1 class="no-responsive__title">Hold on! :)</h1>
} = sizes

const rectColors = ["#44C0E7", "#F5843C"]
const yAxis = d3.axisLeft(yScale).ticks(SVG_HEIGHT / 40, yFormat);
yFormat = yScale.tickFormat(100, yFormat);
const yAxis = d3.axisLeft(yScale).ticks(SVG_HEIGHT / 40);

svgEl.append("g")
.attr("transform", `translate(${MARGIN.LEFT}, ${MARGIN.BOTTOM})`)
Expand Down