Code Monkey home page Code Monkey logo

gridviz's Introduction

Gridviz

npm bundle size npm license

Gridviz is a JavaScript library for visualizing gridded data (or any tabular dataset with x/y coordinates for that matter) in the browser using a large variety of cartographic styles and techniques. Unlike traditional raster-based web mapping tools, Gridviz renders everything client-side, on the fly.

Styles

Visit the style gallery to see the different customisable styles available for visualizing gridded data with gridviz.

Live Demos

Installation

Node.js

npm install gridviz

then

import * as gridviz from 'gridviz'

Or you can cherry-pick only the modules that you need, for example:

import { Map, SquareColorWebGLStyle } from 'gridviz'

Basic example

Here’s a basic example that loads a CSV file of a European population grid (5km resolution):

//define map with initial view
const map = new gridviz.Map(document.getElementById('map'), { x: 4500000, y: 2900000, z: 3000 })

//define dataset
const dataset = new gridviz.CSVGrid(map, "https://raw.githubusercontent.com/eurostat/gridviz/master/assets/csv/Europe/pop_2018_10km.csv", 10000)

//define color for each cell
const colorFunction = (cell) => {
    if (cell.population > 150000) return "#993404"
    else if (cell.population > 60000) return "#d95f0e"
    else if (cell.population > 20000) return "#fe9929"
    else if (cell.population > 6000) return "#fec44f"
    else if (cell.population > 1500) return "#fee391"
    else return "#ffffd4"
}

//define style
const style = new gridviz.ShapeColorSizeStyle({ color: colorFunction })

//add layer to map
map.layers = [new gridviz.GridLayer(dataset, [style])]

See the documentation page for more information.

standalone

<script src="https://unpkg.com/gridviz/dist/gridviz.min.js"></script>

Documentation

See the gridviz documentation page.

The document of the previous version 2.

Grid tiling

In order to visualize large grids efficiently, you can produce tiled grids in a tiled grid format with GridTiler.

About

contributors
version See npm
status Since 2020
license EUPL 1.2

Support and contribution

