<commit_before>var g_plotHandler = null;
var g_xData = null;
var g_yData = null;
var g_sequenceName = null;


// initialize the plotter view
function initPlotter() {
	if (g_plotHandler === null) {
		var canvas = document.getElementById('canvas');
		g_plotHandler = createPlotHandler(canvas);
	}
}


// close the plotter screen and go back to the diagram editor
function closePlotter() {
	showDiagramEditor();
}


// add a sequence to be displayed in the plotter screen
function addSequence(sequenceName) {
	g_sequenceName = sequenceName;
	
	// handle sequence history data received from server
	var handler = function(data) {
		var values = data.values;
		var timestamps = data.timestamps;
		
		// make sure all values are numeric (or null)
		// fix(faster): do on server
		var len = values.length;
		for (var i = 0; i < len; i++) {
			var val = values[i];
			if (val !== null) {
				values[i] = +val;  // convert to number
			}
		}
		
		// create plot using manyplot library
		g_xData = createDataColumn('timestamp', timestamps);
		g_xData.type = 'timestamp';
		g_yData = createDataColumn('value', values);
		g_yData.name = sequenceName;
		var dataPairs = [
			{
				'xData': g_xData,
				'yData': g_yData,
			}
		];
		g_plotHandler.plotter.setData(dataPairs);
		g_plotHandler.drawPlot(null, null);
		
	}
	
	// request sequence history data from server
	var url = '/api/v1/resources' + g_controller.path + '/' + sequenceName;
	var params = {
		count: 10000,
	}
	$.get(url, params, handler);
}


// delete all history for this sequence
function deleteSequenceData() {
	modalConfirm({
		title: 'Delete Sequence Data', 
		'prompt': 'Are you sure you want to <b>delete all data</b> for sequence <b>' + g_sequenceName + '</b>?', 
		yesFunc: function() {
			$.ajax({
				type: 'DELETE',
				url: '/api/v1/resources' + g_controller.path + '/' + g_sequenceName, 
				data: {
					'csrf_token': g_csrfToken, 
					'data_only': 1,
				}, 
				success: function() {
					closePlotter();  // fix(later): just remove/clear this sequence
				},
			});
		} 
	});
}<commit_msg>Using code from sequence.html<commit_after>var g_plotHandler = null;
var g_xData = null;
var g_yData = null;
var g_sequenceName = null;


// initialize the plotter view
function initPlotter() {
	if (g_plotHandler === null) {
		var canvas = document.getElementById('canvas');
		g_plotHandler = createPlotHandler(canvas);
	}
}


// close the plotter screen and go back to the diagram editor
function closePlotter() {
	showDiagramEditor();
}


// add a sequence to be displayed in the plotter screen
function addSequence(sequenceName) {
	g_sequenceName = sequenceName;

	// handle sequence history data received from server
	var handler = function(data) {
		var values = data.values;
		var timestamps = data.timestamps;

		// make sure all values are numeric (or null)
		// fix(faster): do on server
		var len = values.length;
		for (var i = 0; i < len; i++) {
			var val = values[i];
			if (val !== null) {
				values[i] = +val;  // convert to number
			}
		}

		// create plot using manyplot library
		g_xData = createDataColumn('timestamp', timestamps);
		g_xData.type = 'timestamp';
		g_yData = createDataColumn('value', values);
		g_yData.name = sequenceName;
		var dataPairs = [
			{
				'xData': g_xData,
				'yData': g_yData,
			}
		];
		g_plotHandler.plotter.setData(dataPairs);
		g_plotHandler.drawPlot(null, null);

	}

	var updateHandler = function(timestamp, params) {
		console.log('sequence: ' + params['name'] + ', value: ' + params['value']);
		var unixTimestamp = timestamp.unix();
		var value = params['value'];

		// update plot
		g_xData.data.push(unixTimestamp);
		g_yData.data.push(value);
		g_plotHandler.plotter.autoBounds();
		g_plotHandler.drawPlot(null, null);
	}

	// request sequence history data from server
	var url = '/api/v1/resources' + g_controller.path + '/' + sequenceName;
	var params = {
		count: 10000,
	}
	$.get(url, params, handler);
	addMessageHandler('sequence_update', updateHandler);

}


// delete all history for this sequence
function deleteSequenceData() {
	modalConfirm({
		title: 'Delete Sequence Data',
		'prompt': 'Are you sure you want to <b>delete all data</b> for sequence <b>' + g_sequenceName + '</b>?',
		yesFunc: function() {
			$.ajax({
				type: 'DELETE',
				url: '/api/v1/resources' + g_controller.path + '/' + g_sequenceName,
				data: {
					'csrf_token': g_csrfToken,
					'data_only': 1,
				},
				success: function() {
					closePlotter();  // fix(later): just remove/clear this sequence
				},
			});
		}
	});
}
{'fraction_non_alphanumeric': 0.13559322033898305, 'fraction_numerical': 0.003962139555359894, 'mean_word_length': 3.4945598417408505, 'pattern_counts': {'":': 0, '<': 13, '<?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': '1643933', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1497, 'n_words': 416}