Skip to content

Commit 8473254

Browse files
committed
#278: Improve frontend elements
Adds new scss classes and styling for the graph, adds in ellipsis for most texts to not go out of the box / increase the size of the box
1 parent e86af07 commit 8473254

File tree

2 files changed

+151
-70
lines changed

2 files changed

+151
-70
lines changed
Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,117 @@
11
.infoBox {
22
position: absolute;
3-
top: 20px;
4-
right: 20px;
3+
top: 1rem;
4+
right: 1rem;
55

6-
width: clamp(10rem, 30%, 20rem);
7-
max-height: calc(100% - 40px);
6+
width: fit-content;
7+
inline-size: fit-content;
8+
min-inline-size: 14rem;
9+
max-inline-size: 24rem;
10+
11+
height: fit-content;
12+
max-block-size: calc(100% + 4rem);
13+
overflow: hidden;
814

9-
overflow-y: auto;
1015
padding: 0.5rem;
1116
border-radius: 5px;
1217
--tw-bg-opacity: 1;
1318
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
1419
background-color: var(--fallback-b1,oklch(var(--b1)/var(--tw-bg-opacity)));
15-
z-index: 4;
20+
21+
z-index: 1;
22+
23+
display: flex;
24+
flex-direction: column;
25+
gap: 0.5rem;
26+
}
27+
28+
.infoBoxSpace {
29+
height: 1px;
30+
background: oklch(var(--bc) / .2);
31+
margin: 0.25rem 0;
32+
}
33+
34+
.infoRow {
35+
display: grid;
36+
grid-template-columns: 1fr auto;
37+
align-items: baseline;
38+
gap: 1rem;
39+
}
40+
41+
.selectBox {
42+
@apply select select-bordered select-xs;
43+
max-width: 12rem;
44+
min-width: 0;
45+
white-space: nowrap;
46+
overflow: hidden;
47+
text-overflow: ellipsis;
1648
}
1749

1850
.infoBoxLabel {
19-
@apply font-medium text-base-content/80;
51+
@apply font-medium text-base-content/70;
2052
}
2153

2254
.infoBoxValue {
2355
@apply font-semibold text-primary;
2456
}
2557

58+
.infoBoxHeader {
59+
text-align: center;
60+
font-weight: bold;
61+
white-space: nowrap;
62+
overflow: hidden;
63+
text-overflow: ellipsis;
64+
min-width: 0;
65+
max-width: 100%;
66+
}
67+
68+
// Buttons
69+
.addButton {
70+
@apply btn btn-xs btn-outline ml-2;
71+
}
72+
2673
.infoBoxButton {
2774
@apply btn btn-xs btn-outline transition-colors;
2875
vertical-align: middle;
2976
margin-left: 0.5rem;
3077
}
3178

32-
.infoBoxHeader {
33-
text-align: center;
34-
font-weight: bold;
79+
.combineUsersBlock {
80+
display: flex;
81+
align-items: center;
82+
}
83+
84+
// User chips
85+
.userChips {
86+
display: flex;
87+
flex-wrap: wrap;
88+
gap: 0.25rem;
89+
}
90+
91+
.userChip {
92+
@apply badge badge-outline;
93+
display: flex;
94+
align-items: center;
95+
gap: 0.25rem;
96+
max-width: 12rem;
97+
98+
button: {
99+
line-height: 1;
100+
}
101+
}
102+
103+
.userName {
104+
flex: 1 1 auto;
105+
min-width: 0;
106+
max-width: 12rem;
107+
white-space: nowrap;
108+
overflow: hidden;
109+
text-overflow: ellipsis;
35110
}
111+
112+
.chipClose {
113+
flex: 0 0 auto;
114+
line-height: 1;
115+
@apply btn btn-xs btn-ghost p-0 min-h-0 h-auto w-auto;
116+
}
117+

binocular-frontend-new/src/plugins/visualizationPlugins/simpleVisualizationPlugin/src/chart/columnChart.tsx

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ interface InfoState {
2323
}
2424

2525
export const ColumnChart = ({ width, height, data, scale, palette, settings }: BarChartProps) => {
26-
// bounds = area inside the graph axis = calculated by substracting the margins
26+
// bounds = area inside the graph axis = ccalculated by substracting the margins
2727
const svgRef = useRef(null);
2828
const tooltipRef = useRef(null);
2929
const [info, setInfo] = useState<null | InfoState>(null);
3030
const infoRef = useRef<HTMLDivElement | null>(null);
3131
const boundsWidth = width - MARGIN.right - MARGIN.left;
3232
const boundsHeight = height - MARGIN.top - MARGIN.bottom;
33+
const MAX_CHARS = 20; // Maximum characters for x-axis labels
3334

3435
//Create array with users that are visible on zoom, otherwise when opening the infobox it zooms out
3536
const [visibleUsers, setVisibleUsers] = useState<string[]>([]);
@@ -59,6 +60,8 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
5960
}, info?.value ?? 0);
6061
}, [sumUsers, info, data]);
6162

