Giter Club home page Giter Club logo

d3-timeline's Introduction

d3-timeline

A simple d3 timeline plugin.

Get something that looks like

Rectangular Timeline

for a dataset that looks like

var testData = [
  {label: "person a", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {label: "person b", times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]},
  {label: "person c", times: [
    {"starting_time": 1355761910000, "ending_time": 1355763910000}]}
  ];

with a call that looks like

var chart = d3.timeline();

var svg = d3.select("#timeline1").append("svg").attr("width", 500)
  .datum(testData).call(chart);

Works with circles. In case the rectangular edges are too pointy.

Circular Timeline

Combine rectangles and circles to your liking

Rectangular and Circular Timeline

by adding a display key to the data:

var rectAndCircleTestData = [
    {times: [{"starting_time": 1355752800000, "display": "circle"},
             {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
    {times: [{"starting_time": 1355759910000, "display":"circle"}, ]},
    {times: [{"starting_time": 1355761910000, "ending_time": 1355763910000}]}
  ];

Make a pseudo-gantt chart thingy

Gantt chart

with icons

Icon chart

For your really long charts, it supports scrolling. It can even do things on hover, click, and scroll for when someone accidentally interacts with your chart.

You can also specify an optional class key in the data dictionary. This will label each timeline rectangle item within the visualization with the following id property: "timelineItem_"+class. For example, this data

var testData = [
  {class: "pA", label: "person a", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {class: "pB", label: "person b", times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]},
  {class: "pC", label: "person c", times: [
    {"starting_time": 1355761910000, "ending_time": 1355763910000}]}
  ];

would generate <rect> with the following classes: timelineItem_pA,timelineItem_pB,timelineItem_pC. This means that you can dynamically change the visual properties of each timeline item using JQuery like so: $(".timelineSeries_pA").css("fill","blue");. If no custom class is provided, the class attribute will be generated sequentially in the order they have been provided in. e.g.: timelineSeries_0.

Also optional is an id field per data element.

var testData = [
  {label: "person a", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000, "id": "A1"},
    {"starting_time": 1355767900000, "ending_time": 1355774400000, "id": "A2"}]}
  ];

This generates <rect>s with A1 and A2 as ids. If no id is provided, the id attribute will be generated sequentially in the order they have been provided in. e.g.: timelineItem_0_0.

Look at the examples for more details.

Data formats

The simplest data format only requires starting_time and ending_time for each series of data.

[
  {times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]}
];

label can be added if you want names by each series of data. In order for this to properly show up, the timeline needs to be called with .stack()

[
  {label: "person a", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {label: "person b", times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]}
];

icon can be added if you want icons by each series of data. In order for this to properly show up, the timeline needs to be called with .stack(). Icons and labels can also be mixed in together.

[
  {icon: "path/to/img.png", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {label: "person b", times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]}
];

'times' elements array

Each item in the times array must have starting_time and ending_time. You could also specify optional color or label elements within a times item, as well as a property mapped to a color.

[
   {label: "person a", times: [{"color":"green", "label":"Weeee", "starting_time": 1355752800000, "ending_time": 1355759900000}, {"color":"blue", "label":"Weeee", "starting_time": 1355767900000, "ending_time": 1355774400000}]},
   {label: "person b", times: [{"color":"pink", "label":"Weeee", "starting_time": 1355759910000, "ending_time": 1355761900000}, ]},
   {label: "person c", times: [{"color":"yellow", "label":"Weeee", "starting_time": 1355761910000, "ending_time": 1355763910000}]}
];

Method Calls

All methods that take in arguments return the current settings if no argument is passed.

.width(width)

sets the width of the timeline. If the width of the timeline is longer than the width of the svg object, the timeline will automatically scroll. The width of the timeline will default to the width of the svg if width is not set.

.height(height)

sets the height of the timeline. The height of the timeline will be automatically calculated from the height of each item if height is not set on the timeline or the svg.

.itemHeight(height)

sets the height of the data series in the timeline. Defaults to 20px.

.itemMargin(height)

sets the margin between the data series in the timeline. Defaults to 5px.

.margin({left: , right: , top: , bottom: })

sets the margin of the entire timeline inside of the svg. Defaults to 30px all around.

.display("circle" | "rect")

Displays the data series as either circles or rectangles. Defaults to "rect".

.labelFormat(callback)

