import $ from 'jquery'; import React, { PropTypes } from 'react'; import { connect } from 'react-redux'; import { Panel } from 'react-bootstrap'; import visMap from '../../../visualizations/main'; import { d3format } from '../../modules/utils'; import ExploreActionButtons from '../../explore/components/ExploreActionButtons'; const propTypes = { can_download: PropTypes.bool.isRequired, slice_name: PropTypes.string.isRequired, viz_type: PropTypes.string.isRequired, height: PropTypes.string.isRequired, containerId: PropTypes.string.isRequired, json_endpoint: PropTypes.string.isRequired, csv_endpoint: PropTypes.string.isRequired, standalone_endpoint: PropTypes.string.isRequired, query: PropTypes.string.isRequired, column_formats: PropTypes.object, data: PropTypes.any, isChartLoading: PropTypes.bool, }; class ChartContainer extends React.Component { constructor(props) { super(props); this.state = { selector: `#${props.containerId}`, mockSlice: {}, }; } componentWillMount() { this.setState({ mockSlice: this.getMockedSliceObject(this.props) }); } componentDidMount() { this.renderVis(); } componentWillReceiveProps(nextProps) { this.setState({ mockSlice: this.getMockedSliceObject(nextProps) }); } componentDidUpdate() { this.renderVis(); } getMockedSliceObject(props) { return { viewSqlQuery: props.query, data: { csv_endpoint: props.csv_endpoint, json_endpoint: props.json_endpoint, standalone_endpoint: props.standalone_endpoint, }, containerId: props.containerId, jsonEndpoint: () => props.json_endpoint, container: { html: (data) => { // this should be a callback to clear the contents of the slice container $(this.state.selector).html(data); }, css: (dim, size) => { // dimension can be 'height' // pixel string can be '300px' // should call callback to adjust height of chart $(this.state.selector).css(dim, size); }, height: () => parseInt(props.height, 10) - 100, show: () => { this.render(); }, get: (n) => ($(this.state.selector).get(n)), find: (classname) => ($(this.state.selector).find(classname)), }, width: () => this.chartContainerRef.getBoundingClientRect().width, height: () => parseInt(props.height, 10) - 100, selector: this.state.selector, setFilter: () => { // set filter according to data in store // used in FilterBox.onChange() }, getFilters: () => ( // return filter objects from viz.formData {} ), done: () => { // finished rendering callback }, error(msg, xhr) { let errorMsg = msg; let errHtml = ''; try { const o = JSON.parse(msg); if (o.error) { errorMsg = o.error; } } catch (e) { // pass } errHtml = `