File talk:Template map of US states and District of Columbia.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: For 2nd map template instructions see: File talk:Template map of US states and District of Columbia.svg/Instructions. Leave comments and questions below.
Notice Note: See previous map template, its instructions, and its talk page.

Using JavaScript or .xlsx files instead of Google Sheets[edit]

@Timeshifter: Thanks for continuing to use and maintain this template.

You might have seen my chats with @RCraig09: who uses Excel spreadsheets to generate SVG, and @TilmannR: to use JavaScript that replaces itself with static SVG, yet embeds itself as a comment.

Doing the avoids the user needing any software except a web browser, which they likely already use to view Wikipedia. It also avoids using my Google account which periodically goes over quota, making the spreadsheet read-only.

Might you be interested to move and support the template using either method?

Thanks,
cmɢʟee ⋅τaʟκ 14:26, 12 January 2024 (UTC)[reply]

cmglee. I'll try out any tools to make US maps. But I don't have the knowledge to create the tools, or to edit the tools in a significant way. I just do not have the time, health, or energy nowadays. Please keep the current map template while you work on other tools. Are there any ready now that I can try out for US maps? --Timeshifter (talk) 15:24, 12 January 2024 (UTC)[reply]
@Timeshifter: Not yet. I just wanted to gauge interest before starting anything. I envision the user's workflow to be something like this:
  1. Open a template file (or existing file to be amended) in a text editor.
  2. Replace (or amend) parts indicated with relevant data:
    Tab- or comma-separated values
    Headings, colors etc
  3. Delete the "!" and 2 "-" on a particular line, and the 2 "-" on the last line.
  4. Save as a new file (or file to be amended).
  5. Open the file in Firefox or Chrome.
  6. In the web browser, save as another file.
  7. Upload this file to Commons.
Is that reasonable? cmɢʟee ⋅τaʟκ 15:44, 12 January 2024 (UTC)[reply]
P.S. See https://upload.wikimedia.org/wikipedia/commons/1/1b/Gabriel_horn_2d.svg for an example. This one is general-purpose, not map-specific. cmɢʟee ⋅τaʟκ 15:46, 12 January 2024 (UTC)[reply]
I need something I can try out. From your list I see one problem: "Tab- or comma-separated values". The values I deal with are in wiki tables. So I would have to convert a column of values into "Tab- or comma-separated values". I don't know how to do that. I can open csv files in Libreoffice Calc. And there are tools to go the other direction here:
w:Help:Table/Advanced#Spreadsheet/database tables to wikitables.
What would be nice is something like Excel2Wiki for US maps. Where one pastes in a one-column table, and out pops the SVG for a US map. :)
--Timeshifter (talk) 16:03, 12 January 2024 (UTC)[reply]
Tip: A cheap way of converting wiki-tables into .csv is to (1) copy the wikitable, (2) paste into a .txt text file, (3) use find-and-replace to remove any delimiters "|", (4) use Excel to import the .txt file. Separately: my Excel-to-svg conversions are entirely text-based, for making charts/graphs only, not something as complex as a map. RCraig09 (talk) 16:35, 12 January 2024 (UTC)[reply]

See starting point for US minimum wage map:

w:csv file. See w:User:Timeshifter/Sandbox236. I guess this is a space-delimited csv file?:

7.25 11.73 14.35 11.00 16.00 14.42 15.69 13.25 12.00 7.25 14.00 7.25 14.00 7.25 7.25 7.25 7.25 7.25 14.15 15.00 15.00 10.33 10.85 7.25 12.30 10.30 12.00 11.25 7.25 15.13 12.00 15.00 7.25 7.25 10.45 7.25 14.20 7.25 14.00 7.25 11.20 7.25 7.25 7.25 13.67 12.00 16.28 8.75 7.25 7.25 17.00

That's with just the values. It is easy enough to replace the spaces with commas. --Timeshifter (talk) 18:04, 12 January 2024 (UTC)[reply]

