An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: better preview data table
ObservedObserver23c831993c40
diff --git a/README.md b/README.mdindex 8e983eb5..b3e08c5a 100644--- a/README.md+++ b/README.md@@ -32,7 +32,7 @@ First, upload your CSV file, preview your data, and define the analytic type of> We are developing more types of data sources. You are welcome to raise an issue telling us the types of sources you are using. If you are a developer, graphic-walker can be used as an embedding component, and you can pass your parsed data source to it. For example, [Rath](https://github.com/Kanaries/Rath) uses graphic-walker as an embedding components, and it supports many common data sources. You can load your data in [Rath](https://github.com/Kanaries/Rath) and bring the data into graphic-walker. In this way, users can also benefit from data cleaning and transformation features in [Rath](https://github.com/Kanaries/Rath).-+When the data is ready, click the 'Submit' button to use the data. On the left-hand side, `Field List` is all of your original columns in the table. You can drag them into visual channels (rows, columns, color, opacity, etc.) and make visualizations.@@ -41,21 +41,21 @@ When the data is ready, click the 'Submit' button to use the data. On the left-hVisualize your data with drag and drop operation. For measures, you can define the aggregation methods (sum, mean, count etc.)-+You can change the mark type into others to make different charts, for example a line chart.-+To compare different measures, you can create a concat view by adding more than one measure into rows/columns.-+To make a facet view of several subviews divided by the value in dimension, put dimensions into rows or columns to make a facets view. The rules are similar to Tableau.-+When you finish exploration, you can save the result into a local file, which can be imported next time.@@ -63,11 +63,11 @@ Sometimes you may have further questions, such as why sales in Dec. is high. GraFor example, in bike sharing dataset, ask why registered rents in Jan. is lower than expectation, the explainer will try to find some potential explanations:-+(percent of number of working days is less than average)-+## Deploydiff --git a/packages/graphic-walker/src/components/modal.tsx b/packages/graphic-walker/src/components/modal.tsxindex 9fdc5d5d..334d9c10 100644--- a/packages/graphic-walker/src/components/modal.tsx+++ b/packages/graphic-walker/src/components/modal.tsx@@ -56,6 +56,7 @@ const Modal: React.FC<ModalProps> = (props) => {// at a different element and then released when the mouse is moved on the target element.// This case is required to be prevented, especially disturbing when interacting// with a Slider component.+ className="border border-gray-300"onMouseDown={() => (prevMouseDownTimeRef.current = Date.now())}onMouseOut={() => (prevMouseDownTimeRef.current = 0)}onMouseUp={() => {diff --git a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsxindex 90405d9d..70d0fb15 100644--- a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx+++ b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx@@ -64,8 +64,8 @@ const CSVData: React.FC<ICSVData> = (props) => {{t("submit")}</button></div>- <div className="mt-1 mb-1">- <label className="block text-xs text-gray-800">{t("dataset_name")}</label>+ <div className="my-2">+ <label className="block text-xs text-gray-800 mb-1 font-bold">{t("dataset_name")}</label><inputtype="text"placeholder={t("dataset_name")}@@ -73,7 +73,7 @@ const CSVData: React.FC<ICSVData> = (props) => {onChange={(e) => {commonStore.updateTempName(e.target.value);}}- className="text-xs p-1 border border-gray-200 outline-none focus:outline-none focus:border-blue-500"+ className="text-xs p-2 rounded border border-gray-200 outline-none focus:outline-none focus:border-blue-500 placeholder:italic placeholder:text-slate-400"/></div><Table />diff --git a/packages/graphic-walker/src/dataSource/dataSelection/index.tsx b/packages/graphic-walker/src/dataSource/dataSelection/index.tsxindex daeffd4e..7fb047ab 100644--- a/packages/graphic-walker/src/dataSource/dataSelection/index.tsx+++ b/packages/graphic-walker/src/dataSource/dataSelection/index.tsx@@ -1,53 +1,37 @@-import React from 'react';-import { useState } from 'react';-import CSVData from './csvData';-import PublicData from './publicData';-import { useTranslation } from 'react-i18next';+import React, { useMemo } from "react";+import { useState } from "react";+import CSVData from "./csvData";+import PublicData from "./publicData";+import { useTranslation } from "react-i18next";+import PureTabs from "../../components/tabs/pureTab";-const DataSelection: React.FC = props =>{- const [sourceType, setSourceType] = useState<'file' | 'public'>('file');- const { t } = useTranslation('translation', { keyPrefix: 'DataSource' });+const DataSelection: React.FC = (props) => {+ const [sourceType, setSourceType] = useState<"file" | "public">("file");+ const { t } = useTranslation("translation", { keyPrefix: "DataSource" });- return <div className="grid grid-cols-6 text-sm">- <div className="col-span-1 bg-gray-100 pl-2 pr-2 pb-2 pt-1 text-xs">- <h1 className="cursor-default">- {t('dialog.data_types')}- </h1>- <hr className="mt-1 mb-1" />- <div- className={- `pb-1 cursor-pointer ${- sourceType === 'file' ? 'underline' : ''- } hover:bg-gray-200 hover:text-purple-600`- }- onClick={() => { setSourceType('file'); }}- >- {t('dialog.text_file_data')}- </div>- <div- className={- `pb-1 cursor-pointer ${- sourceType === 'public' ? 'underline border-r-2 border-black' : ''- } hover:bg-gray-200 hover:text-purple-600`- }- onClick={() => { setSourceType('public'); }}- >- {t('dialog.public_data')}+ const sourceOptions = useMemo(() => {+ return [+ { label: t("dialog.text_file_data"), key: "file" },+ { label: t("dialog.public_data"), key: "public" },+ ];+ }, []);++ return (+ <div className="text-sm">+ <div className="px-2">+ <PureTabs+ selectedKey={sourceType}+ tabs={sourceOptions}+ onSelected={(sk) => {+ setSourceType(sk as "public" | "file");+ }}+ />+ <hr className="mt-1 mb-1" />+ {sourceType === "file" && <CSVData />}+ {sourceType === "public" && <PublicData />}</div></div>- <div className="col-span-5 pl-2 pr-2">- <h1 className="text-base font-semibold">- {t('dialog.data_source_type', { sourceType })}- </h1>- <hr className="mt-1 mb-1" />- {- sourceType === 'file' && <CSVData />- }- {- sourceType === 'public' && <PublicData />- }- </div>- </div>-}+ );+};export default DataSelection;diff --git a/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsxindex 7a592621..dcc54e0f 100644--- a/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx+++ b/packages/graphic-walker/src/dataSource/dataSelection/publicData.tsx@@ -35,7 +35,7 @@ const PublicData: React.FC<IPublicDataProps> = props => {})})}}- className="border rounded border-gray-400 p-2 m-2 cursor-pointer hover:bg-gray-50"+ className="border rounded border-gray-300 p-2 m-2 cursor-pointer hover:bg-gray-50"><div>{data.title}</div>{/* <p>{data.title}</p> */}diff --git a/packages/graphic-walker/src/dataSource/table.tsx b/packages/graphic-walker/src/dataSource/table.tsxindex 373376a8..229b289a 100644--- a/packages/graphic-walker/src/dataSource/table.tsx+++ b/packages/graphic-walker/src/dataSource/table.tsx@@ -1,9 +1,9 @@-import React, { useMemo } from 'react';-import styled from 'styled-components';-import { observer } from 'mobx-react-lite';-import { IMutField } from '../interfaces';-import { useGlobalStore } from '../store';-import { useTranslation } from 'react-i18next';+import React, { useMemo } from "react";+import styled from "styled-components";+import { observer } from "mobx-react-lite";+import { IMutField } from "../interfaces";+import { useGlobalStore } from "../store";+import { useTranslation } from "react-i18next";interface TableProps {size?: number;@@ -12,17 +12,10 @@ const Container = styled.div`overflow-x: auto;table {box-sizing: content-box;- font-family: Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif;border-collapse: collapse;font-size: 12px;thead {th {- text-align: left;- border: 1px solid #f5f5f5;- padding: 12px;- background-color: #f7f7f7;- margin: 2px;- white-space: nowrap;}th.number {border-top: 3px solid #5cdbd3;@@ -33,12 +26,6 @@ const Container = styled.div`}tbody {td {- border: 1px solid #f5f5f5;- padding: 4px 12px;- color: #434343;- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;}td.number {text-align: right;@@ -51,65 +38,112 @@ const Container = styled.div``;const TYPE_LIST = [{- value: 'dimension',- label: '维度'+ value: "dimension",+ label: "维度",},{- value: 'measure',- label: '度量'- }+ value: "measure",+ label: "度量",+ },];// function getCellType(field: IMutField): 'number' | 'text' {// return field.dataType === 'number' || field.dataType === 'integer' ? 'number' : 'text';// }-function getHeaderType(field: IMutField): 'number' | 'text' {- return field.analyticType === 'dimension'? 'text' : 'number';+function getHeaderType(field: IMutField): "number" | "text" {+ return field.analyticType === "dimension" ? "text" : "number";+}++function getHeaderClassNames(field: IMutField) {+ return field.analyticType === "dimension" ? "border-t-4 border-blue-400" : "border-t-4 border-teal-400";+}++function getSemanticColors(field: IMutField): string {+ switch (field.semanticType) {+ case "nominal":+ return "bg-indigo-100 text-indigo-800";+ case "ordinal":+ return "bg-purple-100 text-purple-800"+ case "quantitative":+ return "bg-green-100 text-green-800"+ case "temporal":+ return "bg-yellow-100 text-yellow-800"+ default:+ return "bg-gray-400";+ }}-const Table: React.FC<TableProps> = props => {+const Table: React.FC<TableProps> = (props) => {const { size = 10 } = props;const { commonStore } = useGlobalStore();const { tmpDSRawFields, tmpDataSource } = commonStore;const { t } = useTranslation();- const analyticTypeList = useMemo<{value: string; label: string}[]>(() => {- return TYPE_LIST.map(at => ({+ const analyticTypeList = useMemo<{ value: string; label: string }[]>(() => {+ return TYPE_LIST.map((at) => ({value: at.value,- label: t(`constant.analytic_type.${at.value}`)- }))- }, [])-+ label: t(`constant.analytic_type.${at.value}`),+ }));+ }, []);+return (- <Container>- <table>- <thead>- <tr>+ <Container className="rounded border-gray-200 border">+ <table className="min-w-full divide-y divide-gray-30">+ <thead className="bg-gray-50">+ <tr className="divide-x divide-gray-200">{tmpDSRawFields.map((field, fIndex) => (- <th key={field.fid} className={getHeaderType(field)}>- <b>{field.name || field.fid}</b>- <div>- <select- className="border-b border-gray-200 hover:bg-gray-100 hover:border-gray-600"- value={field.analyticType} onChange={(e) => {- commonStore.updateTempFieldAnalyticType(field.fid, e.target.value as IMutField['analyticType'])- }}>- {- analyticTypeList.map(type => <option key={type.value} value={type.value}>{type.label}</option>)+ <th key={field.fid} className={""}>+ <div+ className={+ getHeaderClassNames(field) ++ " whitespace-nowrap py-3.5 px-6 text-left text-xs font-semibold text-gray-900 sm:pl-6"+ }+ >+ <b>{field.name || field.fid}</b>+ <div>+ <select+ className={+ "px-2 py font-normal mt-2 rounded-full text-xs text-white " ++ (field.analyticType === "dimension" ? "bg-blue-500" : "bg-teal-500")+ }+ // className="border-b border-gray-200 bg-gray-50 pl-0 mt-2 font-light"+ value={field.analyticType}+ onChange={(e) => {+ commonStore.updateTempFieldAnalyticType(+ field.fid,+ e.target.value as IMutField["analyticType"]+ );+ }}+ >+ {analyticTypeList.map((type) => (+ <option key={type.value} value={type.value}>+ {type.label}+ </option>+ ))}+ </select>+ </div>+ <div+ className={+ "inline-block px-2.5 py-0.5 text-xs font-medium mt-1 rounded-full text-xs text-white " ++ getSemanticColors(field)}- </select>+ >+ {field.semanticType}+ </div></div>-</th>))}</tr></thead>- <tbody>+ <tbody className="divide-y divide-gray-200 bg-white">{tmpDataSource.slice(0, size).map((record, index) => (- <tr key={index}>+ <tr className={"divide-x divide-gray-200 " + (index % 2 ? "bg-gray-50" : "")} key={index}>{tmpDSRawFields.map((field) => (<tdkey={field.fid + index}- // className={getCellType(field)}+ className={+ getHeaderType(field) ++ " whitespace-nowrap py-2 pl-4 pr-3 text-xs text-gray-500 sm:pl-6"+ }>{record[field.fid]}</td>@@ -120,6 +154,6 @@ const Table: React.FC<TableProps> = props => {</table></Container>);-}+};export default observer(Table);diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.jsonindex 33d5d31e..f9fc7fc9 100644--- a/packages/graphic-walker/src/locales/en-US.json+++ b/packages/graphic-walker/src/locales/en-US.json@@ -88,10 +88,10 @@},"dialog": {"create_data_source": "New Data Source",- "data_types": "Choose Data Source Type",- "text_file_data": "Open Local Text File",- "public_data": "Use Public Dataset",- "data_source_type": "Data Source Type: [{{sourceType}}]",+ "data_types": "DataSource Type",+ "text_file_data": "Local Files",+ "public_data": "Public Datasets",+ "data_source_type": "Data Source Type: {{sourceType}}","file": {"open": "Open...","submit": "Submit",diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.jsonindex 72bfb369..cffb7ea6 100644--- a/packages/graphic-walker/src/locales/zh-CN.json+++ b/packages/graphic-walker/src/locales/zh-CN.json@@ -89,9 +89,9 @@"dialog": {"create_data_source": "创建数据源","data_types": "选择类型",- "text_file_data": "从文件中导入",+ "text_file_data": "导入文件","public_data": "公共数据集",- "data_source_type": "数据源类型:[{{sourceType}}]",+ "data_source_type": "数据源类型:{{sourceType}}","file": {"open": "打开文件...","submit": "确认",