registers a function to be called when the text for the label needs to be generated. Useful if your label looks like this:

{
  en: "my label",
  fr: "mon étiquette"
}

The callback function is passed the whatever the datum.label returns, so in this case it would be the object above. So the labelFormat might look something like this:

.labelFormat(function(label){ return label[currentLocale];})

.tickFormat({format: , tickTime: , tickInterval: , tickSize: , numTicks: , tickValues})

sets the formatting of the ticks in the timeline. Defaults to

{
  format: d3.time.format("%I %p"),
  tickTime: d3.time.hours,
  tickInterval: 1,
  tickSize: 6
}

Tick interval/values can be set with:

  • tickTime and tickInterval
  • numTicks and tickInterval
  • tickValues

.rotateTicks(degrees)

sets the degree of rotation of the tickmarks. Defaults to no rotation (0 degrees).

.orient("bottom" | "top")

sets the placement of the axis. Defaults to bottom.

.colors(callback)

sets the d3 color scale the data series in the timeline. Defaults to d3.scale.category20().

.colorProperty(propertyName)

sets the data item property name that maps your data items to your color scale. For example if you set your chart's colors() and colorsProperty() as follows:

var colorScale = d3.scale.ordinal().range(['#6b0000','#ef9b0f','#ffee00'])
            .domain(['apple','orange','lemon']);

var chart = d3.timeline()
            .colors( colorScale )
            .colorProperty('fruit');

And pass this dataset:

