Skip to content

Commit

Permalink
chore: turn params into an object
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloster committed Oct 8, 2024
1 parent 755bc11 commit e349e72
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 56 deletions.
42 changes: 21 additions & 21 deletions client/__tests__/util/stateManager/colorHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions client/src/components/Graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1133,24 +1133,24 @@ class Graph extends React.Component<GraphProps, GraphState> {

/* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ class Category extends React.PureComponent<CategoryProps> {
colorMode === "color by categorical metadata",
colorAccessor,
colorMode,
colorTable: createColorTable(
colorTable: createColorTable({
colorMode,
colorAccessor,
colorData,
colorByAccessor: colorAccessor,
colorByData: colorData,
schema,
userColors,
false
),
isSpatial: false,
}),
};
}

Expand Down
10 changes: 5 additions & 5 deletions client/src/components/Legend/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ class ContinuousLegend extends React.Component<Props> {
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];
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/scatterplot/scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 17 additions & 8 deletions client/src/util/stateManager/colorHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e349e72

Please sign in to comment.