Esri / cedar

JavaScript Charts for ArcGIS
https://esri.github.io/cedar
257 stars 238 forks source link

align Cedar's event API w/ that of the JSAPI #120

Open tomwayson opened 9 years ago

tomwayson commented 9 years ago

Looks like implementation of .off() is incomplete.

Also from @ycabon:

The API for on() is different from the rest of the API. It doesn't return a handler { remove: function() } but instead requires calling off(). I like off() over the handler pattern but for consistancy, on() should return an handler. The event is payload should be one object. with at least a target property, the one that emitted the event.

<div class="row">
  <div class="col-lg-12" id="chart"></div>
</div>

<script>
  //setup a chart using a json file that is the complete definition
  var chart = new Cedar({
    "definition":"../../../cedar/data/definitions/scatter-events.json"
  });

  //render the chart
  chart.show({
    elementId: "#chart"
  });

  //attach handler (can also be done before .show())
  var hdl = chart.on('click', function (event){
    hdl.remove();
    //dump event to console such as mouse location...
    console.dir(event.location);
    //dump data to console...
    console.dir(event.data);
  });

  window.onresize = function() { chart.update() }

</script>
tomwayson commented 9 years ago

I see @ajturner already opened #119, so this issue should just be about aligning w/ the JSAPI.