Feel free to ask support, fork the project or simply star it (it's always a pleasure).

Copyright

The Eurostat NUTS dataset is copyrighted. There are specific provisions for the usage of this dataset which must be respected. The usage of these data is subject to their acceptance. See the Eurostat-GISCO website for more information.

Disclaimer

The designations employed and the presentation of material on these maps do not imply the expression of any opinion whatsoever on the part of the European Union concerning the legal status of any country, territory, city or area or of its authorities, or concerning the delimitation of its frontiers or boundaries. Kosovo*: This designation is without prejudice to positions on status, and is in line with UNSCR 1244/1999 and the ICJ Opinion on the Kosovo declaration of independence. Palestine*: This designation shall not be construed as recognition of a State of Palestine and is without prejudice to the individual positions of the Member States on this issue.

gridviz's People

Contributors

dependabot[bot] avatar jgaffuri avatar joewdavies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gridviz's Issues

Dragging on touch starts too late (ontouchend) – with video

Dragging/Panning the map on a current iPad pro running iOS 16.5.1 I experience the following – even without WMS background layer:

  • the map only moves after I am ending the drag with a touch end

Will post a video of the observed behaviour versus the expected one.

Pinch to zoom not centred when embedded

Check these examples:

Pinch to zoom on a GridViz instance that takes the whole window works like expected, e.g. this one, where the zoom center roughly stays the same
https://eurostat.github.io/gridviz/examples/DE.html

Pinch to zoom in an embedded view (Observable or other) zooms the map but also moves the map in a north-eastern direction so that the detail you wanted to zoom in moves out of the viewport, e.g. in this example
https://observablehq.com/d/3d1d998ba43e1f69

See video here for detail on an iPad pro (iOS 17.1)
https://wahlatlas.net/experimente/testcases/gridviz_pinch_zoom_issue118.mp4

in the video the issue may look subtle, but there are cases, smaller embed, more removed from window edges, where this makes zooming on touch devices a two part action: first zoom, then drag backwards to the original position

Aria labels on tooltip

I have to admit, I am new to aria labels but it looked to me as if the tooltip would not be read by VoiceOver (screenreader assistive technology built into MacOS) until I injected the following aria labels

d3.select("#tooltip_eurostat").attr("role","tooltip").attr("aria-live","polite")

Combine ShapeColorSizeStyle with TextStyle

I could see some real world use cases, here's a photohopped version of how I imagine this.
Probably the additional text-layer would only make sense on lower zoom factors.

combined

Mobile double-tap zoom bug

Navigate to a gridviz map on a mobile device > double tap the screen > watch the chaos ensue

(tested on android)

Control outer diameter of donut shape

Not sure if the donut shape is an established cartographic style in that the outer diameter always equals the grid-size and only the inner diameter is controlled by data but this is what the current implementation in gridviz looks like to me and looks convincing when used on its own.

What I wanted to experiment with, is a ring around a pie chart, maybe as a border or drop shadow or to encode some additional variable. That might turn out to be aesthetically displeasing but I'd like to hear your opinion.

TextStyle properties behave inconsistently

within the TextStyle

the following works

        text: (v) => v >100 ? v : '',  
        fontSize: (v, r, s, zf) => zf >1 ? 0.4*r : 0.6*r,
        color: () => 'lime',

but this doesn't (always results in purple or no text)

        color: (v, r, s, zf) => zf >2 ? 'lime' : 'purple',
        text: (v, r, s, zf) => zf >2 ? v : '',

what am I doing wrong?

the original example has the following for color

        color: (v, r, s) => d3.interpolateSpectral(1 - (v - s.min) / (s.max - s.min))

but it should work without D3-scales, I guess
and, more importantly, it should also work dependent on zoom factor

BlendModes fixed in Firefox

as per
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

the default value for CanvasRenderingContext2D.globalCompositeOperation

is source-over

therefore, if we change the following in GridViz (/src/App.js)

//restore default alpha and blend operation
this.cg.ctx.globalAlpha = 1.0
this.cg.ctx.globalCompositeOperation = "normal"

to

this.cg.ctx.globalCompositeOperation = "source-over"

BlendModes work identical in Firefox as in Safari, see here in action
https://wahlatlas.net/experimente/z11exposee/gridviz/blendMode_Test.html#!4194642,2998537,0.27

WMS Tiles load faster without maxZoom

Hope I don't imagine it but initialy I found WMS tiles to load after a significant pause compared to QGis from the same tile server. However while experimenting with the maxZoom setting in .addBackgroundLayerWMS({ leaving out the maxZoom statement resulted in faster loading and a better initial experience (tests on retina displays):

before (maxZoom: 50)
withmaxzoom

after (//maxZoom)
without maxzoom

Data pre-processing and cellInfoHTML not possible in same layer

I tried everything, obeyed every comma and bracket, different ordering, but it seems that data pre-processing and cellInfoHTML are not possible in the same layer. Once you use preprocess everything in cellInfoHTML will be ignored and you just get the default tooltip with column name and value.

Among your examples I couldn't find an example that uses both.

Time series style

  • Add example with NO population - as sparkline ?
  • Add example with some climatic indicator

Center method not working on mobile

This is a bug related with d3 zoom. If the camera is moved using center([x,y]), then the first pan or zoom event will jerk the camera back to origin [0,0]. This does not occur on desktop.

Add BlendMode to Documentation

Should #110 turn out to achieve cross-browser and cross-os compatibility for blendmodes, please add the

blendOperation: (zf) => zf<1 ? "multiply" : "none",

syntax to the documentation

gvizLegend and tooltip_eurostat shouldn't be appended to body

I have to admit that I haven't fully understood how the legend works but by default it seems to be appended to the body element which is not ideal when used within larger pages where the map doesn't fill the whole viewport.

Might it be preferable to attach legend and tooltip div to the viz-container instead?

Background map and blend modes

Do I understand correctly that part of the perfomance trick gridviz does is, that everything in the viewport is rendered into one canvas element at once and that there are no distinct layers that could be styled individually by css?

I am asking this because background maps can greatly benefit from blend modes, as you can see in this example (1km grid, Census 2011 population counts, mix-blend-mode: multiply)

hd_blenmode_1km_pop_grid

and I was wondering if this could be achieved with gridviz

GridViz with React

Hi,
is there a possibility to use GridViz with React directly?
Or is the current workaround to integrate it with leaflet?

Thanks and best regards :)

opts.onZoomStartFun doesn't seem to fire

from the three zoom/pan events in the options object

onZoomStartFun: (event) => {
    console.log('pan/zoom start', event)
},
onZoomFun: (event) => {
    console.log('zoom', event)
},
onZoomEndFun: (event) => {
    console.log('pan/zoom end', event)
},

it looks to me as if the onZoomStartFun event doesn't fire
I do see "zoom" and "pan/zoom end" in the console but never "pan/zoom start"

Legend div definition

Currently, the div id is given to legendDivId option:
const map = new gridviz.Map(document.getElementById('map'), { x: 4500000, y: 2900000, z: 1000, legendDivId: 'ext_legend' })
instead, it should be a container. So that we can do instead something like:
const map = new gridviz.Map(document.getElementById('map'), { x: 4500000, y: 2900000, z: 1000, legendDiv: document.getElementById('ext_legend') })

Zoomed data-grid shows gaps

Have to investigate further and create example
this is 100m-grid-data with wms background.

works as expected in this zoom level
adjacent100m

same area as above but zoomed in further. results in data grid showing gaps:
zoomed100m

visualize tif ?

@joewdavies et al, once again this is great stuff! keep up the great work!

Would love to use the GridViz to display some grids and I have a 100m resolution tif that even if I rescale it to 1k yields about 200MB as a CSV. As a tif, it has about 2MB ...

I see that you have some tif files in your assets:
https://github.com/eurostat/gridviz/tree/master/assets/tiff/test

CSVs can be very inefficient as they repeat coordinates of the regular grid. An ASC file would reduce that size a little as the first rows define the grid.

But I can't see any reference to the tif assets usage. Are you planning to have some methods to visualize it?

Fix tooltip position

The tooltip position is not right. It happens in observable, and in general when the map is not at the top left of the browser window.
See: GridViz/examples/tooltip.html

The mouse position data seems not to be the right one.

Background Layer from WMS Tiles?

What I would like to accomplish is displaying data on the 100m grid from the German census like I've done in QGis

grid100m_title

So far I have the 100m grid data running for the whole of Germany with gridviz, see
https://wahlatlas.net/experimente/z11exposee/gridviz/basic.html

However the German mapping authority offers their background tiles only as WMS/WMTS, so an individual tile has the following URL
https://sgx.geodatenzentrum.de/wms_basemapde?&service=WMS&request=GetMap&layers=de_basemapde_web_raster_grau&styles=&format=image%2Fjpeg&transparent=false&version=1.1.1&width=256&height=256&srs=EPSG%3A3035&bbox=4198656.00000592,2939904.000260939,4207104.000005504,2948352.0002606986

whereas the Gisco tiles supported so far by gridviz seem to adhere to the slippy map standard like
https://gisco-services.ec.europa.eu/maps/tiles/NaturalEarth/EPSG3035/6/6/5.png

Now I wonder how/if I can make gridviz work with the WMS tiles as I did with e.g. leaflet.
I have looked into The difference between XYZ and TMS tiles and how to convert between them but couldn't figure out how to implement this in BackgroundLayer.js

Tiled format documentation – clarification needed

This looks like a terrific project that could solve a lot of challenges I regularly face. However it seems to me that tiling the csv-files for larger geographies is crucial. Do you have any preliminary documentation of the format no matter how rough around the edges it may be.

Also how did you create the files for your example. Is there any R or Python code to prepare the tiled csv format? That would obviously be even more appreciated than an elaborate documentation of the format.

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.