11<script setup lang="ts">
2- import { ref } from ' vue'
2+ import { computed , ref } from ' vue'
33import CopyButton from ' ../CopyButton/index.vue'
44import GitGraph from ' ./GitGraph.vue'
55
@@ -20,19 +20,35 @@ const emit = defineEmits(['select'])
2020const hoveredCell = ref <string | null >(null )
2121
2222function getBranchColorFromGraphData(branchName : string ): string {
23+ if (! props .graphData ) return ' #888888'
24+
25+ // 检查当前提交的主分支颜色
2326 if (props .graphData .branch === branchName && props .graphData .branchColor ) {
2427 return props .graphData .branchColor
2528 }
2629
30+ // 检查目标分支颜色
2731 if (props .graphData .targetBranch === branchName && props .graphData .targetBranchColor ) {
2832 return props .graphData .targetBranchColor
2933 }
3034
35+ // 检查源分支颜色
3136 if (props .graphData .sourceBranchColors && props .graphData .sourceBranchColors [branchName ]) {
3237 return props .graphData .sourceBranchColors [branchName ]
3338 }
3439
35- return ' #888888'
40+ // 生成一个基于分支名的稳定颜色
41+ // 使用分支名作为唯一标识符来生成一个稳定的哈希值
42+ let hash = 0 ;
43+ for (let i = 0 ; i < branchName .length ; i ++ ) {
44+ hash = ((hash << 5 ) - hash ) + branchName .charCodeAt (i );
45+ hash = hash & hash ; // 转换为32位整数
46+ }
47+
48+ // 使用哈希值选择一个颜色
49+ // 黄金比例法生成分散均匀的颜色
50+ const hue = (hash % 360 + 360 ) % 360 ; // 确保是正数
51+ return ` hsl(${hue }, 70%, 45%) ` ; // 使用 HSL 颜色格式
3652}
3753
3854// 解析Git引用字符串为数组
@@ -100,6 +116,33 @@ function handleDoubleClick() {
100116 console .error (' Error sending commit details:' , error )
101117 }
102118}
119+
120+ // 计算在当前提交处结束(不应向上延伸)的分支
121+ const branchEndingUp = computed (() => {
122+ if (! props .graphData ) return []
123+
124+ const endingBranches = []
125+
126+ // 当前提交的相关分支
127+ if (props .graphData .branch ) {
128+ // 当前分支如果没有父提交,则结束于此
129+ if (! props .commit .parents || props .commit .parents .length === 0 ) {
130+ endingBranches .push (props .graphData .branch )
131+ }
132+ }
133+
134+ // 源分支在此结束
135+ if (props .graphData .sourceBranches && props .graphData .sourceBranches .length ) {
136+ props .graphData .sourceBranches .forEach (branch => {
137+ // 如果源分支不等于主分支,则在此结束
138+ if (branch !== props .graphData .branch ) {
139+ endingBranches .push (branch )
140+ }
141+ })
142+ }
143+
144+ return endingBranches
145+ })
103146 </script >
104147
105148<template >
@@ -117,7 +160,11 @@ function handleDoubleClick() {
117160 <span
118161 class =" ref-item"
119162 :class =" { tag: ref.isTag, branch: !ref.isTag }"
120- :style =" { color: !ref.isTag ? getBranchColorFromGraphData(ref.name) : undefined, borderColor: !ref.isTag ? getBranchColorFromGraphData(ref.name) : undefined }"
163+ :style =" {
164+ backgroundColor: !ref.isTag ? `${getBranchColorFromGraphData(ref.name)}20` : undefined,
165+ color: !ref.isTag ? getBranchColorFromGraphData(ref.name) : undefined,
166+ borderColor: !ref.isTag ? getBranchColorFromGraphData(ref.name) : undefined
167+ }"
121168 >
122169 {{ ref.displayName }}
123170 </span >
@@ -126,7 +173,12 @@ function handleDoubleClick() {
126173 </template >
127174 </div >
128175 <div class =" branch-col commit-cell" :style =" { width: `${columnWidths.branch}px` }" >
129- <GitGraph :graph-data =" graphData" :active-branches =" activeBranches" :is-selected =" isSelected" />
176+ <GitGraph
177+ :graph-data =" graphData"
178+ :active-branches =" activeBranches"
179+ :is-selected =" isSelected"
180+ :branch-ending-up =" branchEndingUp"
181+ />
130182 </div >
131183 <span
132184 class =" hash-col commit-cell" :style =" { width: `${columnWidths.hash}px` }" @mouseenter =" hoveredCell = 'hash'"
@@ -231,6 +283,7 @@ function handleDoubleClick() {
231283.branch-name-col {
232284 white-space : normal ;
233285 overflow : visible ;
286+ padding : 0px ;
234287}
235288
236289.refs-container {
0 commit comments