<commit_before>/* global cancelAnimationFrame, requestAnimationFrame */

"use strict";

import extend from 'extend';
import d3 from 'd3';

/**
 * @typedef {{xAxisHeight: number, yAxisWidth: number, rowHeight: number, rowPadding: number, axisConfigs: *[], container: string}} D3TimelineOptions
 */

/**
 *
 * @param {D3TimelineOptions} options
 * @constructor
 */
function D3Timeline(options) {

    D3Timeline.instancesCount += 1;

    this.instanceNumber = D3Timeline.instancesCount;

    var self = this;

    this.options = extend(true, {}, this.defaults, options);

    /** @type {Array<{id: Number, name: String, elements: Array<{ id: Number, start: Date, end: Date}>}>} */
    this.data = [];

    this.margin = {
        top: this.options.xAxisHeight,
        right: 50,
        bottom: 50,
        left: this.options.yAxisWidth
    };

    /** @type {Number} */
    this.yScale = 0.0;

    this.dimensions = { width: 0, height: 0 };

    this.container = null;

    this.elements = {
        body: null,
        innerContainer: null,
        xAxisContainer: null,
        x2AxisContainer: null,
        yAxisContainer: null,
        defs: null,
        clip: null
    };

    this.scales = {
        x: d3.time.scale(),
        y: d3.scale.linear()
    };

    this.axises = {

        x: d3.svg.axis()
            .scale(this.scales.x)
            .orient('top')
            .tickFormat(this.options.xAxisTicksFormatter)
            .outerTickSize(0)
            .tickPadding(20),

        x2: d3.svg.axis()
            .scale(this.scales.x)
            .orient('top')
            .tickFormat(this.options.xAxis2TicksFormatter)
            .outerTickSize(0)
            .innerTickSize(0),

        y: d3.svg.axis()
            .scale(this.scales.y)
            .orient('left')
            .tickFormat(function(d) {
                if (self._isRound(d)) {
                    return self._entryNameGetter(self.data[(d|0)]);
                } else {
                    return '';
                }
            })
            .outerTickSize(0)
    };

    this.behaviors = {
        zoom: d3.behavior.zoom()
            .scaleExtent([1, 10])
            .on('zoom', this.handleZooming.bind(this))
            .on('zoomend', this.handleZoomingEnd.bind(this)),
        zoomX: d3.behavior.zoom()
            .x(this.scales.x)
            .scale(1)
            .scaleExtent([1, 10]),
        zoomY: d3.behavior.zoom()
            .y(this.scales.y)
            .scale(1)
            .scaleExtent([1, 1]),
        pan: d3.behavior.drag()
            .on('drag', this.handleDragging.bind(this))
    };

    this._lastTranslate = this.behaviors.zoom.translate();
    this._lastScale = this.behaviors.zoom.scale();

    this._currentScaleConfig = null;
    this._dataChangeCount = 0;
    this._dimensionsChangeCount = 0;
    this._lastAvailableWidth = 0;
    this._lastAvailableHeight = 0;
    this._preventDrawing = false;
    this._nextAnimationFrameHandlers = [];
    this._currentElementsGroupTranslate = [0.0, 0.0];
}

/**
 * Default options
 *
 * @type {D3TimelineOptions}
 */
D3Timeline.prototype.defaults = {
    xAxisHeight: 50,
    yAxisWidth: 50,
    rowHeight: 30,
    rowPadding: 5,
    axisConfigs: [
        {
            threshold: 2,
            minutes: 30
        },
        {
            threshold: 4,
            minutes: 15
        },
        {
            threshold: 10,
            minutes: 5
        }
    ],
    container: 'body',
    cullingX: true,
    cullingY: true,
    cullingTolerance: 1,
    renderOnIdle: true,
    flattenRowElements: false, // @todo: make it dynamic
    hideTicksOnZoom: false,
    hideTicksOnDrag: false,
    panYOnWheel: true,
    wheelMultiplier: 1,
    xAxisTicksFormatter: function(d) {
        return d.getMinutes() % 15 ? '' : d3.time.format('%H:%M')(d);
    },
    xAxis2TicksFormatter: function(d) {
        return d.getMinutes() % 15 ? '' : '?/?';
    }
};

D3Timeline.instancesCount = 0;

D3Timeline.prototype.noop = function() {};

