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







      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 at 11:25

























      asked Nov 22 at 6:29









      Dung Ho

      626




      626
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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.



          I should add this to the Crossfilter Gotchas page, since it's something everyone runs into when they start using the library. (I don't remember the rationale at the moment, but I think at one point I determined this is the only consistent way that crossfilter could be implemented.)



          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





















            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









            0














            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.



            I should add this to the Crossfilter Gotchas page, since it's something everyone runs into when they start using the library. (I don't remember the rationale at the moment, but I think at one point I determined this is the only consistent way that crossfilter could be implemented.)



            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


























              0














              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.



              I should add this to the Crossfilter Gotchas page, since it's something everyone runs into when they start using the library. (I don't remember the rationale at the moment, but I think at one point I determined this is the only consistent way that crossfilter could be implemented.)



              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
























                0












                0








                0






                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.



                I should add this to the Crossfilter Gotchas page, since it's something everyone runs into when they start using the library. (I don't remember the rationale at the moment, but I think at one point I determined this is the only consistent way that crossfilter could be implemented.)



                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.



                I should add this to the Crossfilter Gotchas page, since it's something everyone runs into when they start using the library. (I don't remember the rationale at the moment, but I think at one point I determined this is the only consistent way that crossfilter could be implemented.)



                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










                answered Nov 28 at 14:43









                Gordon

                12.9k32159




                12.9k32159






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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







                    Popular posts from this blog

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

                    Berounka

                    I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...