Skip to content

Commit

Permalink
Merge pull request #22 from eurostat/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
joewdavies authored Nov 30, 2020
2 parents 839605e + 9a0938b commit 1b66790
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 48 deletions.
31 changes: 13 additions & 18 deletions build/gridviz.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/gridviz.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/netherlands/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
.colorFieldSelectorLabel("Colour field: ")
.legend({
type: "cells",
orientation: "vertical",
width: 130,
height: 170,
title: "Total Inhabitants per 100m² (2018)",
Expand Down
1 change: 1 addition & 0 deletions examples/portugal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
.colorFieldSelectorLabel("Colour field: ")
.legend({
title: "Inhabitants per km² (2011)",
orentation: "vertical",
titleWidth: 150,
cells: 10,
format: ',.2r'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gridviz",
"version": "1.0.11",
"version": "1.0.12",
"description": "Visualization tool for gridded statistics",
"keywords": [
"statistics",
Expand Down
22 changes: 11 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ Here's a barebones example that loads a CSV containing population data for a 5 k

### Legend

| Method | Type | Default | Description |
| Method / Object | Type | Default | Description |
| ----------------------------- | ------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| viewer.showLegend([value]) | boolean | true | Build d3 colour legend. |
| viewer.legend([legendConfig]) | Object | See legendConfig default values below. |
| legendConfig.type | String | "continuous" | Type of legend to build. Accepted values are "cells" or "continuous". Cells uses [d3-svg-legend](https://d3-legend.susielu.com/) and continuous uses an implementation of Mike Bostock's [color legend](https://observablehq.com/@d3/color-legend) |
| legendConfig.width | int | 140 | width of the legend in pixels |
| legendConfig.height | int | 320 | height of the legend in pixels |
| legendConfig.orientation | int | 320 for "cells" and 50 for "continuous" | height of the legend in pixels. |
| legendConfig.title | String | "Legend" | Title text of the legend. |
| legendConfig.titleWidth | int | 50 | Width of the title text of the legend. |
| legendConfig.format | string | ".0s" | d3.format string used to format the legend values |
| legendConfig.cells | int | 5 | Number of cells (for cell legends only) |
| legendConfig.shapeWidth | int | 30 | width in pixels of legend cell (for cell legends only) |
| viewer.legend([**legendConfig**]) | Object | See legendConfig default values below. |
| **legendConfig**.type | String | "continuous" | Type of legend to build. Accepted values are "cells" or "continuous". Cells uses [d3-svg-legend](https://d3-legend.susielu.com/) and continuous uses an implementation of Mike Bostock's [color legend](https://observablehq.com/@d3/color-legend) |
| **legendConfig**.width | int | 140 | width of the legend in pixels |
| **legendConfig**.height | int | 320 for "cells" and 50 for "continuous" | height of the legend in pixels |
| **legendConfig**.orientation | int | For cells legends only | "vertical" or "horizontal" |
| **legendConfig**.title | String | "Legend" | Title text of the legend. |
| **legendConfig**.titleWidth | int | 50 | Width of the title text of the legend. |
| **legendConfig**.format | string | ".0s" | d3.format string used to format the legend values |
| **legendConfig**.cells | int | 5 | Number of cells (for cell legends only) |
| **legendConfig**.shapeWidth | int | 30 | width in pixels of legend cell (for cell legends only) |

## Developer docs

Expand Down
28 changes: 11 additions & 17 deletions src/js/gridviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function viewer(options) {
title: "Legend",
titleWidth: 50,
format: ".0s",
cells: 13,
cells: 5,
shapeWidth: 30
};
viewer._gridLegend; //legend stored here
Expand Down Expand Up @@ -1020,23 +1020,17 @@ export function viewer(options) {
*/
function addGridToCache(csv, res) {
if (csv) {
for (let i = 0; i < csv.length; i++) {
let x, y;
if (viewer._mobile) {
x = viewer.mobileCoordScale(parseFloat(csv[i].x));
y = viewer.mobileCoordScale(parseFloat(csv[i].y));
} else {
x = csv[i].x;
y = csv[i].y;
if (viewer._mobile) {
for (let i = 0; i < csv.length; i++) {
//scale mobile coordinates to avoid d3 pan/zoom bug
let point = csv[i];
point.x = viewer.mobileCoordScale(parseFloat(csv[i].x));
point.y = viewer.mobileCoordScale(parseFloat(csv[i].y));
if (!gridCaches[res]) gridCaches[res] = [];
gridCaches[res].push(point);
}
let value = csv[i][viewer.colorField_];
let point = {
x,
y,
[viewer.colorField_]: value
};
if (!gridCaches[res]) gridCaches[res] = [];
gridCaches[res].push(point);
} else {
if (!gridCaches[res]) gridCaches[res] = csv
}
}
}
Expand Down

0 comments on commit 1b66790

Please sign in to comment.