@@ -14,7 +14,6 @@ import { commandRangeAtom, commandModeAtom } from "@/store";
1414interface CommandTrendChartProps {
1515 /** Map of command_name -> { week_key -> count } */
1616 data : Record < string , Record < string , number > > ;
17- weeks ?: number ;
1817}
1918
2019// Color palette for commands
@@ -46,7 +45,6 @@ function getISOWeek(date: Date): { year: number; week: number } {
4645 return { year : d . getUTCFullYear ( ) , week : weekNo } ;
4746}
4847
49- type ChartMode = "weekly" | "cumulative" ;
5048type TimeRange = "1m" | "3m" | "all" ;
5149
5250const RANGE_WEEKS : Record < TimeRange , number | null > = {
@@ -55,7 +53,7 @@ const RANGE_WEEKS: Record<TimeRange, number | null> = {
5553 "all" : null ,
5654} ;
5755
58- export function CommandTrendChart ( { data, weeks = 13 } : CommandTrendChartProps ) {
56+ export function CommandTrendChart ( { data } : CommandTrendChartProps ) {
5957 const [ hoverData , setHoverData ] = useState < HoverData | null > ( null ) ;
6058 const [ mode , setMode ] = useAtom ( commandModeAtom ) ;
6159 const [ range , setRange ] = useAtom ( commandRangeAtom ) ;
@@ -97,9 +95,11 @@ export function CommandTrendChart({ data, weeks = 13 }: CommandTrendChartProps)
9795 const commands = commandTotals . slice ( 0 , MAX_COMMANDS ) . map ( ( [ cmd ] ) => cmd ) ;
9896
9997 // Build chart data based on mode
100- const chartData = weekKeys . map ( ( week , idx ) => {
101- const isCurrentWeek = idx === weekKeys . length - 1 ;
102- const point : Record < string , string | number | null > = {
98+ // In weekly mode, exclude the current (incomplete) week
99+ const weeksToRender = mode === "weekly" ? weekKeys . slice ( 0 , - 1 ) : weekKeys ;
100+
101+ const chartData = weeksToRender . map ( ( week , idx ) => {
102+ const point : Record < string , string | number > = {
103103 week : week . replace ( / ^ \d { 4 } - W / , "W" ) ,
104104 } ;
105105
@@ -108,19 +108,14 @@ export function CommandTrendChart({ data, weeks = 13 }: CommandTrendChartProps)
108108 commands . forEach ( ( cmd ) => {
109109 let cumulative = 0 ;
110110 for ( let i = 0 ; i <= idx ; i ++ ) {
111- cumulative += data [ cmd ] ?. [ weekKeys [ i ] ] || 0 ;
111+ cumulative += data [ cmd ] ?. [ weeksToRender [ i ] ] || 0 ;
112112 }
113113 point [ cmd ] = cumulative ;
114114 } ) ;
115115 } else {
116- // Weekly: show each week's data, current week as dot
116+ // Weekly: show each week's data
117117 commands . forEach ( ( cmd ) => {
118- if ( isCurrentWeek ) {
119- point [ cmd ] = null ; // Break the line
120- point [ `${ cmd } _current` ] = data [ cmd ] ?. [ week ] || 0 ;
121- } else {
122- point [ cmd ] = data [ cmd ] ?. [ week ] || 0 ;
123- }
118+ point [ cmd ] = data [ cmd ] ?. [ week ] || 0 ;
124119 } ) ;
125120 }
126121 return point ;
@@ -212,24 +207,13 @@ export function CommandTrendChart({ data, weeks = 13 }: CommandTrendChartProps)
212207 />
213208 < Tooltip
214209 content = { ( { active, payload, label } ) => {
215- // Update external state when tooltip is active
216210 if ( active && payload && payload . length > 0 ) {
217- // Merge _current entries with main entries
218- const merged = new Map < string , { value : number ; color : string } > ( ) ;
219- payload . forEach ( ( p ) => {
220- const name = ( p . name as string ) . replace ( / _ c u r r e n t $ / , "" ) ;
221- const value = ( p . value as number ) ?? 0 ;
222- const existing = merged . get ( name ) ;
223- if ( ! existing || value > 0 ) {
224- merged . set ( name , { value, color : ( p . color as string ) || "#999" } ) ;
225- }
226- } ) ;
227211 const newData : HoverData = {
228212 label : label as string ,
229- items : Array . from ( merged . entries ( ) ) . map ( ( [ name , { value , color } ] ) => ( {
230- name,
231- value,
232- color,
213+ items : payload . map ( ( p ) => ( {
214+ name : p . name as string ,
215+ value : ( p . value as number ) ?? 0 ,
216+ color : ( p . color as string ) || "#999" ,
233217 } ) ) ,
234218 } ;
235219 // Use setTimeout to avoid setState during render
@@ -251,20 +235,6 @@ export function CommandTrendChart({ data, weeks = 13 }: CommandTrendChartProps)
251235 strokeWidth = { 1.5 }
252236 dot = { false }
253237 activeDot = { { r : 3 } }
254- connectNulls = { false }
255- />
256- ) ) }
257- { /* Current week points - shown as dots only in weekly mode */ }
258- { mode === "weekly" && commands . map ( ( cmd , i ) => (
259- < Line
260- key = { `${ cmd } _current` }
261- type = "monotone"
262- dataKey = { `${ cmd } _current` }
263- stroke = { COLORS [ i % COLORS . length ] }
264- strokeWidth = { 0 }
265- dot = { { r : 3 , fill : COLORS [ i % COLORS . length ] , strokeWidth : 0 } }
266- activeDot = { { r : 4 } }
267- legendType = "none"
268238 />
269239 ) ) }
270240 </ LineChart >
0 commit comments