I've found a fix but it's not ideal, I'm still putting it here in case someone finds it useful. Instead of just using the value from the scale, I add a length of the article (a little less actually… told you it wasn't ideal) times the number of articles already displayed. Far from elegant but it works for now, articles never overlap:
div.transition().duration(2000) .style("top", (d, i) -> d3.round(timeScale(timeFormat.parse(d.date))) + i * articleHeight + "px")
The problem is indeed with the height calculation. What you are calculating is the needed height for N articles, where N is the number of articles in your data. However, when you create the scale, you calculate the range from the earliest date to the the latest. So if your first data item is from 01-01-2012 and your last from 31-01-2012, the range will be 30 (or 31 too lazy to check).
So what you basically should do is reuse the d3.extent calculation in the timescale to calculate the height.
Update: Okay, so let me elaborate a bit on this. What you want is non-overlapping articles. Therefore you specify a minimal article height. I assume you are using d3.time.scale for timeScale (which is the correct thing to do). For this scale you (also correctly) set the domain as follows:
.domain(d3.extent(data, (d) -> timeFormat.parse(d.date)))
The d3.extent function gives you the min and max values, in the case the earliest and the latest date. Now, to calculate the required height, you'll need to take account for the maximum number of articles that might be visible, which is (assuming max one article per day) the number of days between the first and the last date as calculated by d3.extent. To do this you have to calculate the number of days between min and max.
Is set up a jsfiddle which demonstrates this calculation here: http://jsfiddle.net/EA5rP/14/
- How can I set a minimum range for an interval for a time scale in d3.js?
- how to set proper domain for date time scale in d3
- How to set a scale for the time series, current x scale gives me NaN?
- d3js set tickValues for time scale axis
- how to config time range for d3.js
- How to set Minimum Radius for Circle Pack in D3JS?
- How to increase time to read d3.json data for large data set and slow networks?
- How can I apply a time scale and show my data in intervals of "n" years?
- d3 time scale add before and after time range a percentage of time interval
- How to get the minimum and maximum value between a given range in data set in d3.js
- How to spcify ticks on x axis for time scale in d3js?
- How can I control the date format for d3 scaleTime and remove unwanted clock time ticks?
- how can I set a height and width for this map in d3.js
- How to set d3 color scale for each element in object array?
- How to configure x-axis and manually set start/end time for d3.js
- How can I check if a value is inside of a d3 scale range
- How do I set a different range for line chart embedded in a bar chart using d3.js
- How can i set the x axis tick interval to be 1 in C3 / d3 js charts?
- Understanding how to select the Range for a scale
- how do I set up a grouping query on the server side. I want set up the query so I can use it for a pie chart in front end, using d3js
- How to make X axis timescale with equal interval between elements on chart independent of time range
- How can I set max value(range) for y-axis and bar width of a bar chart using nvd3.js
- d3.js & nvd3.js -- How to set y-axis range
- How to set text color for my d3 chart title?
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- D3: Create a continuous color scale with many strings/inputs for the range and dynamically changing values of the domain
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- how to set the domain and scale on an axis on a nvd3.js multiBarChart
- D3js: How do I clear the zoom scale set by the d3.zoom event?
More Query from same tag
- D3 rendering map not completely
- How to set default value to dc selectMenu
- d3 v4 why are there duplicate ticks on the X Axis (how to work tickValues)?
- Cannot read property "getPropertyValue" of null in xChart
- updating d3 chart with new data, the old data points not removed
- Nested functions in typescript gives errors
- .attr not defined d3js
- d3.js create the pie chart but square shaped
- how to start axis label at zero?
- Google Chart Issue - Only the Wireframe is Visible
- Why does my JSON update for one API but not the other?
- Importing d3.js in angular 2 project not working
- Is d3.mouse( mySVG) really the right way to address the container?
- d3 getting array of keys from data
- filter the json data and draw the nvd3 chart using filtered data
- D3 Canvas force layout - disjointed group replelling the other group
- Setting X-axis label in d3.js
- How to make expandable tree in d3.js vertical?
- Add image at top of each D3 bar rect
- Center force directed layout after tick using root node (return to center)
- Cannot run python SImpleHTTPServer on windows 10 for d3.js testing (issue changing environment variable)
- how to change data via key not index in a dropdown in d3
- ISO8601 Date Time format D3
- D3v4 - on("end") called before transition.duration is over
- Problems when using the insert() function in d3 java library when trying to insert SVG elements before another
- D3 - How to create multiple line charts from an array of objects
- Bold text in R using networkD3 package
- How do I select an SVG inside an `object` tag?
- d3.js + nvd3 parallel coordinate draggable axes
- Set D3 line stroke according to deviation