-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show column chart for categorical feature in data explorer (#1355)
* Show column chart for categorical feature in data explorer * address comments
- Loading branch information
1 parent
af01ef4
commit 3a0d2b4
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { IGenericChartProps, JointDataset } from "@responsible-ai/core-ui"; | ||
import { IPlotlyProperty } from "@responsible-ai/mlchartlib"; | ||
import _ from "lodash"; | ||
|
||
interface IDatasetExplorerSeries { | ||
name: string; | ||
color?: any; | ||
data: any[]; | ||
} | ||
|
||
export function getDatasetBar( | ||
jointData: JointDataset, | ||
plotlyProps: IPlotlyProperty, | ||
chartProps?: IGenericChartProps | ||
): IDatasetExplorerSeries[] { | ||
const result: IDatasetExplorerSeries[] = []; | ||
const groupedData = new Map<string, number[]>(); | ||
const customData = plotlyProps.data[0].customdata; | ||
const xData = plotlyProps.data[0].x; | ||
const xDataTypeCount = | ||
chartProps?.xAxis.property && | ||
jointData.metaDict[chartProps.xAxis.property].sortedCategoricalValues | ||
?.length; | ||
|
||
if (customData && xData) { | ||
for (const [i, customDatum] of customData.entries()) { | ||
const yValue = (customDatum as any).Y; | ||
if (!groupedData[yValue]) { | ||
groupedData[yValue] = new Array(xDataTypeCount).fill(0); | ||
} | ||
groupedData[yValue][xData[i]] += 1; | ||
} | ||
} | ||
|
||
if (chartProps?.yAxis.property) { | ||
jointData.metaDict[ | ||
chartProps.yAxis.property | ||
].sortedCategoricalValues?.forEach((value) => { | ||
result.push({ | ||
data: groupedData[value], | ||
name: value | ||
}); | ||
}); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { IGenericChartProps, JointDataset } from "@responsible-ai/core-ui"; | ||
import { IPlotlyProperty } from "@responsible-ai/mlchartlib"; | ||
import _ from "lodash"; | ||
|
||
import { getDatasetBar } from "./getDatasetBar"; | ||
|
||
export function getDatasetBarOption( | ||
jointData: JointDataset, | ||
plotlyProps: IPlotlyProperty, | ||
chartProps?: IGenericChartProps | ||
): any { | ||
const series = getDatasetBar(jointData, plotlyProps, chartProps); | ||
const xAxisProp = chartProps?.xAxis.property; | ||
|
||
return { | ||
chart: { | ||
type: "column" | ||
}, | ||
series, | ||
xAxis: { | ||
categories: | ||
xAxisProp && jointData.metaDict[xAxisProp].sortedCategoricalValues | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters