<commit_before>#include "timeline.h"
#include <string>
#include <algorithm>
#include <iomanip>
#include <sstream>

Timeline::Timeline(wxFrame* parent, int lines, bool follow) : wxPanel(parent),
		lines(lines), follow(follow),
		backgroundColor("black"),
		headColor("dark grey"),
		majorTickColor("red"),
		minorTickColor("black"),
		cursorColor("green"),
		cursorBackColor("dark green"),
		textColor("grey"),
		markColor("white"),
		zoomratio(1.5), scrollpanratio(0.1), followratio(0.9),
		majorTicks(9), minorTicks(4),
		start(0.0), length(10.0),
		mousetick(0.0), dragtick(-1.0) {
	Bind(wxEVT_PAINT, &Timeline::onPaint, this);

	Bind(wxEVT_SIZE, &Timeline::onSize, this);

	Bind(wxEVT_MOTION, &Timeline::onMotion, this);
	Bind(wxEVT_MOUSEWHEEL, &Timeline::onWheel, this);
	Bind(wxEVT_LEFT_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_LEFT_UP, &Timeline::onClick, this);
	Bind(wxEVT_MIDDLE_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_MIDDLE_UP, &Timeline::onClick, this);
	Bind(wxEVT_RIGHT_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_RIGHT_UP, &Timeline::onClick, this);
}

void Timeline::insert(int line, Timeline::Mark mark) {
	marks.push_back(std::make_pair(mark, line));
	if (follow) {
		// (mark - start) / length = followratio
		start = mark - followratio * length;
	}
	Refresh();
}

void Timeline::clear() {
	marks.clear();
	Refresh();
}

void Timeline::followInsertions(bool f) {
	follow = f;
}

bool Timeline::getFollow() const {
	return follow;
}

size_t Timeline::size() const {
	return marks.size();
}

void Timeline::onMotion(wxMouseEvent& evt) {
	if (evt.Dragging()) {
		// extend painted area
		if (evt.LeftIsDown() || evt.RightIsDown()) {<commit_msg>gpgrid: timeline bugfix, make point list ordered<commit_after>#include "timeline.h"
#include <string>
#include <algorithm>
#include <iomanip>
#include <sstream>

Timeline::Timeline(wxFrame* parent, int lines, bool follow) : wxPanel(parent),
		lines(lines), follow(follow),
		backgroundColor("black"),
		headColor("dark grey"),
		majorTickColor("red"),
		minorTickColor("black"),
		cursorColor("green"),
		cursorBackColor("dark green"),
		textColor("grey"),
		markColor("white"),
		zoomratio(1.5), scrollpanratio(0.1), followratio(0.9),
		majorTicks(9), minorTicks(4),
		start(0.0), length(10.0),
		mousetick(0.0), dragtick(-1.0) {
	Bind(wxEVT_PAINT, &Timeline::onPaint, this);

	Bind(wxEVT_SIZE, &Timeline::onSize, this);

	Bind(wxEVT_MOTION, &Timeline::onMotion, this);
	Bind(wxEVT_MOUSEWHEEL, &Timeline::onWheel, this);
	Bind(wxEVT_LEFT_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_LEFT_UP, &Timeline::onClick, this);
	Bind(wxEVT_MIDDLE_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_MIDDLE_UP, &Timeline::onClick, this);
	Bind(wxEVT_RIGHT_DOWN, &Timeline::onClick, this);
	Bind(wxEVT_RIGHT_UP, &Timeline::onClick, this);
}

void Timeline::insert(int line, Timeline::Mark mark) {
	// assume that the user doesn't insert ordered points
	//marks.push_back(std::make_pair(mark, line));
	auto m = std::make_pair(mark, line);
	auto pos = std::upper_bound(marks.begin(), marks.end(), m);
	marks.insert(pos, m);
	if (follow) {
		// (mark - start) / length = followratio
		start = mark - followratio * length;
	}
	Refresh();
}

void Timeline::clear() {
	marks.clear();
	Refresh();
}

void Timeline::followInsertions(bool f) {
	follow = f;
}

bool Timeline::getFollow() const {
	return follow;
}

size_t Timeline::size() const {
	return marks.size();
}

void Timeline::onMotion(wxMouseEvent& evt) {
	if (evt.Dragging()) {
		// extend painted area
		if (evt.LeftIsDown() || evt.RightIsDown()) {
{'fraction_non_alphanumeric': 0.17304445694991558, 'fraction_numerical': 0.009566685424873381, 'mean_word_length': 6.167338709677419, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1753539', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1351, 'n_words': 257}