1
1
import "chartjs-adapter-date-fns" ;
2
2
import { useTheme } from "@emotion/react" ;
3
- import LaunchOutlined from "@mui/icons-material/LaunchOutlined" ;
4
- import Button from "@mui/material/Button" ;
5
3
import {
6
4
CategoryScale ,
7
5
Chart as ChartJS ,
@@ -16,7 +14,6 @@ import {
16
14
Tooltip ,
17
15
defaults ,
18
16
} from "chart.js" ;
19
- import annotationPlugin from "chartjs-plugin-annotation" ;
20
17
import {
21
18
HelpTooltip ,
22
19
HelpTooltipContent ,
@@ -38,51 +35,32 @@ ChartJS.register(
38
35
Title ,
39
36
Tooltip ,
40
37
Legend ,
41
- annotationPlugin ,
42
38
) ;
43
39
44
- export interface DataSeries {
45
- label ?: string ;
46
- data : readonly { date : string ; amount : number } [ ] ;
47
- color ?: string ; // Optional custom color
48
- }
49
-
50
40
export interface ActiveUserChartProps {
51
- series : DataSeries [ ] ;
52
- userLimit ?: number ;
41
+ data : readonly { date : string ; amount : number } [ ] ;
53
42
interval : "day" | "week" ;
54
43
}
55
44
56
45
export const ActiveUserChart : FC < ActiveUserChartProps > = ( {
57
- series,
58
- userLimit,
46
+ data,
59
47
interval,
60
48
} ) => {
61
49
const theme = useTheme ( ) ;
62
50
51
+ const labels = data . map ( ( val ) => dayjs ( val . date ) . format ( "YYYY-MM-DD" ) ) ;
52
+ const chartData = data . map ( ( val ) => val . amount ) ;
53
+
63
54
defaults . font . family = theme . typography . fontFamily as string ;
64
55
defaults . color = theme . palette . text . secondary ;
65
56
66
57
const options : ChartOptions < "line" > = {
67
58
responsive : true ,
68
59
animation : false ,
69
- interaction : {
70
- mode : "index" ,
71
- } ,
72
60
plugins : {
73
- legend :
74
- series . length > 1
75
- ? {
76
- display : false ,
77
- position : "top" as const ,
78
- labels : {
79
- usePointStyle : true ,
80
- pointStyle : "line" ,
81
- } ,
82
- }
83
- : {
84
- display : false ,
85
- } ,
61
+ legend : {
62
+ display : false ,
63
+ } ,
86
64
tooltip : {
87
65
displayColors : false ,
88
66
callbacks : {
@@ -92,24 +70,6 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
92
70
} ,
93
71
} ,
94
72
} ,
95
- annotation : {
96
- annotations : [
97
- {
98
- type : "line" ,
99
- scaleID : "y" ,
100
- value : userLimit ,
101
- borderColor : "white" ,
102
- borderWidth : 2 ,
103
- label : {
104
- content : "Active User limit" ,
105
- color : theme . palette . primary . contrastText ,
106
- display : true ,
107
- textStrokeWidth : 2 ,
108
- textStrokeColor : theme . palette . background . paper ,
109
- } ,
110
- } ,
111
- ] ,
112
- } ,
113
73
} ,
114
74
scales : {
115
75
y : {
@@ -118,12 +78,11 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
118
78
ticks : {
119
79
precision : 0 ,
120
80
} ,
121
- stacked : true ,
122
81
} ,
123
82
x : {
124
83
grid : { color : theme . palette . divider } ,
125
84
ticks : {
126
- stepSize : series [ 0 ] . data . length > 10 ? 2 : undefined ,
85
+ stepSize : data . length > 10 ? 2 : undefined ,
127
86
} ,
128
87
type : "time" ,
129
88
time : {
@@ -138,16 +97,16 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
138
97
< Line
139
98
data-chromatic = "ignore"
140
99
data = { {
141
- labels : series [ 0 ] . data . map ( ( val ) =>
142
- dayjs ( val . date ) . format ( "YYYY-MM-DD" ) ,
143
- ) ,
144
- datasets : series . map ( ( s ) => ( {
145
- label : s . label ,
146
- data : s . data . map ( ( val ) => val . amount ) ,
147
- pointBackgroundColor : s . color || theme . roles . active . outline ,
148
- pointBorderColor : s . color || theme . roles . active . outline ,
149
- borderColor : s . color || theme . roles . active . outline ,
150
- } ) ) ,
100
+ labels : labels ,
101
+ datasets : [
102
+ {
103
+ label : ` ${ interval === "day" ? "Daily" : "Weekly" } Active Users` ,
104
+ data : chartData ,
105
+ pointBackgroundColor : theme . roles . active . outline ,
106
+ pointBorderColor : theme . roles . active . outline ,
107
+ borderColor : theme . roles . active . outline ,
108
+ } ,
109
+ ] ,
151
110
} }
152
111
options = { options }
153
112
/>
@@ -161,13 +120,11 @@ type ActiveUsersTitleProps = {
161
120
export const ActiveUsersTitle : FC < ActiveUsersTitleProps > = ( { interval } ) => {
162
121
return (
163
122
< div css = { { display : "flex" , alignItems : "center" , gap : 8 } } >
164
- { interval === "day" ? "Daily" : "Weekly" } User Activity
123
+ { interval === "day" ? "Daily" : "Weekly" } Active Users
165
124
< HelpTooltip >
166
125
< HelpTooltipTrigger size = "small" />
167
126
< HelpTooltipContent >
168
- < HelpTooltipTitle >
169
- How do we calculate user activity?
170
- </ HelpTooltipTitle >
127
+ < HelpTooltipTitle > How do we calculate active users?</ HelpTooltipTitle >
171
128
< HelpTooltipText >
172
129
When a connection is initiated to a user's workspace they are
173
130
considered an active user. e.g. apps, web terminal, SSH. This is for
@@ -179,39 +136,3 @@ export const ActiveUsersTitle: FC<ActiveUsersTitleProps> = ({ interval }) => {
179
136
</ div >
180
137
) ;
181
138
} ;
182
-
183
- export type UserStatusTitleProps = {
184
- interval : "day" | "week" ;
185
- } ;
186
-
187
- export const UserStatusTitle : FC < UserStatusTitleProps > = ( { interval } ) => {
188
- return (
189
- < div css = { { display : "flex" , alignItems : "center" , gap : 8 } } >
190
- { interval === "day" ? "Daily" : "Weekly" } User Status
191
- < HelpTooltip >
192
- < HelpTooltipTrigger size = "small" />
193
- < HelpTooltipContent >
194
- < HelpTooltipTitle > What are user statuses?</ HelpTooltipTitle >
195
- < HelpTooltipText
196
- css = { { display : "flex" , gap : 8 , flexDirection : "column" } }
197
- >
198
- < span >
199
- Active users count towards your license consumption. Dormant or
200
- suspended users do not. Any user who has logged into the coder
201
- platform within the last 90 days is considered active.
202
- </ span >
203
- < Button
204
- component = "a"
205
- startIcon = { < LaunchOutlined /> }
206
- href = "https://coder.com/docs/admin/users#user-status"
207
- target = "_blank"
208
- rel = "noreferrer"
209
- >
210
- Read the docs
211
- </ Button >
212
- </ HelpTooltipText >
213
- </ HelpTooltipContent >
214
- </ HelpTooltip >
215
- </ div >
216
- ) ;
217
- } ;
0 commit comments