<commit_before>var max_displayed_char_timeline = 64;
var eventTimeline;
var items_timeline;
var items_backup;
var use_local_timezone = true;
var mapping_text_to_id = new Map();
var user_manipulation = $('#event_timeline').data('user-manipulation');
var extended_text = $('#event_timeline').data('extended') == 1 ? "extended:1/" : "";
var container_timeline = document.getElementById('event_timeline');
var hardThreshold = 50;
var softThreshold = 30;
var timeline_disabled = false;
var default_editable = {
    add: false,         // add new items by double tapping
    updateTime: true,   // drag items horizontally
    remove: true
};
var relationship_type_mapping = {
   'followed-by': 'after',
   'preceding-by': 'before',
}
var options = {
    template: function (item, element, data) {
        switch(item.group) {
            case "attribute":
                return build_attr_template(item);

            case "object":
                return build_object_template(item);

            case "object_attribute":
                console.log('Error');
                break;

            default:
                break;
        }
    },
    moment: function(date) {
        if (use_local_timezone) {
            return vis.moment(date);
        } else {
            return vis.moment(date).utc();
        }
    },
    verticalScroll: true,
    zoomKey: 'altKey',
    maxHeight: 400,
    minHeight: 400,
    multiselect: true,
    editable: user_manipulation ? default_editable : false,
    tooltipOnItemUpdateTime: true,
    onRemove: function(item, callback) { // clear timestamps
        update_seen(item, 'first', null, false, undefined);
        update_seen(item, 'last', null, false, function() { reflect_change(true); });
        eventTimeline.setSelection([]);
        $('.timelineSelectionTooltip').remove()
    },
    onMove: function(item, callback) {
        var newStart = moment(item.start.toISOString());
        var newEnd = (item.end !== undefined && item.end !== null) ? moment(item.end.toISOString()) : null;
        var c1 = item.first_seen !== null ? !item.first_seen.isSame(newStart) : true;
        var c2 = item.last_seen !== null ? !item.last_seen.isSame(newEnd) && item.seen_enabled : true;
        if (c1) {
            if (item.first_seen === null) {
                if (!c2) {
                    update_seen(item, 'first', newStart, true, undefined);
                } else {
                    update_seen(item, 'first', newStart, false, function() { reflect_change(true); });
                }
            } else {
                update_seen(item, 'first', newStart, !c2, undefined);
            }
        }
        if (c2) {
            update_seen(item, 'last', newEnd, true, undefined);
        }
    }
};
var timeline_typeaheadDataSearch;
var timeline_typeaheadOption = {
    source: function (query, process) {
        if (timeline_typeaheadDataSearch === undefined) { // caching
            timeline_typeaheadDataSearch = Array.from(mapping_text_to_id.keys());
        }
        process(timeline_typeaheadDataSearch);
    },
    updater: function(value) {
        var id = mapping_text_to_id.get(value);
        eventTimeline.focus(id);
        $("#timeline-typeahead").blur();
    },
    autoSelect: true
}

function isDefined(element) {
    return element !== undefined && element !== null;
}

function generate_timeline_tooltip(itemID, target) {
    var item = items_timeline.get(itemID);
    if (
        item.first_seen === undefined
        || item.first_seen === null
        || item.first_seen_overwrite
    ) { // do not generate if first_seen not set
        return;
    }
    var closest = $(target.closest(".vis-selected.vis-editable"));
    var btn_type = item.last_seen !== null ? 'collapse-btn' : 'expand-btn';
    var fct_type = item.last_seen !== null ? 'collapseItem' : 'expandItem';
    var btn = $('<div class="timelineSelectionTooltip vis-expand-action '+btn_type+'" data-itemid="'+item.id+'"></div>')
    if (item.last_seen !== null) {
        btn.click(collapseItem);
    } else {
        btn.click(expandItem);
    }
    closest.append(btn);
}

/* UTIL */
function collapseItem() {
    var itemID = $(this).data('itemid');
    var item = items_timeline.get(itemID);
    update_seen(item, 'last', null, true, undefined);
}
function expandItem() {
    var itemID = $(this).data('itemid');
    var item = items_timeline.get(itemID);
    var newEnd = get_next_step(item.first_seen);
    update_seen(item, 'last', newEnd, true, undefined);
}

function get_next_step(mom) {
    var scale = eventTimeline.timeAxis.step.scale;
    var momAhead = mom.clone();
    momAhead.add(1, scale);
    return momAhead;
}

function build_attr_template(attr) {
    var span = $('<span data-itemID="'+attr.id+'">');
    if (!attr.seen_enabled) {
        span.addClass('timestamp-attr');<commit_msg>fix: [timeline] correctly adapt time scale when expanding items<commit_after>var max_displayed_char_timeline = 64;
var eventTimeline;
var items_timeline;
var items_backup;
var use_local_timezone = true;
var mapping_text_to_id = new Map();
var user_manipulation = $('#event_timeline').data('user-manipulation');
var extended_text = $('#event_timeline').data('extended') == 1 ? "extended:1/" : "";
var container_timeline = document.getElementById('event_timeline');
var hardThreshold = 50;
var softThreshold = 30;
var timeline_disabled = false;
var default_editable = {
    add: false,         // add new items by double tapping
    updateTime: true,   // drag items horizontally
    remove: true
};
var relationship_type_mapping = {
   'followed-by': 'after',
   'preceding-by': 'before',
}
var options = {
    template: function (item, element, data) {
        switch(item.group) {
            case "attribute":
                return build_attr_template(item);

            case "object":
                return build_object_template(item);

            case "object_attribute":
                console.log('Error');
                break;

            default:
                break;
        }
    },
    moment: function(date) {
        if (use_local_timezone) {
            return vis.moment(date);
        } else {
            return vis.moment(date).utc();
        }
    },
    verticalScroll: true,
    zoomKey: 'altKey',
    maxHeight: 400,
    minHeight: 400,
    multiselect: true,
    editable: user_manipulation ? default_editable : false,
    tooltipOnItemUpdateTime: true,
    onRemove: function(item, callback) { // clear timestamps
        update_seen(item, 'first', null, false, undefined);
        update_seen(item, 'last', null, false, function() { reflect_change(true); });
        eventTimeline.setSelection([]);
        $('.timelineSelectionTooltip').remove()
    },
    onMove: function(item, callback) {
        var newStart = moment(item.start.toISOString());
        var newEnd = (item.end !== undefined && item.end !== null) ? moment(item.end.toISOString()) : null;
        var c1 = item.first_seen !== null ? !item.first_seen.isSame(newStart) : true;
        var c2 = item.last_seen !== null ? !item.last_seen.isSame(newEnd) && item.seen_enabled : true;
        if (c1) {
            if (item.first_seen === null) {
                if (!c2) {
                    update_seen(item, 'first', newStart, true, undefined);
                } else {
                    update_seen(item, 'first', newStart, false, function() { reflect_change(true); });
                }
            } else {
                update_seen(item, 'first', newStart, !c2, undefined);
            }
        }
        if (c2) {
            update_seen(item, 'last', newEnd, true, undefined);
        }
    }
};
var timeline_typeaheadDataSearch;
var timeline_typeaheadOption = {
    source: function (query, process) {
        if (timeline_typeaheadDataSearch === undefined) { // caching
            timeline_typeaheadDataSearch = Array.from(mapping_text_to_id.keys());
        }
        process(timeline_typeaheadDataSearch);
    },
    updater: function(value) {
        var id = mapping_text_to_id.get(value);
        eventTimeline.focus(id);
        $("#timeline-typeahead").blur();
    },
    autoSelect: true
}

function isDefined(element) {
    return element !== undefined && element !== null;
}

function generate_timeline_tooltip(itemID, target) {
    var item = items_timeline.get(itemID);
    if (
        item.first_seen === undefined
        || item.first_seen === null
        || item.first_seen_overwrite
    ) { // do not generate if first_seen not set
        return;
    }
    var closest = $(target.closest(".vis-selected.vis-editable"));
    var btn_type = item.last_seen !== null ? 'collapse-btn' : 'expand-btn';
    var fct_type = item.last_seen !== null ? 'collapseItem' : 'expandItem';
    var btn = $('<div class="timelineSelectionTooltip vis-expand-action '+btn_type+'" data-itemid="'+item.id+'"></div>')
    if (item.last_seen !== null) {
        btn.click(collapseItem);
    } else {
        btn.click(expandItem);
    }
    closest.append(btn);
}

/* UTIL */
function collapseItem() {
    var itemID = $(this).data('itemid');
    var item = items_timeline.get(itemID);
    update_seen(item, 'last', null, true, undefined);
}
function expandItem() {
    var itemID = $(this).data('itemid');
    var item = items_timeline.get(itemID);
    var newEnd = get_next_step(item.first_seen);
    update_seen(item, 'last', newEnd, true, undefined);
}

function get_next_step(mom) {
    var scale = adapt_scale(eventTimeline.timeAxis.step.scale);
    var momAhead = mom.clone();
    momAhead.add(1, scale);
    return momAhead;
}

function adapt_scale(scale) {
    first_letter = scale.charAt(0);
    if (first_letter !== 'm' && first_letter !== 'w') {
        return first_letter;
    } else {
        switch (scale) {
            case 'millisecond':
                return 'ms';
            case 'minute':
                return 'm';
            case 'month':
                return 'M';
            case 'week':
                return 'w';
            case 'weekday':
                return 'd';
            default:
                return scale;
        }
    }
}

function build_attr_template(attr) {
    var span = $('<span data-itemID="'+attr.id+'">');
    if (!attr.seen_enabled) {
        span.addClass('timestamp-attr');
{'fraction_non_alphanumeric': 0.13677456984543598, 'fraction_numerical': 0.004180033051424128, 'mean_word_length': 2.5623268698060944, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5276767', 'n_tokens_mistral': 3170, 'n_tokens_neox': 3079, 'n_words': 672}