<commit_before>L.Control.Elevation = L.Control.extend({
	options: {
		position: "topright",
		theme: "lime-theme",
		width: 600,
		height: 175,
		margins: {
			top: 10,
			right: 20,
			bottom: 30,
			left: 50
		},
		useHeightIndicator: true,
		interpolation: "linear",
		hoverNumber: {
			decimalsX: 3,
			decimalsY: 0,
			formatter: undefined
		},
		xTicks: undefined,
		yTicks: undefined,
		collapsed: false
	},

	onRemove: function(map) {
		this._container = null;
		this._data = null;
		this._dist = null;
	},

	onAdd: function(map) {
		this._map = map;

		var opts = this.options;
		var margin = opts.margins;
		opts.width = opts.width - margin.left - margin.right;
		opts.height = opts.height - margin.top - margin.bottom;
		opts.xTicks = opts.xTicks || Math.round(opts.width / 75);
		opts.yTicks = opts.yTicks || Math.round(opts.height / 30);
		opts.hoverNumber.formatter = opts.hoverNumber.formatter || this._formatter;

		//append theme name on body
		d3.select("body").classed(opts.theme, true);

		var x = this._x = d3.scale.linear()
			.range([0, opts.width]);

		var y = this._y = d3.scale.linear()
			.range([opts.height, 0]);

		var area = this._area = d3.svg.area()
			.interpolate(opts.interpolation)
			.x(function(d) {
			return x(d.dist);
		})
			.y0(opts.height)
			.y1(function(d) {
			return y(d.altitude);
		});

		var container = this._container = L.DomUtil.create("div", "elevation");
		
		this._initToggle();

		var complWidth = opts.width + margin.left + margin.right;
		var cont = d3.select(container);
		cont.attr("width", complWidth);
		var svg = cont.append("svg");
		svg.attr("width", complWidth)
			.attr("class", "background")
			.attr("height", opts.height + margin.top + margin.bottom)
			.append("g")
			.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

		var line = d3.svg.line();
		line = line
			.x(function(d) {
			return d3.mouse(svg.select("g"))[0];
		})
			.y(function(d) {
			return opts.height;
		});

		var g = d3.select(this._container).select("svg").select("g");

		this._areapath = g.append("path")
			.attr("class", "area");

		var background = this._background = g.append("rect")
			.attr("width", opts.width)
			.attr("height", opts.height)
			.style("fill", "none")
			.style("stroke", "none")
			.style("pointer-events", "all");

		background.on("mousemove", this._mousemoveHandler.bind(this));
		background.on("mouseout", this._mouseoutHandler.bind(this));

		this._xaxisgraphicnode = g.append("g");
		this._yaxisgraphicnode = g.append("g");
		this._appendXaxis(this._xaxisgraphicnode);
		this._appendYaxis(this._yaxisgraphicnode);

		var focusG = this._focusG = g.append("g");
		this._mousefocus = focusG.append('svg:line')
			.attr('class', 'mouse-focus-line')
			.attr('x2', '0')
			.attr('y2', '0')
			.attr('x1', '0')
			.attr('y1', '0');
		this._focuslabelX = focusG.append("svg:text")
			.style("pointer-events", "none")
			.attr("class", "mouse-focus-label-x");
		this._focuslabelY = focusG.append("svg:text")
			.style("pointer-events", "none")
			.attr("class", "mouse-focus-label-y");

		return container;
	},

	_initToggle: function () {

		/* inspired by L.Control.Layers */

		var container = this._container;

		//Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
		container.setAttribute('aria-haspopup', true);

		if (!L.Browser.touch) {
			L.DomEvent
				.disableClickPropagation(container);
				//.disableScrollPropagation(container);
		} else {
			L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
		}

		if (this.options.collapsed)
		{
			this._collapse();

			if (!L.Browser.android) {
				L.DomEvent
					.on(container, 'mouseover', this._expand, this)
					.on(container, 'mouseout', this._collapse, this);
			}
			var link = this._button = L.DomUtil.create('a', 'elevation-toggle', container);
			link.href = '#';
			link.title = 'Elevation';

			if (L.Browser.touch) {
				L.DomEvent
					.on(link, 'click', L.DomEvent.stop)
					.on(link, 'click', this._expand, this);
			}
			else {
				L.DomEvent.on(link, 'focus', this._expand, this);
			}

			this._map.on('click', this._collapse, this);
			// TODO keyboard accessibility
		}
	},

	_expand: function () {
		this._container.className = this._container.className.replace(' elevation-collapsed', '');
	},

	_collapse: function () {
		L.DomUtil.addClass(this._container, 'elevation-collapsed');
	},

	/*
	 * Fromatting funciton using the given decimals and seperator
	 */
	_formatter: function(num, dec, sep) {
		var res;
		if (dec === 0) {
			res = Math.round(num) + "";
		} else {
			res = L.Util.formatNum(num, dec) + "";
		}
		var numbers = res.split(".");
		if (numbers[1]) {
			var d = dec - numbers[1].length;
			for (; d > 0; d--) {
				numbers[1] += "0";
			}
			res = numbers.join(sep || ".");
		}
		return res;
	},

	_appendYaxis: function(y) {
		y.attr("class", "y axis")
			.call(d3.svg.axis()
			.scale(this._y)
			.ticks(this.options.yTicks)
			.orient("left"))
			.append("text")
			.attr("x", 15)
			.style("text-anchor", "end")
			.text("m");
	},

	_appendXaxis: function(x) {
		x.attr("class", "x axis")
			.attr("transform", "translate(0," + this.options.height + ")")
			.call(d3.svg.axis()
			.scale(this._x)
			.ticks(this.options.xTicks)
			.orient("bottom"))
			.append("text")
			.attr("x", this.options.width + 15)
			.style("text-anchor", "end")
			.text("km");
	},

	_updateAxis: function() {
		this._xaxisgraphicnode.selectAll("axis").remove();
		this._yaxisgraphicnode.selectAll("axis").remove();<commit_msg>fix duplicate labels<commit_after>L.Control.Elevation = L.Control.extend({
	options: {
		position: "topright",
		theme: "lime-theme",
		width: 600,
		height: 175,
		margins: {
			top: 10,
			right: 20,
			bottom: 30,
			left: 50
		},
		useHeightIndicator: true,
		interpolation: "linear",
		hoverNumber: {
			decimalsX: 3,
			decimalsY: 0,
			formatter: undefined
		},
		xTicks: undefined,
		yTicks: undefined,
		collapsed: false
	},

	onRemove: function(map) {
		this._container = null;
		this._data = null;
		this._dist = null;
	},

	onAdd: function(map) {
		this._map = map;

		var opts = this.options;
		var margin = opts.margins;
		opts.width = opts.width - margin.left - margin.right;
		opts.height = opts.height - margin.top - margin.bottom;
		opts.xTicks = opts.xTicks || Math.round(opts.width / 75);
		opts.yTicks = opts.yTicks || Math.round(opts.height / 30);
		opts.hoverNumber.formatter = opts.hoverNumber.formatter || this._formatter;

		//append theme name on body
		d3.select("body").classed(opts.theme, true);

		var x = this._x = d3.scale.linear()
			.range([0, opts.width]);

		var y = this._y = d3.scale.linear()
			.range([opts.height, 0]);

		var area = this._area = d3.svg.area()
			.interpolate(opts.interpolation)
			.x(function(d) {
			return x(d.dist);
		})
			.y0(opts.height)
			.y1(function(d) {
			return y(d.altitude);
		});

		var container = this._container = L.DomUtil.create("div", "elevation");
		
		this._initToggle();

		var complWidth = opts.width + margin.left + margin.right;
		var cont = d3.select(container);
		cont.attr("width", complWidth);
		var svg = cont.append("svg");
		svg.attr("width", complWidth)
			.attr("class", "background")
			.attr("height", opts.height + margin.top + margin.bottom)
			.append("g")
			.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

		var line = d3.svg.line();
		line = line
			.x(function(d) {
			return d3.mouse(svg.select("g"))[0];
		})
			.y(function(d) {
			return opts.height;
		});

		var g = d3.select(this._container).select("svg").select("g");

		this._areapath = g.append("path")
			.attr("class", "area");

		var background = this._background = g.append("rect")
			.attr("width", opts.width)
			.attr("height", opts.height)
			.style("fill", "none")
			.style("stroke", "none")
			.style("pointer-events", "all");

		background.on("mousemove", this._mousemoveHandler.bind(this));
		background.on("mouseout", this._mouseoutHandler.bind(this));

		this._xaxisgraphicnode = g.append("g");
		this._yaxisgraphicnode = g.append("g");
		this._appendXaxis(this._xaxisgraphicnode);
		this._appendYaxis(this._yaxisgraphicnode);

		var focusG = this._focusG = g.append("g");
		this._mousefocus = focusG.append('svg:line')
			.attr('class', 'mouse-focus-line')
			.attr('x2', '0')
			.attr('y2', '0')
			.attr('x1', '0')
			.attr('y1', '0');
		this._focuslabelX = focusG.append("svg:text")
			.style("pointer-events", "none")
			.attr("class", "mouse-focus-label-x");
		this._focuslabelY = focusG.append("svg:text")
			.style("pointer-events", "none")
			.attr("class", "mouse-focus-label-y");

		return container;
	},

	_initToggle: function () {

		/* inspired by L.Control.Layers */

		var container = this._container;

		//Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
		container.setAttribute('aria-haspopup', true);

		if (!L.Browser.touch) {
			L.DomEvent
				.disableClickPropagation(container);
				//.disableScrollPropagation(container);
		} else {
			L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
		}

		if (this.options.collapsed)
		{
			this._collapse();

			if (!L.Browser.android) {
				L.DomEvent
					.on(container, 'mouseover', this._expand, this)
					.on(container, 'mouseout', this._collapse, this);
			}
			var link = this._button = L.DomUtil.create('a', 'elevation-toggle', container);
			link.href = '#';
			link.title = 'Elevation';

			if (L.Browser.touch) {
				L.DomEvent
					.on(link, 'click', L.DomEvent.stop)
					.on(link, 'click', this._expand, this);
			}
			else {
				L.DomEvent.on(link, 'focus', this._expand, this);
			}

			this._map.on('click', this._collapse, this);
			// TODO keyboard accessibility
		}
	},

	_expand: function () {
		this._container.className = this._container.className.replace(' elevation-collapsed', '');
	},

	_collapse: function () {
		L.DomUtil.addClass(this._container, 'elevation-collapsed');
	},

	/*
	 * Fromatting funciton using the given decimals and seperator
	 */
	_formatter: function(num, dec, sep) {
		var res;
		if (dec === 0) {
			res = Math.round(num) + "";
		} else {
			res = L.Util.formatNum(num, dec) + "";
		}
		var numbers = res.split(".");
		if (numbers[1]) {
			var d = dec - numbers[1].length;
			for (; d > 0; d--) {
				numbers[1] += "0";
			}
			res = numbers.join(sep || ".");
		}
		return res;
	},

	_appendYaxis: function(y) {
		y.attr("class", "y axis")
			.call(d3.svg.axis()
			.scale(this._y)
			.ticks(this.options.yTicks)
			.orient("left"))
			.append("text")
			.attr("x", 15)
			.style("text-anchor", "end")
			.text("m");
	},

	_appendXaxis: function(x) {
		x.attr("class", "x axis")
			.attr("transform", "translate(0," + this.options.height + ")")
			.call(d3.svg.axis()
			.scale(this._x)
			.ticks(this.options.xTicks)
			.orient("bottom"))
			.append("text")
			.attr("x", this.options.width + 15)
			.style("text-anchor", "end")
			.text("km");
	},

	_updateAxis: function() {
		this._xaxisgraphicnode.selectAll("g").remove();
		this._xaxisgraphicnode.selectAll("path").remove();
		this._xaxisgraphicnode.selectAll("text").remove();
		this._yaxisgraphicnode.selectAll("g").remove();
		this._yaxisgraphicnode.selectAll("path").remove();
		this._yaxisgraphicnode.selectAll("text").remove();
{'fraction_non_alphanumeric': 0.1892010922223201, 'fraction_numerical': 0.009865233858891922, 'mean_word_length': 3.4024815820085306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5154316', 'n_tokens_mistral': 4771, 'n_tokens_neox': 4090, 'n_words': 767}