<commit_before>/**
 *  This file is part of PerSE. PerSE is a visual analytics app for
 *  event periodicity detection and analysis.
 *  Copyright (C) 2015  <NAME>
 */

define([
    'jquery',
    'd3',
    'pertimeline/pertimelinedatasetbuilder',
    // no namespace
    '$.calendars',
    'bootstrap'
], function ($, d3, pertimelinedatasetbuilder) {

    var timeline = {};

    timeline.Timeline = function (calendarName, resolution) {
        this.calendarName = calendarName;
        this.resolution = resolution;
        this.contentAttribute = undefined;
        this.metadata = undefined;
        this.listeners = [];
        this.container = $('<div>').attr({'class': 'timeline'});
        this.svg = undefined;
        this.margin = {left: 30, right: 3, top: 10, bottom: 15};
        this.size = {
            width: 1125 - this.margin.right - this.margin.left,
            height: 70 - this.margin.top - this.margin.bottom
        };
        this.xScale = undefined;
        this.yScale = undefined;
        this.brush = undefined;

    };

    timeline.Timeline.prototype.render = function (parent) {
        $(parent).append(this.container);
        return this;
    };

    timeline.Timeline.prototype.build = function (data) {
        var that = this,
            extent = {
                x: this.getXExtent(),
                y: this.getYExtent(data)
            },
            brushMove,
            brushEnd,
            brushG;

        this.xScale = d3.scale.linear()
            .domain([extent.x.min, extent.x.max])
            .range([0, this.size.width]);


        this.yScale = d3.scale.linear()
            .domain([0, extent.y.max])
            .range([this.size.height, 0]);

        this.svg = d3.select(this.container.get(0))
            .append('svg')
            .attr('width', this.size.width + this.margin.left + this.margin.right)
            .attr('height', this.size.height + this.margin.top + this.margin.bottom)
            .append('g')
            .attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');

        this.dateScale = d3.scale.linear()
            .domain([0, this.size.width])
            .range([extent.x.min, extent.x.max]);

        this.svg
            .on('mousemove', function () {
                var cal = $.calendars.instance(that.calendarName),
                    myDate = cal.fromJD(that.dateScale(d3.mouse(that.svg.node())[0]));
                that.updateLabel([myDate.day(), cal.local.monthNames[myDate.month() - 1], myDate.year()].join(' '));
            })
            .on('mouseout', function () {
                that.updateLabel('');
            });

        this.updateResolution(data);

        brushMove = function () {
            var bExtent = that.brush.extent(),
                cal = $.calendars.instance(that.calendarName),
                bDate = cal.fromJD(bExtent[0]),
                eDate = cal.fromJD(bExtent[1]);

            that.updateLabel([
                [bDate.day(), cal.local.monthNamesShort[bDate.month() - 1], bDate.year()].join('-'),
                [eDate.day(), cal.local.monthNamesShort[eDate.month() - 1], eDate.year()].join('-')
            ].join(' to '));
        };

        brushEnd = function () {
            that.notifyListeners('onTimelineSelectionChanged', {context: that});
        };

        this.brush = d3.svg.brush()
            .x(this.xScale)
            .on('brush', brushMove)
            .on('brushend', brushEnd);

        brushG = this.svg.insert('g', '.timeline-bars')
            .attr('class', 'brush')
            .call(this.brush);

        brushG.selectAll("rect")
            .attr("height", this.size.height);

        this.svg.append('text')
            .attr('id', 'timeline-label');

    };

    timeline.Timeline.prototype.updateResolution = function (data) {
        var that = this,
            extent = {
                x: this.getXExtent(),
                y: this.getYExtent(data)
            },
            barsG;

        this.yScale = d3.scale.linear()
            .domain([0, extent.y.max])
            .range([this.size.height, 0]);

        this.svg.selectAll('g.timeline-bars').remove();

        barsG = this.svg.selectAll('g.timeline-bars')
            .data(data);
<commit_msg>cleaned linter errors<commit_after>/**
 *  This file is part of PerSE. PerSE is a visual analytics app for
 *  event periodicity detection and analysis.
 *  Copyright (C) 2015  <NAME>
 */

define([
    'jquery',
    'd3',
    'pertimeline/pertimelinedatasetbuilder',
    // no namespace
    '$.calendars',
    'bootstrap'
], function ($, d3, pertimelinedatasetbuilder) {

    var timeline = {};

    timeline.Timeline = function (calendarName, resolution) {
        this.calendarName = calendarName;
        this.resolution = resolution;
        this.contentAttribute = undefined;
        this.metadata = undefined;
        this.listeners = [];
        this.container = $('<div>').attr({'class': 'timeline'});
        this.svg = undefined;
        this.margin = {left: 30, right: 3, top: 10, bottom: 15};
        this.size = {
            width: 1125 - this.margin.right - this.margin.left,
            height: 70 - this.margin.top - this.margin.bottom
        };
        this.xScale = undefined;
        this.yScale = undefined;
        this.brush = undefined;

    };

    timeline.Timeline.prototype.render = function (parent) {
        $(parent).append(this.container);
        return this;
    };

    timeline.Timeline.prototype.build = function (data) {
        var that = this,
            extent = {
                x: this.getXExtent(),
                y: this.getYExtent(data)
            },
            brushMove,
            brushEnd,
            brushG;

        this.xScale = d3.scale.linear()
            .domain([extent.x.min, extent.x.max])
            .range([0, this.size.width]);


        this.yScale = d3.scale.linear()
            .domain([0, extent.y.max])
            .range([this.size.height, 0]);

        this.svg = d3.select(this.container.get(0))
            .append('svg')
            .attr('width', this.size.width + this.margin.left + this.margin.right)
            .attr('height', this.size.height + this.margin.top + this.margin.bottom)
            .append('g')
            .attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');

        this.dateScale = d3.scale.linear()
            .domain([0, this.size.width])
            .range([extent.x.min, extent.x.max]);

        this.svg
            .on('mousemove', function () {
                var cal = $.calendars.instance(that.calendarName),
                    myDate = cal.fromJD(that.dateScale(d3.mouse(that.svg.node())[0]));
                that.updateLabel([myDate.day(), cal.local.monthNames[myDate.month() - 1], myDate.year()].join(' '));
            })
            .on('mouseout', function () {
                that.updateLabel('');
            });

        this.updateResolution(data);

        brushMove = function () {
            var bExtent = that.brush.extent(),
                cal = $.calendars.instance(that.calendarName),
                bDate = cal.fromJD(bExtent[0]),
                eDate = cal.fromJD(bExtent[1]);

            that.updateLabel([
                [bDate.day(), cal.local.monthNamesShort[bDate.month() - 1], bDate.year()].join('-'),
                [eDate.day(), cal.local.monthNamesShort[eDate.month() - 1], eDate.year()].join('-')
            ].join(' to '));
        };

        brushEnd = function () {
            that.notifyListeners('onTimelineSelectionChanged', {context: that});
        };

        this.brush = d3.svg.brush()
            .x(this.xScale)
            .on('brush', brushMove)
            .on('brushend', brushEnd);

        brushG = this.svg.insert('g', '.timeline-bars')
            .attr('class', 'brush')
            .call(this.brush);

        brushG.selectAll('rect')
            .attr('height', this.size.height);

        this.svg.append('text')
            .attr('id', 'timeline-label');

    };

    timeline.Timeline.prototype.updateResolution = function (data) {
        var that = this,
            extent = {
                x: this.getXExtent(),
                y: this.getYExtent(data)
            },
            barsG;

        this.yScale = d3.scale.linear()
            .domain([0, extent.y.max])
            .range([this.size.height, 0]);

        this.svg.selectAll('g.timeline-bars').remove();

        barsG = this.svg.selectAll('g.timeline-bars')
            .data(data);

{'fraction_non_alphanumeric': 0.15729020159399906, 'fraction_numerical': 0.009142053445850914, 'mean_word_length': 1.7659643435980552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7462879', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2518, 'n_words': 434}