Changeset 709779
- Timestamp:
- 05/08/2013 08:38:57 AM (13 years ago)
- Location:
- ipu-chart
- Files:
-
- 17 added
- 9 edited
- 1 copied
-
assets/banner-772x250.png (modified) (previous)
-
assets/screenshot-9.png (added)
-
tags/0.5 (copied) (copied from ipu-chart/trunk)
-
tags/0.5/css/ipu-chart.css (modified) (1 diff)
-
tags/0.5/ipu-chart.php (modified) (2 diffs)
-
tags/0.5/js/d3/d3.geo.projection.v0.min.js (added)
-
tags/0.5/js/d3/queue.v1.min.js (added)
-
tags/0.5/js/d3/topojson.v0.min.js (added)
-
tags/0.5/js/ipu-chart.js (modified) (14 diffs)
-
tags/0.5/raw (added)
-
tags/0.5/raw/.htaccess (added)
-
tags/0.5/raw/world-110m.json (added)
-
tags/0.5/raw/world-50m.json (added)
-
tags/0.5/raw/world-ISO-3166-1-numeric.tsv (added)
-
tags/0.5/readme.txt (modified) (9 diffs)
-
trunk/css/ipu-chart.css (modified) (1 diff)
-
trunk/ipu-chart.php (modified) (2 diffs)
-
trunk/js/d3/d3.geo.projection.v0.min.js (added)
-
trunk/js/d3/queue.v1.min.js (added)
-
trunk/js/d3/topojson.v0.min.js (added)
-
trunk/js/ipu-chart.js (modified) (14 diffs)
-
trunk/raw (added)
-
trunk/raw/.htaccess (added)
-
trunk/raw/world-110m.json (added)
-
trunk/raw/world-50m.json (added)
-
trunk/raw/world-ISO-3166-1-numeric.tsv (added)
-
trunk/readme.txt (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ipu-chart/tags/0.5/css/ipu-chart.css
r705521 r709779 17 17 18 18 .chart svg { 19 //border: 2px solid red;19 // border: 2px solid red; 20 20 font: 0.8em sans-serif; 21 } 22 23 /* Map chart definitions */ 24 25 .ISO-3166-1 { 26 //color: transparent; 27 font-size: 0.8em; 28 } 29 30 .stroke { 31 fill: none; 32 stroke: dimgray; 33 stroke-width: 0.5px; 34 } 35 36 .fill { 37 fill: #fff; 38 } 39 40 .graticule { 41 fill: none; 42 stroke: #777; 43 stroke-width: .5px; 44 stroke-opacity: .5; 45 } 46 47 .land { 48 fill: #222; 49 } 50 51 .boundary { 52 fill: none; 53 stroke: #fff; 54 stroke-width: .5px; 21 55 } 22 56 -
ipu-chart/tags/0.5/ipu-chart.php
r708090 r709779 2 2 /* 3 3 Plugin Name: IPU-Chart 4 Plugin URI: https://www.ipublia.com/ ipu-chart5 Description: Creates SVG based charts out of your comma or tab separated data. Currently supports bar, pie, donut, line and scattercharts.4 Plugin URI: https://www.ipublia.com/support/docs/ipu-chart-for-wordpress-user-guide/ 5 Description: Creates SVG based charts out of your comma or tab separated data. Currently supports bar, pie, donut, line, scatter and world map charts. 6 6 Author: ipublia, Thomas Müller Flury 7 Version: 0. 4.17 Version: 0.5 8 8 Author URI: https://www.ipublia.com/author/thmufl/ 9 9 Text Domain: ipuchart … … 129 129 // Add plug-in's scripts to the header of the pages 130 130 function ipu_add_custom_scripts() { 131 wp_register_script('custom-script-d3', plugins_url( '/js/d3/d3.v3.min.js', __FILE__ )); 131 wp_register_script('custom-script-d3', plugins_url( '/js/d3/d3.v3.min.js', __FILE__ )); 132 wp_register_script('custom-script-queue', plugins_url( '/js/d3/queue.v1.min.js', __FILE__ )); 133 wp_register_script('custom-script-d3-geo-projection', plugins_url( '/js/d3/d3.geo.projection.v0.min.js', __FILE__ )); 134 wp_register_script('custom-script-topojson', plugins_url( '/js/d3/topojson.v0.min.js', __FILE__ )); 132 135 wp_register_script('custom-script-ipuc', plugins_url( '/js/ipu-chart.js', __FILE__ )); 133 136 134 wp_enqueue_script('custom-script-d3'); 137 wp_enqueue_script('custom-script-d3'); 138 wp_enqueue_script('custom-script-queue'); 139 wp_enqueue_script('custom-script-d3-geo-projection'); 140 wp_enqueue_script('custom-script-topojson'); 135 141 wp_enqueue_script('custom-script-ipuc'); 136 142 } -
ipu-chart/tags/0.5/js/ipu-chart.js
r708090 r709779 6 6 touch_device = window.Touch ? true : false, 7 7 svgSupport = window.SVGSVGElement ? true : false, 8 pluginPath = getPluginPath(), 8 9 defaultOpacity = 0.7, 9 10 tooltip; 11 12 function getPluginPath() { 13 var scripts = document.getElementsByTagName('script'); 14 var path = ''; 15 if(scripts && scripts.length>0) { 16 for(var i in scripts) { 17 if(scripts[i].src && scripts[i].src.indexOf("js/ipu-chart.js") > 0) { 18 file = scripts[i].src; 19 path = file.substring(0, file.indexOf("js/ipu-chart.js")); 20 break; 21 } 22 } 23 } 24 return path; 25 }; 10 26 11 27 function toArray(l) { … … 17 33 } 18 34 35 var dateFormat = d3.time.format("%d-%b-%Y"); 36 var numberFormat = d3.format("n"); 37 38 function isNumber(n) { 39 return !isNaN(parseFloat(n)) && isFinite(n); 40 } 41 19 42 function parserFor(format) { 20 43 format = format.trim(); 44 if(format == "n" || format == "number") return parseFloat; 21 45 if(format == "i" || format == "integer") return parseInt; 22 46 if(format == "f" || format == "float") return parseFloat; … … 96 120 var svg = figure.append("svg"); 97 121 98 svg.append("g") 99 .attr("class", "meta") 100 .append("title").text(title) 101 .append("description").text(description); 122 var meta = svg.append("g") 123 .attr("class", "meta"); 124 125 meta.append("title").text(title); 126 meta.append("description").text(description); 127 meta.append("a") 128 .attr("href", "https://www.ipublia.com/products/ipu-chart-svg-chart-library/") 129 .text(version + " (IPU448032107)"); 102 130 103 131 figure.append("figcaption").text(title); … … 141 169 142 170 console.log("PLUGIN: " 143 + "\n\t " + version);144 171 + "\n\tversion: " + version 172 + "\n\tpath: " + getPluginPath()); 145 173 146 174 console.log("CALL RENDER CHART: " … … 179 207 color = toArray(color); 180 208 animate = toArray(animate); 181 209 182 210 if(animate[0] == "slow") animate = ["5000", "linear"]; 183 211 else if(animate[0] == "medium") animate = ["2000", "linear"]; … … 233 261 234 262 data = parseData(data, category, value, format, debug); 235 263 236 264 if(type.toLowerCase().trim() == "bar") 237 265 renderBar(figure, data, category, value, format, color, sort, interpolate, animate, debug); … … 252 280 renderScatter(figure, data, category, value, format, color, sort, interpolate, animate, debug); 253 281 282 else if(type.toLowerCase().trim() == "map.world.countries") 283 renderMapWorldCountries(figure, data, category, value, format, color, sort, interpolate, animate, debug); 284 254 285 else if(type.toLowerCase().trim() == "table") 255 286 renderTable(figure, data, category, value, debug); … … 259 290 } 260 291 292 function renderMapWorldCountries(figure, data, category, value, format, color, sort, interpolate, animate, debug) { 293 if(debug) console.log("START RENDER WORLD MAP COUNTRIES"); 294 295 var color = d3.scale.log() 296 .domain(d3.extent(data, function(d) { return d[value[0]] })) 297 .range([color[0], color[1]]); 298 299 var svg = figure.select("svg"); 300 var g = svg.select("g.main"); 301 302 var margin = {top: 1, right: 1, bottom: 1, left: 1}, 303 width = parseInt(svg.attr("width")) - margin.left - margin.right, 304 height = parseInt(svg.attr("height")) - margin.top - margin.bottom, 305 centered; 306 307 var projection = d3.geo.kavrayskiy7() 308 .scale(105) 309 .translate([width / 2, height / 2]) 310 .precision(.1); 311 312 var path = d3.geo.path() 313 .projection(projection); 314 315 var graticule = d3.geo.graticule(); 316 317 g.append("defs").append("path") 318 .datum({type: "Sphere"}) 319 .attr("id", "sphere") 320 .attr("d", path); 321 322 g.append("use") 323 .attr("class", "stroke") 324 .attr("xlink:href", "#sphere"); 325 326 g.append("use") 327 .attr("class", "fill") 328 .attr("xlink:href", "#sphere"); 329 330 g.append("path") 331 .datum(graticule) 332 .attr("class", "graticule") 333 .attr("d", path); 334 335 queue() 336 .defer(d3.json, pluginPath + "raw/world-110m.json") 337 .defer(d3.tsv, pluginPath + "raw/world-ISO-3166-1-numeric.tsv") 338 .await(ready); 339 340 function ready(error, world, names) { 341 var globe = {type: "Sphere"}, 342 land = topojson.object(world, world.objects.land), 343 countries = topojson.object(world, world.objects.countries).geometries, 344 borders = topojson.mesh(world, world.objects.countries, function(a, b) { return a.id !== b.id; }); 345 346 countries = countries.filter(function(d) { 347 return names.some(function(n) { 348 if (d.id == n["ISO-3166-1"]) return d.name = n.name; 349 }); 350 }).sort(function(a, b) { 351 return a.name.localeCompare(b.name); 352 }); 353 354 355 data.forEach(function(d, i) { 356 countries.forEach(function(c, j) { 357 if (c.id == d["ISO-3166-1"]) { 358 value.forEach(function(v, k) { 359 c[v] = d[v]; 360 }); 361 return; 362 } 363 }); 364 }); 365 366 g.selectAll(".country") 367 .data(countries) 368 .enter().insert("path", ".graticule") 369 .attr("class", "country") 370 .attr("d", path) 371 .style("fill", function(d, i) { return d[value[0]] ? color(d[value[0]]) : "gray"; }) 372 .style("opacity", defaultOpacity); 373 374 g.insert("path", ".graticule") 375 .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; })) 376 .attr("class", "boundary") 377 .attr("d", path); 378 379 if(touch_device) { 380 g.selectAll(".country") 381 .on("touchstart", showTooltip); 382 } else { 383 g.selectAll(".country") 384 .on("mouseover", showTooltip) 385 .on("mousemove", moveTooltip) 386 .on("mouseout", hideTooltip) 387 .on("click", zoom); 388 } 389 390 function zoom(d) { 391 var x, y, k; 392 393 if (d && centered !== d) { 394 var centroid = path.centroid(d); 395 x = centroid[0]; 396 y = centroid[1]; 397 k = 4; 398 centered = d; 399 } else { 400 x = width / 2; 401 y = height / 2; 402 k = 1; 403 centered = null; 404 } 405 406 g.selectAll(".country") 407 .classed("active", centered && function(d) { return d === centered; }); 408 409 g.transition() 410 .duration(1000) 411 .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")") 412 .style("stroke-width", 1.5 / k + "px"); 413 } 414 415 if(debug) { console.log("END RENDER WORLD MAP COUNTRIES") }; 416 }; 417 } 418 261 419 function renderScatter(figure, data, category, value, format, color, sort, interpolate, animate, debug) { 262 420 if(debug) { console.log("START RENDER SCATTER"); } … … 803 961 .enter() 804 962 .append("td") 805 .text(function(d) { return d.value; });963 .text(function(d) { return isNumber(d.value) ? numberFormat(d.value) : d.value; }); 806 964 807 965 if(debug) { console.log("END RENDER TABLE"); } … … 853 1011 .enter() 854 1012 .append("td") 855 .text(function(d) { return d.value; });1013 .text(function(d) { return isNumber(d.value) ? numberFormat(d.value) : d.value; }); 856 1014 857 1015 if(debug) { console.log("END RENDER TABLE (deprecated)"); } … … 875 1033 .duration(100) 876 1034 .style("opacity", defaultOpacity); 1035 1036 d3.selectAll(".country").transition() 1037 .duration(100) 1038 .style("opacity", defaultOpacity); 877 1039 878 1040 d3.select(this).transition() … … 880 1042 .delay(100) 881 1043 .style("opacity", 1.0); 882 883 var dateFormat = d3.time.format("%d-%b-%Y %X"); 884 1044 885 1045 tooltip.html(function() { 886 1046 var str = ""; … … 890 1050 if(val instanceof Date) { 891 1051 val = dateFormat(val); 1052 } else if(isNumber(val)) { 1053 val = numberFormat(val); 892 1054 } 893 1055 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 894 1056 } 895 } else { 1057 } else { 896 1058 for(var e in d) { 897 1059 var val = d[e]; 898 1060 if(val instanceof Date) { 899 1061 val = dateFormat(val); 900 } 901 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1062 } else if(isNumber(val)) { 1063 val = numberFormat(val); 1064 } 1065 if(d.type == "Polygon" || d.type == "MultiPolygon") { 1066 if(e == 'id') { 1067 str += "<span class='ISO-3166-1'>" + val + "</span><br/>"; 1068 } else if(e != 'type' && e != 'coordinates') { 1069 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1070 } 1071 } else { 1072 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1073 } 902 1074 } 903 1075 } … … 947 1119 .style("opacity", defaultOpacity); 948 1120 1121 d3.selectAll(".country").transition() 1122 .duration(200) 1123 .style("opacity", defaultOpacity); 1124 949 1125 tooltip.transition() 950 1126 .duration(200) -
ipu-chart/tags/0.5/readme.txt
r708153 r709779 1 1 === Plugin Name === 2 2 Contributors: thmufl 3 Tags: chart, diagram, svg, csv, excel, numbers, bar chart, pie chart, line chart, donut chart, scatter chart, animation, quotes3 Tags: chart, bar chart, pie chart, line chart, donut chart, scatter chart, world map, map, countries, animation, quotes, diagram, csv, tsv, excel, numbers, svg, d3, d3js 4 4 Requires at least: 3.0.1 5 5 Tested up to: 3.5.1 6 Stable tag: 0. 4.16 Stable tag: 0.5 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 Creates SVG based, animated bar, pie, donut, line and scattercharts out of your data. A powerful, easy to use shortcode.10 Creates SVG based, animated bar, pie, donut, line, scatter and word map charts out of your data. A powerful, easy to use shortcode. 11 11 12 12 == Description == 13 13 14 IPU-Chart is an easy to use shortcode that creates SVG based bar, pie, donut, line and scattercharts out of your csv (comma separated) or tsv (tab separated) data.14 IPU-Chart is an easy to use shortcode that creates SVG based bar, pie, donut, line, scatter and world map charts out of your csv (comma separated) or tsv (tab separated) data. 15 15 16 16 The plugin allows you to load the data to display as a chart from a remote service that delivers csv or tsv formatted data. You can also export you data from favorite spreadsheet application (Excel, Numbers, Open Office) and display it as a chart in your blog or page. … … 18 18 IPU-Chart is based on [SVG](http://www.w3.org/TR/SVG/) and [D3](http://d3js.org/). It works perfectly on large computer screens as well as on tablets and smaller mobile screens. For browsers that do not support SVG an alternative image can be set. 19 19 20 The styling of all chart types can be done precisely and easily with css. 20 The styling of all chart types can be done precisely and easily with css. 21 21 22 22 = Features = 23 23 24 * Create bar, pie, donut, line and scattercharts24 * Create bar, pie, donut, line, scatter charts and world map charts 25 25 * Enter the csv/tsv data directy in you blog or page 26 26 * Load the csv/tsv data from a remote location … … 28 28 * Style the charts with css 29 29 * Tooltip for chart details (see screenshots) 30 * Animated bar charts30 * Animated world map and bar charts 31 31 * Define colors and number formats of the chart 32 32 * Create an additional table view of the data 33 33 34 34 = Usage = 35 36 *Read our blog [Create a World Map in WordPress](https://www.ipublia.com/create-a-world-map-in-wordpress/ "Create a World Map in WordPress") for a short introduction of the new world map chart.* 35 37 36 38 First, define your data. You can create it immediately in WordPress or copy and paste it from an export of your favourite spreadsheet application. Example: … … 45 47 </pre> 46 48 47 Second, define the chart. Reference the csv (or tsv). Set the chart type and the category and value column. Define the format (string, integer, float or date) of the category and value columns. Enter a title and a description for the chart:49 Second, define the chart. Reference the csv (or tsv). Set the chart type and the category and value column. Define the format (string, number, integer, float or date) of the category and value columns. Enter a title and a description for the chart: 48 50 49 51 <pre> … … 52 54 category='Country' 53 55 value='Population' 54 format='string, float'56 format='string, number' 55 57 title='Top five most populous countries of the world...' 56 58 description='The top five most populous countries of the world...' 57 59 animate='medium'] 58 60 </pre> 61 62 **Important:** Please enter the attributes in one line without the linefeeds (otherwise WordPress will not understand the shortcode). The linefeeds in the example are for legibility only. 59 63 60 64 But the data can of course also be requested by url: … … 65 69 category='Date' 66 70 value='Sales ($)' 67 format='dd.mm.yy, float'71 format='dd.mm.yy, number' 68 72 color='green' 69 73 title='Sales of the week'] … … 106 110 5. Line chart 107 111 6. Interpolated line chart 108 7. Scatter chart (simple)112 7. Scatter chart 109 113 8. Line chart with an alternative layout 114 9. World map chart 110 115 111 116 == Changelog == … … 145 150 * [tsv] shortcode added 146 151 152 = 0.5 = 153 * World Map chart type (map.world.countries) added 154 * number (n) as format added 155 * Improvements in formatting numbers 156 147 157 == Upgrade Notice == 148 158 … … 168 178 * Tables can now be defined with [chart type="table" ...]. The columns to display can now be choosen with the 'category' and 'value' attributes. 169 179 * The [table] shortcode is still supported but deprecated. 180 181 = 0.5 = 182 * World Map chart type (map.world.countries) added 183 * number (n) as format added 184 * Improvements in formatting numbers -
ipu-chart/trunk/css/ipu-chart.css
r705521 r709779 17 17 18 18 .chart svg { 19 //border: 2px solid red;19 // border: 2px solid red; 20 20 font: 0.8em sans-serif; 21 } 22 23 /* Map chart definitions */ 24 25 .ISO-3166-1 { 26 //color: transparent; 27 font-size: 0.8em; 28 } 29 30 .stroke { 31 fill: none; 32 stroke: dimgray; 33 stroke-width: 0.5px; 34 } 35 36 .fill { 37 fill: #fff; 38 } 39 40 .graticule { 41 fill: none; 42 stroke: #777; 43 stroke-width: .5px; 44 stroke-opacity: .5; 45 } 46 47 .land { 48 fill: #222; 49 } 50 51 .boundary { 52 fill: none; 53 stroke: #fff; 54 stroke-width: .5px; 21 55 } 22 56 -
ipu-chart/trunk/ipu-chart.php
r708090 r709779 2 2 /* 3 3 Plugin Name: IPU-Chart 4 Plugin URI: https://www.ipublia.com/ ipu-chart5 Description: Creates SVG based charts out of your comma or tab separated data. Currently supports bar, pie, donut, line and scattercharts.4 Plugin URI: https://www.ipublia.com/support/docs/ipu-chart-for-wordpress-user-guide/ 5 Description: Creates SVG based charts out of your comma or tab separated data. Currently supports bar, pie, donut, line, scatter and world map charts. 6 6 Author: ipublia, Thomas Müller Flury 7 Version: 0. 4.17 Version: 0.5 8 8 Author URI: https://www.ipublia.com/author/thmufl/ 9 9 Text Domain: ipuchart … … 129 129 // Add plug-in's scripts to the header of the pages 130 130 function ipu_add_custom_scripts() { 131 wp_register_script('custom-script-d3', plugins_url( '/js/d3/d3.v3.min.js', __FILE__ )); 131 wp_register_script('custom-script-d3', plugins_url( '/js/d3/d3.v3.min.js', __FILE__ )); 132 wp_register_script('custom-script-queue', plugins_url( '/js/d3/queue.v1.min.js', __FILE__ )); 133 wp_register_script('custom-script-d3-geo-projection', plugins_url( '/js/d3/d3.geo.projection.v0.min.js', __FILE__ )); 134 wp_register_script('custom-script-topojson', plugins_url( '/js/d3/topojson.v0.min.js', __FILE__ )); 132 135 wp_register_script('custom-script-ipuc', plugins_url( '/js/ipu-chart.js', __FILE__ )); 133 136 134 wp_enqueue_script('custom-script-d3'); 137 wp_enqueue_script('custom-script-d3'); 138 wp_enqueue_script('custom-script-queue'); 139 wp_enqueue_script('custom-script-d3-geo-projection'); 140 wp_enqueue_script('custom-script-topojson'); 135 141 wp_enqueue_script('custom-script-ipuc'); 136 142 } -
ipu-chart/trunk/js/ipu-chart.js
r708090 r709779 6 6 touch_device = window.Touch ? true : false, 7 7 svgSupport = window.SVGSVGElement ? true : false, 8 pluginPath = getPluginPath(), 8 9 defaultOpacity = 0.7, 9 10 tooltip; 11 12 function getPluginPath() { 13 var scripts = document.getElementsByTagName('script'); 14 var path = ''; 15 if(scripts && scripts.length>0) { 16 for(var i in scripts) { 17 if(scripts[i].src && scripts[i].src.indexOf("js/ipu-chart.js") > 0) { 18 file = scripts[i].src; 19 path = file.substring(0, file.indexOf("js/ipu-chart.js")); 20 break; 21 } 22 } 23 } 24 return path; 25 }; 10 26 11 27 function toArray(l) { … … 17 33 } 18 34 35 var dateFormat = d3.time.format("%d-%b-%Y"); 36 var numberFormat = d3.format("n"); 37 38 function isNumber(n) { 39 return !isNaN(parseFloat(n)) && isFinite(n); 40 } 41 19 42 function parserFor(format) { 20 43 format = format.trim(); 44 if(format == "n" || format == "number") return parseFloat; 21 45 if(format == "i" || format == "integer") return parseInt; 22 46 if(format == "f" || format == "float") return parseFloat; … … 96 120 var svg = figure.append("svg"); 97 121 98 svg.append("g") 99 .attr("class", "meta") 100 .append("title").text(title) 101 .append("description").text(description); 122 var meta = svg.append("g") 123 .attr("class", "meta"); 124 125 meta.append("title").text(title); 126 meta.append("description").text(description); 127 meta.append("a") 128 .attr("href", "https://www.ipublia.com/products/ipu-chart-svg-chart-library/") 129 .text(version + " (IPU448032107)"); 102 130 103 131 figure.append("figcaption").text(title); … … 141 169 142 170 console.log("PLUGIN: " 143 + "\n\t " + version);144 171 + "\n\tversion: " + version 172 + "\n\tpath: " + getPluginPath()); 145 173 146 174 console.log("CALL RENDER CHART: " … … 179 207 color = toArray(color); 180 208 animate = toArray(animate); 181 209 182 210 if(animate[0] == "slow") animate = ["5000", "linear"]; 183 211 else if(animate[0] == "medium") animate = ["2000", "linear"]; … … 233 261 234 262 data = parseData(data, category, value, format, debug); 235 263 236 264 if(type.toLowerCase().trim() == "bar") 237 265 renderBar(figure, data, category, value, format, color, sort, interpolate, animate, debug); … … 252 280 renderScatter(figure, data, category, value, format, color, sort, interpolate, animate, debug); 253 281 282 else if(type.toLowerCase().trim() == "map.world.countries") 283 renderMapWorldCountries(figure, data, category, value, format, color, sort, interpolate, animate, debug); 284 254 285 else if(type.toLowerCase().trim() == "table") 255 286 renderTable(figure, data, category, value, debug); … … 259 290 } 260 291 292 function renderMapWorldCountries(figure, data, category, value, format, color, sort, interpolate, animate, debug) { 293 if(debug) console.log("START RENDER WORLD MAP COUNTRIES"); 294 295 var color = d3.scale.log() 296 .domain(d3.extent(data, function(d) { return d[value[0]] })) 297 .range([color[0], color[1]]); 298 299 var svg = figure.select("svg"); 300 var g = svg.select("g.main"); 301 302 var margin = {top: 1, right: 1, bottom: 1, left: 1}, 303 width = parseInt(svg.attr("width")) - margin.left - margin.right, 304 height = parseInt(svg.attr("height")) - margin.top - margin.bottom, 305 centered; 306 307 var projection = d3.geo.kavrayskiy7() 308 .scale(105) 309 .translate([width / 2, height / 2]) 310 .precision(.1); 311 312 var path = d3.geo.path() 313 .projection(projection); 314 315 var graticule = d3.geo.graticule(); 316 317 g.append("defs").append("path") 318 .datum({type: "Sphere"}) 319 .attr("id", "sphere") 320 .attr("d", path); 321 322 g.append("use") 323 .attr("class", "stroke") 324 .attr("xlink:href", "#sphere"); 325 326 g.append("use") 327 .attr("class", "fill") 328 .attr("xlink:href", "#sphere"); 329 330 g.append("path") 331 .datum(graticule) 332 .attr("class", "graticule") 333 .attr("d", path); 334 335 queue() 336 .defer(d3.json, pluginPath + "raw/world-110m.json") 337 .defer(d3.tsv, pluginPath + "raw/world-ISO-3166-1-numeric.tsv") 338 .await(ready); 339 340 function ready(error, world, names) { 341 var globe = {type: "Sphere"}, 342 land = topojson.object(world, world.objects.land), 343 countries = topojson.object(world, world.objects.countries).geometries, 344 borders = topojson.mesh(world, world.objects.countries, function(a, b) { return a.id !== b.id; }); 345 346 countries = countries.filter(function(d) { 347 return names.some(function(n) { 348 if (d.id == n["ISO-3166-1"]) return d.name = n.name; 349 }); 350 }).sort(function(a, b) { 351 return a.name.localeCompare(b.name); 352 }); 353 354 355 data.forEach(function(d, i) { 356 countries.forEach(function(c, j) { 357 if (c.id == d["ISO-3166-1"]) { 358 value.forEach(function(v, k) { 359 c[v] = d[v]; 360 }); 361 return; 362 } 363 }); 364 }); 365 366 g.selectAll(".country") 367 .data(countries) 368 .enter().insert("path", ".graticule") 369 .attr("class", "country") 370 .attr("d", path) 371 .style("fill", function(d, i) { return d[value[0]] ? color(d[value[0]]) : "gray"; }) 372 .style("opacity", defaultOpacity); 373 374 g.insert("path", ".graticule") 375 .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; })) 376 .attr("class", "boundary") 377 .attr("d", path); 378 379 if(touch_device) { 380 g.selectAll(".country") 381 .on("touchstart", showTooltip); 382 } else { 383 g.selectAll(".country") 384 .on("mouseover", showTooltip) 385 .on("mousemove", moveTooltip) 386 .on("mouseout", hideTooltip) 387 .on("click", zoom); 388 } 389 390 function zoom(d) { 391 var x, y, k; 392 393 if (d && centered !== d) { 394 var centroid = path.centroid(d); 395 x = centroid[0]; 396 y = centroid[1]; 397 k = 4; 398 centered = d; 399 } else { 400 x = width / 2; 401 y = height / 2; 402 k = 1; 403 centered = null; 404 } 405 406 g.selectAll(".country") 407 .classed("active", centered && function(d) { return d === centered; }); 408 409 g.transition() 410 .duration(1000) 411 .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")") 412 .style("stroke-width", 1.5 / k + "px"); 413 } 414 415 if(debug) { console.log("END RENDER WORLD MAP COUNTRIES") }; 416 }; 417 } 418 261 419 function renderScatter(figure, data, category, value, format, color, sort, interpolate, animate, debug) { 262 420 if(debug) { console.log("START RENDER SCATTER"); } … … 803 961 .enter() 804 962 .append("td") 805 .text(function(d) { return d.value; });963 .text(function(d) { return isNumber(d.value) ? numberFormat(d.value) : d.value; }); 806 964 807 965 if(debug) { console.log("END RENDER TABLE"); } … … 853 1011 .enter() 854 1012 .append("td") 855 .text(function(d) { return d.value; });1013 .text(function(d) { return isNumber(d.value) ? numberFormat(d.value) : d.value; }); 856 1014 857 1015 if(debug) { console.log("END RENDER TABLE (deprecated)"); } … … 875 1033 .duration(100) 876 1034 .style("opacity", defaultOpacity); 1035 1036 d3.selectAll(".country").transition() 1037 .duration(100) 1038 .style("opacity", defaultOpacity); 877 1039 878 1040 d3.select(this).transition() … … 880 1042 .delay(100) 881 1043 .style("opacity", 1.0); 882 883 var dateFormat = d3.time.format("%d-%b-%Y %X"); 884 1044 885 1045 tooltip.html(function() { 886 1046 var str = ""; … … 890 1050 if(val instanceof Date) { 891 1051 val = dateFormat(val); 1052 } else if(isNumber(val)) { 1053 val = numberFormat(val); 892 1054 } 893 1055 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 894 1056 } 895 } else { 1057 } else { 896 1058 for(var e in d) { 897 1059 var val = d[e]; 898 1060 if(val instanceof Date) { 899 1061 val = dateFormat(val); 900 } 901 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1062 } else if(isNumber(val)) { 1063 val = numberFormat(val); 1064 } 1065 if(d.type == "Polygon" || d.type == "MultiPolygon") { 1066 if(e == 'id') { 1067 str += "<span class='ISO-3166-1'>" + val + "</span><br/>"; 1068 } else if(e != 'type' && e != 'coordinates') { 1069 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1070 } 1071 } else { 1072 str += "<span class='label'>" + e + "</span>" + val + "<br/>"; 1073 } 902 1074 } 903 1075 } … … 947 1119 .style("opacity", defaultOpacity); 948 1120 1121 d3.selectAll(".country").transition() 1122 .duration(200) 1123 .style("opacity", defaultOpacity); 1124 949 1125 tooltip.transition() 950 1126 .duration(200) -
ipu-chart/trunk/readme.txt
r708153 r709779 1 1 === Plugin Name === 2 2 Contributors: thmufl 3 Tags: chart, diagram, svg, csv, excel, numbers, bar chart, pie chart, line chart, donut chart, scatter chart, animation, quotes3 Tags: chart, bar chart, pie chart, line chart, donut chart, scatter chart, world map, map, countries, animation, quotes, diagram, csv, tsv, excel, numbers, svg, d3, d3js 4 4 Requires at least: 3.0.1 5 5 Tested up to: 3.5.1 6 Stable tag: 0. 4.16 Stable tag: 0.5 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 Creates SVG based, animated bar, pie, donut, line and scattercharts out of your data. A powerful, easy to use shortcode.10 Creates SVG based, animated bar, pie, donut, line, scatter and word map charts out of your data. A powerful, easy to use shortcode. 11 11 12 12 == Description == 13 13 14 IPU-Chart is an easy to use shortcode that creates SVG based bar, pie, donut, line and scattercharts out of your csv (comma separated) or tsv (tab separated) data.14 IPU-Chart is an easy to use shortcode that creates SVG based bar, pie, donut, line, scatter and world map charts out of your csv (comma separated) or tsv (tab separated) data. 15 15 16 16 The plugin allows you to load the data to display as a chart from a remote service that delivers csv or tsv formatted data. You can also export you data from favorite spreadsheet application (Excel, Numbers, Open Office) and display it as a chart in your blog or page. … … 18 18 IPU-Chart is based on [SVG](http://www.w3.org/TR/SVG/) and [D3](http://d3js.org/). It works perfectly on large computer screens as well as on tablets and smaller mobile screens. For browsers that do not support SVG an alternative image can be set. 19 19 20 The styling of all chart types can be done precisely and easily with css. 20 The styling of all chart types can be done precisely and easily with css. 21 21 22 22 = Features = 23 23 24 * Create bar, pie, donut, line and scattercharts24 * Create bar, pie, donut, line, scatter charts and world map charts 25 25 * Enter the csv/tsv data directy in you blog or page 26 26 * Load the csv/tsv data from a remote location … … 28 28 * Style the charts with css 29 29 * Tooltip for chart details (see screenshots) 30 * Animated bar charts30 * Animated world map and bar charts 31 31 * Define colors and number formats of the chart 32 32 * Create an additional table view of the data 33 33 34 34 = Usage = 35 36 *Read our blog [Create a World Map in WordPress](https://www.ipublia.com/create-a-world-map-in-wordpress/ "Create a World Map in WordPress") for a short introduction of the new world map chart.* 35 37 36 38 First, define your data. You can create it immediately in WordPress or copy and paste it from an export of your favourite spreadsheet application. Example: … … 45 47 </pre> 46 48 47 Second, define the chart. Reference the csv (or tsv). Set the chart type and the category and value column. Define the format (string, integer, float or date) of the category and value columns. Enter a title and a description for the chart:49 Second, define the chart. Reference the csv (or tsv). Set the chart type and the category and value column. Define the format (string, number, integer, float or date) of the category and value columns. Enter a title and a description for the chart: 48 50 49 51 <pre> … … 52 54 category='Country' 53 55 value='Population' 54 format='string, float'56 format='string, number' 55 57 title='Top five most populous countries of the world...' 56 58 description='The top five most populous countries of the world...' 57 59 animate='medium'] 58 60 </pre> 61 62 **Important:** Please enter the attributes in one line without the linefeeds (otherwise WordPress will not understand the shortcode). The linefeeds in the example are for legibility only. 59 63 60 64 But the data can of course also be requested by url: … … 65 69 category='Date' 66 70 value='Sales ($)' 67 format='dd.mm.yy, float'71 format='dd.mm.yy, number' 68 72 color='green' 69 73 title='Sales of the week'] … … 106 110 5. Line chart 107 111 6. Interpolated line chart 108 7. Scatter chart (simple)112 7. Scatter chart 109 113 8. Line chart with an alternative layout 114 9. World map chart 110 115 111 116 == Changelog == … … 145 150 * [tsv] shortcode added 146 151 152 = 0.5 = 153 * World Map chart type (map.world.countries) added 154 * number (n) as format added 155 * Improvements in formatting numbers 156 147 157 == Upgrade Notice == 148 158 … … 168 178 * Tables can now be defined with [chart type="table" ...]. The columns to display can now be choosen with the 'category' and 'value' attributes. 169 179 * The [table] shortcode is still supported but deprecated. 180 181 = 0.5 = 182 * World Map chart type (map.world.countries) added 183 * number (n) as format added 184 * Improvements in formatting numbers
Note: See TracChangeset
for help on using the changeset viewer.