<commit_before>scratchpad.modules.define("charts", {
	strings: {
		edit: "Edit",
		create: "Add",
	},
	editExisting: false,
	html: '\
		<div noprint class="dialog chart-dialog large-dialog" hidden>\
		<span class="dialog-title"><span class="action"></span> Chart</span>\
		<div class="dialog-content">\
			<div class="chart-type-chooser">\
			<div class="item"> <div class="radio"> <input autoselect="" id="pie" name="charts" checked="" type="radio"> <label for="pie"></label> </div> Pie </div>\
			<div class="item"><div class="radio"> <input id="doughnut" name="charts" type="radio"> <label for="doughnut"></label> </div> Doughnut</div>\
			<div class="item"><div class="radio"> <input id="line" name="charts" type="radio"> <label for="line"></label> </div> Line</div>\
			<div class="item"><div class="radio"> <input id="stacked-area" name="charts" type="radio"> <label for="stacked-area"></label> </div> Stacked Area</div>\
			<div class="item"><div class="radio"> <input id="column-bar" name="charts" type="radio"> <label for="column-bar"></label> </div> Bar</div>\
			<div class="item"><div class="radio"> <input id="scatter" name="charts" type="radio"> <label for="scatter"></label> </div> Scatter</div>\
			<div class="item"><div class="radio"> <input id="bubble" name="charts" type="radio"> <label for="bubble"></label> </div> Bubble</div>\
			<div class="item"><div class="radio"> <input id="table" name="charts" type="radio"> <label for="table"></label> </div> Table</div>\
			</div>\
\
 <ul class="tabs chart-tabs"> \
	 <li ripple class="selected" id="chart-edit">edit</a></li> \
	 <li ripple id="chart-preview">preview</li> \
		</ul>\
<div class="table-editor">\
<table class="table">\
<thead class="table-head-region">\
<tr>\
<th contenteditable="true" spellcheck="false"></th>\
<th contenteditable="" spellcheck="false"></th>\
</tr>\
</thead>\
<tbody><tr>\
<td contenteditable="true" spellcheck="false"></td>\
<td contenteditable="" spellcheck="false"></td></tr></tbody>\
</table>\
<div class="add-button add-column">+</div>\
<div class="add-button add-row">+</div>\
		</div>\
	<iframe sandbox="allow-scripts" class="chart-preview-field"></iframe>\
		</div>\
		<div class="dialog-footer">\
			<span class="float-right">\
				<button id="charts-cancel-button" class="button dialog-cancel color-accent-color">Cancel</button>\
				<button id="charts-okay-button" class="button dialog-confirm color-accent-color"><span class="action"></span> Chart</button>\
			</span>\
		</div>\
	</div>\
	',
	getFMScriptSource: function (type) {
		switch (type) {
		case "pie":
			return '<link rel="stylesheet" href="https://factmint.io/pie.css"/><script src="https://factmint.io/pie.js"></script>';
			break;
		case "doughnut":
			return '<link rel="stylesheet" href="https://factmint.io/doughnut.css"/><script src="https://factmint.io/doughnut.js"></script>';
			break;
		case "line":
			return '<link rel="stylesheet" href="https://factmint.io/line.css"/><script src="https://factmint.io/line.js"></script>';
			break;
		case "column-bar":
			return '<link rel="stylesheet" href="https://factmint.io/column-bar.css"><script src="https://factmint.io/column-bar.js"></script>';
			break;
		case "scatter":
			return '<link rel="stylesheet" href="https://factmint.io/scatter.css"><script src="https://factmint.io/scatter.js"></script>';
			break;
		case "bubble":
			return '<link rel="stylesheet" href="https://factmint.io/bubble.css"><script src="https://factmint.io/bubble.js"></script>';
			break;
		case "stacked-area":
			return '<link rel="stylesheet" href="https://factmint.io/stacked-area.css"><script src="https://factmint.io/stacked-area.js"></script>';
			break;
		case "table":
			return '<style>table {font-family:sans-serif;}th,td {padding:0.66em}</style><link rel="stylesheet" href="https://factmint.io/fallback-table.css">';
			break;
		}
	},
	renderChart: function (tabledata, type, el) {
		var chartdata = "<table class='fm-" + type + "'>" + tabledata + "</table>";
		var scripts = this.getFMScriptSource(type);
		el.attr("sandbox", "allow-scripts");
		el.attr("srcdoc", chartdata + scripts);
		el.removeClass("chartplaceholder").addClass("extend-block").addClass("chart-extend-block").attr("data-table", tabledata);
	},
	editTable: function (el) {
		var table = el;
		var columns = table.rows[0].cells.length;
		$(".table td").attr("contenteditable", "true");
		$(".add-row").click(function () {
			var rowtemplate = "<td contenteditable spellcheck='false'></td>"
			var rowinnerhtml = ""
			for (var i = 0; i < columns; i++) {
				rowinnerhtml += rowtemplate
			}
			$(".table").append("<tr>" + rowinnerhtml + "</tr>");
		});

		$(".add-column").click(function () {
			var template = "<td contenteditable  spellcheck='false'></td>"
			var htemplate = "<th contenteditable  spellcheck='false'></th>"
			$(".table tbody tr").append(template);
			$(".table thead tr").append(htemplate);
			columns++;
		});
	},
	ondialogopen: function () {
		if (!this.editExisting) { //if a new chart is being created, add a placeholder
			var input = "<iframe class='chartplaceholder'> </iframe>"; //add a placeholder to mark the cursor position
			scratchpad.caret.pasteHtmlAtCaret(input, false);
			$(".chart-dialog .action").html(this.strings.create); //switch the strings
		} else {
			$(".chart-dialog .action").html(this.strings.edit); //switch the strings
		}
	},
	ondialogcancel: function () {
		if (!this.editExisting) { //if the chart is a new chart, delete it on dialog cancel<commit_msg>keyboard navigation in the table editor<commit_after>scratchpad.modules.define("charts", {
	strings: {
		edit: "Edit",
		create: "Add",
	},
	editExisting: false,
	html: '\
		<div noprint class="dialog chart-dialog large-dialog" hidden>\
		<span class="dialog-title"><span class="action"></span> Chart</span>\
		<div class="dialog-content">\
			<div class="chart-type-chooser">\
			<div class="item"> <div class="radio"> <input autoselect="" id="pie" name="charts" checked="" type="radio"> <label for="pie"></label> </div> Pie </div>\
			<div class="item"><div class="radio"> <input id="doughnut" name="charts" type="radio"> <label for="doughnut"></label> </div> Doughnut</div>\
			<div class="item"><div class="radio"> <input id="line" name="charts" type="radio"> <label for="line"></label> </div> Line</div>\
			<div class="item"><div class="radio"> <input id="stacked-area" name="charts" type="radio"> <label for="stacked-area"></label> </div> Stacked Area</div>\
			<div class="item"><div class="radio"> <input id="column-bar" name="charts" type="radio"> <label for="column-bar"></label> </div> Bar</div>\
			<div class="item"><div class="radio"> <input id="scatter" name="charts" type="radio"> <label for="scatter"></label> </div> Scatter</div>\
			<div class="item"><div class="radio"> <input id="bubble" name="charts" type="radio"> <label for="bubble"></label> </div> Bubble</div>\
			<div class="item"><div class="radio"> <input id="table" name="charts" type="radio"> <label for="table"></label> </div> Table</div>\
			</div>\
\
 <ul class="tabs chart-tabs"> \
	 <li ripple class="selected" id="chart-edit">edit</a></li> \
	 <li ripple id="chart-preview">preview</li> \
		</ul>\
<div class="table-editor">\
<table class="table">\
<thead class="table-head-region">\
<tr>\
<th contenteditable="true" spellcheck="false"></th>\
<th contenteditable="" spellcheck="false"></th>\
</tr>\
</thead>\
<tbody><tr>\
<td contenteditable="true" spellcheck="false"></td>\
<td contenteditable="" spellcheck="false"></td></tr></tbody>\
</table>\
<div class="add-button add-column">+</div>\
<div class="add-button add-row">+</div>\
		</div>\
	<iframe sandbox="allow-scripts" class="chart-preview-field"></iframe>\
		</div>\
		<div class="dialog-footer">\
			<span class="float-right">\
				<button id="charts-cancel-button" class="button dialog-cancel color-accent-color">Cancel</button>\
				<button id="charts-okay-button" class="button dialog-confirm color-accent-color"><span class="action"></span> Chart</button>\
			</span>\
		</div>\
	</div>\
	',
	getFMScriptSource: function (type) {
		switch (type) {
		case "pie":
			return '<link rel="stylesheet" href="https://factmint.io/pie.css"/><script src="https://factmint.io/pie.js"></script>';
			break;
		case "doughnut":
			return '<link rel="stylesheet" href="https://factmint.io/doughnut.css"/><script src="https://factmint.io/doughnut.js"></script>';
			break;
		case "line":
			return '<link rel="stylesheet" href="https://factmint.io/line.css"/><script src="https://factmint.io/line.js"></script>';
			break;
		case "column-bar":
			return '<link rel="stylesheet" href="https://factmint.io/column-bar.css"><script src="https://factmint.io/column-bar.js"></script>';
			break;
		case "scatter":
			return '<link rel="stylesheet" href="https://factmint.io/scatter.css"><script src="https://factmint.io/scatter.js"></script>';
			break;
		case "bubble":
			return '<link rel="stylesheet" href="https://factmint.io/bubble.css"><script src="https://factmint.io/bubble.js"></script>';
			break;
		case "stacked-area":
			return '<link rel="stylesheet" href="https://factmint.io/stacked-area.css"><script src="https://factmint.io/stacked-area.js"></script>';
			break;
		case "table":
			return '<style>table {font-family:sans-serif;}th,td {padding:0.66em}</style><link rel="stylesheet" href="https://factmint.io/fallback-table.css">';
			break;
		}
	},
	renderChart: function (tabledata, type, el) {
		var chartdata = "<table class='fm-" + type + "'>" + tabledata + "</table>";
		var scripts = this.getFMScriptSource(type);
		el.attr("sandbox", "allow-scripts");
		el.attr("srcdoc", chartdata + scripts);
		el.removeClass("chartplaceholder").addClass("extend-block").addClass("chart-extend-block").attr("data-table", tabledata);
	},
	editTable: function (el) {
		var table = el;
		var columns = table.rows[0].cells.length;
		$(".table td").attr("contenteditable", "true");
		$(".add-row").click(function () {
			var rowtemplate = "<td contenteditable spellcheck='false'></td>"
			var rowinnerhtml = ""
			for (var i = 0; i < columns; i++) {
				rowinnerhtml += rowtemplate
			}
			$("<tr>").html(rowinnerhtml).appendTo(".table").get(0).focus();
		});

		$(".add-column").click(function () {
			var template = "<td contenteditable  spellcheck='false'></td>"
			var htemplate = "<th contenteditable  spellcheck='false'></th>"
			$(".table tbody tr").append(template);
			$(".table thead tr").append(htemplate);
			columns++;
			$(".table thead tr > th").last().get(0).focus(); //focus the heading for the new row we created
		});

		$(".table").on("keydown", "td", function (e) {
			var $this = $(this);
			if (e.keyCode == 9 && !$this.next()[0] && !$this.parent().next()[0]) { //if the tab key was pressed, and this is the last cell in the row, and this is the last row in the table, we should add a new row
				$(".add-row").trigger("click");
			}
		});
	},
	ondialogopen: function () {
		if (!this.editExisting) { //if a new chart is being created, add a placeholder
			var input = "<iframe class='chartplaceholder'> </iframe>"; //add a placeholder to mark the cursor position
			scratchpad.caret.pasteHtmlAtCaret(input, false);
			$(".chart-dialog .action").html(this.strings.create); //switch the strings
		} else {
			$(".chart-dialog .action").html(this.strings.edit); //switch the strings
		}
	},
	ondialogcancel: function () {
		if (!this.editExisting) { //if the chart is a new chart, delete it on dialog cancel
{'fraction_non_alphanumeric': 0.22329842931937172, 'fraction_numerical': 0.0013089005235602095, 'mean_word_length': 4.67095497278575, 'pattern_counts': {'":': 16, '<': 294, '<?xml version=': 0, '>': 293, 'https://': 30, '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': '4469250', 'n_tokens_mistral': 4109, 'n_tokens_neox': 3787, 'n_words': 816}