Crossfilter - Cannot get filtered records from other groups (NOT from associate groups)












2















I'm working with "airplane" data set from this reference http://square.github.io/crossfilter/



date,delay,distance,origin,destination
01010001,14,405,MCI,MDW
01010530,-11,370,LAX,PHX
...

// Create the crossfilter for the relevant dimensions and groups.
var flight = crossfilter(flights),
all = flight.groupAll(),
date = flight.dimension(function(d) { return d.date; }),
dates = date.group(d3.time.day),
hour = flight.dimension(function(d) { return d.date.getHours() + d.date.getMinutes() / 60; }),
hours = hour.group(Math.floor),
delay = flight.dimension(function(d) { return Math.max(-60, Math.min(149, d.delay)); }),
delays = delay.group(function(d) { return Math.floor(d / 10) * 10; }),
distance = flight.dimension(function(d) { return Math.min(1999, d.distance); }),
distances = distance.group(function(d) { return Math.floor(d / 50) * 50; });


Following document of Crossfilter, "groups don't observe the filters on their own dimension" => we can get filtered records from groups that theirs dimension are not filtered at this moment, can't we?



I have performed some test but this is not correct:



  console.dir(date.group().all()); // 50895 records
console.dir(distance.group().all()); // 297 records

date.filter([new Date(2001, 1, 1), new Date(2001, 2, 1)]);

console.dir(date.group().all()); // 50895 records => this number still the same because we are filtering on its dimension
console.dir(distance.group().all()); // 297 records => but this number still the same too. I don't know why



  1. Could you please explain for me why number of "distance.group().all()" still the same as before we perform the filter? Am I missing something here?


  2. If we really cannot get "filtered records" from "distance dimension" by this way, how can I achive this?



Thanks.










share|improve this question





























    2















    I'm working with "airplane" data set from this reference http://square.github.io/crossfilter/



    date,delay,distance,origin,destination
    01010001,14,405,MCI,MDW
    01010530,-11,370,LAX,PHX
    ...

    // Create the crossfilter for the relevant dimensions and groups.
    var flight = crossfilter(flights),
    all = flight.groupAll(),
    date = flight.dimension(function(d) { return d.date; }),
    dates = date.group(d3.time.day),
    hour = flight.dimension(function(d) { return d.date.getHours() + d.date.getMinutes() / 60; }),
    hours = hour.group(Math.floor),
    delay = flight.dimension(function(d) { return Math.max(-60, Math.min(149, d.delay)); }),
    delays = delay.group(function(d) { return Math.floor(d / 10) * 10; }),
    distance = flight.dimension(function(d) { return Math.min(1999, d.distance); }),
    distances = distance.group(function(d) { return Math.floor(d / 50) * 50; });


    Following document of Crossfilter, "groups don't observe the filters on their own dimension" => we can get filtered records from groups that theirs dimension are not filtered at this moment, can't we?



    I have performed some test but this is not correct:



      console.dir(date.group().all()); // 50895 records
    console.dir(distance.group().all()); // 297 records

    date.filter([new Date(2001, 1, 1), new Date(2001, 2, 1)]);

    console.dir(date.group().all()); // 50895 records => this number still the same because we are filtering on its dimension
    console.dir(distance.group().all()); // 297 records => but this number still the same too. I don't know why



    1. Could you please explain for me why number of "distance.group().all()" still the same as before we perform the filter? Am I missing something here?


    2. If we really cannot get "filtered records" from "distance dimension" by this way, how can I achive this?



    Thanks.










    share|improve this question



























      2












      2








      2


      1






      I'm working with "airplane" data set from this reference http://square.github.io/crossfilter/



      date,delay,distance,origin,destination
      01010001,14,405,MCI,MDW
      01010530,-11,370,LAX,PHX
      ...

      // Create the crossfilter for the relevant dimensions and groups.
      var flight = crossfilter(flights),
      all = flight.groupAll(),
      date = flight.dimension(function(d) { return d.date; }),
      dates = date.group(d3.time.day),
      hour = flight.dimension(function(d) { return d.date.getHours() + d.date.getMinutes() / 60; }),
      hours = hour.group(Math.floor),
      delay = flight.dimension(function(d) { return Math.max(-60, Math.min(149, d.delay)); }),
      delays = delay.group(function(d) { return Math.floor(d / 10) * 10; }),
      distance = flight.dimension(function(d) { return Math.min(1999, d.distance); }),
      distances = distance.group(function(d) { return Math.floor(d / 50) * 50; });


      Following document of Crossfilter, "groups don't observe the filters on their own dimension" => we can get filtered records from groups that theirs dimension are not filtered at this moment, can't we?



      I have performed some test but this is not correct:



        console.dir(date.group().all()); // 50895 records
      console.dir(distance.group().all()); // 297 records

      date.filter([new Date(2001, 1, 1), new Date(2001, 2, 1)]);

      console.dir(date.group().all()); // 50895 records => this number still the same because we are filtering on its dimension
      console.dir(distance.group().all()); // 297 records => but this number still the same too. I don't know why



      1. Could you please explain for me why number of "distance.group().all()" still the same as before we perform the filter? Am I missing something here?


      2. If we really cannot get "filtered records" from "distance dimension" by this way, how can I achive this?



      Thanks.










      share|improve this question
















      I'm working with "airplane" data set from this reference http://square.github.io/crossfilter/



      date,delay,distance,origin,destination
      01010001,14,405,MCI,MDW
      01010530,-11,370,LAX,PHX
      ...

      // Create the crossfilter for the relevant dimensions and groups.
      var flight = crossfilter(flights),
      all = flight.groupAll(),
      date = flight.dimension(function(d) { return d.date; }),
      dates = date.group(d3.time.day),
      hour = flight.dimension(function(d) { return d.date.getHours() + d.date.getMinutes() / 60; }),
      hours = hour.group(Math.floor),
      delay = flight.dimension(function(d) { return Math.max(-60, Math.min(149, d.delay)); }),
      delays = delay.group(function(d) { return Math.floor(d / 10) * 10; }),
      distance = flight.dimension(function(d) { return Math.min(1999, d.distance); }),
      distances = distance.group(function(d) { return Math.floor(d / 50) * 50; });


      Following document of Crossfilter, "groups don't observe the filters on their own dimension" => we can get filtered records from groups that theirs dimension are not filtered at this moment, can't we?



      I have performed some test but this is not correct:



        console.dir(date.group().all()); // 50895 records
      console.dir(distance.group().all()); // 297 records

      date.filter([new Date(2001, 1, 1), new Date(2001, 2, 1)]);

      console.dir(date.group().all()); // 50895 records => this number still the same because we are filtering on its dimension
      console.dir(distance.group().all()); // 297 records => but this number still the same too. I don't know why



      1. Could you please explain for me why number of "distance.group().all()" still the same as before we perform the filter? Am I missing something here?


      2. If we really cannot get "filtered records" from "distance dimension" by this way, how can I achive this?



      Thanks.







      javascript crossfilter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 11:25







      Dung Ho

















      asked Nov 22 '18 at 6:29









      Dung HoDung Ho

      646




      646
























          1 Answer
          1






          active

          oldest

          votes


















          1














          So, yes, this is the expected behavior.



          Crossfilter will create a "bin" in the group for every value it finds by applying the dimension key and group key functions. Then when a filter is applied, it will apply the reduce-remove function, which by default subtracts the count of rows removed.



          The result is that empty bins still exist, but they have a value of 0.



          EDIT: here is the Crossfilter Gotchas entry with further explanation.



          If you want to remove the zeros, you can use a "fake group" to do that.



          function remove_empty_bins(source_group) {
          return {
          all:function () {
          return source_group.all().filter(function(d) {
          //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
          return d.value !== 0; // if integers only
          });
          }
          };
          }


          https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins



          This function wraps the group in an object which implements .all() by calling source_group.all() and then filters the result. So if you're using dc.js you could supply this fake group to your chart like so:



          chart.group(remove_empty_bins(yourGroup));





          share|improve this answer


























          • You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

            – Dung Ho
            Feb 6 at 14:13













          • Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

            – Gordon
            Feb 6 at 15:48











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425052%2fcrossfilter-cannot-get-filtered-records-from-other-groups-not-from-associate%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          So, yes, this is the expected behavior.



          Crossfilter will create a "bin" in the group for every value it finds by applying the dimension key and group key functions. Then when a filter is applied, it will apply the reduce-remove function, which by default subtracts the count of rows removed.



          The result is that empty bins still exist, but they have a value of 0.



          EDIT: here is the Crossfilter Gotchas entry with further explanation.



          If you want to remove the zeros, you can use a "fake group" to do that.



          function remove_empty_bins(source_group) {
          return {
          all:function () {
          return source_group.all().filter(function(d) {
          //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
          return d.value !== 0; // if integers only
          });
          }
          };
          }


          https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins



          This function wraps the group in an object which implements .all() by calling source_group.all() and then filters the result. So if you're using dc.js you could supply this fake group to your chart like so:



          chart.group(remove_empty_bins(yourGroup));





          share|improve this answer


























          • You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

            – Dung Ho
            Feb 6 at 14:13













          • Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

            – Gordon
            Feb 6 at 15:48
















          1














          So, yes, this is the expected behavior.



          Crossfilter will create a "bin" in the group for every value it finds by applying the dimension key and group key functions. Then when a filter is applied, it will apply the reduce-remove function, which by default subtracts the count of rows removed.



          The result is that empty bins still exist, but they have a value of 0.



          EDIT: here is the Crossfilter Gotchas entry with further explanation.



          If you want to remove the zeros, you can use a "fake group" to do that.



          function remove_empty_bins(source_group) {
          return {
          all:function () {
          return source_group.all().filter(function(d) {
          //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
          return d.value !== 0; // if integers only
          });
          }
          };
          }


          https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins



          This function wraps the group in an object which implements .all() by calling source_group.all() and then filters the result. So if you're using dc.js you could supply this fake group to your chart like so:



          chart.group(remove_empty_bins(yourGroup));





          share|improve this answer


























          • You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

            – Dung Ho
            Feb 6 at 14:13













          • Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

            – Gordon
            Feb 6 at 15:48














          1












          1








          1







          So, yes, this is the expected behavior.



          Crossfilter will create a "bin" in the group for every value it finds by applying the dimension key and group key functions. Then when a filter is applied, it will apply the reduce-remove function, which by default subtracts the count of rows removed.



          The result is that empty bins still exist, but they have a value of 0.



          EDIT: here is the Crossfilter Gotchas entry with further explanation.



          If you want to remove the zeros, you can use a "fake group" to do that.



          function remove_empty_bins(source_group) {
          return {
          all:function () {
          return source_group.all().filter(function(d) {
          //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
          return d.value !== 0; // if integers only
          });
          }
          };
          }


          https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins



          This function wraps the group in an object which implements .all() by calling source_group.all() and then filters the result. So if you're using dc.js you could supply this fake group to your chart like so:



          chart.group(remove_empty_bins(yourGroup));





          share|improve this answer















          So, yes, this is the expected behavior.



          Crossfilter will create a "bin" in the group for every value it finds by applying the dimension key and group key functions. Then when a filter is applied, it will apply the reduce-remove function, which by default subtracts the count of rows removed.



          The result is that empty bins still exist, but they have a value of 0.



          EDIT: here is the Crossfilter Gotchas entry with further explanation.



          If you want to remove the zeros, you can use a "fake group" to do that.



          function remove_empty_bins(source_group) {
          return {
          all:function () {
          return source_group.all().filter(function(d) {
          //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
          return d.value !== 0; // if integers only
          });
          }
          };
          }


          https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins



          This function wraps the group in an object which implements .all() by calling source_group.all() and then filters the result. So if you're using dc.js you could supply this fake group to your chart like so:



          chart.group(remove_empty_bins(yourGroup));






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 6 at 15:47

























          answered Nov 28 '18 at 14:43









          GordonGordon

          13.4k32262




          13.4k32262













          • You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

            – Dung Ho
            Feb 6 at 14:13













          • Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

            – Gordon
            Feb 6 at 15:48



















          • You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

            – Dung Ho
            Feb 6 at 14:13













          • Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

            – Gordon
            Feb 6 at 15:48

















          You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

          – Dung Ho
          Feb 6 at 14:13







          You're absolutely right. The value of "value" of these record (297 records) have been changed by the filter. Not the number of records (297 will be persist). Many thanks for your help and sorry for the late reponse!

          – Dung Ho
          Feb 6 at 14:13















          Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

          – Gordon
          Feb 6 at 15:48





          Glad I could help & thanks for following up. I've created a Crossfilter Gotcha for this and linked it above.

          – Gordon
          Feb 6 at 15:48




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425052%2fcrossfilter-cannot-get-filtered-records-from-other-groups-not-from-associate%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini