<commit_before>import React from 'react'

/*
function MergeRecursive (obj1, obj2) {
  for (var p in obj2) {
    try {
      // Property in destination object set; update its value.
      if (obj2[p].constructor === Object) {
        obj1[p] = MergeRecursive(obj1[p], obj2[p])
      } else {
        obj1[p] = obj2[p]
      }
    } catch (e) {
      // Property in destination object not set; create it and set its value.
      obj1[p] = obj2[p]
    }
  }

  return obj1
}
*/

export default class ActiveLayersContainer extends React.Component {
  state = {
    layers: {'31241': {'id': 31241,
      'title': 'Alces alces',
      'subTitle': 'elg',
      'imageUrl': 'https://farm5.staticflickr.com/4107/4839886016_d11b6d2cdf.jpg',
      'dataUrl': 'http://webtjenester.artsdatabanken.no/Artskart/api/listhelper/31241/observations?&fromYear=1981&toYear=2012&fromMonth=1&toMonth=12&type=all&region=all&scientificNameId=48103',
      'source': 'geojson',
      'visible': true,
      'raster': false,
      'paint': {
        fillColor: '#f03030',
        fillColor2: '#ff0000',
        coverage: 0.95,
        fillOpacity: 0.93,
        radius: 0.3,
        renderMethod: 'scatterplot',
//        renderMethod: 'hexagon',
        blendMode: 'multiply',
        lowerPercentile: 0,
        upperPercentile: 1.0,
        elevationMin: 0.0,
        elevationMax: 0.5
      }
    }
    }
  }

  render () {
    const props = {
      layers: this.state.layers,
      onAddLayer: this.handleAddLayer,
      onDeleteLayer: this.handleDeleteLayer,
      onUpdateLayerProp: this.handleUpdateLayerProp
    }
    const childrenWithProps = React.Children.map(this.props.children,
      (child) => {
        if (!child) return child // result of conditionals for example
        return React.cloneElement(child, props)
      })
    return <div>{childrenWithProps}</div>
  }

  handleAddLayer = (layer) => {
    let newLayer = {
      id: layer.id,
      title: layer.scientificName,
      subTitle: layer.popularName + ' (' + layer.taxonGroup + ')',
      imageUrl: layer.imageUrl,
      dataUrl: `http://webtjenester.artsdatabanken.no/Artskart/api/listhelper/${layer.id}/observations?&fromYear=1981&toYear=2012&fromMonth=1&toMonth=12&type=all&region=all&scientificNameId=${layer.scientificNameId}`,
      source: 'geojson',
      visible: true,
      raster: false,
      paint: {
        fillColor: '#ff0000',
        fillOpacity: 1.0,
        coverage: 1.0,
        renderMethod: 'hexagon',
        blendMode: 'multiply',
        radius: 1.0,
        extruded: true,
        elevationScale: 500,
        upperPercentile: 1.0,
        elevationMin: 0,
        elevationMax: 10000
      }
    }
    this.setState(prevState => {
      prevState.layers[newLayer.id] = newLayer
      return prevState
    })
  }

  handleDeleteLayer = (layer) => {
    this.setState(prevState => {
      delete prevState[layer.id]
      return prevState
    })
  }

  handleUpdateLayerProp = (layer, key, value) => {
    console.log('Update layer #' + layer.id + ': ' + key + '=' + value)
    this.setState(prevState => {
      let layers = this.state.layers
      let _layer = prevState.layers[layer.id]
      _layer.paint[key] = value
      return layers
    })
  }
}
<commit_msg>Adjusted sample render color (complemenatry color)<commit_after>import React from 'react'

/*
function MergeRecursive (obj1, obj2) {
  for (var p in obj2) {
    try {
      // Property in destination object set; update its value.
      if (obj2[p].constructor === Object) {
        obj1[p] = MergeRecursive(obj1[p], obj2[p])
      } else {
        obj1[p] = obj2[p]
      }
    } catch (e) {
      // Property in destination object not set; create it and set its value.
      obj1[p] = obj2[p]
    }
  }

  return obj1
}
*/

export default class ActiveLayersContainer extends React.Component {
  state = {
    layers: {'31241': {'id': 31241,
      'title': 'Alces alces',
      'subTitle': 'elg',
      'imageUrl': 'https://farm5.staticflickr.com/4107/4839886016_d11b6d2cdf.jpg',
      'dataUrl': 'http://webtjenester.artsdatabanken.no/Artskart/api/listhelper/31241/observations?&fromYear=1981&toYear=2012&fromMonth=1&toMonth=12&type=all&region=all&scientificNameId=48103',
      'source': 'geojson',
      'visible': true,
      'raster': false,
      'paint': {
        fillColor: '#916446',
        fillOpacity: 0.86,
        coverage: 0.95,
        radius: 0.3,
        renderMethod: 'scatterplot',
//        renderMethod: 'hexagon',
        blendMode: 'multiply',
        lowerPercentile: 0,
        upperPercentile: 1.0,
        elevationMin: 0.0,
        elevationMax: 0.5
      }
    }
    }
  }

  render () {
    const props = {
      layers: this.state.layers,
      onAddLayer: this.handleAddLayer,
      onDeleteLayer: this.handleDeleteLayer,
      onUpdateLayerProp: this.handleUpdateLayerProp
    }
    const childrenWithProps = React.Children.map(this.props.children,
      (child) => {
        if (!child) return child // result of conditionals for example
        return React.cloneElement(child, props)
      })
    return <div>{childrenWithProps}</div>
  }

  handleAddLayer = (layer) => {
    let newLayer = {
      id: layer.id,
      title: layer.scientificName,
      subTitle: layer.popularName + ' (' + layer.taxonGroup + ')',
      imageUrl: layer.imageUrl,
      dataUrl: `http://webtjenester.artsdatabanken.no/Artskart/api/listhelper/${layer.id}/observations?&fromYear=1981&toYear=2012&fromMonth=1&toMonth=12&type=all&region=all&scientificNameId=${layer.scientificNameId}`,
      source: 'geojson',
      visible: true,
      raster: false,
      paint: {
        fillColor: '#916446',
        fillOpacity: 0.86,
        coverage: 1.0,
        renderMethod: 'hexagon',
        blendMode: 'multiply',
        radius: 1.0,
        extruded: true,
        elevationScale: 500,
        upperPercentile: 1.0,
        elevationMin: 0,
        elevationMax: 10000
      }
    }
    this.setState(prevState => {
      prevState.layers[newLayer.id] = newLayer
      return prevState
    })
  }

  handleDeleteLayer = (layer) => {
    this.setState(prevState => {
      delete prevState[layer.id]
      return prevState
    })
  }

  handleUpdateLayerProp = (layer, key, value) => {
    console.log('Update layer #' + layer.id + ': ' + key + '=' + value)
    this.setState(prevState => {
      let layers = this.state.layers
      let _layer = prevState.layers[layer.id]
      _layer.paint[key] = value
      return layers
    })
  }
}

{'fraction_non_alphanumeric': 0.1339381823773643, 'fraction_numerical': 0.036444717822543445, 'mean_word_length': 2.5080906148867315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '3619818', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2167, 'n_words': 413}