+CC @TilmannR:
SVG-JavaScript-generated
@Timeshifter: I missed your latest reply and have created this new SVG based on File:Maternal_mortality_rates_per_100,000_births_by_state._US_map.svg. Data is located between the lines
/// User editable data below until the next ///
and
`; /// list state name (optionally then a space and value) above in this order:
The procedure to use it is as in the above numbered list, subject to change. Does it make sense so far? cmɢʟee ⋅τaʟκ 18:38, 14 January 2024 (UTC)[reply]
Please subscribe to our threads.
I figured it out. Thanks for this!
As a test I just redid the minimum wage map with the Jan 1, 2024 values listed here:
File talk:Template map of U.S. states and District of Columbia.svg/Instructions#List
And I substituted in the font sizes, background colors, min, max, decimal places, title, description from the current map (Jan 1, 2024 values):
File:Map of US minimum wage by state.svg
I think I can rewrite the instructions page fairly easily in the next few days.
Please keep both templates for now until I finish up the new instructions.
Then maybe we can redirect the old template to the new one since some people have links to it.
And we can redirect the talk page and instructions page to the new template.
File talk:Template map of U.S. states and District of Columbia.svg - (this page we are talking on).
File talk:Template map of U.S. states and District of Columbia.svg/Instructions
I don't want to lose the talk page we are on now. It has a lot of valuable info.
Does this work with Edge and Opera too?
--Timeshifter (talk) 23:35, 14 January 2024 (UTC)[reply]
Thank you very much! Before you start mass-producing them, I'd like to finalise the JavaScript code and especially inline comments, as I rushed through it last night. If you can think of better ways to word things, please let me know.
I'll try it on Edge and Chrome but don't have Opera.
Yes, let's keep the old template but mark it as superseded when the new one is finalized.
I'm unsure what you meant by "Please subscribe to our threads." Cheers, cmɢʟee ⋅τaʟκ 01:35, 15 January 2024 (UTC)[reply]
I am talking about the "subscribe" links at the top of every talk section.
Opera is quick and easy to install.
I have been thinking about whether we should encourage people to delete everything between the script tags after they generate an SVG map. And then send people back to the main template since it is where updated code and inline comments will happen.
A superseded template sounds like a better idea than a redirect. This way we keep the knowledge of both methods. And then we will not have to redirect the talk page. We can start a new talk page for the new template. And then people will not be confused about old talk, and what it refers to.
I can mark the old instructions page as superseded and deprecated. So we keep that knowledge about the old template.
I can copy the old instructions to the new instructions page. And then adapt it. It shouldn't be that hard since most of the steps are the same.
After you work on the new template for awhile, I could clarify the inline comments further if you want. After you clarify them.
I can use the old template in the meantime. It is pretty easy for me now. Though not as easy as the new one.
--Timeshifter (talk) 02:27, 15 January 2024 (UTC)[reply]
Thanks, I agree about superseded template and talk pages.
The script intentionally embeds a copy of itself in the SVG file (it's trivial to not do this). This is so that anyone with the SVG can update the table and rerun the script after removing a few characters. Sending back to the template loses the raw data.
For my own file management, if the file to upload is X.svg, I name the file with the removed characters X.gen.svg. After updating X.gen.svg, I open it in Firefox and Save As file X.svg.
Cheers, cmɢʟee ⋅τaʟκ 03:51, 15 January 2024 (UTC)[reply]
P.S. I've updated the SVG. That's about as much as I can do at the moment. I plan to derive the state codes from the state names so that they can be specified in any order but am currently unsure how to make it robust to any variation in spelling e.g. specifying DC as "Washington" or "District of Columbia" while Washington state is missing. cmɢʟee ⋅τaʟκ 04:54, 15 January 2024 (UTC)[reply]

You're right. The script needs to stay in the file, so that updates are simple. I hadn't thought of that. I don't have to reenter the styling each time I do an update. I just enter the new list of locations and values. --Timeshifter (talk) 04:06, 16 January 2024 (UTC)[reply]

Thanks. That's right; in the grand scheme of things, a few kilobytes is negligible.
In case it interests you, I've asked about the matching algorithm on http://en.wikipedia.org/w/index.php?title=Wikipedia%3AReference_desk%2FComputing&diff=1196100959&oldid=1196027585 . Cheers, cmɢʟee ⋅τaʟκ 09:08, 16 January 2024 (UTC)[reply]
Might be good to link to the new instructions page from within the script section. That way when the file is inevitably used outside Wikipedia, or adapted to be a different map on the Commons, people can always get to the clearer instructions, and the latest template. New mapmakers may forget to link to the template on the file description page.
Ambitious people could even copy the latest script over from the template. I don't know if that is always possible since an updated script may need changes higher up in the SVG file too.
The new instructions could explain all that. Feel free to start, or add to, the new instructions. I have a lot going on right now, and possibly off and on for a couple weeks.
It might be nice if the script accepted the state names via full names or abbreviations. In any order. That would be especially helpful since it is easy to mess up the order. See:
w:Help:Tables and locations#Convert US state abbreviations to full names
I don't think accepting other abbreviations is that important. A couple word-wrapped paragraphs in the script section would help: 1 for full names, and 1 for abbreviations. So people would know what was accepted. They should be in the order that is required. That is if order will matter. Alphabetical order by full names (with Washington D.C. at the end):
Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming Washington D.C.
--Timeshifter (talk) 14:21, 16 January 2024 (UTC)[reply]

Instructions for new template[edit]

Good points. I've created
http://commons.wikimedia.org/wiki/File_talk:Template_map_of_US_states_and_District_of_Columbia.svg/Instructions
to host the instructions and shall populate it when I can. In my latest version, I've also added a link to it.
I'll work on the arbitrary-order matching when I get a satisfactory answer from the computing reference desk.
Cheers, cmɢʟee ⋅τaʟκ 15:44, 16 January 2024 (UTC)[reply]
P.S. The latest version lets states be specified in any order and tolerates minor spelling differences. If much greater differences must be supported, add more entries to the map_states dictionary e.g. 'districtofcolumbia':'DC'. States without data can also be omitted from the table.
http://en.wikipedia.org/w/index.php?title=Wikipedia:Reference_desk/Computing&diff=prev&oldid=1196413257 has details on the algorithm. cmɢʟee ⋅τaʟκ 10:57, 17 January 2024 (UTC)[reply]
Will the latest template allow using 2-letter abbreviations? In any order? Many US state databases use 2-letter abbreviations. So I could skip converting them to full names. It would be super easy to create US maps from those databases. --Timeshifter (talk) 17:19, 17 January 2024 (UTC)[reply]
Looks like both of us have been doing unnecessary work. I would much prefer the data with 2-letter abbreviation, actually. I'll just adapt my script to work with both names and abbreviations. cmɢʟee ⋅τaʟκ 02:42, 18 January 2024 (UTC)[reply]
The latest version now evaluates the data table, ignoring case and non-alphanumeric characters, in this order:
  1. Name as in en:List_of_states_and_territories_of_the_United_States or "Washington, D.C."
  2. USPS 2-letter (postal) abbreviation or "DC"
  3. Smallest Levenshtein distance to name in (1) above – if tied, the first in alphabetical order
Cheers, cmɢʟee ⋅τaʟκ 01:29, 19 January 2024 (UTC)[reply]

cmglee. Feel free to fill in some instructions for the new template:

Eventually I will get around to filling it out more. It may be awhile though. --Timeshifter (talk) 18:28, 19 January 2024 (UTC)[reply]

Discussion archive: "Algorithm to match U.S. state names to USPS state codes":
w:Wikipedia:Reference desk/Archives/Computing/2024 January 16
Fixed above link. --Timeshifter (talk) 21:03, 17 March 2024 (UTC)[reply]

Tab- or comma-separated values[edit]

cmglee. It's been awhile. Lots of problems and projects. I worked off and on for weeks on this page:

Finally nailed down the references for good data on US homicide rates from the FBI and CDC. And why they get slightly different numbers. These 2 maps are now made from the new template:

Thanks for the new template. It is easier to use, and more forgiving.

From the instruction summary on the new instruction page what do you mean by "Tab- or comma-separated values"? Can a paragraph of those values be pasted in somewhere? See:

I added "Or a list". Feel free to edit that page in any way. --Timeshifter (talk) 12:15, 6 March 2024 (UTC)[reply]

cmglee. I don't know if you saw this. --Timeshifter (talk) 21:30, 17 March 2024 (UTC)[reply]
Sorry I missed this. I've clarified it as such: In the list following the line "const state_space_value...", update the numbers, or add a space and the value after the state name. (If a value is unavailable, leave the value blank.) Is that clearer? Cheers, cmɢʟee ⋅τaʟκ 02:50, 18 March 2024 (UTC)[reply]
Thanks for clarifying that, cmglee. --Timeshifter (talk) 04:14, 18 March 2024 (UTC)[reply]

More maps[edit]

Cmglee, TilmannR, RCraig09, Glrx and all. I may or may not be able to do much for awhile. Problems, projects, health problems, etc., etc.. Others can create maps too if they can somehow find out about the easier map template.

The instruction page (linked below) needs more details. It would be nice if others helped on that too:

I am interested in having some maps from these pages:

"More than 800 up-to-date health indicators at the state level can be mapped, ranked, and downloaded":

CDC. Stats of the States:

Some of the above pages have maps and graphs. They can be copied to the Commons via Template:PD-map and Template:PD-chart. They are in the public domain (read PD template pages). This is if people haven't figured out the new template to put the data right on the US map by state.

I will list some more ideas for maps if I see some possibilities. Feel free to list more ideas for map topics. And data links like the above links if possible.

Anybody can create these maps. I may or may not get around to it. I can maybe help clean up the file description pages for maps created by others. --Timeshifter (talk) 23:03, 17 March 2024 (UTC)[reply]

Hi @Timeshifter: I'm unfamiliar with these topics, so could you rank the requests by priority and add which articles and sections they should appear on?
May I also suggest asking on Commons:Graphic_Lab/Map_workshop and en:Wikipedia:Graphics_Lab/Map_workshop? cmɢʟee ⋅τaʟκ 02:35, 18 March 2024 (UTC)[reply]
cmglee. Thanks for the links. I may use them. I also added them to the instruction page:
File talk:Template map of US states and District of Columbia.svg/Instructions#Map workshops of the Graphic Labs
Do you live in Malaysia? I was reading your Wikipedia user page: en:User:Cmglee. Maybe you and/or your collaborators can make a template map for Malaysian states? Or other countries. The more the better. That might also help in people gaining familiarity with this type of map template.
--Timeshifter (talk) 04:11, 18 March 2024 (UTC)[reply]
Penang ethnicity heat map
My pleasure. Good idea to add a suggested priority list to the instruction page.
I live in the UK and am visiting Malaysia. I met some local Wikipedians who also make thematic maps such as this one. I offered to make them a template similar to ours but they prefer to use QGIS.
Cheers,
cmɢʟee ⋅τaʟκ 04:48, 18 March 2024 (UTC)[reply]

Getting the word out about these maps[edit]

I updated to the new template here:

Feel free to copy that section elsewhere. I did:

I used the maps here (scroll down the section):

I started sections here:

--Timeshifter (talk) 18:05, 30 March 2024 (UTC)[reply]

Thanks very much, @Timeshifter: cmɢʟee ⋅τaʟκ 15:03, 31 March 2024 (UTC)[reply]
@Cmglee: You're welcome. I later added a link to examples to all of the above posts: Category:English-language SVG maps of the United States made with templates. --Timeshifter (talk) 19:18, 3 April 2024 (UTC)[reply]

Template may have stopped working[edit]

cmglee. I can't get it to work today.

Last map I used the template for successfully was uploaded on April 10, 2024:

Today I was trying to update this map to 2022:

See: User:Timeshifter/Sandbox 14. I tried both Firefox and Chrome. --Timeshifter (talk) 02:31, 21 May 2024 (UTC)[reply]

I don't think so. I start with a copy of the template which has no period in the file name. So at no point in the creation process does the file name have a period in it. When the new map is complete I upload to a file with a period in the file name.
I am unable to complete the process. The script code never resets. So the uploader sees the script and blocks it from completing the upload. --Timeshifter (talk) 00:44, 25 May 2024 (UTC)[reply]