63+
const ellipsis = (label: string) => (label.length > MAX_CHARS ? label.slice(0, MAX_CHARS - 1) + '…' : label);
64+
6265
//This is needed to make sure that the chart stays zoomed in when clicking on a user for the infobox
6366
useEffect(() => {
6467
if (!isZoomed) setVisibleUsers(allUsers);
@@ -133,7 +136,7 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
133136
// d3/typescript sometimes does weird things and throws an error where no error is.
134137
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
135138
// @ts-expect-error
136-
svgElement.select('.xAxis').transition().duration(1000).call(d3.axisBottom(xScale));
139+
svgElement.select('.xAxis').transition().duration(1000).call(d3.axisBottom(xScale).tickFormat(ellipsis));
137140

138141
if (settings.showMean) {
139142
svgElement.selectAll('.meanLine').remove();
@@ -158,7 +161,7 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
158161
.append('g')
159162
.attr('class', 'xAxis')
160163
.attr('transform', `translate(0,${boundsHeight})`)
161-
.call(d3.axisBottom(xScale))
164+
.call(d3.axisBottom(xScale).tickFormat(ellipsis))
162165
.selectAll('text')
163166
.style('text-anchor', 'middle');
164167

@@ -213,12 +216,7 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
213216
{info && (
214217
<div ref={infoRef} onClick={() => setInfo(null)}>
215218
<div onClick={(e) => e.stopPropagation()} className={columnChartStyles.infoBox}>
216-
217-
<button
218-
aria-label="Close"
219-
onClick={() => setInfo(null)}
220-
className="btn btn-sm btn-ghost absolute right-0.5 top-0.5"
221-
>
219+
<button aria-label="Close" onClick={() => setInfo(null)} className="btn btn-sm btn-ghost absolute right-0.5 top-0.5">
222220
<strong>X</strong>
223221
</button>
224222

@@ -232,10 +230,10 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
232230
<span className={columnChartStyles.infoBoxValue}>{info.avgCommitsPerWeek} </span>
233231
</p>
234232

235-
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }} className={columnChartStyles.infoBoxLabel}>
236-
Diff&nbsp;to:
237-
<select className={columnChartStyles.infoBoxValue} value={compareUser} onChange={(e) => setCompareUser(e.target.value)}>
238-
<option value={''} className={columnChartStyles.infoBoxValue} disabled>
233+
<div className={columnChartStyles.infoRow}>
234+
<span className={columnChartStyles.infoBoxLabel}> Diff&nbsp;to:</span>
235+
<select className={columnChartStyles.selectBox} value={compareUser} onChange={(e) => setCompareUser(e.target.value)}>
236+
<option value={''} className={columnChartStyles.infoBoxValue}>
239237
Pick user...
240238
</option>
241239
{allUsers
@@ -246,63 +244,64 @@ export const ColumnChart = ({ width, height, data, scale, palette, settings }: B
246244
</option>
247245
))}
248246
</select>
249-
</label>
247+
</div>
250248

251249
{diffCommits !== null && (
252250
<span>
253251
<strong className={columnChartStyles.infoBoxValue}>{diffCommits} Commits</strong>
254252
</span>
255253
)}
256254

257-
<div>
258-
<span className={columnChartStyles.infoBoxLabel}>Sum with user:</span>
259-
<select className={columnChartStyles.infoBoxValue} value={userToAdd} onChange={(e) => setUserToAdd(e.target.value)}>
260-
<option value={''} className={columnChartStyles.infoBoxValue} disabled>
261-
Pick user...
262-
</option>
263-
{allUsers
264-
.filter((u) => u !== info.label && !sumUsers.includes(u))
265-
.map((u) => (
266-
<option key={u} value={u} className={columnChartStyles.infoBoxValue}>
267-
{u}
268-
</option>
269-
))}
270-
</select>
271-
272-
<button
273-
className={columnChartStyles.infoBoxButton}
274-
onClick={() => {
275-
if (userToAdd && !sumUsers.includes(userToAdd)) {
276-
setSumUsers((prev) => [...prev, userToAdd]);
277-
setUserToAdd('');
278-
}
279-
}}>
280-
<strong>+</strong>
281-
</button>
282-
283-
{sumUsers.length > 0 && (
284-
<div>
285-
<p>
286-
<strong className={columnChartStyles.infoBoxValue}>{sumCommits} Commits</strong>
287-
</p>
288-
<span className={columnChartStyles.infoBoxLabel}>Remove user from sum:</span>
289-
<div>
290-
{sumUsers.map((u) => (
291-
<span key={u} className={columnChartStyles.infoBoxValue}>
255+
<div className={columnChartStyles.infoRow}>
256+
<span className={columnChartStyles.infoBoxLabel}>Sum with</span>
257+
<div className={columnChartStyles.combineUsersBlock}>
258+
<select className={columnChartStyles.selectBox} value={userToAdd} onChange={(e) => setUserToAdd(e.target.value)}>
259+
<option value={''} disabled>
260+
Pick user...
261+
</option>
262+
{allUsers
263+
.filter((u) => u !== info.label && !sumUsers.includes(u))
264+
.map((u) => (
265+
<option key={u} value={u} className={columnChartStyles.userName}>
292266
{u}
293-
<button
294-
className={columnChartStyles.infoBoxButton}
295-
onClick={() => {
296-
setSumUsers((prev) => prev.filter((user) => user !== u));
297-
}}>
298-
<strong>x</strong>
299-
</button>
300-
</span>
267+
</option>
301268
))}
302-
</div>
303-
</div>
304-
)}
269+
</select>
270+
<button
271+
className={columnChartStyles.addButton}
272+
onClick={() => {
273+
if (userToAdd && !sumUsers.includes(userToAdd)) {
274+
setSumUsers((prev) => [...prev, userToAdd]);
275+
setUserToAdd('');
276+
}
277+
}}>
278+
+
279+
</button>
280+
</div>
305281
</div>
282+
283+
{sumUsers.length > 0 && (
284+
<div>
285+
<p>
286+
<strong className={columnChartStyles.infoBoxValue}>{sumCommits} Commits</strong>
287+
</p>
288+
<span className={columnChartStyles.infoBoxLabel}>Remove user from sum:</span>
289+
<div className={columnChartStyles.userChips}>
290+
{sumUsers.map((u) => (
291+
<span key={u} className={columnChartStyles.userChip}>
292+
<span className={columnChartStyles.userName}>{u}</span>
293+
<button
294+
className={columnChartStyles.chipClose}
295+
onClick={() => {
296+
setSumUsers((prev) => prev.filter((user) => user !== u));
297+
}}>
298+
x
299+
</button>
300+
</span>
301+
))}
302+
</div>
303+
</div>
304+
)}
306305
</div>
307306
</div>
308307
)}

0 commit comments

Comments
 (0)