Skip to content

Commit bd5c5a7

Browse files
Add extra few days in SuccessRateLine if survey is still running
1 parent 2addf8f commit bd5c5a7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

assets/js/components/charts/SuccessRateLine.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ export default class SuccessRateLine extends Component<Props> {
6868
-1
6969
)
7070
const oneMonthFromStart = d3.timeMonth.offset(initialTime, 1)
71-
lastTime = d3.max([d3.max(data.values, (d) => d.time), oneMonthFromStart])
71+
const surveyLastDay = d3.max(data.values, (d) => d.time)
72+
// Select lastTime to show as max x-axis value in the chart
73+
//
74+
// We want the chart to show at least 1 month.
75+
// If the survey is still running and for more than one month already,
76+
// we add some extra days to give the sense of incompleteness
77+
const lastDay = data.isRunning ? d3.timeDay.offset(surveyLastDay, 5) : surveyLastDay
78+
lastTime = d3.max([lastDay, oneMonthFromStart])
7279
}
7380

7481
const x = d3.scaleTime().domain([initialTime, lastTime]).range([0, width])

assets/js/components/surveys/SurveyShow.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ class SurveyShow extends Component<any, State> {
8787
}
8888
}
8989

90+
surveyIsRunning(survey){
91+
return survey && survey.state == "running"
92+
}
93+
9094
showHistograms() {
9195
const { survey } = this.props
92-
return survey && survey.state == "running"
96+
return this.surveyIsRunning(survey)
9397
}
9498

9599
stopSurvey() {
@@ -201,7 +205,7 @@ class SurveyShow extends Component<any, State> {
201205

202206
let stopComponent = null
203207
let switchComponent = null
204-
if (!readOnly && survey.state == "running") {
208+
if (!readOnly && this.surveyIsRunning(survey)) {
205209
if (project.level == "owner" || project.level == "admin") {
206210
let lockOpenClass, lockClass
207211
if (survey.locked) {
@@ -303,6 +307,7 @@ class SurveyShow extends Component<any, State> {
303307
label: "Success rate",
304308
color: "#000000",
305309
id: "successRate",
310+
isRunning: this.surveyIsRunning(survey),
306311
values: percentages.successRate.map((v) => ({
307312
time: new Date(v.date),
308313
value: Number(v.percent),
@@ -311,7 +316,7 @@ class SurveyShow extends Component<any, State> {
311316

312317

313318
forecasts = forecasts.map((d) => {
314-
if (this.shouldForecast(d, 100, survey.state == "running")) {
319+
if (this.shouldForecast(d, 100, this.surveyIsRunning(survey))) {
315320
return {
316321
...d,
317322
forecast: this.getForecast(d.values[0], d.values[d.values.length - 1], 100),

0 commit comments

Comments
 (0)