GithubHelp home page GithubHelp logo

Comments (4)

vasturiano avatar vasturiano commented on August 20, 2024 1

@pvictor you're right, there was a bug in the lib, in which changes to label or tooltipContent were not being taken into account. This is now fixed, so your example above should work in v1.0.6.
Thanks for the report!

from cartogram-chart.

vasturiano avatar vasturiano commented on August 20, 2024

@pvictor thanks for putting together this R wrapper. Looks great!
About the tooltip update, on select change you are changing the .value() accessor, but not the .label() so it still shows the same format as when it was initialized.

You probably just have to do:

$('#select').on('change', function() {
 selectValue = this.value;
 carto
   .value(function(d) { return d.properties[selectValue]; })
   .label(function(d) {
      return "Population of" + d.properties.name + "(" + d.properties[selectValue] + ")";
    })
 });

from cartogram-chart.

pvictor avatar pvictor commented on August 20, 2024

Thanks for your reply. This doesn't seems to work or I'm doing someting wrong (my JS skills are limited)

Here an adaptation of your world example :

<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js"></script>
    <script src="https://unpkg.com/cartogram-chart"></script>
</head>

<body>

<div class="form-group">
  <label class="control-label" for="select">Value:</label>
  <div>
    <select id="select" class="form-control">
	<option value="POP_EST" selected>POP_EST</option>
	<option value="GDP_MD_EST">GDP_MD_EST</option></select>
  </div>
</div>

    <div id="world"></div>

    <script>		
        d3.json('./ne_110m_admin_0_countries.json', (error, world) => {
            if (error) throw error;

            // exclude antarctica
            world.objects.countries.geometries.splice(
                world.objects.countries.geometries.findIndex(d => d.properties.ISO_A2 === 'AQ'),
                1
            );

            const colorScale = d3.scaleOrdinal([...d3.schemeCategory20, ...d3.schemeCategory20b, ...d3.schemeCategory20c]);

            carto = Cartogram()
                .topoJson(world)
                .topoObjectName('countries')
                .iterations(60)
                .value(({ properties }) => properties.POP_EST)
                .color(({ properties: { ISO_A2 } }) => colorScale(ISO_A2))
                .label(({ properties: p }) => `Population of ${p.NAME} (${p.ISO_A2})`)
                .valFormatter(d3.format(".3s"))
                .onClick(d => console.info(d))
                (document.getElementById('world'));
				
          document.getElementById("select").addEventListener("change", function() {
            var selectValue = document.getElementById("select").value;
            carto
              .value(function(d) {
                return d.properties[selectValue];
              })
              .label(function(d) {
                return "Population of" + d.properties.name + "(" + d.properties[selectValue] + ")";
              })
          }, false);
        });
		
		
    </script>
</body>

from cartogram-chart.

pvictor avatar pvictor commented on August 20, 2024

Amazing ! Many thanks !

from cartogram-chart.

Related Issues (7)

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.