Skip to content

Commit

Permalink
add padding to svg width and height to fix axis overflow issues. #224
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcncgr committed Apr 17, 2024
1 parent e693130 commit 89c24cd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/lis-histogram-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,28 @@ export class LisHistogramElement extends LitElement {
this._histogramContainerRef.value.innerHTML = '';
//const histogramContainer = d3.select(this._histogramContainerRef.value);

const padding = 50; // padding around the SVG
const width = 500 - 2 * padding; // adjust width
const height = 500 - 2 * padding; // adjust height

const svgContainer = d3
.select(this._histogramContainerRef.value)
.append('svg')
.attr('width', 500)
.attr('height', 500);
.attr('width', width + 2 * padding)
.attr('height', height + 2 * padding)
.append('g')
.attr('transform', `translate(${padding}, ${padding})`);

const x = d3
.scaleBand()
.domain(theHistogram.map((d) => d.name))
.range([0, 500])
.range([0, width])
.padding(0.1);

const y = d3
.scaleLinear()
.domain([0, d3.max(theHistogram, (d) => d.count) as number])
.range([500, 0]);
.range([height, 0]);

// Create the bars
svgContainer
Expand All @@ -122,8 +128,8 @@ export class LisHistogramElement extends LitElement {
svgContainer
.append('text')
.attr('transform', 'rotate(-90)')
.attr('y', 0 - 50)
.attr('x', 0 - 500 / 2)
.attr('y', 50)
.attr('x', 500 / 2)
.attr('dy', '1em')
.style('text-anchor', 'middle')
.style('fill', 'black')
Expand Down

0 comments on commit 89c24cd

Please sign in to comment.