From b0f09a6bc87e990bc68ee249bce1f95af80aa537 Mon Sep 17 00:00:00 2001 From: Miriam Date: Wed, 6 Oct 2021 11:42:17 +0200 Subject: [PATCH] #35: create files for the graph and some graph styles create first try for the graph and show for every commit a Box. Box Size, Color and which Commit-Information should be shown can be changed --- .../File-Evolution/chart/chart.js | 129 ++++++++++++++++++ .../File-Evolution/chart/index.js | 31 +++++ .../visualizations/File-Evolution/styles.scss | 17 +++ 3 files changed, 177 insertions(+) create mode 100644 ui/src/visualizations/File-Evolution/chart/chart.js create mode 100644 ui/src/visualizations/File-Evolution/chart/index.js diff --git a/ui/src/visualizations/File-Evolution/chart/chart.js b/ui/src/visualizations/File-Evolution/chart/chart.js new file mode 100644 index 00000000..9ac8e06d --- /dev/null +++ b/ui/src/visualizations/File-Evolution/chart/chart.js @@ -0,0 +1,129 @@ +'use strict'; + +import React from 'react'; +import * as d3 from 'd3'; + +import styles from '../styles.scss'; +import ReactDOM from 'react-dom'; + +export default class FileEvolution extends React.Component { + constructor(props) { + super(props); + } + componentWillReceiveProps(nextProps) {} + + componentDidMount() {} + + render() { + const space = 50; + const commitBoxes = this.getCommitsDraw(space); + //const svgHeight = (commitRects.length / 2 + 1) * this.props.commitBoxHeight + (commitRects.length / 2) * space; + const svgHeight = this.props.commitBoxHeight + space; + const svgWidth = (commitBoxes.length / 2 + 1) * this.props.commitBoxHeight + (commitBoxes.length / 2) * space; + return ( +
+
+ {commitBoxes} +
+
+ ); + } + + getCommitsDraw(space) { + function getBoxColor(props, commit) { + let color = 'red'; + if (props.commitBoxColor === 'author') { + color = props.authorsColorPalette[commit.signature]; + } else if (props.commitBoxColor === 'branch') { + //TODO branch color + color = 'yellow'; + } + return color; + } + + function getCommitInfo(props, commit) { + //TODO font size + const commitInfo = []; + if (props.showCommitMessage === 'header') { + commitInfo.push({commit.messageHeader}); + } else if (props.showCommitMessage === 'all') { + commitInfo.push({commit.message}); + } + if (props.showCommitDate) { + if (commitInfo.length > 0) { + commitInfo.push(
); + } + commitInfo.push({commit.date}); + } + if (props.showCommitAuthor) { + if (commitInfo.length > 0) { + commitInfo.push(
); + } + commitInfo.push({commit.signature}); + } + return commitInfo; + } + + function getArrow(x, y, height, width) { + //TODO Arrow + const arrow = []; + + const lineXstart = x + width + 5; + const lineY = y + height / 2; + const lineXend = x + width + space - 5; + const pointsForLine = '' + lineXstart.toString() + ',' + lineY.toString() + ' ' + lineXend.toString() + ',' + lineY.toString(); + + const arrowHeadYup = y + height / 4; + const arrowHeadYdown = y + (height / 4) * 3; + const arrowHeadX = lineXstart + ((lineXend - lineXstart) / 4) * 3; + const pointsForArrowHead = + '' + + arrowHeadX.toString() + + ',' + + arrowHeadYup.toString() + + ' ' + + lineXend.toString() + + ',' + + lineY.toString() + + ' ' + + arrowHeadX.toString() + + ',' + + arrowHeadYdown.toString(); + + arrow.push(); + arrow.push(); + return arrow; + } + const commitData = this.props.commits; + const width = this.props.commitBoxWidth; + const height = this.props.commitBoxHeight; + const commitRects = []; + let x = 20; + let y = 20; + for (const i in commitData) { + const commit = commitData[i]; + if (this.props.selectedAuthors.indexOf(commit.signature) > -1) { + const color = getBoxColor(this.props, commit); + commitRects.push( + + + + {getCommitInfo(this.props, commit)} + + + ); + + commitRects.push( + + {getArrow(x, y, height, width)} + + ); + + x = x + width + space; + //y = y + height + space; //TODO auskommentieren + } + } + commitRects.pop(); //remove last arrow + return commitRects; + } +} diff --git a/ui/src/visualizations/File-Evolution/chart/index.js b/ui/src/visualizations/File-Evolution/chart/index.js new file mode 100644 index 00000000..14f5f569 --- /dev/null +++ b/ui/src/visualizations/File-Evolution/chart/index.js @@ -0,0 +1,31 @@ +'use strict'; + +import { connect } from 'react-redux'; + +import Chart from './chart.js'; + +const mapStateToProps = (state /*, ownProps*/) => { + const FileEvolutionState = state.visualizations.fileEvolution.state; + console.log(FileEvolutionState); + return { + branches: FileEvolutionState.data.data.branches, + committers: FileEvolutionState.data.data.committers, + commits: FileEvolutionState.data.data.commits, + authorsColorPalette: FileEvolutionState.data.data.authorsColorPalette, + branchesColorPalette: FileEvolutionState.data.data.branchesColorPalette, + selectedAuthors: FileEvolutionState.config.selectedAuthors, + selectedBranches: FileEvolutionState.config.selectedBranches, + commitBoxHeight: FileEvolutionState.config.commitBoxHeight, + commitBoxWidth: FileEvolutionState.config.commitBoxWidth, + commitBoxColor: FileEvolutionState.config.commitBoxColor, + showCommitDate: FileEvolutionState.config.showCommitDate, + showCommitAuthor: FileEvolutionState.config.showCommitAuthor, + showCommitMessage: FileEvolutionState.config.showCommitMessage + }; +}; + +const mapDispatchToProps = (dispatch /*, ownProps*/) => { + return {}; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(Chart); diff --git a/ui/src/visualizations/File-Evolution/styles.scss b/ui/src/visualizations/File-Evolution/styles.scss index b717df68..c96ffa9d 100644 --- a/ui/src/visualizations/File-Evolution/styles.scss +++ b/ui/src/visualizations/File-Evolution/styles.scss @@ -33,3 +33,20 @@ .configContainer{ } + +.chartContainer{ +.chartDiv { + width: 500px; + height: 100vh; + overflow-x: scroll; + overflow-y: scroll; +} + svg{ + position: relative; + overflow: scroll; + } + + foreignObject{ + overflow: scroll; + } +}