<commit_before>'use strict';


angular.module('emuwebApp')
	.directive('osci', function (viewState) {
		return {
			templateUrl: 'views/osci.html',
			replace: true,
			restrict: 'E',
			link: function postLink(scope, element, attrs) {


				// select the needed DOM elements from the template
				var canvasLength = element.find('canvas').length;
				var canvas = element.find('canvas')[0];
				var markupCanvas = element.find('canvas')[canvasLength - 1];
				scope.order = attrs.order;

				scope.enlargeCanvas = {
					'height': 100 / scope.cps.vals.perspectives[viewState.curPerspectiveIdx].signalCanvases.order.length + '%'
				};

				///////////////
				// watches

				scope.$watch('vs.curPerspectiveIdx', function () {
					scope.updateCSS();
				}, true);

				scope.$watch('vs.playHeadAnimationInfos', function () {
					if (!$.isEmptyObject(scope.shs)) {
						if (!$.isEmptyObject(scope.shs.wavJSO)) {
							drawPlayHead(scope, scope.cps);
						}
					}
				}, true);

				// scope.$watch('tds.data', function () {
				// 	if (!$.isEmptyObject(scope.shs)) {
				// 		if (!$.isEmptyObject(scope.shs.wavJSO)) {
				// 			console.log(scope.tds.data)
				// 			drawVpOsciMarkup(scope, scope.cps, true);
				// 		}
				// 	}
				// }, true);

				scope.$watch('vs.movingBoundary', function () {
					if (!$.isEmptyObject(scope.shs)) {
						if (!$.isEmptyObject(scope.shs.wavJSO)) {
							drawVpOsciMarkup(scope, scope.cps, true);
						}
					}
				}, true);

				scope.$watch('vs.curViewPort', function (newValue, oldValue) {
					if (!$.isEmptyObject(scope.shs)) {
						if (!$.isEmptyObject(scope.shs.wavJSO)) {
							// check for changed zoom
							if (oldValue.sS !== newValue.sS || oldValue.sE !== newValue.sE || newValue.selectS === -1) { // SIC -1 check not that clean...
								var allPeakVals = scope.dhs.calculatePeaks(scope.vs, canvas, scope.shs.wavJSO.Data);
								scope.dhs.osciPeaks = allPeakVals;
								scope.dhs.freshRedrawDrawOsciOnCanvas(scope.vs, canvas, scope.dhs.osciPeaks, scope.shs.wavJSO.Data, scope.cps);
							}
							drawVpOsciMarkup(scope, scope.cps, true);
							scope.updateCSS();
						}
					}
				}, true);
				
				//
				/////////////////////////

				/**
				 *
				 */
				scope.redraw = function () {
					drawVpOsciMarkup(scope, scope.cps, true);
					scope.updateCSS();
				};

				/**
				 *
				 */
				scope.updateCSS = function () {
					var parts = scope.cps.vals.perspectives[viewState.curPerspectiveIdx].signalCanvases.order.length;
					if (viewState.getenlarge() == -1) {
						scope.enlargeCanvas = {
							'height': 100 / parts + '%'
						};
					} else {
						if (viewState.getenlarge() == scope.order) {
							scope.enlargeCanvas = {
								'height': 3 * 100 / (parts + 2) + '%'
							};
						} else {
							scope.enlargeCanvas = {
								'height': 100 / (parts + 2) + '%'
							};
						}
					}
				};


				/**
				 *
				 */
				function drawPlayHead(scope, config) {
					var viewState = scope.vs;
					var ctx = markupCanvas.getContext('2d');
					ctx.clearRect(0, 0, canvas.width, canvas.height);

					var posS = viewState.getPos(markupCanvas.width, viewState.playHeadAnimationInfos.sS);
					var posCur = viewState.getPos(markupCanvas.width, viewState.playHeadAnimationInfos.curS);
					// console.log(viewState.playHeadAnimationInfos.curS)

					ctx.fillStyle = scope.cps.vals.colors.selectedAreaColor;
					ctx.fillRect(posS, 0, posCur - posS, canvas.height);

					//console.log(posS,posCur);

					drawVpOsciMarkup(scope, config, false);

				}

				function getScaleW(ctx, str, scale) {
					return ctx.measureText(str).width * scale;
				}

				function getScaleH(ctx, str, scale) {
					return ctx.measureText(str).width * scale;
				}

				function getScaleWidth(ctx, str1, str2, scaleX) {
					if (str1.toString().length > str2.toString().length) {
						return getScaleW(ctx, str1, scaleX);
					} else {
						return getScaleW(ctx, str2, scaleX);
					}
				}

				/**
				 * draws markup of osci according to
				 * the information that is specified in
				 * the viewport
				 */

				function drawVpOsciMarkup(scope, config, reset) {

					var viewState = scope.vs;
					var ctx = markupCanvas.getContext('2d');
					if (reset) {
						ctx.clearRect(0, 0, markupCanvas.width, markupCanvas.height);
					}

					var xOffset, sDist;
					sDist = viewState.getSampleDist(markupCanvas.width);

					// draw moving boundary line if moving
					scope.dhs.drawMovingBoundaryLine(ctx);

					// draw current viewport selected
					scope.dhs.drawCurViewPortSelected(ctx, true);

					// draw view port times
					scope.dhs.drawViewPortTimes(ctx, true);

					// ctx.strokeStyle = config.vals.colors.labelColor;
					// ctx.fillStyle = config.vals.colors.labelColor;
					// ctx.font = (config.vals.font.fontPxSize + 'px' + ' ' + config.vals.font.fontType);

					// // lines to corners
					// ctx.beginPath();
					// ctx.moveTo(0, 0);
					// ctx.lineTo(5, 5);
					// ctx.moveTo(markupCanvas.width, 0);
					// ctx.lineTo(markupCanvas.width - 5, 5);
					// ctx.closePath();
					// ctx.stroke();

					// var scaleX = ctx.canvas.width / ctx.canvas.offsetWidth;
					// var scaleY = ctx.canvas.height / ctx.canvas.offsetHeight;

					// var sTime;
					// var eTime;
					// var horizontalText;
					// var space;

					// if (viewState.curViewPort) {
					// 	//draw time and sample nr

					// 	sTime = viewState.round(viewState.curViewPort.sS / scope.shs.wavJSO.SampleRate, 6);
					// 	eTime = viewState.round(viewState.curViewPort.eS / scope.shs.wavJSO.SampleRate, 6);

					// 	horizontalText = scope.fontImage.getTextImageTwoLines(ctx, viewState.curViewPort.sS, sTime, config.vals.font.fontPxSize, config.vals.font.fontType, config.vals.colors.labelColor, true);
					// 	// ctx.drawImage(horizontalText, 0, 0, horizontalText.width, horizontalText.height, 0, 0, horizontalText.width, horizontalText.height);
					// 	ctx.drawImage(horizontalText, 5, 5);

					// 	space = getScaleWidth(ctx, viewState.curViewPort.eS, eTime, scaleX);
					// 	horizontalText = scope.fontImage.getTextImageTwoLines(ctx, viewState.curViewPort.eS, eTime, config.vals.font.fontPxSize, config.vals.font.fontType, config.vals.colors.labelColor, false);
					// 	ctx.drawImage(horizontalText, 0, 0, horizontalText.width, horizontalText.height, markupCanvas.width - space - 5, 0, horizontalText.width, horizontalText.height);


					// 	//draw dot at edge of image
					// 	// var spaceW = getScaleWidth(ctx, viewState.curViewPort.eS, eTime, scaleX);
					// 	// var startPoint = (Math.PI / 180) * 0;
					// 	// var endPoint = (Math.PI / 180) * 360;
					// 	// ctx.beginPath();
					// 	// ctx.arc(spaceW, config.vals.font.fontPxSize * 2 * scaleY, 10, startPoint, endPoint, true);
					// 	// ctx.fill();
					// 	// ctx.closePath();


					// }
				}
			}
		};
	});<commit_msg>towards isolated scope for osci<commit_after>'use strict';


