-
I noticed this summarize function in the documentation but I can't seem to call it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Ah, good question. I'll update the docs to be more clear. In this case, since it depends on moment, you need to install a separate package. If you're using npm, you'd do this as follows:
Then you could use it: import { summarizeMomentGranularity } from '@tidyjs/tidy-moment'; If you're using the unpkg CDN, you would import it: (note that the order of the script tags matters) <!-- tidy + dependencies -->
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="https://www.unpkg.com/@tidyjs/tidy/dist/umd/tidy.min.js"></script>
<!-- tidy-moment + dependencies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://www.unpkg.com/@tidyjs/tidy-moment/dist/umd/tidy-moment.min.js"></script>
<!-- code to use tidy and tidy moment -->
<script>
const { tidy, sum } = Tidy;
const { summarizeMomentGranularity } = TidyMoment;
const data = [
{ str: "foo", date: moment.utc("2020-01-01"), value: 3 },
{ str: "foo", date: moment.utc("2020-01-03"), value: 1 },
{ str: "bar", date: moment.utc("2020-01-10"), value: 3 },
{ str: "bar", date: moment.utc("2020-01-21"), value: 1 },
{ str: "bar", date: moment.utc("2020-01-29"), value: 2 },
{ str: "bar", date: moment.utc("2020-02-01"), value: 5 }
];
const results = tidy(
data,
summarizeMomentGranularity("weeks", { value: sum("value") })
);
</script> Let me know if you have any further difficulties! |
Beta Was this translation helpful? Give feedback.
-
Hi, Any suggestions? Thanks! |
Beta Was this translation helpful? Give feedback.
Ah, good question. I'll update the docs to be more clear. In this case, since it depends on moment, you need to install a separate package. If you're using npm, you'd do this as follows:
Then you could use it:
If you're using the unpkg CDN, you would import it: (note that the order of the script tags matters)