Merge pull request #5401 from tsiegleauq/assignment-poll-chart-abstain
Hide abstain bar in assignment polls chart
This commit is contained in:
commit
ff9125fb9f
@ -309,49 +309,55 @@ 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
|
||||||
return {
|
.filter(key => {
|
||||||
data: this.getResultFromPoll(poll, key),
|
return this.getPollDataFieldsByPercentBase(poll).includes(key);
|
||||||
label: key.toUpperCase(),
|
})
|
||||||
backgroundColor: PollColor[key],
|
.map(key => {
|
||||||
hoverBackgroundColor: PollColor[key],
|
return {
|
||||||
barThickness: PollChartBarThickness,
|
data: this.getResultFromPoll(poll, key),
|
||||||
maxBarThickness: PollChartBarThickness
|
label: key.toUpperCase(),
|
||||||
} as ChartDate;
|
backgroundColor: PollColor[key],
|
||||||
});
|
hoverBackgroundColor: PollColor[key],
|
||||||
|
barThickness: PollChartBarThickness,
|
||||||
|
maxBarThickness: PollChartBarThickness
|
||||||
|
} as ChartDate;
|
||||||
|
});
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
private getPollDataFieldsByMethod(poll: PollData | ViewBasePoll): CalculablePollKey[] {
|
||||||
isAssignment = poll.pollClassType === 'assignment';
|
switch (poll.pollmethod) {
|
||||||
} else {
|
case AssignmentPollMethod.YNA: {
|
||||||
isAssignment = Object.keys(poll.options[0]).includes('user');
|
return ['yes', 'no', 'abstain'];
|
||||||
}
|
|
||||||
|
|
||||||
if (isAssignment) {
|
|
||||||
if (poll.pollmethod === AssignmentPollMethod.YNA) {
|
|
||||||
fields = ['yes', 'no', 'abstain'];
|
|
||||||
} else if (poll.pollmethod === AssignmentPollMethod.YN) {
|
|
||||||
fields = ['yes', 'no'];
|
|
||||||
} else {
|
|
||||||
fields = ['yes'];
|
|
||||||
}
|
}
|
||||||
} else {
|
case AssignmentPollMethod.YN: {
|
||||||
if (poll.onehundred_percent_base === PercentBase.YN) {
|
return ['yes', 'no'];
|
||||||
fields = ['yes', 'no'];
|
}
|
||||||
} else if (poll.onehundred_percent_base === PercentBase.Cast) {
|
default: {
|
||||||
fields = ['yes', 'no', 'abstain', 'votesinvalid'];
|
return ['yes'];
|
||||||
} 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