angular.module('emuwebApp')
	.directive('osci', function (viewState, Soundhandlerservice, ConfigProviderService, Drawhelperservice) {
		return {
			templateUrl: 'views/osci.html',
			replace: true,
			restrict: 'E',
			// scope: {},
			link: function postLink(scope, element, attrs) {


				// select the needed DOM elements from the template
				var canvasLength = element.find('canvas').length;
				var canvas = element.find('canvas')[0];
				var markupCanvas = element.find('canvas')[canvasLength - 1];
				scope.order = attrs.order;

				scope.enlargeCanvas = {
					'height': 100 / ConfigProviderService.vals.perspectives[viewState.curPerspectiveIdx].signalCanvases.order.length + '%'
				};

				scope.cpi = viewState.curPerspectiveIdx;
				scope.phai = viewState.playHeadAnimationInfos;
				scope.cvp = viewState.curViewPort;
				scope.mb = viewState.movingBoundary;

				///////////////
				// watches

				scope.$watch('cpi', function () {
					scope.updateCSS();
				}, true);

				scope.$watch('phai', function () {
					if (!$.isEmptyObject(Soundhandlerservice)) {
						if (!$.isEmptyObject(Soundhandlerservice.wavJSO)) {
							drawPlayHead(scope, ConfigProviderService);
						}
					}
				}, true);

				// scope.$watch('tds.data', function () {
				// 	if (!$.isEmptyObject(Soundhandlerservice)) {
				// 		if (!$.isEmptyObject(Soundhandlerservice.wavJSO)) {
				// 			console.log(scope.tds.data)
				// 			drawVpOsciMarkup(scope, ConfigProviderService, true);
				// 		}
				// 	}
				// }, true);

				scope.$watch('mb', function () {
					if (!$.isEmptyObject(Soundhandlerservice)) {
						if (!$.isEmptyObject(Soundhandlerservice.wavJSO)) {
							drawVpOsciMarkup(scope, ConfigProviderService, true);
						}
					}
				}, true);

				scope.$watch('cvp', function (newValue, oldValue) {
					if (!$.isEmptyObject(Soundhandlerservice)) {
						if (!$.isEmptyObject(Soundhandlerservice.wavJSO)) {
							// check for changed zoom
							if (oldValue.sS !== newValue.sS || oldValue.sE !== newValue.sE || newValue.selectS === -1) { // SIC -1 check not that clean...
								var allPeakVals = Drawhelperservice.calculatePeaks(viewState, canvas, Soundhandlerservice.wavJSO.Data);
								Drawhelperservice.osciPeaks = allPeakVals;
								Drawhelperservice.freshRedrawDrawOsciOnCanvas(viewState, canvas, Drawhelperservice.osciPeaks, Soundhandlerservice.wavJSO.Data, ConfigProviderService);
							}
							drawVpOsciMarkup(scope, ConfigProviderService, true);
							scope.updateCSS();
						}
					}
				}, true);

				//
				/////////////////////////

				/**
				 *
				 */
				scope.redraw = function () {
					drawVpOsciMarkup(scope, ConfigProviderService, true);
					scope.updateCSS();
				};

				/**
				 *
				 */
				scope.updateCSS = function () {
					var parts = ConfigProviderService.vals.perspectives[viewState.curPerspectiveIdx].signalCanvases.order.length;
					if (viewState.getenlarge() == -1) {
						scope.enlargeCanvas = {
							'height': 100 / parts + '%'
						};
					} else {
						if (viewState.getenlarge() == scope.order) {
							scope.enlargeCanvas = {
								'height': 3 * 100 / (parts + 2) + '%'
							};
						} else {
							scope.enlargeCanvas = {
								'height': 100 / (parts + 2) + '%'
							};
						}
					}
				};


				/**
				 *
				 */
				function drawPlayHead(scope, config) {
					var viewState = viewState;
					var ctx = markupCanvas.getContext('2d');
					ctx.clearRect(0, 0, canvas.width, canvas.height);

					var posS = viewState.getPos(markupCanvas.width, viewState.playHeadAnimationInfos.sS);
					var posCur = viewState.getPos(markupCanvas.width, viewState.playHeadAnimationInfos.curS);
					// console.log(viewState.playHeadAnimationInfos.curS)

					ctx.fillStyle = ConfigProviderService.vals.colors.selectedAreaColor;
					ctx.fillRect(posS, 0, posCur - posS, canvas.height);

					//console.log(posS,posCur);

					drawVpOsciMarkup(scope, config, false);

				}

				function getScaleW(ctx, str, scale) {
					return ctx.measureText(str).width * scale;
				}

				function getScaleH(ctx, str, scale) {
					return ctx.measureText(str).width * scale;
				}

				function getScaleWidth(ctx, str1, str2, scaleX) {
					if (str1.toString().length > str2.toString().length) {
						return getScaleW(ctx, str1, scaleX);
					} else {
						return getScaleW(ctx, str2, scaleX);
					}
				}

				/**
				 * draws markup of osci according to
				 * the information that is specified in
				 * the viewport
				 */

				function drawVpOsciMarkup(scope, config, reset) {

					var ctx = markupCanvas.getContext('2d');
					if (reset) {
						ctx.clearRect(0, 0, markupCanvas.width, markupCanvas.height);
					}

					var xOffset, sDist;
					sDist = viewState.getSampleDist(markupCanvas.width);

					// draw moving boundary line if moving
					Drawhelperservice.drawMovingBoundaryLine(ctx);

					// draw current viewport selected
					Drawhelperservice.drawCurViewPortSelected(ctx, true);

					// draw view port times
					Drawhelperservice.drawViewPortTimes(ctx, true);

					// ctx.strokeStyle = config.vals.colors.labelColor;
					// ctx.fillStyle = config.vals.colors.labelColor;
					// ctx.font = (config.vals.font.fontPxSize + 'px' + ' ' + config.vals.font.fontType);

					// // lines to corners
					// ctx.beginPath();
					// ctx.moveTo(0, 0);
					// ctx.lineTo(5, 5);
					// ctx.moveTo(markupCanvas.width, 0);
					// ctx.lineTo(markupCanvas.width - 5, 5);
					// ctx.closePath();
					// ctx.stroke();

					// var scaleX = ctx.canvas.width / ctx.canvas.offsetWidth;
					// var scaleY = ctx.canvas.height / ctx.canvas.offsetHeight;

					// var sTime;
					// var eTime;
					// var horizontalText;
					// var space;

					// if (viewState.curViewPort) {
					// 	//draw time and sample nr

					// 	sTime = viewState.round(viewState.curViewPort.sS / Soundhandlerservice.wavJSO.SampleRate, 6);
					// 	eTime = viewState.round(viewState.curViewPort.eS / Soundhandlerservice.wavJSO.SampleRate, 6);

					// 	horizontalText = scope.fontImage.getTextImageTwoLines(ctx, viewState.curViewPort.sS, sTime, config.vals.font.fontPxSize, config.vals.font.fontType, config.vals.colors.labelColor, true);
					// 	// ctx.drawImage(horizontalText, 0, 0, horizontalText.width, horizontalText.height, 0, 0, horizontalText.width, horizontalText.height);
					// 	ctx.drawImage(horizontalText, 5, 5);

					// 	space = getScaleWidth(ctx, viewState.curViewPort.eS, eTime, scaleX);
					// 	horizontalText = scope.fontImage.getTextImageTwoLines(ctx, viewState.curViewPort.eS, eTime, config.vals.font.fontPxSize, config.vals.font.fontType, config.vals.colors.labelColor, false);
					// 	ctx.drawImage(horizontalText, 0, 0, horizontalText.width, horizontalText.height, markupCanvas.width - space - 5, 0, horizontalText.width, horizontalText.height);


					// 	//draw dot at edge of image
					// 	// var spaceW = getScaleWidth(ctx, viewState.curViewPort.eS, eTime, scaleX);
					// 	// var startPoint = (Math.PI / 180) * 0;
					// 	// var endPoint = (Math.PI / 180) * 360;
					// 	// ctx.beginPath();
					// 	// ctx.arc(spaceW, config.vals.font.fontPxSize * 2 * scaleY, 10, startPoint, endPoint, true);
					// 	// ctx.fill();
					// 	// ctx.closePath();


					// }
				}
			}
		};
	});
{'fraction_non_alphanumeric': 0.1524205482347967, 'fraction_numerical': 0.009160735677542104, 'mean_word_length': 2.558676028084253, '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': '1856600', 'n_tokens_mistral': 6209, 'n_tokens_neox': 4649, 'n_words': 817}