Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/analytics #54

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_SUBSQUID_URL="https://squid.subsquid.io/origin-squid/v/v5/graphql"
VITE_SUBSQUID_URL="https://squid.subsquid.io/origin-squid/v/v6/graphql"
4 changes: 0 additions & 4 deletions .graphqlconfig

This file was deleted.

1 change: 1 addition & 0 deletions graphql.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schema: https://squid.subsquid.io/origin-squid/v/v6/graphql
12 changes: 12 additions & 0 deletions libs/analytics/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions libs/analytics/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/analytics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# analytics

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test analytics` to execute the unit tests via [Jest](https://jestjs.io).
16 changes: 16 additions & 0 deletions libs/analytics/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "analytics",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/analytics/src",
"projectType": "library",
"tags": [],
"targets": {
apexearth marked this conversation as resolved.
Show resolved Hide resolved
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/analytics/**/*.{ts,tsx,js,jsx}"]
}
}
}
}
68 changes: 68 additions & 0 deletions libs/analytics/src/TimeLineChart.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { faker } from '@faker-js/faker';
import { Container } from '@mui/material';
import dayjs from 'dayjs';

import { TimeLineChart } from './TimeLineChart';

import type { Meta, StoryObj } from '@storybook/react';

faker.seed(4548);

function array<T>(n: number, initial: T, fn: (last: T) => T) {
let last: T = initial;
return new Array(n).fill(0).map((_, index) => {
if (index === 0) return last;
return (last = fn(last));
});
}

const ema = (p: number) => {
let last: number;
return (val: number) => {
return (last = (val + (last ?? val) * (p - 1)) / p);
};
};

const smooth = ema(7);

const meta: Meta<typeof TimeLineChart> = {
component: TimeLineChart,
title: 'Analytics/TimeLineChart',
args: {
title: 'APY',
filter: {
options: ['1W', '1M', '6M', '1Y', 'All'],
value: '1W',
onChange: (value) => console.log(value),
},
data: {
datasets: [
{
type: 'line',
data: array(180, { x: new Date('2023-01-01'), y: 0.05 }, (last) => ({
x: dayjs(last.x).add(1, 'day').toDate(),
y: faker.number.float({
min: last.y * 0.9,
max: last.y * 1.1,
}),
})).map((d) => ({
x: d.x,
y: smooth(d.y),
})),
},
],
},
formatValues: (val) => {
return `${Math.floor(Number(val) * 10000) / 100}%`;
},
},
render: (args) => (
<Container>
<TimeLineChart {...args} />
</Container>
),
};

export default meta;

export const Default: StoryObj<typeof TimeLineChart> = {};
Loading
Loading