Truncating everything over 50% to the value of 50% is easily done with
const scale = d3.scaleLinear() .domain([0, 0.5]) .range([0, 500]) .clamp(true); d3.range(11).map(d => console.log(d * 10 + "% in the scale is: " + scale(d / 10)))
On the other hand, if you want a different range for those domain values outside the limit, just set a domain and a range with intermediate values. For instance, here the regular domain (from 0 to 50%) goes from 0 to 500 in the range, and everything over 50% will be positioned at 520:
const scale = d3.scaleLinear() .domain([0, 0.5, (0.5 + 1e-6), 1]) .range([0, 500, 520, 520]); d3.range(11).map(d=>console.log(d * 10 + "% in the scale is: " + scale(d/10)))
- Linear + threshold unified scale
- d3 color scale - linear with multiple colors?
- Use d3 log scale instead of linear scale
- How do we change the tick values generated by a linear scale in a d3.js line plot?
- Understanding invertExtent in a threshold scale
- d3.js linear scale returns NaN
- render d3 linear nice scale with whole numbers only
- custom d3 linear scale that returns null for null values instead of 0
- D3.js using ordinal scale over linear scale
- D3.js v5 - Creating a relative, zoomable timeline-like axis on a linear scale
- Starting linear scale from 1 instead of 0 (D3.js)
- Crosshair / x value tooltip for linear scale
- Change D3 scale from linear to pow by pushing a button
- Threshold scale for position
- Format linear scale large number replace G to B
- Linear piecewise scale in D3
- D3 linear scale , how to show customised strings as ticks ?
- Creating a d3.js linear scale with multiple domains?
- D3: Giving a linear scale a dynamic domain
- D3 - Shrink Linear Scale Range
- Tick line not visible in linear time scale
- D3 SVG path is not filling with linear scale gradient
- Linear scale inconsistency between x/y and width/height
- d3 linear color scale output is wrong
- D3js linear color scale with custom values (ticks)?
- d3 linear scale - invalid value
- Linear scale with labels in D3
- D3 Applying colour from a linear scale to my data
- How to reverse linear scale for d3?
- Cannot get line to draw on log scale y-axis, but can on linear
More Query from same tag
- Programmatically open nested, collapsed (hidden) nodes in d3.js v6
- Unable to render simple graph in d3.js by reading data from MySQL using JSON
- d3.tree => transform does not seem to work
- Transition only on the y value of a line point?
- d3 choropleth queue and fill issues
- Show effect only when that section is reached in a website
- d3.js updating from v3 to v5
- TopoJSON - adding properties to a topoJSON file
- Can I add a moving scale or axis in plots using Vegalite?
- Why do GeoJSON features appear like a negative photo of the features themselves?
- Images not Generating D3
- how to add new elements to d3 data set used in enter.append?
- Forced network diagram in R
- Convert Excel file to JSON: design of JSON code check
- D3.js Accessing local file in IE9 and firefox
- D3.js: Pie graph, adding a border only to the outter region
- Line Chart using .csv data format by d3.js
- Reference a div from d3 inside a iframe
- D3 axes render on top of graph
- Most efficient access to the rightmost/leftmost cousin node in a d3 tree
- Dynamically project a Single County
- AngularJS + D3 Animations Bar Chart Directive
- zoomable bar chart using d3.js
- D3.js text. what is wrong in this code.
- D3.js v4 - how to add zoom button with the default wheelmouse zoom behavior
- d3 graph: What code to write in dblclick handler to change a node text
- Insert text inside Circle in D3 chart
- Drawing data 1 by 1 D3 js
- Large gap between columns in D3js column chart