almende / chap-links-library

a web based visualization library for displaying graphs, networks, and timelines
http://almende.github.com/chap-links-library
Apache License 2.0
599 stars 167 forks source link

Start and group after double click #352

Closed meydey232 closed 9 years ago

meydey232 commented 9 years ago

Hey, I need to pass datas from one function to another. So I need and action when I double click on some free cluster to open my modal form with filled start date and group where I clicked. Any ideas how to get this datas? Currently I've got modal form which is opening with addlistener.

One more thing - I'm using JSON array which is loaded from asp.net class but after saving new event I can't refresh datas. I mean I don't have problem with taking this Json again but redraw() function is not working that how I expected.

josdejong commented 9 years ago

The Timeline of the successor of chap-links-library, vis.js, has eventlisteners like click and doubleClick which you can use.

About refreshing data: without a code example of what you're doing there isn't much I can say about that. When loading new data you have to apply it using Timeline.setData(), do you do that?

meydey232 commented 9 years ago

I have working action and modal form but I need to pass the datas from the clicked cluster - I mean if I have few groups and I click on 9 July in group "abcd" i need to pass the start date and name of group into this modal form. Ohh, thanks. I didn't check with setData() - maybe it will help, let you know.

josdejong commented 9 years ago

I mean if I have few groups and I click on 9 July in group "abcd" i need to pass the start date and name of group into this modal form.

There is no built-in way to get this information, you will have to hack something for this into the Timeline yourself. The event listeners of vis.js do provide this information, however, the Timeline of vis.js doesn't yet have support for clustering.

meydey232 commented 9 years ago

I did it this way: First we need this function:

function getSelectedRow() {
    var row = undefined;
    var sel = timeline.getSelection();
    if (sel.length) {
        if (sel[0].row != undefined) {
            row = sel[0].row;
        }
    }
    return row;
}

Now everything what we have to do is add a variable into our listener function (it's running on double click):

var onadd = function () {
        var test = timeline.getItem(getSelectedRow());
        $('#form').modal('show');
    };

links.events.addListener(timeline, 'add', onadd);
josdejong commented 9 years ago

What do you mean? Do you mean you solved it like this?

meydey232 commented 9 years ago

Yep, It is working fine. Variable test return an object like this: content: "New" group: "abcd" start: Date {Thu Jul 16 2015 22:21:52 GMT+0200} type: "box"

josdejong commented 9 years ago

Ah now I get what you mean. Ok great you solved it, I will close the issue then.