Hi
Many thanks for your great work with this - much appreciated.
I'm getting an issue where only about 1/3 of the states are being filled and having a tool-tip assigned.
Looking at the inspector is see the following:
If you look at id=Texas you can see that it's not getting the fill color or the title(tooltip) assigned.
I have amended your code to this; mainly only to get the data and initially remove the onclick as I don't know what's in the 'sp_DBR_single' sp.
declare v_tot_claims int;
declare v_map_url varchar(200);
select sum(28Day) into v_tot_claims
from tblrh_analysis
where year(period)=year(curdate());
create temporary table state_claims (State varchar(100), claims int, primary key(State));
insert into state_claims
select trim(replace(replace(cast(state as char(100)), ' ', ''),'"','')), sum(round(Quantity/28,0))
from tblrh_cop_dc_mth
where year(InvMonth)=year(curdate())
group by 1;
insert into state_claims
select trim(replace(replace(cast(state as char(100)), ' ', ''),'"','')), sum(round(Quantity/28,0))
from tblrh_cop_ev_mth
where year(InvMonth)=year(curdate())
group by 1
on duplicate key update claims=claims+values(claims);
-- select * from state_claims;
select 'dbr.javascript', '
function add_svg_color_tooltip(map_svg, id, text, color) {
var node = document.createElementNS("http://www.w3.org/2000/svg", "title");
var textnode = document.createTextNode(text);
node.appendChild(textnode);
elem = map_svg.getElementById(id);
elem.style.fill = "#"+color;
elem.appendChild(node);
}
';
select 'dbr.title', 'US Population';
select 'dbr.text', 'Data is added to a SVG chart (color, tooltip and a myDBR link)
You can hover your mouse on top of a state and click on it
', 'comment';
select 'dbr.html','<object id="us_map" type="image/svg+xml" data="user/images/Map_of_USA_States_with_names_white.svg"></object>';
select 'dbr.html', '<script>
var map = document.getElementById("us_map");
map.addEventListener("load", function() {
var map_svg = map.getSVGDocument();
';
select 'dbr.html', concat("add_svg_color_tooltip(map_svg, '",state, "',","'Population ",format(claims,0),"','",f_color_scale( 'FFF8F8', 'FF0000', claims/v_tot_claims ),"');")
from state_claims;
select 'dbr.html', '});
</script>';
set v_map_url = 'https://commons.wikimedia.org/wiki/File:Map_of_USA_States_with_names_white.svg';
select 'dbr.text', concat('Map courtesy of ',v_map_url,'
Gigillo83, original of 70.29.208.129 / CC BY-SA (https://creativecommons.org/licenses/by-sa/4.0)'), 'comment';
A sample of the data in the temporary table state_claims:
As you can see Texas is in the data - in fact it is the state with the most claims (highest ratio).
Could this be happening due to the map loading before the data is ready? If so how do you fix this?
Many thanks for all your effort here.
Jake