score:2
calling y1.range()
(without any arguments) will return you the [min, max]
of the scale.
from the docs:
if values is not specified, returns the scale's current output range.
most accessor functions in d3 work like this, they return you (get) the value if you call them without any arguments and set the value if you call them with arguments and return the this
object for easy chaining:
d3object.propertyname = function (_) {
if (!arguments.length) return propertyname;
propertyname = _;
return this;
}
however, the zoom
behaviour alters the domain
and not the range
of the scales.
from the docs:
specifies an x-scale whose domain should be automatically adjusted when zooming.
hence, you do do not need to get/set the range
, but instead the domain
of the scales y1
and y2
: y2.domain(y1.domain())
.
score:2
since the zoom function already manages all the ratios, a more abbreviated answer would be:
var zoomfirst = d3.behavior.zoom()
.x(x)
.y(y1)
.scaleextent([0, 3])
.size([w, h])
.on("zoom", function() {
zoomsecond.scale(zoom.scale());
zoomsecond.translate(zoom.translate());
// update visual. both y domains will now be updated
});
// create copy for y2 scale
var zoomsecond = d3.behavior.zoom()
.x(x)
.y(y2) // <-- second scale
.scaleextent([0, 3]) // <-- extent
this assumes you have called only zoomfirst to your visual.
Source: stackoverflow.com
Related Query
- d3js: zooming when there are two y axes
- Using d3.js is there a way to zero align two Y Axes with positive and negative values
- Using c3 js, Is there a way to show more x-axis values when zooming in?
- How to make grid lines when axes are aligned at the middle?
- what is the point of calling selectAll when there are no existing nodes yet on D3.js
- How to load data to D3 chart from JSON when there are only tuples
- Why labels on chart are not shown when drawn after axes
- There are duplicate viewreset events when loading different path features in Leaflet with D3.js
- d3 doesn't plot tree when there are exclusively single children?
- how to improve the drilling performance of d3 sunburst chart when there are too many paths? like dynamically show partial levels?
- Dimple Js repeats ticks when there are only a few values
- two graph of d3 in same page are getting effected when events happening in other graph
- How to Show all the child nodes when there are many
- Javascript: Array of Objects is returning undefined when accessing to a single Element. Even though there are 696 Objects saved in it
- d3 sankey plugin not drawing when there are too many links?
- How to convert SVG to canvas to PNG when there are multiple SVGs in a page
- Delete a line when ticks are clicked - d3js
- d3 barchart in jquery mobile -- why are there two checkboxes?
- Appending svg of d3 chart to separate divs when there are multiple json files
- Are there any simple examples for single axis zooming in d3?
- d3 x-axis has issue when there are duplicate values
- Why does d3.js v3 break my force graph when implementing zooming when v2 doesn't?
- D3 keep line width same when zooming
- JS based influxdb graph editors like Grafana, Influga, are there reusable libraries?
- Are there any tutorials or examples for cubism.js + WebSocket?
- How to change speed of translate and scale when zooming in and out in D3 (using zoom.on & d3.event.translate, d3.event.zoom)?
- Limiting domain when zooming or panning in D3.js
- why isn't the checkbox change event triggered when i do it programatically in d3js
- How to avoid the overlapping of text elements on the TreeMap when child elements are opened in D3.js?
- SVG circles don't get repositioned when zooming leaflet map
More Query from same tag
- how to create separate bar chart with JSON array set?
- d3.js: Ordinal scale
- Converting an Array of Arrays to an Array of Objects Using Built-in d3.js Methods
- Gauge chart with steps of colors
- How to make a semi-circle in d3?
- Force Directed D3 Graph -- Debug
- Formatting numbers with commas in D3
- d3.js and self signed SSL certificate
- d3.js hierarchical edge bundling: embed json data in variable
- How to vary the size of piechart in d3 with tree layout
- How to fill a single value in the 'Donut Chart'
- Changing "fill" style on axis tick labels not working (d3.js)
- What's the purpose of appending an "m" when measureText
- D3 scaleLinear() returns rgb value although the range is in hex values
- D3 area graph animation
- Binding configuration to a function using a closure
- D3 js update plot just adds new points on top
- DC.js xAxis range, show only a subset
- How to generate an elliptical Tilford tree in D3.js
- d3.js mapping a dataset into a new one with different keys
- Argentina not showing up on world map with d3.js
- Implementing d3 Codeflower source code
- D3 time axis like plottable.js
- Only one D3 Visualization is showing up on my page?
- Removing text on mouseout event
- D3 Bar chart. How to set custom x and y axis based on JSON data?
- Can i over-ride IE enterprise mode from HTML?
- d3/cola: Layout configuration for UML-like diagram
- How to reuse variables in a d3.js selection?
- Delete and add nodes with click on a node in d3.js