Skip to content

Commit

Permalink
Merge pull request #1288 from visualize-admin/feat/segment-by-tempora…
Browse files Browse the repository at this point in the history
…l-dimensions

feat: Temporal segmentations
  • Loading branch information
bprusinowski authored Dec 8, 2023
2 parents 7e28592 + f6071d7 commit 78582b7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

- Features
- Localized cube landing pages are now supported (dcat:landingPage) 🌎
- Temporal dimensions can now be used as segmentation fields (excluding area and line charts)
- Fixes
- Copying a link to a new visualization from a dataset preview now correctly includes a data source

Expand Down
1 change: 1 addition & 0 deletions app/charts/chart-config-ui-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ interface ChartSpecs {
const SEGMENT_COMPONENT_TYPES: ComponentType[] = [
"NominalDimension",
"OrdinalDimension",
"TemporalDimension",
"TemporalOrdinalDimension",
"GeoCoordinatesDimension",
"GeoShapesDimension",
Expand Down
54 changes: 33 additions & 21 deletions app/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,17 +999,23 @@ const chartConfigsAdjusters: ChartConfigsAdjusters = {
}
} else {
const oldSegment = oldValue as Exclude<typeof oldValue, TableFields>;
newSegment = {
componentIri: oldSegment.componentIri,
palette: oldSegment.palette,
colorMapping: oldSegment.colorMapping,
sorting:
"sorting" in oldSegment &&
oldSegment.sorting &&
"sortingOrder" in oldSegment.sorting
? oldSegment.sorting ?? DEFAULT_FIXED_COLOR_FIELD
: DEFAULT_SORTING,
};
const segmentDimension = dimensions.find(
(d) => d.iri === oldValue.componentIri
);

if (!isTemporalDimension(segmentDimension)) {
newSegment = {
componentIri: oldSegment.componentIri,
palette: oldSegment.palette,
colorMapping: oldSegment.colorMapping,
sorting:
"sorting" in oldSegment &&
oldSegment.sorting &&
"sortingOrder" in oldSegment.sorting
? oldSegment.sorting ?? DEFAULT_FIXED_COLOR_FIELD
: DEFAULT_SORTING,
};
}
}

return produce(newChartConfig, (draft) => {
Expand Down Expand Up @@ -1084,16 +1090,22 @@ const chartConfigsAdjusters: ChartConfigsAdjusters = {
}
} else {
const oldSegment = oldValue as Exclude<typeof oldValue, TableFields>;
newSegment = {
componentIri: oldSegment.componentIri,
palette: oldSegment.palette,
colorMapping: oldSegment.colorMapping,
sorting: adjustSegmentSorting({
segment: oldSegment,
acceptedValues: AREA_SEGMENT_SORTING.map((d) => d.sortingType),
defaultValue: "byTotalSize",
}),
};
const segmentDimension = dimensions.find(
(d) => d.iri === oldValue.componentIri
);

if (!isTemporalDimension(segmentDimension)) {
newSegment = {
componentIri: oldSegment.componentIri,
palette: oldSegment.palette,
colorMapping: oldSegment.colorMapping,
sorting: adjustSegmentSorting({
segment: oldSegment,
acceptedValues: AREA_SEGMENT_SORTING.map((d) => d.sortingType),
defaultValue: "byTotalSize",
}),
};
}
}

return produce(newChartConfig, (draft) => {
Expand Down
3 changes: 2 additions & 1 deletion app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,8 @@ const ChartFieldMultiFilter = ({
<legend style={{ display: "none" }}>
<Trans id="controls.section.filter">Filter</Trans>
</legend>
{isTemporalDimension(component) ? (
{/* For temporal-based segments, we want to treat values as nominal. */}
{isTemporalDimension(component) && field !== "segment" ? (
<TimeFilter
dimension={component}
disableInteractiveFilters={encoding.disableInteractiveFilters}
Expand Down

1 comment on commit 78582b7

@vercel
Copy link

@vercel vercel bot commented on 78582b7 Dec 8, 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-alpha.vercel.app
visualization-tool-git-main-ixt1.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.