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

Update pie and bar colors to their hovered versions #242

Merged
merged 1 commit into from
Oct 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions frontend/src/Components/Charts/Contraband/Contraband.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Contraband(props) {
axios
.get(url)
.then((res) => {
const colors = ['#80d9d8', '#beb4fa', '#ca8794', '#ffeeb2', '#8598ac', '#cab6c7'];
const colors = ['#02bcbb', '#8879fc', '#9c0f2e', '#ffe066', '#0c3a66', '#9e7b9b'];
const data = {
labels: ['White', 'Black', 'Hispanic', 'Asian', 'Native American', 'Other'],
datasets: [
Expand All @@ -150,6 +150,7 @@ function Contraband(props) {
fill: false,
backgroundColor: colors,
borderColor: colors,
hoverBackgroundColor: colors,
borderWidth: 1,
},
],
Expand All @@ -168,9 +169,9 @@ function Contraband(props) {
.get(url)
.then((res) => {
const colors = {
'Safety Violation': '#CFA9D6',
'Regulatory Equipment': '#ffa500',
Other: '#ACE1AF',
'Safety Violation': '#b173bc',
'Regulatory Equipment': '#e69500',
Other: '#7dd082',
};
const stopPurposeDataSets = res.data.map((ds) => ({
axis: 'x',
Expand All @@ -179,6 +180,7 @@ function Contraband(props) {
fill: false,
backgroundColor: colors[ds.stop_purpose],
borderColor: colors[ds.stop_purpose],
hoverBackgroundColor: colors[ds.stop_purpose],
borderWidth: 1,
}));
const data = {
Expand All @@ -199,18 +201,19 @@ function Contraband(props) {
.get(url)
.then((res) => {
const colors = {
Drugs: '#feaba6',
Alcohol: '#86c6dd',
Weapons: '#c2e9bf',
Money: '#dbc3df',
Other: '#ffd4a0',
Drugs: '#3C91E6',
Alcohol: '#9FD356',
Weapons: '#ED217C',
Money: '#EFCEFA',
Other: '#2F4858',
};
const stopPurposeDataSets = res.data.map((sp) => ({
labels: ['W', 'B', 'H', 'A', 'NA', 'O'],
datasets: sp.data.map((ds) => ({
label: ds.contraband,
data: ds.data,
backgroundColor: colors[ds.contraband],
hoverBackgroundColor: colors[ds.contraband],
})),
}));
setContrabandGroupedStopPurposeData(stopPurposeDataSets);
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/Components/Charts/TrafficStops/TrafficStops.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ function TrafficStops(props) {
STATIC_LEGEND_KEYS.map((k) => ({ ...k }))
);

const pieColors = ['#02bcbb', '#8879fc', '#9c0f2e', '#ffe066', '#0c3a66', '#9e7b9b'];

const [byPercentageLineData, setByPercentageLineData] = useState([]);
const pieChartLabels = ['White', 'Black', 'Hispanic', 'Asian', 'Native American', 'Other'];
const pieChartConfig = {
backgroundColor: ['#80d9d8', '#beb4fa', '#ca8794', '#ffeeb2', '#8598ac', '#cab6c7'],
borderColor: ['#02bcbb', '#8879fc', '#9c0f2e', '#ffe066', '#0c3a66', '#9e7b9b'],
backgroundColor: pieColors,
borderColor: pieColors,
hoverBackgroundColor: pieColors,
borderWidth: 1,
};
const [byPercentagePieData, setByPercentagePieData] = useState({
Expand All @@ -120,8 +123,9 @@ function TrafficStops(props) {
max_step_size: null,
});
const groupedPieChartConfig = {
backgroundColor: ['#80d9d8', '#beb4fa', '#ca8794', '#ffeeb2', '#8598ac', '#cab6c7'],
borderColor: ['#02bcbb', '#8879fc', '#9c0f2e', '#ffe066', '#0c3a66', '#9e7b9b'],
backgroundColor: pieColors,
borderColor: pieColors,
hoverBackgroundColor: pieColors,
borderWidth: 1,
};
const groupedPieChartLabels = ['White', 'Black', 'Hispanic', 'Asian', 'Native American', 'Other'];
Expand Down
4 changes: 2 additions & 2 deletions nc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ def create_dataset(self, contraband_qs, stop_purpose, *args, **kwargs):
}
for c in self.columns:
searches_df = self.create_searches_df(searches_qs, year)
if not searches_df:
if not searches_df or searches_df.empty:
continue
contraband_df = self.create_contraband_df(contraband_qs, contraband)

Expand Down Expand Up @@ -978,7 +978,7 @@ def get(self, request, agency_id):
contraband_qs = self.get_qs(Q(stop__agency__id=agency_id, person__type="D"), year)

contraband_df = self.create_contraband_df(contraband_qs, contraband_type)
if not contraband_df:
if not contraband_df or contraband_df.empty:
return Response(data={}, status=200)
contraband_df = contraband_df[contraband_df["stop_purpose_group"] == grouped_stop_purpose]
contraband_df = contraband_df[contraband_df[contraband_type] == True] # noqa E712
Expand Down