Skip to content

Commit

Permalink
fixed margin and padding in plots
Browse files Browse the repository at this point in the history
added padding for x domain and y domain to display each point clearly.
  • Loading branch information
MohamedNasser8 committed Nov 9, 2023
1 parent 97e50dd commit 7d3447b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions source/components/VisualTools/Chart/DensityChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ function DensityChart(props) {
.attr('height', rect.height)
.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);

const paddingPercent = 0.1; // Adjust the percentage of padding as needed
const domainExtentX = d3.extent(props.data, (d) => d[props.fields.x]);
const domainPaddingX = (domainExtentX[1] - domainExtentX[0]) * paddingPercent;
const domainExtentY = d3.extent(props.data, (d) => d[props.fields.y]);
const domainPaddingY = (domainExtentY[1] - domainExtentY[0]) * paddingPercent;
scales.current.x
.domain(d3.extent(props.data, (d) => d[props.fields.x]))
.domain([domainExtentX[0] - domainPaddingX,
domainExtentX[1] + domainPaddingX])
.range([0, innerWidth]);

scales.current.y
.domain(d3.extent(props.data, (d) => d[props.fields.y]))
.domain([domainExtentY[0] - domainPaddingY,
domainExtentY[1] + domainPaddingY])
.range([innerHeight, 0]);

svg.current
Expand Down Expand Up @@ -104,7 +110,6 @@ function DensityChart(props) {
svg.current
.insert('g', 'g')
.attr('id', 'draw_area')
.attr('transform', `translate(${margin.left},${-margin.bottom})`)
.selectAll('path')
.data(densityData)
.enter()
Expand Down
6 changes: 5 additions & 1 deletion source/components/VisualTools/Chart/ScatterChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ export default class ScatterChart extends PureComponent {
}

createScaleLiner(f, range) {
const paddingPercent = 0.1; // Adjust the percentage of padding as needed
const domainExtent = d3.extent(this.state.data, (d) => d[f]);
const domainPadding = (domainExtent[1] - domainExtent[0]) * paddingPercent;
const scaleLiner = d3
.scaleLinear()
.domain(d3.extent(this.state.data, (d) => d[f]))
.domain([domainExtent[0] - domainPadding,
domainExtent[1] + domainPadding])
.range(range)
.nice();
return scaleLiner;
Expand Down

0 comments on commit 7d3447b

Please sign in to comment.