diff --git a/client/__tests__/util/stateManager/colorHelpers.test.ts b/client/__tests__/util/stateManager/colorHelpers.test.ts index 505de8668..213db54d2 100644 --- a/client/__tests__/util/stateManager/colorHelpers.test.ts +++ b/client/__tests__/util/stateManager/colorHelpers.test.ts @@ -89,14 +89,14 @@ describe("categorical color helpers", () => { ); test("default category order", () => { - const ct = createColorTable( - "color by categorical metadata", - "categoricalColumn", - obsDataframe, + const ct = createColorTable({ + colorMode: "color by categorical metadata", + colorByAccessor: "categoricalColumn", + colorByData: obsDataframe, schema, - null, - isSpatial - ); + userColors: null, + isSpatial, + }); expect(ct).toBeDefined(); const data = obsDataframe.col("categoricalColumn").asArray(); const cats = schema.annotations.obsByName.categoricalColumn.categories; @@ -108,14 +108,14 @@ describe("categorical color helpers", () => { test("shuffle category order", () => { const schemaClone = indexSchema(JSON.parse(JSON.stringify(schema))); shuffle(schemaClone.annotations.obsByName.categoricalColumn.categories); - const ct = createColorTable( - "color by categorical metadata", - "categoricalColumn", - obsDataframe, - schemaClone, - null, - isSpatial - ); + const ct = createColorTable({ + colorMode: "color by categorical metadata", + colorByAccessor: "categoricalColumn", + colorByData: obsDataframe, + schema: schemaClone, + userColors: null, + isSpatial, + }); expect(ct).toBeDefined(); const data = obsDataframe.col("categoricalColumn").asArray(); const cats = schemaClone.annotations.obsByName.categoricalColumn.categories; @@ -144,14 +144,14 @@ describe("categorical color helpers", () => { const userColors = loadUserColorConfig(userDefinedColorTable); expect(userColors).toBeDefined(); - const ct = createColorTable( - "color by categorical metadata", - "categoricalColumn", - obsDataframe, + const ct = createColorTable({ + colorMode: "color by categorical metadata", + colorByAccessor: "categoricalColumn", + colorByData: obsDataframe, schema, userColors, - isSpatial - ); + isSpatial, + }); expect(ct).toBeDefined(); const data = obsDataframe.col("categoricalColumn").asArray(); for (let i = 0; i < schema.dataframe.nObs; i += 1) { diff --git a/client/src/components/Graph/Graph.tsx b/client/src/components/Graph/Graph.tsx index de1930e8d..0088941fb 100644 --- a/client/src/components/Graph/Graph.tsx +++ b/client/src/components/Graph/Graph.tsx @@ -1133,24 +1133,24 @@ class Graph extends React.Component { /* update color table state */ if (!colors || !colorDf) { - return createColorTable( - null, // default mode - null, - null, + return createColorTable({ + colorMode: null, // default mode + colorByAccessor: null, + colorByData: null, schema, - null, - isSpatial - ); + userColors: null, + isSpatial, + }); } const { colorAccessor, userColors, colorMode } = colors; - return createColorTable( + return createColorTable({ colorMode, - colorAccessor, - colorDf, + colorByAccessor: colorAccessor, + colorByData: colorDf, schema, userColors, - isSpatial - ); + isSpatial, + }); } createColorByQuery(colors: RootState["colors"]): [Field, Query] | null { diff --git a/client/src/components/LeftSidebar/components/Categorical/components/Category/Category.tsx b/client/src/components/LeftSidebar/components/Categorical/components/Category/Category.tsx index 8af277c56..ee916d917 100644 --- a/client/src/components/LeftSidebar/components/Categorical/components/Category/Category.tsx +++ b/client/src/components/LeftSidebar/components/Categorical/components/Category/Category.tsx @@ -253,14 +253,14 @@ class Category extends React.PureComponent { colorMode === "color by categorical metadata", colorAccessor, colorMode, - colorTable: createColorTable( + colorTable: createColorTable({ colorMode, - colorAccessor, - colorData, + colorByAccessor: colorAccessor, + colorByData: colorData, schema, userColors, - false - ), + isSpatial: false, + }), }; } diff --git a/client/src/components/Legend/Legend.tsx b/client/src/components/Legend/Legend.tsx index 03a913770..ddb35a03a 100644 --- a/client/src/components/Legend/Legend.tsx +++ b/client/src/components/Legend/Legend.tsx @@ -183,14 +183,14 @@ class ContinuousLegend extends React.Component { const colorDf = colorQuery ? await annoMatrix.fetch(...colorQuery, globals.numBinsObsX) : null; - const colorTable = createColorTable( + const colorTable = createColorTable({ colorMode, - colorAccessor, - colorDf, + colorByAccessor: colorAccessor, + colorByData: colorDf, schema, userColors, - false - ); + isSpatial: false, + }); const colorScale = colorTable.scale; const range = (colorScale?.range ?? (() => [0, 0])) as ColorRange; const [domainMin, domainMax] = colorScale?.domain?.() ?? [0, 0]; diff --git a/client/src/components/scatterplot/scatterplot.tsx b/client/src/components/scatterplot/scatterplot.tsx index 9030e31a6..8465f10e7 100644 --- a/client/src/components/scatterplot/scatterplot.tsx +++ b/client/src/components/scatterplot/scatterplot.tsx @@ -349,14 +349,14 @@ class Scatterplot extends React.PureComponent<{}, State> { const { annoMatrix } = this.props; const { schema } = annoMatrix; const { colorAccessor, userColors, colorMode } = colors; - return createColorTable( + return createColorTable({ colorMode, - colorAccessor, - colorDf, + colorByAccessor: colorAccessor, + colorByData: colorDf, schema, userColors, - false - ); + isSpatial: false, + }); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. diff --git a/client/src/util/stateManager/colorHelpers.ts b/client/src/util/stateManager/colorHelpers.ts index 4c42950ff..00000c1f0 100644 --- a/client/src/util/stateManager/colorHelpers.ts +++ b/client/src/util/stateManager/colorHelpers.ts @@ -125,14 +125,23 @@ export interface ColorTable { * @param isSpatial - is in spatial mode * @returns colors scale and RGB array as an object */ -function _createColorTable( - colorMode: string | null, - colorByAccessor: LabelType | null, - colorByData: Dataframe | null, - schema: Schema, - userColors: ConvertedUserColors | null = null, - isSpatial: boolean -): ColorTable { +function _createColorTable(params: { + colorMode: string | null; + colorByAccessor: LabelType | null; + colorByData: Dataframe | null; + schema: Schema; + userColors?: ConvertedUserColors | null; + isSpatial: boolean; +}): ColorTable { + const { + colorMode, + colorByAccessor, + colorByData, + schema, + userColors = null, + isSpatial, + } = params; + if (colorMode === null || colorByData === null) { return defaultColors(schema.dataframe.nObs, isSpatial); }