<commit_before>import { SettingsService, SettingsServiceSubscriber } from "../../state/settings.service"
import "./detailPanel.component.scss"
import {
	BuildingHoveredEventSubscriber,
	BuildingSelectedEventSubscriber,
	CodeMapBuildingTransition,
	CodeMapMouseEventService
} from "../codeMap/codeMap.mouseEvent.service"
import { Settings, KeyValuePair, MetricData, RecursivePartial } from "../../codeCharta.model"
import { Node } from "../../codeCharta.model"
import { MetricService, MetricServiceSubscriber } from "../../state/metric.service"
import { FileStateService } from "../../state/fileState.service"
import { FileStateHelper } from "../../util/fileStateHelper"

interface CommonDetails {
	areaAttributeName: string
	heightAttributeName: string
	colorAttributeName: string
}

interface SpecificDetails {
	name: string
	area: number
	height: number
	color: number
	heightDelta: number
	areaDelta: number
	colorDelta: number
	link: string
	origin: string
	path: string
	attributes: KeyValuePair
	deltas: KeyValuePair
}

interface Details {
	common: CommonDetails
	hovered: SpecificDetails
	selected: SpecificDetails
}

export class DetailPanelController
	implements SettingsServiceSubscriber, BuildingHoveredEventSubscriber, BuildingSelectedEventSubscriber, MetricServiceSubscriber {
	private _viewModel: {
		maximizeDetailPanel: boolean
		metrics: string[]
		details: Details
	} = {
		maximizeDetailPanel: null,
		metrics: [],
		details: {
			common: {
				areaAttributeName: null,
				heightAttributeName: null,
				colorAttributeName: null
			},
			hovered: {
				name: null,
				area: null,
				height: null,
				color: null,
				heightDelta: null,
				areaDelta: null,
				colorDelta: null,
				link: null,
				origin: null,
				path: null,
				attributes: null,
				deltas: null
			},
			selected: {
				name: null,
				area: null,
				height: null,
				color: null,
				heightDelta: null,
				areaDelta: null,
				colorDelta: null,
				link: null,
				origin: null,
				path: null,
				attributes: null,
				deltas: null
			}
		}
	}

	/* @ngInject */
	constructor(
		private $rootScope,
		private settingsService: SettingsService,
		private $timeout,
		private fileStateService: FileStateService
	) {
		MetricService.subscribe(this.$rootScope, this)
		SettingsService.subscribe(this.$rootScope, this)
		CodeMapMouseEventService.subscribeToBuildingHoveredEvents(this.$rootScope, this)
		CodeMapMouseEventService.subscribeToBuildingSelectedEvents(this.$rootScope, this)
	}

	public onMetricDataAdded(metricData: MetricData[], event: angular.IAngularEvent) {
		this._viewModel.metrics = metricData.map(x => x.name)
	}

	public onMetricDataRemoved(event: angular.IAngularEvent) {}

	public onBuildingHovered(data: CodeMapBuildingTransition, event: angular.IAngularEvent) {
		this.onHover(data)
	}

	public onBuildingSelected(data: CodeMapBuildingTransition, event: angular.IAngularEvent) {
		this.onSelect(data)
	}

	public onSettingsChanged(settings: Settings, update: RecursivePartial<Settings>, event: angular.IAngularEvent) {
		this._viewModel.details.common.areaAttributeName = settings.dynamicSettings.areaMetric
		this._viewModel.details.common.heightAttributeName = settings.dynamicSettings.heightMetric
		this._viewModel.details.common.colorAttributeName = settings.dynamicSettings.colorMetric
		this._viewModel.maximizeDetailPanel = settings.appSettings.maximizeDetailPanel

		if (update && update.fileSettings && update.fileSettings.blacklist) {
			this.setSelectedDetails(null)
			this.setHoveredDetails(null)
		}
	}

	public onSelect(data: CodeMapBuildingTransition) {
		if (data.to && data.to.node) {
			this.setSelectedDetails(data.to.node)
		} else {
			this.clearSelectedDetails()
		}
	}

	public onHover(data: CodeMapBuildingTransition) {
		if (data.to && data.to.node) {
			this.setHoveredDetails(data.to.node)
		} else {
			this.clearHoveredDetails()
		}
	}

	public isHovered() {
		if (this._viewModel.details && this._viewModel.details.hovered) {
			return !!this._viewModel.details.hovered.name
		} else {
			return false<commit_msg>use other method to clear #576<commit_after>import { SettingsService, SettingsServiceSubscriber } from "../../state/settings.service"
import "./detailPanel.component.scss"
import {
	BuildingHoveredEventSubscriber,
	BuildingSelectedEventSubscriber,
	CodeMapBuildingTransition,
	CodeMapMouseEventService
} from "../codeMap/codeMap.mouseEvent.service"
import { Settings, KeyValuePair, MetricData, RecursivePartial } from "../../codeCharta.model"
import { Node } from "../../codeCharta.model"
import { MetricService, MetricServiceSubscriber } from "../../state/metric.service"
import { FileStateService } from "../../state/fileState.service"
import { FileStateHelper } from "../../util/fileStateHelper"

interface CommonDetails {
	areaAttributeName: string
	heightAttributeName: string
	colorAttributeName: string
}

interface SpecificDetails {
	name: string
	area: number
	height: number
	color: number
	heightDelta: number
	areaDelta: number
	colorDelta: number
	link: string
	origin: string
	path: string
	attributes: KeyValuePair
	deltas: KeyValuePair
}

interface Details {
	common: CommonDetails
	hovered: SpecificDetails
	selected: SpecificDetails
}

export class DetailPanelController
	implements SettingsServiceSubscriber, BuildingHoveredEventSubscriber, BuildingSelectedEventSubscriber, MetricServiceSubscriber {
	private _viewModel: {
		maximizeDetailPanel: boolean
		metrics: string[]
		details: Details
	} = {
		maximizeDetailPanel: null,
		metrics: [],
		details: {
			common: {
				areaAttributeName: null,
				heightAttributeName: null,
				colorAttributeName: null
			},
			hovered: {
				name: null,
				area: null,
				height: null,
				color: null,
				heightDelta: null,
				areaDelta: null,
				colorDelta: null,
				link: null,
				origin: null,
				path: null,
				attributes: null,
				deltas: null
			},
			selected: {
				name: null,
				area: null,
				height: null,
				color: null,
				heightDelta: null,
				areaDelta: null,
				colorDelta: null,
				link: null,
				origin: null,
				path: null,
				attributes: null,
				deltas: null
			}
		}
	}

	/* @ngInject */
	constructor(
		private $rootScope,
		private settingsService: SettingsService,
		private $timeout,
		private fileStateService: FileStateService
	) {
		MetricService.subscribe(this.$rootScope, this)
		SettingsService.subscribe(this.$rootScope, this)
		CodeMapMouseEventService.subscribeToBuildingHoveredEvents(this.$rootScope, this)
		CodeMapMouseEventService.subscribeToBuildingSelectedEvents(this.$rootScope, this)
	}

	public onMetricDataAdded(metricData: MetricData[], event: angular.IAngularEvent) {
		this._viewModel.metrics = metricData.map(x => x.name)
	}

	public onMetricDataRemoved(event: angular.IAngularEvent) {}

	public onBuildingHovered(data: CodeMapBuildingTransition, event: angular.IAngularEvent) {
		this.onHover(data)
	}

	public onBuildingSelected(data: CodeMapBuildingTransition, event: angular.IAngularEvent) {
		this.onSelect(data)
	}

	public onSettingsChanged(settings: Settings, update: RecursivePartial<Settings>, event: angular.IAngularEvent) {
		this._viewModel.details.common.areaAttributeName = settings.dynamicSettings.areaMetric
		this._viewModel.details.common.heightAttributeName = settings.dynamicSettings.heightMetric
		this._viewModel.details.common.colorAttributeName = settings.dynamicSettings.colorMetric
		this._viewModel.maximizeDetailPanel = settings.appSettings.maximizeDetailPanel

		if (update && update.fileSettings && update.fileSettings.blacklist) {
			this.clearSelectedDetails()
			this.clearHoveredDetails()
		}
	}

	public onSelect(data: CodeMapBuildingTransition) {
		if (data.to && data.to.node) {
			this.setSelectedDetails(data.to.node)
		} else {
			this.clearSelectedDetails()
		}
	}

	public onHover(data: CodeMapBuildingTransition) {
		if (data.to && data.to.node) {
			this.setHoveredDetails(data.to.node)
		} else {
			this.clearHoveredDetails()
		}
	}

	public isHovered() {
		if (this._viewModel.details && this._viewModel.details.hovered) {
			return !!this._viewModel.details.hovered.name
		} else {
			return false
{'fraction_non_alphanumeric': 0.10254206066560236, 'fraction_numerical': 0.00036841458921773305, 'mean_word_length': 4.601100412654746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2654178', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2444, 'n_words': 502}