Skip to content

Commit

Permalink
Merge pull request #1013 from visualize-admin/fix/table-color-mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski authored Apr 5, 2023
2 parents f7c8ee8 + 7aa283b commit e03a61f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
24 changes: 12 additions & 12 deletions app/configurator/components/filters.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { t, Trans } from "@lingui/macro";
import {
Accordion,
AccordionDetails,
AccordionSummary,
Box,
Button,
ClickAwayListener,
Typography,
Divider,
Theme,
FormControlLabel,
IconButton,
Tooltip,
Accordion,
AccordionSummary,
AccordionDetails,
InputAdornment,
Input,
FormControlLabel,
InputAdornment,
Switch,
Theme,
Tooltip,
Typography,
} from "@mui/material";
import { styled } from "@mui/material/styles";
import { makeStyles } from "@mui/styles";
Expand All @@ -25,7 +25,7 @@ import keyBy from "lodash/keyBy";
import orderBy from "lodash/orderBy";
import sortBy from "lodash/sortBy";
import uniqBy from "lodash/uniqBy";
import React, {
import {
forwardRef,
MouseEventHandler,
MutableRefObject,
Expand Down Expand Up @@ -165,9 +165,9 @@ const getColorConfig = (
return;
}

const path = `${config.activeField}${
colorConfigPath ? `.${colorConfigPath}` : ""
}`;
const path = colorConfigPath
? [config.activeField, colorConfigPath]
: [config.activeField];

return get(config.chartConfig.fields, path) as
| GenericSegmentField
Expand Down
53 changes: 37 additions & 16 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { mapValueIrisToColor } from "@/configurator/components/ui-helpers";
import {
ChartConfig,
ChartType,
ColorMapping,
ColumnStyleCategory,
ConfiguratorState,
ConfiguratorStateConfiguringChart,
ConfiguratorStateSelectingDataSet,
Expand All @@ -53,8 +55,10 @@ import {
isColumnConfig,
isMapConfig,
isSegmentInConfig,
isTableConfig,
} from "@/configurator/config-types";
import { FIELD_VALUE_NONE } from "@/configurator/constants";
import { toggleInteractiveFilterDataDimension } from "@/configurator/interactive-filters/interactive-filters-config-state";
import {
DimensionValue,
canDimensionBeMultiFiltered,
Expand Down Expand Up @@ -89,8 +93,6 @@ import { migrateChartConfig } from "@/utils/chart-config/versioning";
import { createChartId } from "@/utils/create-chart-id";
import { unreachableError } from "@/utils/unreachable";

import { toggleInteractiveFilterDataDimension } from "./interactive-filters/interactive-filters-config-state";

export type ConfiguratorStateAction =
| {
type: "INITIALIZED";
Expand Down Expand Up @@ -1033,20 +1035,39 @@ export const updateColorMapping = (
if (draft.state === "CONFIGURING_CHART") {
const { field, colorConfigPath, dimensionIri, values, random } =
action.value;
const path = `fields.${field}${
colorConfigPath ? `.${colorConfigPath}` : ""
}`;
const fieldValue = get(draft.chartConfig, path) as
| (GenericField & { palette: string })
| undefined;

if (fieldValue?.componentIri === dimensionIri) {
const colorMapping = mapValueIrisToColor({
palette: fieldValue.palette,
dimensionValues: values,
random,
});
setWith(draft.chartConfig, `${path}.colorMapping`, colorMapping);
const path = colorConfigPath
? ["fields", field, colorConfigPath]
: ["fields", field];
let colorMapping: ColorMapping | undefined;

if (isTableConfig(draft.chartConfig)) {
const fieldValue = get(draft.chartConfig, path) as
| ColumnStyleCategory
| undefined;

if (fieldValue) {
colorMapping = mapValueIrisToColor({
palette: fieldValue.palette,
dimensionValues: values,
random,
});
}
} else {
const fieldValue = get(draft.chartConfig, path) as
| (GenericField & { palette: string })
| undefined;

if (fieldValue?.componentIri === dimensionIri) {
colorMapping = mapValueIrisToColor({
palette: fieldValue.palette,
dimensionValues: values,
random,
});
}
}

if (colorMapping) {
setWith(draft.chartConfig, path.concat("colorMapping"), colorMapping);
}
}

Expand Down
14 changes: 12 additions & 2 deletions app/configurator/table/table-chart-options.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { t, Trans } from "@lingui/macro";
import { Box, Alert, Typography } from "@mui/material";
import { Alert, Box, Typography } from "@mui/material";
import get from "lodash/get";
import React, { ChangeEvent, useCallback, useEffect, useRef } from "react";
import { ChangeEvent, useCallback, useEffect, useRef } from "react";

import { Checkbox } from "@/components/form";
import { ColorPalette } from "@/configurator/components/chart-controls/color-palette";
Expand Down Expand Up @@ -194,6 +194,13 @@ export const TableColumnOptions = ({
label: t({ id: "columnStyle.bar", message: `Bar Chart` }),
},
]
: isTemporalDimension(component)
? [
{
value: "text",
label: t({ id: "columnStyle.text", message: `Text` }),
},
]
: [
{
value: "text",
Expand All @@ -204,6 +211,7 @@ export const TableColumnOptions = ({
label: t({ id: "columnStyle.categories", message: `Categories` }),
},
];

return (
<div
key={`control-panel-table-column-${activeField}`}
Expand Down Expand Up @@ -330,8 +338,10 @@ export const TableColumnOptions = ({
) : (
<DimensionValuesMultiFilter
key={component.iri}
field={component.iri}
dimensionIri={component.iri}
dataSetIri={metaData.iri}
colorComponent={component}
colorConfigPath="columnStyle"
/>
)}
Expand Down

1 comment on commit e03a61f

@vercel
Copy link

@vercel vercel bot commented on e03a61f Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-git-main-ixt1.vercel.app
visualization-tool-ixt1.vercel.app
visualization-tool-alpha.vercel.app

Please sign in to comment.