Skip to content

Commit

Permalink
#3221: Charts | Tree: A setting to not show nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksashka11 committed Jan 20, 2025
1 parent 7e1672a commit f1631e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 9 additions & 2 deletions packages/Charts/src/utils/tree-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class TreeUtils {

static async toTree(dataFrame: DG.DataFrame, splitByColumnNames: string[], rowMask: DG.BitSet,
visitNode: ((arg0: TreeDataType) => void) | null = null, aggregations:
AggregationInfo[] = [], linkSelection: boolean = true, selection?: boolean, inherit?: boolean): Promise<TreeDataType> {
AggregationInfo[] = [], linkSelection: boolean = true, selection?: boolean, inherit?: boolean, includeNulls?: boolean): Promise<TreeDataType> {
const data: TreeDataType = {
name: 'All',
value: 0,
Expand All @@ -27,7 +27,14 @@ export class TreeUtils {
builder.add(aggregation.type, aggregation.columnName, aggregation.propertyName);
}

const aggregated = builder.aggregate();
let aggregated = builder.aggregate();
if (!includeNulls) {
const colList: DG.Column[] = aggregated.columns.toList().filter((col) => splitByColumnNames.includes(col.name));
const filter = DG.BitSet.create(aggregated.rowCount, (rowI: number) => {
return colList.every((col) => !col.isNone(rowI));
});
aggregated = aggregated.clone(filter);
}

if (linkSelection) {
grok.data.linkTables(dataFrame, aggregated, splitByColumnNames,
Expand Down
7 changes: 4 additions & 3 deletions packages/Charts/src/viewers/tree/tree-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class TreeViewer extends EChartViewer {
fontSize: number;
showCounts: boolean;
onClick: onClickOptions;
includeNulls: boolean;

constructor() {
super();
Expand All @@ -66,6 +67,7 @@ export class TreeViewer extends EChartViewer {
this.fontSize = this.int('fontSize', 12);
this.showCounts = this.bool('showCounts', false);
this.onClick = <onClickOptions> this.string('onClick', 'Select', { choices: ['Select', 'Filter']});
this.includeNulls = this.bool('includeNulls', true);

this.option = {
series: [
Expand Down Expand Up @@ -188,7 +190,7 @@ export class TreeViewer extends EChartViewer {
this.rowSource = rowSourceMap[this.onClick as onClickOptions] || this.rowSource;
if (p?.name === 'hierarchyColumnNames' || p?.name === 'sizeColumnName' ||
p?.name === 'sizeAggrType' || p?.name === 'colorColumnName' || p?.name === 'colorAggrType' ||
p?.name === 'fontSize' || p?.name === 'showCounts') {
p?.name === 'fontSize' || p?.name === 'showCounts' || p?.name === 'includeNulls') {
if (p?.name === 'hierarchyColumnNames')
this.chart.clear();
if (p?.name === 'colorColumnName' || p?.name === 'colorAggrType')
Expand Down Expand Up @@ -260,8 +262,7 @@ export class TreeViewer extends EChartViewer {
if (this.colorColumnName && this.applyColorAggr)
aggregations.push({ type: <DG.AggregationType> this.colorAggrType,
columnName: this.colorColumnName, propertyName: 'color' });

return [await TreeUtils.toTree(this.dataFrame, this.hierarchyColumnNames, this.filter, null, aggregations)];
return [await TreeUtils.toTree(this.dataFrame, this.hierarchyColumnNames, this.filter, null, aggregations, true, undefined, undefined, this.includeNulls)];
}

render(): void {
Expand Down

0 comments on commit f1631e3

Please sign in to comment.