score:1
Accepted answer
well, finally i implemented what i want.
result: https://jsfiddle.net/2yqbvrwp/
details: first of all, i decided to remove second scale, bc i need it only in runtime. so, my zoom function is changed to:
d3.zoom().scaleextent([ 1, 10 ])
// i am not sure if i need the line below since code works same without it
// i think below is default value
//.translateextent([ [ 0, 0 ], [ width, height ] ])
.on("zoom", (event) => {
const transform = event.transform;
// the new scale i use for runtime
// the important part here is clamp method. it prevents from moving
// segments outside of axis
const newscalex = transform.rescalex(xscale).clamp(true);
// so i just applied new scale to current axis
xaxis.scale(newscalex)
svg.select("g.axis-x").call(xaxis);
svg.selectall("rect.segment")
.attr("x", (d) => newscalex(d[0]))
.attr("width", (d) => newscalex(d[1]) - newscalex(d[0]));
})
svg.call(zoom);
also i removed rect
transform from css and added margin left in code. but i think i will return it back since native css is faster.
Source: stackoverflow.com
Related Query
- D3 v6: How to zoom stacked bar by selected segment to stretch only selected segment and shrink rest segments (and keep initial chart width)?
- How to create a d3 stacked bar chart that only iterates through columns 1 and 2 of data file?
- How do you create a stacked bar chart in d3 when each individual segment is an object?
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- How to make grouped stacked bar chart in d3js?
- d3/dc.js - How to create a stacked bar chart while telling crossfilter to treat elements in an array as separate records?
- Disable zoom on selected elements only
- How to line up x axis on stacked bar chart with a line overlay in d3.js
- How to create a stacked bar chart using dc.js?
- How to show values stacked bar chart utilizing dc.js and d3.js?
- How do I define a value accessor for a stacked bar graph?
- D3 transition from stacked bar to bar chart only works the first time
- how to create a stacked bar chart with images in d3
- D3: How to do an update pattern on normalized stacked bar chart?
- d3.js - How to do data mapping and filter for Stacked Bar graph
- How to add live data to stacked bar chart
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
- How do I know which bar the mouse is in for D3 stacked bar?
- How to use log scale to show proper stacked bar chart using d3 JS?
- How to zoom only on the X axis in a line chart in d3.js (v7)
- How to proper zoom and pan only the y-axis in D3 v5 y-axis
- How can I make the legend's similar to the stacked bar chart (and change the legend's label) in D3 v6?
- How to display the total value of a stacked bar chart in d3js
- D3: How to show only top 3 of 6 items in bar chart?
- How to filter data and populate D3.js stacked bar chart?
- how to update text added in dimple.js stacked bar chart on data updation
- How plot and symbolize only selected columns from csv in plotting in d3?
- How to keep group of stacked bar charts in a particular order
- Stacked bar chart 24hr @ 15 minute data, to only display 2hr ticks
- How to give a Bar in a Stacked Bar Chart a minimal height using D3?
More Query from same tag
- Change attribute back to before calculated attribute in d3?
- Omitting trailing zeroes / using sigfigs with d3.format()
- D3.js : How can I select the first property value from an array of objects?
- Error: D3 V4 Multi-series line chart with Angular-cli - <path> attribute d: Expected number
- xAxis ordinal() does not start in left corner
- Issue with useInteractiveGuideline() in nvd3.js
- Can you use transition().delay() and .classed() together?
- D3: Repositioning Pie Chart Labels on Update
- SI-prefix with significant digits but trimming trailing decimal zeros in d3.js
- How to "map" JSON values from a second Object level with d3.js
- d3.js - prevent "clustering" with parent / other groups in force-directed graph
- returning an array equally spaced between two given times with a given variable x
- D3js Line graph doesn't go through all of my points when I use .interpolate('basis')?
- D3 removal animation 'delayed' by updating - any way to prevent multiple calls to the same animation?
- d3 add multiple classes with function
- Add padding to sunburst layout d3 v4
- How to use d3.js to select an svg element and modify its attr?
- How to call a function on 'load' event in D3?
- Setting d3.js code to point to my .csv instead of #csv?
- D3 How to update the chart after selection from drop down menu with new data
- How do you find the last data point in d3 and draw a circle and a line on it?
- JavaScript D3: overlapping of color areas
- Get x,y location of D3 point on path
- D3.js IE9 error on checking nodes in graphdata
- D3 Bubble Chart
- path fill color in d3
- read width of d3 text element
- D3 - start y.domain and min value
- Reload nested data in D3.js
- DataMap/D3 - how to reset zoom?