// Copyright 2019-2020 The Lux Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import React, { Component } from 'react'; import { VegaLite } from 'react-vega'; import SelectableCard from './selectableCard'; import _ from 'lodash'; import { withStyles } from "@material-ui/core/styles"; import Button from '@material-ui/core/Button'; import Tooltip from '@material-ui/core/Tooltip'; interface currentVisProps{ intent:string, currentVisSpec: object, numRecommendations: number, onChange: Function, plottingScale: number } class CurrentVisComponent extends Component { constructor(props:any) { super(props); var initialState = { selected: -1 }; this.state = initialState; } onItemSelected() { if (this.state.selected == 0) { this.setState({ selected: -1 }); this.props.onChange(-2); } else { this.setState({ selected: 0 }); this.props.onChange(-1); } } render() { if (!_.isEmpty(this.props.currentVisSpec)){ var vislib = "vegalite"; var img_str = ""; if ('vislib' in this.props.currentVisSpec && 'config' in this.props.currentVisSpec) { vislib = JSON.stringify(this.props.currentVisSpec['vislib']); vislib = vislib.substring(1, vislib.length - 1); const png_string = JSON.stringify(this.props.currentVisSpec['config']); img_str = "data:image/png;base64," + png_string.substring(1, png_string.length - 1) + "\ "; } if (this.props.numRecommendations == 0) { return (
{vislib === 'matplotlib' ? : }
); } else { const styles = { tooltip: { width: "100px", fontSize: "13px", marginTop: "10px", textAlign: 'center' as const } }; const CustomTooltip = withStyles(styles)(Tooltip); const hasCurrentVis = "vislib" in this.props.currentVisSpec const width: string = (300 + (this.props.plottingScale - 1) * 185).toString() + "px"; return hasCurrentVis ? (
{this.props.currentVisSpec["allcols"] ?

Dataframe Visualization

based on all columns in the dataframe

:

Current Visualization

based on user specified 

}
-1} onClick={(e) => this.onItemSelected()}> {vislib === 'matplotlib' ? : }
) : null; } } else { return (
) } } } export default CurrentVisComponent;