An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
feat: generate json schema for IChart DSL. (#341)
islxyqwe68782e867740
diff --git a/.gitignore b/.gitignoreindex a1dd3307..b2fd46e4 100644--- a/.gitignore+++ b/.gitignore@@ -14,3 +14,5 @@ doc_images**/public/datasetsapp-dist.vercel+chartinfo.json+stoinfo_v2.jsondiff --git a/packages/graphic-walker/package.json b/packages/graphic-walker/package.jsonindex 8b1ef68d..1076fff6 100644--- a/packages/graphic-walker/package.json+++ b/packages/graphic-walker/package.json@@ -4,7 +4,8 @@"scripts": {"dev:front_end": "vite --host","dev": "npm run dev:front_end",- "build": "vite build && tsc --build",+ "gen-schema": "node scripts/create-json-schema.js",+ "build": "vite build && tsc --build && yarn gen-schema","build:app": "vite build --config vite-app.config.ts","serve": "vite preview","type": "tsc src/lib.ts --declaration --emitDeclarationOnly --jsx react --esModuleInterop --outDir dist",@@ -133,6 +134,7 @@"@vercel/analytics": "^0.1.8","@vitejs/plugin-react": "^3.1.0","styled-components": "^5.3.6",+ "ts-json-schema-generator": "^1.5.0","ts-xor": "^1.3.0","typescript": "^5.2.2","vite": "^4.1.1"diff --git a/packages/graphic-walker/public/stoinfo_v2.json b/packages/graphic-walker/public/stoinfo_v2.jsondeleted file mode 100644index b5383c70..00000000--- a/packages/graphic-walker/public/stoinfo_v2.json+++ /dev/null@@ -1,103 +0,0 @@-{- "$schema": "http://json-schema.org/draft-07/schema#",- "properties": {- "datasets": {- "items": {- "properties": {- "data": {- "items": {- "additionalProperties": {},- "type": "object"- },- "type": "array"- },- "id": {- "type": "string"- },- "metaId": {- "type": "string"- },- "name": {- "type": "string"- }- },- "type": "object",- "required": [- "id",- "metaId",- "name",- "data"- ]- },- "type": "array"- },- "metaDict": {- "additionalProperties": {- "items": {- "properties": {- "analyticType": {- "enum": [- "dimension",- "measure"- ],- "type": "string"- },- "basename": {- "type": "string"- },- "disable": {- "type": "boolean"- },- "fid": {- "type": "string"- },- "key": {- "type": "string"- },- "name": {- "type": "string"- },- "path": {- "items": {- "type": "string"- },- "type": "array"- },- "semanticType": {- "enum": [- "nominal",- "ordinal",- "quantitative",- "temporal"- ],- "type": "string"- }- },- "type": "object",- "required": [- "fid",- "semanticType",- "analyticType"- ]- },- "type": "array"- },- "type": "object"- },- "specDict": {- "additionalProperties": {- "items": {- "type": "string"- },- "type": "array"- },- "type": "object"- }- },- "type": "object",- "required": [- "metaDict",- "datasets",- "specDict"- ]-}\ No newline at end of filediff --git a/packages/graphic-walker/scripts/create-json-schema.js b/packages/graphic-walker/scripts/create-json-schema.jsnew file mode 100644index 00000000..9fabb306--- /dev/null+++ b/packages/graphic-walker/scripts/create-json-schema.js@@ -0,0 +1,17 @@+const { resolve } = require('path');+const fs = require('fs');+const tsj = require('ts-json-schema-generator');+/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */+const config = {+ path: resolve(__dirname, '../src/interfaces.ts'),+ tsconfig: resolve(__dirname, '../tsconfig.json'),+ type: '*',+ topRef: false,+};++const generator = tsj.createGenerator(config);+if (!fs.existsSync(resolve(__dirname, '../public'))){+ fs.mkdirSync(resolve(__dirname, '../public'));+}+fs.writeFileSync(resolve(__dirname, '../public/chartinfo.json'), JSON.stringify(generator.createSchema('IChart'), undefined, 4));+fs.writeFileSync(resolve(__dirname, '../public/stoinfo_V2.json'), JSON.stringify(generator.createSchema('IStoInfoV2'), undefined, 4));diff --git a/packages/graphic-walker/src/index.css b/packages/graphic-walker/src/index.cssindex f1d9ce9c..f4e6bf3e 100644--- a/packages/graphic-walker/src/index.css+++ b/packages/graphic-walker/src/index.css@@ -9,6 +9,10 @@ code {'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';}+.dark.App {+ color-scheme: dark;+}+* {border-color: hsl(var(--border));}diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex 2466acc1..e72b9157 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -1,6 +1,6 @@import { Config as VgConfig, View } from 'vega';import { Config as VlConfig } from 'vega-lite';-import type { FeatureCollection } from 'geojson';+import type { FeatureCollection, Geometry, GeoJsonProperties } from 'geojson';import type { feature } from 'topojson-client';import { DATE_TIME_DRILL_LEVELS } from './constants';import { ToolbarItemProps } from './components/toolbar';@@ -389,7 +389,7 @@ export interface IVisualConfig {width: number;height: number;};- geojson?: FeatureCollection;+ geojson?: FeatureCollection<Geometry, GeoJsonProperties>;geoKey?: string;geoUrl?: IGeoUrl;limit: number;@@ -423,7 +423,7 @@ export interface IVisualLayout {height: number;};useSvg?: boolean;- geojson?: FeatureCollection;+ geojson?: FeatureCollection<Geometry, GeoJsonProperties>;geoKey?: string;geoUrl?: IGeoUrl;geoMapTileUrl?: string;@@ -1108,3 +1108,21 @@ export interface IColorPalette {900: string;950: string;}++export interface IStoInfoOld {+ $schema: undefined;+ datasets: IDataSet[];+ specList: IVisSpec[];+ dataSources: IDataSource[];+}++export const IStoInfoV2SchemaUrl = 'https://graphic-walker.kanaries.net/stoinfo_v2.json';++export interface IStoInfoV2 {+ $schema: typeof IStoInfoV2SchemaUrl;+ metaDict: Record<string, IMutField[]>;+ datasets: Required<IDataSource>[];+ specDict: Record<string, string[]>;+}++export type IStoInfo = IStoInfoOld | IStoInfoV2;diff --git a/packages/graphic-walker/src/lib/sql.ts b/packages/graphic-walker/src/lib/sql.tsindex ce5abcc3..3d1c352a 100644--- a/packages/graphic-walker/src/lib/sql.ts+++ b/packages/graphic-walker/src/lib/sql.ts@@ -1,4 +1,4 @@-import parser from 'pgsql-ast-parser';+import * as parser from 'pgsql-ast-parser';import { IMutField, IRow, ISemanticType } from '../interfaces';import { sum, mean, median, stdev, variance, max, min, countTruly, distinctCount } from './op/stat';import { dataframe2Dataset } from './execExp';diff --git a/packages/graphic-walker/src/store/dataStore.ts b/packages/graphic-walker/src/store/dataStore.tsindex 45da3685..31eed5c3 100644--- a/packages/graphic-walker/src/store/dataStore.ts+++ b/packages/graphic-walker/src/store/dataStore.ts@@ -1,5 +1,5 @@-import { IAnalyticType, IDataSource, IMutField, IRow, ISemanticType } from '../interfaces';-import { IStoInfo, IStoInfoV2, IStoInfoV2SchemaUrl, forwardVisualConfigs, visSpecDecoder } from '../utils/save';+import { IAnalyticType, IDataSource, IMutField, IRow, ISemanticType, IStoInfo, IStoInfoV2, IStoInfoV2SchemaUrl } from '../interfaces';+import { forwardVisualConfigs, visSpecDecoder } from '../utils/save';import { uniqueId } from '../models/utils';import { convertChart, exportFullRaw, fromFields, fromSnapshot } from '../models/visSpecHistory';diff --git a/packages/graphic-walker/src/utils/save.ts b/packages/graphic-walker/src/utils/save.tsindex 5a027a39..caaaea53 100644--- a/packages/graphic-walker/src/utils/save.ts+++ b/packages/graphic-walker/src/utils/save.ts@@ -1,8 +1,6 @@import {DraggableFieldState,- IDataSet,- IDataSource,- IMutField,+ IStoInfoOld,IVisSpec,IVisualConfig,IVisualConfigNew,@@ -141,23 +139,6 @@ export const forwardVisualConfigs = (content: IStoInfoOld['specList'][number]):},};};-export interface IStoInfoOld {- $schema: undefined;- datasets: IDataSet[];- specList: IVisSpec[];- dataSources: IDataSource[];-}--export const IStoInfoV2SchemaUrl = 'https://graphic-walker.kanaries.net/stoinfo_v2.json';--export interface IStoInfoV2 {- $schema: typeof IStoInfoV2SchemaUrl;- metaDict: Record<string, IMutField[]>;- datasets: Required<IDataSource>[];- specDict: Record<string, string[]>;-}--export type IStoInfo = IStoInfoOld | IStoInfoV2;export function download(data: string, filename: string, type: string) {var file = new Blob([data], { type: type });diff --git a/packages/playground/package.json b/packages/playground/package.jsonindex ba0dd94c..5e109b14 100644--- a/packages/playground/package.json+++ b/packages/playground/package.json@@ -7,7 +7,7 @@"dev": "vite","build:gw": "yarn workspace @kanaries/graphic-walker build","build:db": "yarn workspace @kanaries/duckdb-computation build",- "build": "npm run build:gw && npm run build:db && tsc && vite build",+ "build": "npm run build:gw && npm run build:db && tsc && cp ../graphic-walker/public/* ./public && vite build","lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0","preview": "vite preview"},diff --git a/yarn.lock b/yarn.lockindex fa843477..2bb79713 100644--- a/yarn.lock+++ b/yarn.lock@@ -2471,6 +2471,13 @@ brace-expansion@^1.1.7:balanced-match "^1.0.0"concat-map "0.0.1"+brace-expansion@^2.0.1:+ version "2.0.1"+ resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"+ integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==+ dependencies:+ balanced-match "^1.0.0"+braces@^3.0.2, braces@~3.0.2:version "3.0.2"resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"@@ -2731,6 +2738,11 @@ commander@7:resolved "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==+commander@^11.0.0:+ version "11.1.0"+ resolved "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz#62fdce76006a68e5c1ab3314dc92e800eb83d906"+ integrity sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==+commander@^4.0.0:version "4.1.1"resolved "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"@@ -3455,6 +3467,17 @@ glob@^7.1.3, glob@^7.1.4:once "^1.3.0"path-is-absolute "^1.0.0"+glob@^8.0.3:+ version "8.1.0"+ resolved "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"+ integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==+ dependencies:+ fs.realpath "^1.0.0"+ inflight "^1.0.4"+ inherits "2"+ minimatch "^5.0.1"+ once "^1.3.0"+globals@^11.1.0:version "11.12.0"resolved "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"@@ -4382,6 +4405,13 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:dependencies:brace-expansion "^1.1.7"+minimatch@^5.0.1:+ version "5.1.6"+ resolved "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"+ integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==+ dependencies:+ brace-expansion "^2.0.1"+mobx-react-lite@^3.2.1:version "3.4.3"resolved "https://registry.npmjs.org/mobx-react-lite/-/mobx-react-lite-3.4.3.tgz#3a4c22c30bfaa8b1b2aa48d12b2ba811c0947ab7"@@ -5126,6 +5156,11 @@ rxjs@^7.3.0:dependencies:tslib "^2.1.0"+safe-stable-stringify@^2.4.3:+ version "2.4.3"+ resolved "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz#138c84b6f6edb3db5f8ef3ef7115b8f55ccbf886"+ integrity sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==+"safer-buffer@>= 2.1.2 < 3.0.0":version "2.1.2"resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"@@ -5505,6 +5540,19 @@ ts-jest@^29.1.1:semver "^7.5.3"yargs-parser "^21.0.1"+ts-json-schema-generator@^1.5.0:+ version "1.5.0"+ resolved "https://registry.npmjs.org/ts-json-schema-generator/-/ts-json-schema-generator-1.5.0.tgz#9f5cea606c27ebcf13060157542ac1d3b225430f"+ integrity sha512-RkiaJ6YxGc5EWVPfyHxszTmpGxX8HC2XBvcFlAl1zcvpOG4tjjh+eXioStXJQYTvr9MoK8zCOWzAUlko3K0DiA==+ dependencies:+ "@types/json-schema" "^7.0.12"+ commander "^11.0.0"+ glob "^8.0.3"+ json5 "^2.2.3"+ normalize-path "^3.0.0"+ safe-stable-stringify "^2.4.3"+ typescript "~5.3.2"+ts-xor@^1.3.0:version "1.3.0"resolved "https://registry.npmmirror.com/ts-xor/-/ts-xor-1.3.0.tgz#3e59f24f0321f9f10f350e0cee3b534b89a2c70b"@@ -5547,6 +5595,11 @@ typescript@^5.2.2:resolved "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==+typescript@~5.3.2:+ version "5.3.3"+ resolved "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"+ integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==+typical@^4.0.0:version "4.0.0"resolved "https://registry.npmmirror.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4"