Skip to content

Commit

Permalink
feat: add step overrides to config
Browse files Browse the repository at this point in the history
  • Loading branch information
albaranau committed Jan 21, 2025
1 parent 51477bd commit 24d0cc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/components/MultivariateLegend/MultivariateLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Legend as BiLegend, MCDALegend } from '@konturio/ui-kit';
import { generateMCDALegendColors } from '~utils/mcda/mcdaLegendsUtils';
import { BIVARIATE_LEGEND_SIZE } from '~components/BivariateLegend/const';
import { DEFAULT_MULTIBIVARIATE_STEPS } from '~utils/multivariate/constants';
import { invertClusters } from '~utils/bivariate';
import { invertClusters, type Step } from '~utils/bivariate';
import type { ColorTheme } from '~core/types';
import type { MultivariateLayerConfig } from '~core/logical_layers/renderers/MultivariateRenderer/types';
import type { MCDAConfig } from '~core/logical_layers/renderers/stylesConfigs/mcda/types';
Expand Down Expand Up @@ -30,15 +30,21 @@ function createMCDALegend(mcdaConfig: MCDAConfig): JSX.Element {
return <MCDALegend title={mcdaConfig.name} steps={5} colors={legendColors} />;
}

function createBivariateLegend(score: MCDAConfig, base: MCDAConfig, colors: ColorTheme) {
function createBivariateLegend(
score: MCDAConfig,
base: MCDAConfig,
scoreSteps: Step[],
baseSteps: Step[],
colors: ColorTheme,
) {
const xAxis: MultiBivariateLegendAxisProp = {
label: base.name,
steps: DEFAULT_MULTIBIVARIATE_STEPS,
steps: baseSteps,
quotient: ['', ''],
};
const yAxis: MultiBivariateLegendAxisProp = {
label: score.name,
steps: DEFAULT_MULTIBIVARIATE_STEPS,
steps: scoreSteps,
quotient: ['', ''],
};
const cells = invertClusters(
Expand All @@ -64,6 +70,8 @@ export function MultivariateLegend({ config }: MultivariateLegendProps) {
return createBivariateLegend(
config.score.config,
config.base.config,
config.stepOverrides?.scoreSteps ?? DEFAULT_MULTIBIVARIATE_STEPS,
config.stepOverrides?.baseSteps ?? DEFAULT_MULTIBIVARIATE_STEPS,
config.colors.colors,
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Step } from '~utils/bivariate';
import type { ColorTheme } from '~core/types';
import type { SymbolLayerSpecification } from 'maplibre-gl';
import type {
Expand Down Expand Up @@ -34,6 +35,10 @@ export interface MultivariateLayerConfig {
name: string;
score: MultivariateAxis;
base?: MultivariateAxis;
stepOverrides?: {
baseSteps?: Step[];
scoreSteps?: Step[];
};
strength?: MultivariateAxis | number;
tileLabel?: LabelAxis;
extrusionMin?: MultivariateAxis | number;
Expand Down
6 changes: 4 additions & 2 deletions src/utils/multivariate/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export const DEFAULT_MULTIBIVARIATE_STEPS = [
import type { Step } from '~utils/bivariate';

export const DEFAULT_MULTIBIVARIATE_STEPS: Step[] = [
{
value: 0,
},
{
value: 0.33,
},
{
value: 0.66,
value: 0.67,
},
{
value: 1,
Expand Down
11 changes: 8 additions & 3 deletions src/utils/multivariate/multivariateStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type { ExpressionSpecification, FillLayerSpecification } from 'maplibre-g
export interface MultivaritateBivariateGeneratorProps {
score: MCDALayerStyle['config'];
base: MCDALayerStyle['config'];
baseSteps: Step[];
scoreSteps: Step[];
colors: OverlayColor[];
id?: string;
sourceLayer?: string;
Expand All @@ -43,6 +45,8 @@ export function generateBivariateColorsAndStyleForMultivariateLayer(
const bivariateStyle = createBivariateMultivariateStyle({
score: config.score.config,
base: config.base.config,
baseSteps: config.stepOverrides?.baseSteps ?? DEFAULT_MULTIBIVARIATE_STEPS,
scoreSteps: config.stepOverrides?.scoreSteps ?? DEFAULT_MULTIBIVARIATE_STEPS,
colors,
sourceLayer,
});
Expand Down Expand Up @@ -90,6 +94,8 @@ function setupColorClasses(
function createBivariateMultivariateStyle({
score,
base,
scoreSteps,
baseSteps,
colors,
sourceLayer,
id = 'multivariate-bivariate',
Expand All @@ -107,9 +113,8 @@ function createBivariateMultivariateStyle({
'fill-color': setupColorClasses(
baseValueExpression,
annexValueExpression,
// TODO: multivariate - Where do we get steps from?
DEFAULT_MULTIBIVARIATE_STEPS,
DEFAULT_MULTIBIVARIATE_STEPS,
baseSteps,
scoreSteps,
colorsMap(colors),
),
'fill-opacity': 1,
Expand Down

0 comments on commit 24d0cc7

Please sign in to comment.