Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chart colors #3557

Merged
merged 1 commit into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/components/Chart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { CHART_COLORS } from 'app/components/Chart/utils';

const DistributionBarChart = ({
dataKey,
chartColors = CHART_COLORS,
distributionData,
}: {
distributionData: DistributionDataPoint[];
chartColors: string[];
dataKey: string;
}) => {
return (
Expand All @@ -33,7 +35,7 @@ const DistributionBarChart = ({
{distributionData.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={CHART_COLORS[index % CHART_COLORS.length]}
fill={chartColors[index % chartColors.length]}
/>
))}
</Bar>
Expand Down
4 changes: 3 additions & 1 deletion app/components/Chart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {

const DistributionPieChart = ({
dataKey,
chartColors = CHART_COLORS,
distributionData,
}: {
distributionData: DistributionDataPoint[];
chartColors: string[];
dataKey: string;
}) => {
return (
Expand All @@ -27,7 +29,7 @@ const DistributionPieChart = ({
{distributionData.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={CHART_COLORS[index % CHART_COLORS.length]}
fill={chartColors[index % chartColors.length]}
/>
))}
</Pie>
Expand Down
6 changes: 6 additions & 0 deletions app/routes/surveys/components/Submissions/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Select from 'react-select';
import DistributionBarChart from 'app/components/Chart/BarChart';
import ChartLabel from 'app/components/Chart/ChartLabel';
import DistributionPieChart from 'app/components/Chart/PieChart';
import { CHART_COLORS } from 'app/components/Chart/utils';
import { selectTheme, selectStyles } from 'app/components/Form/SelectInput';
import InfoBubble from 'app/components/InfoBubble';
import type { SurveyEntity, QuestionEntity } from 'app/reducers/surveys';
Expand Down Expand Up @@ -131,6 +132,9 @@ const Results = ({

return true;
});
const chartColors = CHART_COLORS.filter(
(_, i) => !colorsToRemove.includes(i)
);
const graphType = graphOptions.find(
(a) => a.value === question.displayType
);
Expand All @@ -152,11 +156,13 @@ const Results = ({
{question.displayType !== 'bar_chart' ? (
<DistributionPieChart
distributionData={pieData}
chartColors={chartColors}
dataKey="selections"
/>
) : (
<DistributionBarChart
distributionData={pieData}
chartColors={chartColors}
dataKey="selections"
/>
)}
Expand Down