[@portaljs/components][m] - LineChart fix

This commit is contained in:
Luccas Mateus de Medeiros Gomes
2023-05-25 13:29:37 -03:00
parent b1845dd2c9
commit de4c666f80
5 changed files with 4115 additions and 14321 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "@portaljs/components", "name": "@portaljs/components",
"version": "0.1.3", "version": "0.1.5",
"type": "module", "type": "module",
"description": "https://portaljs.org", "description": "https://portaljs.org",
"keywords": [ "keywords": [

View File

@@ -4,7 +4,10 @@ import { Grid } from '@githubocto/flat-ui';
const queryClient = new QueryClient(); const queryClient = new QueryClient();
export async function getCsv(url: string) { export async function getCsv(url: string, corsProxy?: string) {
if (corsProxy) {
url = corsProxy + url
}
const response = await fetch(url, { const response = await fetch(url, {
headers: { headers: {
Range: 'bytes=0-5132288', Range: 'bytes=0-5132288',
@@ -61,21 +64,23 @@ export interface FlatUiTableProps {
url?: string; url?: string;
data?: { [key: string]: number | string }[]; data?: { [key: string]: number | string }[];
rawCsv?: string; rawCsv?: string;
corsProxy?: string;
} }
export const FlatUiTable: React.FC<FlatUiTableProps> = ({ export const FlatUiTable: React.FC<FlatUiTableProps> = ({
url, url,
data, data,
rawCsv, rawCsv,
corsProxy,
}) => { }) => {
return ( return (
// Provide the client to your App // Provide the client to your App
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<TableInner url={url} data={data} rawCsv={rawCsv} /> <TableInner corsProxy={corsProxy} url={url} data={data} rawCsv={rawCsv} />
</QueryClientProvider> </QueryClientProvider>
); );
}; };
const TableInner: React.FC<FlatUiTableProps> = ({ url, data, rawCsv }) => { const TableInner: React.FC<FlatUiTableProps> = ({ url, data, rawCsv, corsProxy }) => {
if (data) { if (data) {
return ( return (
<div className="w-full" style={{height: '500px'}}> <div className="w-full" style={{height: '500px'}}>
@@ -85,11 +90,12 @@ const TableInner: React.FC<FlatUiTableProps> = ({ url, data, rawCsv }) => {
} }
const { data: csvString, isLoading: isDownloadingCSV } = useQuery( const { data: csvString, isLoading: isDownloadingCSV } = useQuery(
['dataCsv', url], ['dataCsv', url],
() => getCsv(url) () => getCsv(url as string, corsProxy),
{ enabled: !!url }
); );
const { data: parsedData, isLoading: isParsing } = useQuery( const { data: parsedData, isLoading: isParsing } = useQuery(
['dataPreview', csvString], ['dataPreview', csvString],
() => parseCsv(rawCsv ? rawCsv : csvString), () => parseCsv(rawCsv ? rawCsv as string : csvString as string),
{ enabled: rawCsv ? true : !!csvString } { enabled: rawCsv ? true : !!csvString }
); );
if (isParsing || isDownloadingCSV) if (isParsing || isDownloadingCSV)
@@ -102,4 +108,6 @@ const TableInner: React.FC<FlatUiTableProps> = ({ url, data, rawCsv }) => {
<Grid data={parsedData.data} /> <Grid data={parsedData.data} />
</div> </div>
); );
return <Spinning />
}; };

View File

@@ -25,7 +25,7 @@ export function LineChart({
const spec = { const spec = {
$schema: 'https://vega.github.io/schema/vega-lite/v5.json', $schema: 'https://vega.github.io/schema/vega-lite/v5.json',
title, title,
width: 'container', width: 600,
height: 300, height: 300,
mark: { mark: {
type: 'line', type: 'line',

View File

@@ -16,6 +16,9 @@ const meta: Meta = {
}, },
url: { url: {
description: "Fetch the data from a CSV file remotely. only the first 5MB of data will be displayed" description: "Fetch the data from a CSV file remotely. only the first 5MB of data will be displayed"
},
corsProxy: {
description: "Optionally you cant set a CORS Proxy to which all your requests you be redirected"
} }
}, },
}; };