/**
  * Return the HTML code to display a row with all places found in a generation.
  *
  * @param array $data Data array
  * @param int $analysis_level Level of subdivision of analysis
  * @return string HTML code for all places row
  */
 protected function htmlGenerationAllPlacesRow($data, $analysis_level)
 {
     $html = '<table class="geodispersion_bigrow">
         <tr>';
     $sum_gen = $data['sum'];
     $unknownother = $data['unknown'] + $data['other'];
     foreach ($data['places'] as $placename => $dataplace) {
         $levels = array_map('trim', explode(',', $placename));
         $content = '';
         if (isset($dataplace['flag'])) {
             $content .= '<td class="geodispersion_flag">' . FunctionsPrint::htmlPlaceIcon($dataplace['place'], $dataplace['flag']) . '</td><td>';
         } else {
             $content .= '<td><span title="' . implode(I18N::$list_separator, array_reverse($levels)) . '">' . $levels[$analysis_level - 1] . '</span><br/>';
         }
         $count = $dataplace['count'];
         $content .= I18N::number($count);
         $perc = Functions::safeDivision($count, $sum_gen + $unknownother);
         $perc2 = Functions::safeDivision($count, $sum_gen);
         if ($perc2 >= 0.1) {
             $content .= '<br/><span class="small">(' . I18N::percentage($perc2, 1) . ')</span>';
         }
         $content .= '</td>';
         $html .= '
             <td class="geodispersion_rowitem" width="' . max(round(100 * $perc, 0), 1) . '%">
                 <table>
                     <tr>
                         <td>
                             <table>
                                 <tr>' . $content . '</tr>
                             </table>
                         </td>
                     </tr>
                 </table>
             </td>';
     }
     if ($unknownother > 0) {
         $perc = Functions::safeDivision($unknownother, $sum_gen + $unknownother);
         $html .= '<td class="geodispersion_unknownitem left" >' . I18N::number($unknownother);
         if ($perc >= 0.1) {
             $html .= '<br/><span class="small">(' . I18N::percentage($perc, 1) . ')</span>';
         }
         $html .= '</td>';
     }
     $html .= '</tr>
     </table>';
     return $html;
 }
    /**
     * {@inheritDoc}
     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisTabGeneralView::htmlAnalysisData()
     */
    protected function htmlAnalysisData()
    {
        /** @var OutlineMap $map */
        $map = $this->data->get('map');
        $canvas = $map->getCanvas();
        $subdvisions_results = $this->data->get('results_by_subdivisions');
        $nb_found = $this->data->get('stats_gen_nb_found');
        $nb_other = $this->data->get('stats_gen_nb_other');
        $html = '<script>
			var tip = null;
			var tipText = "";
			var over = false;
			var isin = false;

			function addTip(node, txt){
			    jQuery(node).bind({
			    	mouseover : function(){
			    		oldisin = isin;
			    		isin = true;
			    		if(oldisin != isin){
			       			tipText = txt;
			       			tip.stop(true, true).fadeIn();
			       			over = true;
			       		}
			    	},
			    	mouseout : function(){
			    		oldisin = isin;
			    		isin = false;
			    		if(oldisin != isin){
			       			tip.stop(true, true).fadeOut("fast");
			       			over = false;
			       		}
			    	}

			    });
			}
			jQuery(document).ready(function() {
				tip = $("#geodispersion_tip").hide();

				var positionTab = jQuery("#geodispersion-tabs").offset();

				jQuery("#geodispersion_map").mousemove(function(e){
				    if (over){
					  tip.css("left", e.pageX + 20 - positionTab.left).css("top", e.pageY + 20 - positionTab.top);
				      tip.html(tipText);
				    }
				});

				var paper = new Raphael(document.getElementById("geodispersion_map"), ' . $canvas->width . ', ' . $canvas->height . ');
				var background = paper.rect(0, 0, ' . $canvas->width . ', ' . $canvas->height . ');
				background.attr({"fill" : "' . $canvas->background_color . '", "stroke" : "' . $canvas->background_stroke . '", "stroke-width": 1, "stroke-linejoin": "round" });
				var attr = { fill: "' . $canvas->default_color . '", stroke: "' . $canvas->default_stroke . '", "stroke-width": 1, "stroke-linejoin": "round" };
				var map = {};
		';
        foreach ($subdvisions_results as $name => $location) {
            $html .= 'map.area' . $location['id'] . ' = paper.path("' . $location['coord'] . '").attr(attr);';
            if (isset($location['transparency'])) {
                $textToolTip = '<strong>' . $location['displayname'] . '</strong><br/>';
                if ($this->data->get('use_flags') && $location['flag'] != '') {
                    $textToolTip .= '<span class="geodispersion_flag">' . FunctionsPrint::htmlPlaceIcon($location['place'], $location['flag']) . '</span><br/>';
                }
                $textToolTip .= I18N::translate('%d individuals', $location['count']) . '<br/>' . I18N::percentage(Functions::safeDivision($location['count'], $nb_found - $nb_other), 1);
                $html .= 'addTip(map.area' . $location['id'] . '.node, "' . Filter::escapeJs($textToolTip) . '");';
                $html .= 'map.area' . $location['id'] . '.attr({"fill" : "' . $canvas->max_color . '", "fill-opacity" : ' . $location['transparency'] . ' });';
                $html .= 'map.area' . $location['id'] . '.mouseover(function () {' . 'map.area' . $location['id'] . '.stop().animate({"fill" : "' . $canvas->hover_color . '", "fill-opacity" : 1}, 100, "linear");' . '});' . 'map.area' . $location['id'] . '.mouseout(function () {' . 'map.area' . $location['id'] . '.stop().animate({"fill" : "' . $canvas->max_color . '", "fill-opacity" : ' . $location['transparency'] . '}, 100, "linear");' . '});';
            }
        }
        $html .= '});
            </script>
            
            <div id="geodispersion_map"></div>
    	   <div id="geodispersion_tip"></div>';
        return $html;
    }