D3Timeline.prototype.initialize = function() {<commit_msg>change default formatter for xAxis2<commit_after>/* global cancelAnimationFrame, requestAnimationFrame */

"use strict";

import extend from 'extend';
import d3 from 'd3';

/**
 * @typedef {{xAxisHeight: number, yAxisWidth: number, rowHeight: number, rowPadding: number, axisConfigs: *[], container: string}} D3TimelineOptions
 */

/**
 *
 * @param {D3TimelineOptions} options
 * @constructor
 */
function D3Timeline(options) {

    D3Timeline.instancesCount += 1;

    this.instanceNumber = D3Timeline.instancesCount;

    var self = this;

    this.options = extend(true, {}, this.defaults, options);

    /** @type {Array<{id: Number, name: String, elements: Array<{ id: Number, start: Date, end: Date}>}>} */
    this.data = [];

    this.margin = {
        top: this.options.xAxisHeight,
        right: 50,
        bottom: 50,
        left: this.options.yAxisWidth
    };

    /** @type {Number} */
    this.yScale = 0.0;

    this.dimensions = { width: 0, height: 0 };

    this.container = null;

    this.elements = {
        body: null,
        innerContainer: null,
        xAxisContainer: null,
        x2AxisContainer: null,
        yAxisContainer: null,
        defs: null,
        clip: null
    };

    this.scales = {
        x: d3.time.scale(),
        y: d3.scale.linear()
    };

    this.axises = {

        x: d3.svg.axis()
            .scale(this.scales.x)
            .orient('top')
            .tickFormat(this.options.xAxisTicksFormatter)
            .outerTickSize(0)
            .tickPadding(20),

        x2: d3.svg.axis()
            .scale(this.scales.x)
            .orient('top')
            .tickFormat(this.options.xAxis2TicksFormatter)
            .outerTickSize(0)
            .innerTickSize(0),

        y: d3.svg.axis()
            .scale(this.scales.y)
            .orient('left')
            .tickFormat(function(d) {
                if (self._isRound(d)) {
                    return self._entryNameGetter(self.data[(d|0)]);
                } else {
                    return '';
                }
            })
            .outerTickSize(0)
    };

    this.behaviors = {
        zoom: d3.behavior.zoom()
            .scaleExtent([1, 10])
            .on('zoom', this.handleZooming.bind(this))
            .on('zoomend', this.handleZoomingEnd.bind(this)),
        zoomX: d3.behavior.zoom()
            .x(this.scales.x)
            .scale(1)
            .scaleExtent([1, 10]),
        zoomY: d3.behavior.zoom()
            .y(this.scales.y)
            .scale(1)
            .scaleExtent([1, 1]),
        pan: d3.behavior.drag()
            .on('drag', this.handleDragging.bind(this))
    };

    this._lastTranslate = this.behaviors.zoom.translate();
    this._lastScale = this.behaviors.zoom.scale();

    this._currentScaleConfig = null;
    this._dataChangeCount = 0;
    this._dimensionsChangeCount = 0;
    this._lastAvailableWidth = 0;
    this._lastAvailableHeight = 0;
    this._preventDrawing = false;
    this._nextAnimationFrameHandlers = [];
    this._currentElementsGroupTranslate = [0.0, 0.0];
}

/**
 * Default options
 *
 * @type {D3TimelineOptions}
 */
D3Timeline.prototype.defaults = {
    xAxisHeight: 50,
    yAxisWidth: 50,
    rowHeight: 30,
    rowPadding: 5,
    axisConfigs: [
        {
            threshold: 2,
            minutes: 30
        },
        {
            threshold: 4,
            minutes: 15
        },
        {
            threshold: 10,
            minutes: 5
        }
    ],
    container: 'body',
    cullingX: true,
    cullingY: true,
    cullingTolerance: 1,
    renderOnIdle: true,
    flattenRowElements: false, // @todo: make it dynamic
    hideTicksOnZoom: false,
    hideTicksOnDrag: false,
    panYOnWheel: true,
    wheelMultiplier: 1,
    xAxisTicksFormatter: function(d) {
        return d.getMinutes() % 15 ? '' : d3.time.format('%H:%M')(d);
    },
    xAxis2TicksFormatter: function(d) {
        return '';
    }
};

D3Timeline.instancesCount = 0;

D3Timeline.prototype.noop = function() {};

D3Timeline.prototype.initialize = function() {
{'fraction_non_alphanumeric': 0.13744134354161522, 'fraction_numerical': 0.020375401333662634, 'mean_word_length': 1.9376133478418571, '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': '5128965', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2566, 'n_words': 476}