Code Monkey home page Code Monkey logo

timeline-arrows's Introduction

Timeline-arrow

Following the issue of vis almende/vis#1699, and thanks to the comments of @frboyer and @JimmyCheng, I have created a class to easily draw lines to connect items in the vis Timeline module.

CapturaTime

Install & initialize

1 - Download the package

npm install timeline-arrows

2 - Import the class Arrow from arrow.js in your project

3 - Create your timeline as usual (see vis-timeline docs).

For instance:

const myTimeline = new vis.Timeline(container, items, groups, options);

4 - Create your arrows as an array of objects. These objets must have, at least, the following properties:

  • id
  • id_item_1 (id of one timeline's items)
  • id_item_2 (id of the other timeline's items that you want to connect with)

And optionally:

  • title (insert a text and it will show a title if you hover the mouse in the arrow)

For instance:

var arrowsSpecs = [
    { id: 2, id_item_1: 1, id_item_2: 2 },
    { id: 5, id_item_1: 3, id_item_2: 5, title:'Hello!!!' },
    { id: 7, id_item_1: 6, id_item_2: 7 },
    { id: 10, id_item_1: 3, id_item_2: 8, title:'I am a title!!!' }
];

5 - Create your Arrow instance for your timeline and your arrows.

For instance:

const myArrows = new Arrow(myTimeline, arrowsSpecs);

That's it :)

Options

Options can be used to customize the arrows. Options are defined as a JSON object. All options are optional.

const options = {
    followRelationships: true,
    color: "#039E00",
    tooltipConfig: (el, title) => {
        // tooltip initialization
    },
};

const myArrows = new Arrow(myTimeline, arrowsSpecs, options);

followRelationships - defaults to false. If true, arrows can point backwards and will follow the relationships set in the data. If false, arrows will only follow the timeline direction (left to right).

color - defaults to "#9c0000". Sets the arrows color.

strokeWidth - defaults to 3 (px). Sets the arrows width in pixels.

tooltipConfig - if arrows have a title property, the default behavior will add a title attribute that shows on hover. However, you might not want to use the title attribute, but instead your own tooltip configuration. This method takes two arguments, el - the arrow - and title - the content of the title property set in the arrow data.

hideWhenItemsNotVisible - defaults to true. When you zoom the timeline and both items go out of the screen. You can set if the arrow is still visible. By default, the arrow hides, but you can change it setting this option to false.

Methods

I have created the following methods:

getArrow ( arrow id ) Returns the arrow whith this arrow_id.

For instance:

myArrow.getArrow(2);

getIdArrows () Returns the list of Id arrows

For instance:

myArrow.getIdArrows();

addArrow ( arrow object ) Inserts a new arrow.

For instance:

myArrow.addArrow({ id: 13, id_item_1: 15, id_item_2: 16 });

removeArrow ( arrow_Id ) Removes the arrows with this arrow_Id.

For instance:

myArrow.removeArrow( 10 );

removeItemArrows ( item_Id ) Removes the arrows connected with Items with this item_Id. Returns an array with the id's of the removed arrows.

For instance:

myArrow.removeItemArrows( 23 );

removeArrowsBetweenItems (itemId1, itemId2) Removes the arrows between item 1 and item 2.

For instance:

myArrow.removeArrowsBetweenItems( 3, 8);

Examples

You can see some working examples here:

https://javdome.github.io/timeline-arrows/index.html

timeline-arrows's People

Contributors

jan-dolejsi avatar javdome avatar paulinemss 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

Watchers

 avatar  avatar  avatar  avatar  avatar

timeline-arrows's Issues

License

Hello, this library is great! Are you open to adding a license file to the repository?

arrow ends are dependent on date/dom placement and isn't honouring the relationships

Hi

Doesn't seem like the arrows can point backwards - i.e. an item on the right (ahead in the timeline) can't point to an item behind it (before in the timeline), regardless of what is specified in the options.

eg:
var arrows_array = [ { id: 7, id_item_1: 1, id_item_2: 2, title:'works' }, { id: 1, id_item_1: 3, id_item_2: 2, title:'problem. 2 points to 3 instead of 3 pointing to 2' }, ];
Where 1 is before 2 which is before 3 on vis-timeline.

Hopefully, it's something I'm doing wrong? All the examples are showing a more typical waterfall approach where nothing points back in time.

Great lib btw. We're hoping to use it for a demo if this issue can be sorted.

Simon

When both items are not visible, the arrows are hidden

Demo video:
https://screenapp.io/app/#/shared/530b09db-03ff-4338-a2e8-4df988efcdb0
The arrow between "Item 3" and "Item 5" disappears, once both items are out of the visible area. Is there a way to overcome this problem and make it easier to follow the arrow lines in case of distant items (both horizontally and vertically)?

In the original issue, there are 2 comments where the example makes it possible:
almende/vis#1699 (comment)
and
almende/vis#1699 (comment)

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.