import React from "react"; import styles from "../App.module.css"; import cx from "../utils/cx"; import Feature from "./Feature"; import Spinner from "./Spinner"; import LabelButton from "./LabelButton"; import Contributions from "./Contributions"; import { VisualizationOutput } from "../models/visualizationOutput"; interface VisualizationProps { data: VisualizationOutput; instance: number; onTargetClick: ( labelIndex: number, inputIndex: number, modelIndex: number, callback: () => void ) => void; } interface VisualizationState { loading: boolean; } class Visualization extends React.Component< VisualizationProps, VisualizationState > { constructor(props: VisualizationProps) { super(props); this.state = { loading: false, }; } onTargetClick = ( labelIndex: number, inputIndex: number, modelIndex: number ) => { this.setState({ loading: true }); this.props.onTargetClick(labelIndex, inputIndex, modelIndex, () => this.setState({ loading: false }) ); }; //TODO: Refactor the visualization table as a instead of columns, in order to have cleaner styling render() { const data = this.props.data; const isFirstInGroup = this.props.data.model_index === 0; const features = data.feature_outputs.map((f) => ( )); return ( <> {this.state.loading && (
)} {!isFirstInGroup &&
}
{isFirstInGroup && (
Predicted
)}
Model {data.model_index + 1}
{data.predicted.map((p) => (
{p.label} ({p.score.toFixed(3)})
))}
{isFirstInGroup && (
Label
)}
{data.actual.label}
{isFirstInGroup && (
Contribution
)}
{features}
); } } export default Visualization;