Hide abstain bar in assignment polls chart
If the percent base does not include "abstain", the grey abstain bar will not be shown in the assignment poll chart
This commit is contained in:
parent
8451cd2d88
commit
6efdc9a3dd
@ -309,7 +309,11 @@ export abstract class PollService {
|
|||||||
public generateChartData(poll: PollData | ViewBasePoll): ChartData {
|
public generateChartData(poll: PollData | ViewBasePoll): ChartData {
|
||||||
const fields = this.getPollDataFields(poll);
|
const fields = this.getPollDataFields(poll);
|
||||||
|
|
||||||
const data: ChartData = fields.map(key => {
|
const data: ChartData = fields
|
||||||
|
.filter(key => {
|
||||||
|
return this.getPollDataFieldsByPercentBase(poll).includes(key);
|
||||||
|
})
|
||||||
|
.map(key => {
|
||||||
return {
|
return {
|
||||||
data: this.getResultFromPoll(poll, key),
|
data: this.getResultFromPoll(poll, key),
|
||||||
label: key.toUpperCase(),
|
label: key.toUpperCase(),
|
||||||
@ -324,34 +328,36 @@ export abstract class PollService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getPollDataFields(poll: PollData | ViewBasePoll): CalculablePollKey[] {
|
protected getPollDataFields(poll: PollData | ViewBasePoll): CalculablePollKey[] {
|
||||||
let fields: CalculablePollKey[];
|
const isAssignment: boolean = (poll as ViewBasePoll).pollClassType === 'assignment';
|
||||||
let isAssignment: boolean;
|
return isAssignment ? this.getPollDataFieldsByMethod(poll) : this.getPollDataFieldsByPercentBase(poll);
|
||||||
|
|
||||||
if (poll instanceof ViewBasePoll) {
|
|
||||||
isAssignment = poll.pollClassType === 'assignment';
|
|
||||||
} else {
|
|
||||||
isAssignment = Object.keys(poll.options[0]).includes('user');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAssignment) {
|
private getPollDataFieldsByMethod(poll: PollData | ViewBasePoll): CalculablePollKey[] {
|
||||||
if (poll.pollmethod === AssignmentPollMethod.YNA) {
|
switch (poll.pollmethod) {
|
||||||
fields = ['yes', 'no', 'abstain'];
|
case AssignmentPollMethod.YNA: {
|
||||||
} else if (poll.pollmethod === AssignmentPollMethod.YN) {
|
return ['yes', 'no', 'abstain'];
|
||||||
fields = ['yes', 'no'];
|
}
|
||||||
} else {
|
case AssignmentPollMethod.YN: {
|
||||||
fields = ['yes'];
|
return ['yes', 'no'];
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return ['yes'];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (poll.onehundred_percent_base === PercentBase.YN) {
|
|
||||||
fields = ['yes', 'no'];
|
|
||||||
} else if (poll.onehundred_percent_base === PercentBase.Cast) {
|
|
||||||
fields = ['yes', 'no', 'abstain', 'votesinvalid'];
|
|
||||||
} else {
|
|
||||||
fields = ['yes', 'no', 'abstain'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
private getPollDataFieldsByPercentBase(poll: PollData | ViewBasePoll): CalculablePollKey[] {
|
||||||
|
switch (poll.onehundred_percent_base) {
|
||||||
|
case PercentBase.YN: {
|
||||||
|
return ['yes', 'no'];
|
||||||
|
}
|
||||||
|
case PercentBase.Cast: {
|
||||||
|
return ['yes', 'no', 'abstain', 'votesinvalid'];
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return ['yes', 'no', 'abstain'];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user