<commit_before>/**
 * Root of the React component tree.
 * @flow
 */
'use strict';

import type {TwoBitSource} from './sources/TwoBitDataSource';
import type {VisualizedTrack, VizWithOptions} from './types';

import React from 'react';
import Controls from './Controls';
import Menu from './Menu';
import VisualizationWrapper from './VisualizationWrapper';

type Props = {
  referenceSource: TwoBitSource;
  tracks: VisualizedTrack[];
  initialRange: GenomeRange;
};

class Root extends React.Component {
  props: Props;
  state: {
    contigList: string[];
    range: ?GenomeRange;
    settingsMenuKey: ?string;
    updateSize: boolean;
  };
  trackReactElements: Array<Object>; //it's an array of reactelement that are created for tracks

  constructor(props: Object) {
    super(props);
    this.state = {
      contigList: this.props.referenceSource.contigList(),
      range: null,
      updateSize: false,
      settingsMenuKey: null
    };
    this.trackReactElements = [];
  }

  componentDidMount() {
    this.props.referenceSource.on('contigs', () => {
      this.setState({
        contigList: this.props.referenceSource.contigList(),
      });
    });

    if (!this.state.range) {
      this.handleRangeChange(this.props.initialRange);
    }
    // in case the contigs came in between getInitialState() and here.
    this.setState({contigList: this.props.referenceSource.contigList()});
  }

  handleRangeChange(newRange: GenomeRange) {
    this.props.referenceSource.normalizeRange(newRange).then(range => {
      this.setState({range: range});

      // Inform all the sources of the range change (including referenceSource).
      this.props.tracks.forEach(track => {
        track.source.rangeChanged(range);
      });
    }).done();
  }

  toggleSettingsMenu(key: string, e: SyntheticEvent) {
    if (this.state.settingsMenuKey == key) {
      this.setState({settingsMenuKey: null});
    } else {
      this.setState({settingsMenuKey: key});
    }
  }
  
  handleSelectOption(trackKey: string, optionKey: string) {
    this.setState({settingsMenuKey: null});

    var viz = this.props.tracks[Number(trackKey)].visualization;
    var oldOpts = viz.options;
    var newOpts = viz.component.handleSelectOption(optionKey, oldOpts);
    viz.options = newOpts;
    if (newOpts != oldOpts) {
      this.forceUpdate();
    }
  }

  makeDivForTrack(key: string, track: VisualizedTrack): React.Element {
    //this should be improved, but I have no idea how (when trying to
    //access this.trackReactElements wih string key, flow complains)
    var intKey = parseInt(key); 
    var trackEl = (
        <VisualizationWrapper visualization={track.visualization}
            range={this.state.range}
            onRangeChange={this.handleRangeChange.bind(this)}
            source={track.source}
            referenceSource={this.props.referenceSource}
            ref = {(c) => return this.trackReactElements[intKey]=c}
          />);
    
    var trackName = track.track.name || '(track name)';

    var gearIcon = null,
        settingsMenu = null;
    if (track.visualization.component.getOptionsMenu) {<commit_msg>lint issues<commit_after>/**
 * Root of the React component tree.
 * @flow
 */
'use strict';

import type {TwoBitSource} from './sources/TwoBitDataSource';
import type {VisualizedTrack, VizWithOptions} from './types';

import React from 'react';
import Controls from './Controls';
import Menu from './Menu';
import VisualizationWrapper from './VisualizationWrapper';

type Props = {
  referenceSource: TwoBitSource;
  tracks: VisualizedTrack[];
  initialRange: GenomeRange;
};

class Root extends React.Component {
  props: Props;
  state: {
    contigList: string[];
    range: ?GenomeRange;
    settingsMenuKey: ?string;
    updateSize: boolean;
  };
  trackReactElements: Array<Object>; //it's an array of reactelement that are created for tracks

  constructor(props: Object) {
    super(props);
    this.state = {
      contigList: this.props.referenceSource.contigList(),
      range: null,
      updateSize: false,
      settingsMenuKey: null
    };
    this.trackReactElements = [];
  }

  componentDidMount() {
    this.props.referenceSource.on('contigs', () => {
      this.setState({
        contigList: this.props.referenceSource.contigList(),
      });
    });

    if (!this.state.range) {
      this.handleRangeChange(this.props.initialRange);
    }
    // in case the contigs came in between getInitialState() and here.
    this.setState({contigList: this.props.referenceSource.contigList()});
  }

  handleRangeChange(newRange: GenomeRange) {
    this.props.referenceSource.normalizeRange(newRange).then(range => {
      this.setState({range: range});

      // Inform all the sources of the range change (including referenceSource).
      this.props.tracks.forEach(track => {
        track.source.rangeChanged(range);
      });
    }).done();
  }

  toggleSettingsMenu(key: string, e: SyntheticEvent) {
    if (this.state.settingsMenuKey == key) {
      this.setState({settingsMenuKey: null});
    } else {
      this.setState({settingsMenuKey: key});
    }
  }
  
  handleSelectOption(trackKey: string, optionKey: string) {
    this.setState({settingsMenuKey: null});

    var viz = this.props.tracks[Number(trackKey)].visualization;
    var oldOpts = viz.options;
    var newOpts = viz.component.handleSelectOption(optionKey, oldOpts);
    viz.options = newOpts;
    if (newOpts != oldOpts) {
      this.forceUpdate();
    }
  }

  makeDivForTrack(key: string, track: VisualizedTrack): React.Element {
    //this should be improved, but I have no idea how (when trying to
    //access this.trackReactElements wih string key, flow complains)
    var intKey = parseInt(key); 
    var trackEl = (
        <VisualizationWrapper visualization={track.visualization}
            range={this.state.range}
            onRangeChange={this.handleRangeChange.bind(this)}
            source={track.source}
            referenceSource={this.props.referenceSource}
            ref = {(c) => {this.trackReactElements[intKey]=c}}
          />);
    
    var trackName = track.track.name || '(track name)';

    var gearIcon = null,
        settingsMenu = null;
    if (track.visualization.component.getOptionsMenu) {
{'fraction_non_alphanumeric': 0.12489991993594876, 'fraction_numerical': 0.0, 'mean_word_length': 3.228842247799594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6912581', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1825, 'n_words': 418}