var testData = [
  {label: "fruit 1", fruit: "orange", times: [
    {"starting_time": 1355759910000, "ending_time": 1355761900000}]},
  {label: "fruit 2", fruit: "apple", times: [
    {"starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000}]},
  {label: "fruit3", fruit: "lemon", times: [
    {"starting_time": 1355761910000, "ending_time": 1355763910000}]}
  ];

Your chart's bar colors will be determined based on the value of the fruit property:

Color Timeline

You can also set the color property for a specific time object:

var testData = [
  {label: "fruit 2", fruit: "apple", times: [
    {fruit: "orange", "starting_time": 1355752800000, "ending_time": 1355759900000},
    {"starting_time": 1355767900000, "ending_time": 1355774400000},
    {fruit: "lemon", "starting_time": 1355774400000, "ending_time": 1355775500000}]}
  ];

Properties set in the time object will override the property set for the series:

Timeline With Per-Time Colors

.beginning(date)

sets the time that the timeline should start. If beginning and ending are not set, the timeline will calculate it based off of the smallest and largest times.

.ending(date)

sets the time that the timeline should end. If beginning and ending are not set, the timeline will calculate it based off of the smallest and largest times.

.stack()

Takes in no arguments. Toggles the stacking/unstacking of data series in the timeline. Needs to be true in order for icons and labels to show up properly.

.relativeTime()

Takes in no arguments. Toggles the calculation and use of relative timestamps. The origin of the timeline will be set to 0 and the starting_time of the first data dictionary in the data array will be subtracted from every subsequent timestamp.

.showToday()

Takes in no arguments. Toggles a vertical line showing the current Date.now() time. Uses showTodayFormat for the line formatting.

.showTodayFormat({marginTop: , marginBottom: , width: , color: })

Sets the formatting of the showToday line. Color cycle can also be of the format rgb(x, y, z).

.showBorderLine()

Takes in no arguments. Toggles a vertical line showing the borders of one specific timeline. Uses showBorderFormat for the line formatting.

.showBorderFormat({marginTop: , marginBottom:, width: , color: })

Sets the formatting of the showBorder line. Color cycle can also be of the format rgb(x, y, z).

.showTimeAxis()

Takes in no arguments. Toggles the visibility of the time axis.

.showTimeAxisTick()

Takes in no arguments. Shows tick marks along the X axis according to the arguments for showTimeAxisTickFormat. Useful for datasets with a lot of stacked elements.

Timeline With tick marks

.showTimeAxisTickFormat(format)

Format for showTimeAxisTick. Defaults to {stroke: "stroke-dasharray", spacing: "4 10"}.

Defaults to

{
  marginTop: 25,
  marginBottom: 0,
  width: 1,
  color: colorCycle
}

.rowSeparators(color)

Sets the display of horizontal lines betweens rows.

.background(color)

Sets the background of the rows. Useful for creating a continuous effect when there are gaps in your data.

.hover(callback)

takes in a callback called on mousemove of the timeline data. Example

d3.timeline()
  .hover(function (d, i, datum) {
    // d is the current rendering object
    // i is the index during d3 rendering
    // datum is the data object
  });

.mouseover(callback)

takes in a callback called on mouseover of the timeline data. Example

d3.timeline()
  .mouseover(function (d, i, datum) {
    // d is the current rendering object
    // i is the index during d3 rendering
    // datum is the data object
  });

.mouseout(callback)

takes in a callback called on mouseout of the timeline data. Example

d3.timeline()
  .mouseout(function (d, i, datum) {
    // d is the current rendering object
    // i is the index during d3 rendering
    // datum is the data object
  });

.click(callback)

takes in a callback called on click of the timeline data. Example

d3.timeline()
  .click(function (d, i, datum) {
    // d is the current rendering object
    // i is the index during d3 rendering
    // datum is the data object
  });

.scroll(callback)

takes in a callback called on scroll of the timeline data. Example

d3.timeline()
  .scroll(function (x, scale) {
    // x is the current position of the scroll
    // scale is the scale of the axis used
  });

License

MIT

d3-timeline's People

Contributors

amit-git avatar asutosh97 avatar blinskey avatar charlesfracchia avatar colin-scott avatar coolov avatar danhunsaker avatar geordie avatar gilxa1226 avatar gurobokum avatar inodb avatar jiahuang avatar jkatsnelson avatar joscha avatar kgeis avatar luigima avatar refenkcs avatar shermanlai avatar sleepycat avatar steven-gomez avatar teian avatar wenzul avatar zeejab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3-timeline's Issues

d3.time.days not working

I want to show a series of points (circles) across several months. I can't get a scale going with days instead of hours. All your examples use hours. Please explain how to achieve ticks in the "23 Feb" format.

At the moment I have this:

    var chart = d3.timeline()
        .tickFormat({
            format: d3.time.format("%e %b"),
            tickTime: d3.time.days,
            tickInterval: 1,
            tickSize: 20
        })
      .display("circle");

But I only get a blank tick on the left and right of my axis with the following test data:

  var testData = [
    {times: [
        {"starting_time": 1431248400, "ending_time": 1431252000},
        {"starting_time": 1431338400, "ending_time": 1431342000},
        {"starting_time": 1431680400, "ending_time": 1431684000}
    ]},
    {times: [
        {"starting_time": 1432285200, "ending_time": 1432292400},
        {"starting_time": 1433156400, "ending_time": 1433160000},
        {"starting_time": 1433332800, "ending_time": 1433340000}
    ]},
    {times: [
        {"starting_time": 1430229600, "ending_time": 1430236800},
        {"starting_time": 1430305200, "ending_time": 1430312400},
        {"starting_time": 1431874800, "ending_time": 1431885600}
    ]}
  ];

Thanks

showing live data

How could one plot live data? Lets say I have a variable data that changes every second. It can have values 1 to 5 (should be plotted with different colors).

var data  =  {
  value: chance.integer( { min: 1, max: 5 } ),
  timestamp: new Date().getTime()
}

Text alignment

In the readme: https://github.com/jiahuang/d3-timeline/blob/master/examples/timeline4.png

"person" is vertically aligned with the bar. This is pleasing! 👍

However, when I look at the example (https://github.com/jiahuang/d3-timeline/blob/master/examples/example.html) it is not well aligned at all. "person" is shifted down several pixels. (See screenshot.)

I literally downloaded the example, so I'm not sure what I could have done wrong:

  • clone the repro to /tmp
  • Open file:///tmp/d3-timeline/examples/example.html in Firefox on OSX

mozilla_firefox

How to show ticks only at the start and end of each block

Sample Timeline

The label At Loading and At Unloading are overlapping and the timeline is for 2-3 days. In order to show a wide timeline like that I would prefer start and end ticks and their corresponding time values only. How to hide those unnecessary ticks

Zoomable timeline

It would be great if one could zoom in on the timeline with the mousewheel (perhaps only along x axis) and move the timeline with dragging. Currently there are only examples of using the mousewheel for horizontal scrolling. Any suggestions on how one could implement this?

Show time/days since start on x axis instead of date

Currently the timeline shows the date on the x axis. In certain situations it would be more useful to show number of days/time since the first event. Do you have any tips on how to add this to d3-timeline?

vertical scrolling

Vertical scrolling should work like horizontal scrolling. Maybe also have the axis be hoverable?

The tick labels isn't displayed

I try to run next code:

var timeData = JSON.parse('[{"label":"200","times":[{"starting_time":1438934855,"ending_time":1438936712,"color":"rgb(81, 163, 81)"}]},{"label":"0","times":[{"starting_time":1438935515,"ending_time":1438936724,"color":"rgb(189, 54, 47)"}]}]');

var chart = d3.timeline();

var svg = d3.select("#timeline1").append("svg").attr("width", window.innerWidth - 600)
                .datum(timeData).call(chart);

But I don't see the tick labels
What I'm doing wrong?

Errors when all times are coincident

If it transpires that all of your data points are coincident then beginning will equal ending and https://github.com/jiahuang/d3-timeline/blob/master/src/d3-timeline.js#L223 will become undefined causing errors like:

Error: <circle> attribute cx: Expected length, "NaN".

It's trivial to add a default window in such cases, although the choice of sensible width is not obvious.

// (after line 220)
//
// If all the times are the same, force the timeline to cover
// 12 hours on either side.
//
if (beginning === ending) {
  beginning -= (12 * 60 * 60 * 1000);
  ending += (12 * 60 * 60 * 1000);
}

Regression testing

I assume most regression testing is currently done by looking at example.html and seeing if any of the examples break. Maybe we can add a screenshot of example.html in the repo to be able to see on GitHub how the commits change the example page, similar to: cBioPortal/clinical-timeline@05e9245. That screenshot has been generated with PhantomJS. A screenshot per example would be better, but it's a start. I'm not very familiar with JS testing so let me know what you think.

how can i added times row at label

I want to added times(multi row) at label.
how can i added times?

like below

person a weebee1 weebee2
<>>>>>> weebee3
<>>>>>>>>>>>> weebee4

person b

<>>>> is just cheat..
maybe this board remove the blank..

Timezone support?

I'm struggling trying to add timezone support for my little project, but I can't yet figure out how to show the data (which is in UTC) to UTC. Instead of that, I get the translated time (UTC-3) in my case. I'm missing something?

Use both rectangels and circles

I think it would be great to allow one to make a timeline with both rectangles and circles. That way events without a stop date could be displayed as a circle, whereas events with start and stop date could be a rectangle. Is this possible in the current implementation?

Get element id inside hover function

I would like to display a tooltip on each time point using qTip. I believe I need to get the id of each element inside the hover function to call qtip on it. Problem is that I can't seem to reconstruct the name of the element using d,i and datum. The element id should be in the form of timelineItem_j_i, but I don't know what the recommended way is to get the j variable (Im using a stacked timeline). I could set the class attribute in the data, but I'd prefer to keep the styling logic out.

Using relativeTime() together with ending() causes hang

I'm not sure what's causing it, but trying to specify a end date/time while using relativeTime() will cause it (and the browser) to hang.

Minimized test case as follows, by modifying the example html:

var data = [
{times: [{starting_time: 1466100000000, ending_time: 1466100000000}]},
];

var width = 600;
var chart = d3.timeline()
             .ending(1466100000000)
             .relativeTime();

var svg = d3.select("#timeline1").append("svg").attr("width", width)
            .datum(data).call(chart);

Prevent label overlap

When horizontal scrolling is enabled, how do I prevent the label from being overlapped by the data?

Duplicate IDs

If a time series contains more than one item, the plugin will produce rect elements with duplicate IDs. This can be seen in several of the timelines in the example timeline, such as timeline5. This is invalid HTML and also prevents us from using callbacks like mouseover and hover to uniquely identify a segment of the timeline.

I've implemented a simple fix for this in my fork of the project, but it will break any existing code that relies on the duplicate IDs to highlight an entire timeline. I'd imagine it would probably be best to use a class rather than IDs to provide that functionality.

I'd be happy to help if you're interested in fixing this, though I don't know how you'd want to approach the issue of maintaining compatibility with old code. Thanks for the great plugin!

Migration to date

Thanks for your timeline, which is working good. Can I able to use this for Dateline purpose like below
screen shot 2018-03-08 at 1 07 08 pm
If it possible then kindly tell me the steps

height=0 for timelines rendered behind a tab

If I render a timeline behind a Bootstrap tab that is not visible, the timeline is created with an attribute of height="0".

For example, consider a page with two tabs named A and B. B will contain the timeline and is asynchronously loaded. That is, when the page is loaded, A is visible by default and users can click B to see the timeline. If the user clicks B before the data is loaded, they see a "loading" message.

The bug is: If the timeline renders before the user clicks B, the svg will have a height of 0 (it is not visible).

Note that if the user clicks B while the timeline is loading, things work as expected.

I think that the height calculation is somehow dependent on whether the timeline is visible or not. I've worked around the issue by setting the height explicitly.

Label don't appear with bower install

Example.html labels don't appear when d3-timeline is installed with bower. But works when I replace code from src/d3-timeline.js

FYI bower installed 0.0.5 version

spelling of .rowSeperators(color)

The word "sepArators" is spelled with an a, not an e as in "sepErators". If changing the name of the function isn't desirable due to breaking backwards compatibility, perhaps adding a wrapper function with the correct spelling could be useful?

How to change the timescale to seconds

Interesting library, kudos to the creators!

Looked through the code unfortunately could not figure out how to change the time scale. In particular i want to have seconds on X axis. Here is my data set I try to render:

{
  "times": [
    {
      "starting_time": 1458012262211,
      "ending_time": 1458012262720,
      "label": "[Follower]",
      "color": "green"
    },
    {
      "starting_time": 1458012262720,
      "ending_time": 1458012263121,
      "label": "[Candidate]",
      "color": "Purple"
    },
    {
      "starting_time": 1458012263121,
      "ending_time": 1458012263288,
      "label": "[Leader]",
      "color": "blue"
    }
  ],
  "label": "10.10.10.1,3000"
}

Any hint highly appreciated,
Cheers!

Scroll to the end

Hi. You work is great that is saved me lots of work. Is there a way to programmatically move the timeline to the right if it is scrollable?

Thank you!

Labels moved

With the latest released version (0.0.5) the graph's labels are not shown. After downloading the newest changes those labels do appear, but they are moved a few pixels to the bottom, whereas the previous version (0.0.4) did work correctly.
Is there something I need to consider using the newest version or should still work the same?

orient("top") causes an the axis labels to overlap

On one of the examples, if you change add the .orient("top") to the chart as such

 function timelineLabelColor() {
        var chart = d3.timeline()
          .beginning(1355752800000) // we can optionally add beginning and ending times to speed up rendering a little
          .ending(1355774400000)
          .stack() // toggles graph stacking
          .orient("top") // AS SUCH
          .margin({left:70, right:30, top:0, bottom:0})
          ;
        var svg = d3.select("#timeline6").append("svg").attr("width", width)
          .datum(labelColorTestData).call(chart);
      }

You end up with axis labels overlapping the chart content
image

README.md - Headings Formatting

Hi. I know this isn't a real issue, but it seems like your headings are not set properly in the Docs on GitHub. Perhaps if you add a space after the # in each heading, that would resolve it... unless your formatting is intentional, of course.

What time format is the examples in?

In the README.md what format is the starting_time and ending_time in?

If I have a dates like (Jun 1 2014, July 1 2014, Aug 1 2014), how do I put those on this time series?

Stack times?

Firstly thanks for this library, I've been enjoying using it on an internal project.

I was wondering if there is a way to stack the times as well as the timeline items so that you can see overlapping data?

Version Bump?

Can you please create a new tag + version bump in the bower.json + package.json?
It's not so nice to have the lib included with git url + branch :(

Thanks in advance

Label alignment

The labels don't appear to move with a change to the top margin.

Not familiar with pulling/amending/adding code here, so here's a suggestion to keep the label aligned with the bar.

I have amended the "var rowsDown" line.

var appendLabel = function (gParent, yAxisMapping, index, hasLabel, datum) {
  var fullItemHeight    = itemHeight + itemMargin;
  var rowsDown          =  margin.top + (fullItemHeight/2) + fullItemHeight * (yAxisMapping[index] || 1);

  gParent.append("text")
    .attr("class", "timeline-label")
    .attr("transform", "translate(" + labelMargin + "," + rowsDown + ")")
    .text(hasLabel ? labelFunction(datum.label) : datum.id)
    .on("click", function (d, i) { click(d, index, datum); });
};

No labels on gant chart

Looks like the gant chart examples do not show labels on the left. This is shown in the PNG's but none of these examples show code that will product the picture

           var labelTestData = [ 
             {label: "person a", times: [{"starting_time": 1355752800000, "ending_time": 1355759900000}, {"starting_time": 1355767900000, "ending_time": 1355774400000}]}, 
             {label: "person b", times: [{"starting_time": 1355759910000, "ending_time": 1355761900000}, ]}, 
             {label: "person c", times: [{"starting_time": 1355761910000, "ending_time": 1355763910000}]}, 
            ];

Markdown issue

Change #d3-timeline A simple d3 timeline plugin.
to # d3-timeline A simple d3 timeline plugin.

Stay a blank space before your content. Then you can see the heading format on your README.md. Like the following,

d3-timeline A simple d3 timeline plugin.

Crop data when beginning and end are specified

I have a big dataset and want to show only some of my data. I'm using beginning() and end() for that.
But the data is visible outside the axis (in the margin). The data should be cropped by beginning() and end !
error timeline

x axis labels truncated at bottom

I am having a problem that my x axis labels are truncated. I can only see the top 5 pixels approximately. So the words are cut off, see screenshot.
image

I am using Chrome Version 41.0.2272.118 (64-bit)
Code snippets below. Adding CSS did not help.

<div class="biolog-timeline">
        <svg id="timeline" width="100%"></svg>
    </div>
.biolog-timeline {
    width: 1200px;
    margin-bottom: 100px;
}
#timeline {
    margin-bottom: 100px;
}
Template.timeline.rendered = function() {
    timelineChart = d3.timeline()
        .stack()
        .tickFormat({
            format: d3.time.format("%-m/%y"),
            tickTime: d3.time.months,
            tickInterval: 1,
            tickSize: 5
        })
        .itemHeight(15)
        .margin({left:100, top: 0, right: 0, bottom: 200})
        .orient("bottom")
        .width(1200);
};
Tracker.autorun(function () {
    var timelineDataObj = getTimelineData();
    //console.log("timeline Tracker.autorun: timelineChart?" + (! timelineChart) + "; timelineDataObj=" + JSON.stringify(timelineDataObj));
    if (!timelineChart) return;

    timelineChart.beginning(timelineDataObj.beginning);
    timelineChart.ending(timelineDataObj.ending);

    if (!timelineDataObj.data || !timelineDataObj.data.length) return;
    console.log("PLOTTING: " + JSON.stringify(timelineDataObj));
    var svg = d3.select("#timeline")
        .append("svg")
        .attr("width", "800")
        .datum(timelineDataObj.data)
        .call(timelineChart);
});

Here is my data

PLOTTING: {"data":[{"id":"edb6076fab7b392dfbb4a177","label":"Chest pain (started 4/13)","times":[{"starting_time":1423583272059,"ending_time":1429599600000}]},{"id":"653fac290920a5bebfb8141f","label":"Diabetes type 2 (started 3/15)","times":[{"starting_time":1427698800000,"ending_time":1430550000000}]},{"id":"c279492f8260d0d680457710","label":"Benign Essential hypertension (HTN) (started 3/15)","times":[{"starting_time":1427698800000,"ending_time":1430463600000}]},{"id":"849525affdbd3e916b6294f5","label":"Hypoglycemia (low blood sugar) (started 3/15)","times":[{"starting_time":1427785200000,"ending_time":1430550000000}]},{"id":"7fa3bc97eaec7dc90c089769","label":"History of heart attack (started 4/15)","times":[{"starting_time":1428811200000,"ending_time":1429070400000}]},{"id":"b8f02798aa6367eb7722eef4","label":"Dyspnea (shortness of breath) on exertion (started 3/15)","times":[{"starting_time":1425186000000,"ending_time":1428842762059}]}],"beginning":1423583272059,"ending":1430550000000}

Labels at the beginning

Is there a reason why labels are not showing at the beginning and end of the timeline but only in the middle?
Thank you!

screen shot 2016-07-08 at 14 54 37

rotateTicks rotates ticks and labels

adding rotateTicks when you have times with labels rotates the ticks and the labels.

here's a patch to just rotate ticks:

  if (rotateTicks) {
    g.selectAll(".tick text")
      .attr("transform", function(d) {
        return "rotate(" + rotateTicks + ")translate("
          + (this.getBBox().width / 2 + 10) + "," // TODO: change this 10
          + this.getBBox().height / 2 + ")";
      });
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.