Skip to content

Commit

Permalink
multiple input cohorts now work for createAutomatically
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwolfmayr committed Sep 17, 2023
1 parent 379619d commit b80aee4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
17 changes: 9 additions & 8 deletions src/Taskview/Taskview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,16 +673,17 @@ export default class Taskview {
taskWithSelectedOutput.push(currTaskParam);
}
}
// Update the input cohorts
this.updateInput();
}

// show the preview for the current task
this.$node.dispatchEvent(new PreviewChangeEvent(taskWithSelectedOutput, this.taskAttributes));
// Update the input cohorts
this.updateInput();

// Add the new cohorts to the output side
this.setOutputCohorts(outputCohorts);
ev.detail.desc[0].attr.forEach((att) => this.addAttributeColumn(att));
}
// show the preview for the current task
this.$node.dispatchEvent(new PreviewChangeEvent(taskWithSelectedOutput, this.taskAttributes));

// Add the new cohorts to the output side
this.setOutputCohorts(outputCohorts);
ev.detail.desc[0].attr.forEach((att) => this.addAttributeColumn(att));
}

async handleFilterEvent(ev: FilterEvent | SplitEvent) {
Expand Down
15 changes: 5 additions & 10 deletions src/Taskview/visualizations/AVegaVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import {
recommendSplit,
createAutomatically, createDBCohortAutomatically
createDBCohortAutomatically
} from './../../base/rest';

export const MISSING_VALUES_LABEL = 'Missing Values';
Expand Down Expand Up @@ -256,7 +256,7 @@ export abstract class AVegaVisualization implements IVegaVisualization {
abstract show(container: HTMLDivElement, attributes: IAttribute[], cohorts: ICohort[]);
abstract filter(): void;
abstract split(): void;
abstract createAutomatically(): void;
abstract createAutomatically?(): void;
abstract showImpl(chart: HTMLDivElement, data: Array<IdValuePair>); // probably the method impl from SingleAttributeVisualization can be moved here

destroy() {
Expand Down Expand Up @@ -700,21 +700,17 @@ export abstract class SingleAttributeVisualization extends AVegaVisualization {

const bins = this.getSelectedData();
let newCohortIds = [];
if (bins.length === 1) { // TODO: what about more than one?
let cohort = bins[0].cohort;
let cohortDescs: INewCohortDesc[];
cohortDescs = [];
for (const cohort of this.cohorts) {
const params: ICohortMultiAttrDBDataParams = {
cohortId: cohort.dbId,
attribute0: this.attribute.dataKey,
attribute0type: this.attribute.type
};
newCohortIds = await createDBCohortAutomatically(params)
console.log("createAutomatically data", newCohortIds);
}

let cohortDescs: INewCohortDesc[];
cohortDescs = [];
// for every selected cohort
for (const cohort of this.cohorts) {
// for every newCohort create a filter (for now... the filter is actually not needed, will be changed in the future)
for (const newCohort of newCohortIds){
cohortDescs.push({
Expand All @@ -724,7 +720,6 @@ export abstract class SingleAttributeVisualization extends AVegaVisualization {
});
}
}

this.container.dispatchEvent(new AutoSplitEvent(cohortDescs));
}

Expand Down
4 changes: 4 additions & 0 deletions src/Taskview/visualizations/AreaChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class AreaChart extends MultiAttributeVisualization {
super(vegaLiteOptions);
}

async createAutomatically() {
log.info('no automatic creation for Area Chart yet');
}

getSpec(data: IdValuePair[]): VegaLiteSpec {
if (!(this.attributes.length === 2 && this.attributes.every((attr) => ['categorical', 'string'].includes(attr.type)))) {
throw new Error(`Area chart requires attributes of type categorical`); // TODO generalize, could also be used for binned numerical
Expand Down
1 change: 0 additions & 1 deletion src/Taskview/visualizations/Scatterplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { AxisType, MultiAttributeVisualization } from './MultiAttributeVisualiza

import {
createDBCohortAutomatically,
createAutomatically
} from '../../base/rest';

export class Scatterplot extends MultiAttributeVisualization {
Expand Down
2 changes: 1 addition & 1 deletion src/data/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class ServerColumnAttribute extends Attribute {
if (autofilter) {
if (Array.isArray(filter)) {
const label = rangeLabel || "label";
return createCohortAutoSplit(cht, niceName(this.id), "label", this.id, filter, newCohortId);
return createCohortAutoSplit(cht, niceName(this.id), "label", this.id, newCohortId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/data/IAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface IAttribute {

filter(cht: ICohort, filter: INumRange[] | IEqualsList, rangeLabel?: string): Promise<ICohort>;

getAutoCohort(cht: ICohort, attribute: IAttribute, newCohortId: number): Promise<ICohort>;
getAutoCohort?(cht: ICohort, attribute: IAttribute, newCohortId: number): Promise<ICohort>;

toJSON();
}

0 comments on commit b80aee4

Please sign in to comment.