plugin-elastic-report 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/elastic-report/SKILLS.md +32 -0
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/851.488fdbf5bc5b6a36.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +99 -0
- package/dist/locale/vi-VN.json +99 -0
- package/dist/locale/zh-CN.json +99 -0
- package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
- package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
- package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
- package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
- package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
- package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
- package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
- package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
- package/dist/server/acl-guard.js +107 -0
- package/dist/server/collections/es-report-data-views.js +79 -0
- package/dist/server/collections/es-reports.js +95 -0
- package/dist/server/index.js +58 -0
- package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +417 -0
- package/dist/server/plugin.js +395 -0
- package/dist/server/services/ElasticReportService.js +263 -0
- package/dist/server/services/ElasticsearchConnectionService.js +332 -0
- package/dist/server/services/ReportQueryCompiler.js +858 -0
- package/dist/shared/constants.js +81 -0
- package/dist/shared/types.js +24 -0
- package/package.json +61 -4
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.tsx +19 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +311 -0
- package/src/client-v2/api.ts +224 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +399 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +160 -0
- package/src/client-v2/components/ElasticReportRenderer.tsx +707 -0
- package/src/client-v2/components/HighlightText.tsx +50 -0
- package/src/client-v2/components/ReportSelect.tsx +72 -0
- package/src/client-v2/index.tsx +14 -0
- package/src/client-v2/locale.ts +23 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +85 -0
- package/src/client-v2/pages/ElasticReportManager.tsx +1047 -0
- package/src/client-v2/plugin.tsx +52 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +99 -0
- package/src/locale/vi-VN.json +99 -0
- package/src/locale/zh-CN.json +99 -0
- package/src/server/__tests__/query-compiler.test.ts +231 -0
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +377 -0
- package/src/server/acl-guard.ts +103 -0
- package/src/server/collections/es-report-data-views.ts +58 -0
- package/src/server/collections/es-reports.ts +74 -0
- package/src/server/index.ts +15 -0
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +417 -0
- package/src/server/plugin.ts +431 -0
- package/src/server/services/ElasticReportService.ts +326 -0
- package/src/server/services/ElasticsearchConnectionService.ts +401 -0
- package/src/server/services/ReportQueryCompiler.ts +1017 -0
- package/src/shared/constants.ts +29 -0
- package/src/shared/types.ts +175 -0
- package/README.md +0 -3
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DATA_VIEWS_COLLECTION, REPORTS_COLLECTION, SERVICE_RESOURCE } from '../shared/constants';
|
|
11
|
+
import type {
|
|
12
|
+
EsConnectionSummary,
|
|
13
|
+
EsDataViewRecord,
|
|
14
|
+
EsFieldCapability,
|
|
15
|
+
EsReportRecord,
|
|
16
|
+
ID,
|
|
17
|
+
ReportExecutionResult,
|
|
18
|
+
ReportRuntimeOverrides,
|
|
19
|
+
ReportSpec,
|
|
20
|
+
} from '../shared/types';
|
|
21
|
+
|
|
22
|
+
export interface ApiClientLike {
|
|
23
|
+
request: (config: {
|
|
24
|
+
url: string;
|
|
25
|
+
method?: 'get' | 'post';
|
|
26
|
+
params?: Record<string, unknown>;
|
|
27
|
+
data?: Record<string, unknown>;
|
|
28
|
+
}) => Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface McpInfoPayload {
|
|
32
|
+
serverName: string;
|
|
33
|
+
endpointPath: string;
|
|
34
|
+
internalUrl: string;
|
|
35
|
+
useUserContext: boolean;
|
|
36
|
+
tools: Array<{
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
inputSchema: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
44
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function unwrapApiData<T>(raw: unknown): T {
|
|
48
|
+
if (!isRecord(raw)) return raw as T;
|
|
49
|
+
const outer = raw.data;
|
|
50
|
+
if (isRecord(outer) && 'data' in outer) {
|
|
51
|
+
return outer.data as T;
|
|
52
|
+
}
|
|
53
|
+
return (outer ?? raw) as T;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function fetchEsConnections(api: ApiClientLike): Promise<EsConnectionSummary[]> {
|
|
57
|
+
const res = await api.request({
|
|
58
|
+
url: `${SERVICE_RESOURCE}:listConnections`,
|
|
59
|
+
method: 'get',
|
|
60
|
+
});
|
|
61
|
+
const data = unwrapApiData<unknown>(res);
|
|
62
|
+
return Array.isArray(data) ? (data as EsConnectionSummary[]) : [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function fetchEsIndices(api: ApiClientLike, dataSourceKey: string, indexPattern = '*'): Promise<string[]> {
|
|
66
|
+
const res = await api.request({
|
|
67
|
+
url: `${SERVICE_RESOURCE}:listIndices`,
|
|
68
|
+
method: 'post',
|
|
69
|
+
data: { dataSourceKey, indexPattern },
|
|
70
|
+
});
|
|
71
|
+
const data = unwrapApiData<unknown>(res);
|
|
72
|
+
return Array.isArray(data) ? data.filter((v): v is string => typeof v === 'string') : [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function fetchDataViews(api: ApiClientLike): Promise<EsDataViewRecord[]> {
|
|
76
|
+
const res = await api.request({
|
|
77
|
+
url: `${DATA_VIEWS_COLLECTION}:list`,
|
|
78
|
+
method: 'get',
|
|
79
|
+
params: { pageSize: 200, sort: ['-id'] },
|
|
80
|
+
});
|
|
81
|
+
const data = unwrapApiData<unknown>(res);
|
|
82
|
+
return Array.isArray(data) ? (data as EsDataViewRecord[]) : [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function saveDataView(
|
|
86
|
+
api: ApiClientLike,
|
|
87
|
+
payload: {
|
|
88
|
+
id?: ID;
|
|
89
|
+
title: string;
|
|
90
|
+
dataSourceKey: string;
|
|
91
|
+
indexPattern: string;
|
|
92
|
+
timeField?: string | null;
|
|
93
|
+
description?: string | null;
|
|
94
|
+
},
|
|
95
|
+
): Promise<EsDataViewRecord> {
|
|
96
|
+
const res = await api.request({
|
|
97
|
+
url: `${SERVICE_RESOURCE}:upsertDataView`,
|
|
98
|
+
method: 'post',
|
|
99
|
+
data: payload as Record<string, unknown>,
|
|
100
|
+
});
|
|
101
|
+
return unwrapApiData<EsDataViewRecord>(res);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function removeDataView(api: ApiClientLike, id: ID): Promise<void> {
|
|
105
|
+
await api.request({
|
|
106
|
+
url: `${DATA_VIEWS_COLLECTION}:destroy`,
|
|
107
|
+
method: 'post',
|
|
108
|
+
params: { filterByTk: id },
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function fetchDataViewFields(
|
|
113
|
+
api: ApiClientLike,
|
|
114
|
+
dataViewId: ID,
|
|
115
|
+
refresh = false,
|
|
116
|
+
): Promise<{ dataView: EsDataViewRecord; fields: EsFieldCapability[] }> {
|
|
117
|
+
const res = await api.request({
|
|
118
|
+
url: `${SERVICE_RESOURCE}:inspectFields`,
|
|
119
|
+
method: 'post',
|
|
120
|
+
data: { dataViewId, refresh },
|
|
121
|
+
});
|
|
122
|
+
return unwrapApiData<{ dataView: EsDataViewRecord; fields: EsFieldCapability[] }>(res);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function fetchAllReports(api: ApiClientLike): Promise<EsReportRecord[]> {
|
|
126
|
+
const res = await api.request({
|
|
127
|
+
url: `${REPORTS_COLLECTION}:list`,
|
|
128
|
+
method: 'get',
|
|
129
|
+
params: { pageSize: 200, appends: ['dataView'], sort: ['-updatedAt', '-id'] },
|
|
130
|
+
});
|
|
131
|
+
const data = unwrapApiData<unknown>(res);
|
|
132
|
+
return Array.isArray(data) ? (data as EsReportRecord[]) : [];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function fetchPublishedReports(api: ApiClientLike, search?: string): Promise<EsReportRecord[]> {
|
|
136
|
+
const res = await api.request({
|
|
137
|
+
url: `${SERVICE_RESOURCE}:listPublishedReports`,
|
|
138
|
+
method: 'get',
|
|
139
|
+
params: search ? { search } : undefined,
|
|
140
|
+
});
|
|
141
|
+
const data = unwrapApiData<unknown>(res);
|
|
142
|
+
return Array.isArray(data) ? (data as EsReportRecord[]) : [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function persistReport(
|
|
146
|
+
api: ApiClientLike,
|
|
147
|
+
payload: {
|
|
148
|
+
id?: ID;
|
|
149
|
+
title: string;
|
|
150
|
+
description?: string | null;
|
|
151
|
+
dataViewId: ID;
|
|
152
|
+
spec: ReportSpec;
|
|
153
|
+
published: boolean;
|
|
154
|
+
},
|
|
155
|
+
): Promise<EsReportRecord> {
|
|
156
|
+
const res = await api.request({
|
|
157
|
+
url: `${SERVICE_RESOURCE}:saveReport`,
|
|
158
|
+
method: 'post',
|
|
159
|
+
data: payload as unknown as Record<string, unknown>,
|
|
160
|
+
});
|
|
161
|
+
return unwrapApiData<EsReportRecord>(res);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function removeReport(api: ApiClientLike, id: ID): Promise<void> {
|
|
165
|
+
await api.request({
|
|
166
|
+
url: `${REPORTS_COLLECTION}:destroy`,
|
|
167
|
+
method: 'post',
|
|
168
|
+
params: { filterByTk: id },
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function executeReportPreview(
|
|
173
|
+
api: ApiClientLike,
|
|
174
|
+
dataViewId: ID,
|
|
175
|
+
spec: ReportSpec,
|
|
176
|
+
overrides?: ReportRuntimeOverrides,
|
|
177
|
+
): Promise<{ dataView: EsDataViewRecord; result: ReportExecutionResult }> {
|
|
178
|
+
const res = await api.request({
|
|
179
|
+
url: `${SERVICE_RESOURCE}:previewReport`,
|
|
180
|
+
method: 'post',
|
|
181
|
+
data: {
|
|
182
|
+
dataViewId,
|
|
183
|
+
spec,
|
|
184
|
+
...(overrides ? { overrides } : {}),
|
|
185
|
+
} as unknown as Record<string, unknown>,
|
|
186
|
+
});
|
|
187
|
+
return unwrapApiData<{ dataView: EsDataViewRecord; result: ReportExecutionResult }>(res);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function fetchReportMeta(
|
|
191
|
+
api: ApiClientLike,
|
|
192
|
+
reportId: ID,
|
|
193
|
+
): Promise<{ report: EsReportRecord; dataView: EsDataViewRecord; fields: EsFieldCapability[] }> {
|
|
194
|
+
const res = await api.request({
|
|
195
|
+
url: `${SERVICE_RESOURCE}:getReportMeta`,
|
|
196
|
+
method: 'get',
|
|
197
|
+
params: { reportId },
|
|
198
|
+
});
|
|
199
|
+
return unwrapApiData<{ report: EsReportRecord; dataView: EsDataViewRecord; fields: EsFieldCapability[] }>(res);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export async function executeSavedReport(
|
|
203
|
+
api: ApiClientLike,
|
|
204
|
+
reportId: ID,
|
|
205
|
+
overrides?: ReportRuntimeOverrides,
|
|
206
|
+
): Promise<{ report: EsReportRecord; dataView: EsDataViewRecord; result: ReportExecutionResult }> {
|
|
207
|
+
const res = await api.request({
|
|
208
|
+
url: `${SERVICE_RESOURCE}:runReport`,
|
|
209
|
+
method: 'post',
|
|
210
|
+
data: {
|
|
211
|
+
reportId,
|
|
212
|
+
...(overrides ? { overrides } : {}),
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
return unwrapApiData<{ report: EsReportRecord; dataView: EsDataViewRecord; result: ReportExecutionResult }>(res);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export async function fetchMcpInfo(api: ApiClientLike): Promise<McpInfoPayload> {
|
|
219
|
+
const res = await api.request({
|
|
220
|
+
url: `${SERVICE_RESOURCE}:getMcpInfo`,
|
|
221
|
+
method: 'get',
|
|
222
|
+
});
|
|
223
|
+
return unwrapApiData<McpInfoPayload>(res);
|
|
224
|
+
}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Button, Card, Empty, Space, Statistic, Table, Tooltip, Typography, theme } from 'antd';
|
|
11
|
+
import React, { useId, useState } from 'react';
|
|
12
|
+
import type { ReportHistogramBucket, ReportSeriesPoint, ReportVisualizationType } from '../../shared/types';
|
|
13
|
+
import { useT } from '../locale';
|
|
14
|
+
|
|
15
|
+
const { Text } = Typography;
|
|
16
|
+
|
|
17
|
+
const PALETTE = ['#1677ff', '#13c2c2', '#52c41a', '#fa8c16', '#722ed1', '#eb2f96', '#2f54eb', '#faad14'];
|
|
18
|
+
|
|
19
|
+
function formatCompactNumber(val: number): string {
|
|
20
|
+
if (!Number.isFinite(val)) return '0';
|
|
21
|
+
if (Math.abs(val) >= 1_000_000) return `${(val / 1_000_000).toFixed(2)}M`;
|
|
22
|
+
if (Math.abs(val) >= 1_000) return `${(val / 1_000).toFixed(1)}k`;
|
|
23
|
+
return Number.isInteger(val) ? String(val) : val.toFixed(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function truncateLabel(text: string, maxLen = 18): string {
|
|
27
|
+
if (text.length <= maxLen) return text;
|
|
28
|
+
return `${text.slice(0, maxLen - 1)}…`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ReportHistogramStripProps {
|
|
32
|
+
buckets: ReportHistogramBucket[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const ReportHistogramStrip: React.FC<ReportHistogramStripProps> = ({ buckets }) => {
|
|
36
|
+
const t = useT();
|
|
37
|
+
const { token } = theme.useToken();
|
|
38
|
+
const titleId = useId();
|
|
39
|
+
|
|
40
|
+
if (!buckets.length) return null;
|
|
41
|
+
const maxCount = Math.max(1, ...buckets.map((b) => b.count));
|
|
42
|
+
const width = 720;
|
|
43
|
+
const height = 68;
|
|
44
|
+
const barGap = 2;
|
|
45
|
+
const barWidth = Math.max(4, (width - barGap * buckets.length) / buckets.length);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<figure style={{ margin: '0 0 12px 0' }}>
|
|
49
|
+
<svg
|
|
50
|
+
role="img"
|
|
51
|
+
aria-labelledby={titleId}
|
|
52
|
+
viewBox={`0 0 ${width} ${height}`}
|
|
53
|
+
style={{ width: '100%', height: 68, display: 'block' }}
|
|
54
|
+
>
|
|
55
|
+
<title id={titleId}>{t('Date Histogram')}</title>
|
|
56
|
+
{buckets.map((bucket, index) => {
|
|
57
|
+
const barHeight = Math.max(bucket.count > 0 ? 3 : 1, Math.round((bucket.count / maxCount) * (height - 14)));
|
|
58
|
+
const x = index * (barWidth + barGap);
|
|
59
|
+
const y = height - barHeight - 2;
|
|
60
|
+
return (
|
|
61
|
+
<Tooltip key={`${bucket.key}-${index}`} title={`${bucket.key}: ${bucket.count}`}>
|
|
62
|
+
<rect
|
|
63
|
+
x={x}
|
|
64
|
+
y={y}
|
|
65
|
+
width={barWidth}
|
|
66
|
+
height={barHeight}
|
|
67
|
+
rx={2}
|
|
68
|
+
fill={bucket.count > 0 ? token.colorPrimary : token.colorFillSecondary}
|
|
69
|
+
opacity={0.85}
|
|
70
|
+
/>
|
|
71
|
+
</Tooltip>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</svg>
|
|
75
|
+
<figcaption
|
|
76
|
+
style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11, color: token.colorTextSecondary }}
|
|
77
|
+
>
|
|
78
|
+
<span>{buckets[0]?.key}</span>
|
|
79
|
+
<span>{buckets[buckets.length - 1]?.key}</span>
|
|
80
|
+
</figcaption>
|
|
81
|
+
</figure>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export interface ElasticBasicChartProps {
|
|
86
|
+
title: string;
|
|
87
|
+
visualization: Exclude<ReportVisualizationType, 'table'>;
|
|
88
|
+
series: ReportSeriesPoint[];
|
|
89
|
+
metricValue: number | null;
|
|
90
|
+
metricLabel: string;
|
|
91
|
+
totalHits: number;
|
|
92
|
+
onSelectBucket?: (bucketKey: string) => void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const ElasticBasicChart: React.FC<ElasticBasicChartProps> = ({
|
|
96
|
+
title,
|
|
97
|
+
visualization,
|
|
98
|
+
series,
|
|
99
|
+
metricValue,
|
|
100
|
+
metricLabel,
|
|
101
|
+
totalHits,
|
|
102
|
+
onSelectBucket,
|
|
103
|
+
}) => {
|
|
104
|
+
const t = useT();
|
|
105
|
+
const { token } = theme.useToken();
|
|
106
|
+
const svgTitleId = useId();
|
|
107
|
+
const [showTableAlt, setShowTableAlt] = useState(false);
|
|
108
|
+
|
|
109
|
+
if (visualization === 'metric') {
|
|
110
|
+
return (
|
|
111
|
+
<Card bordered={false} style={{ textAlign: 'center', padding: '16px 8px' }}>
|
|
112
|
+
<Statistic
|
|
113
|
+
title={metricLabel || title}
|
|
114
|
+
value={metricValue ?? 0}
|
|
115
|
+
valueStyle={{ fontSize: 36, fontWeight: 600, color: token.colorPrimary }}
|
|
116
|
+
/>
|
|
117
|
+
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
118
|
+
{t('Hits')}: {totalHits.toLocaleString()}
|
|
119
|
+
</Text>
|
|
120
|
+
</Card>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!series.length) {
|
|
125
|
+
return <Empty description={t('No matching documents')} />;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const maxVal = Math.max(1, ...series.map((p) => Math.abs(p.value)));
|
|
129
|
+
const svgWidth = 760;
|
|
130
|
+
const svgHeight = 260;
|
|
131
|
+
const padLeft = 56;
|
|
132
|
+
const padRight = 24;
|
|
133
|
+
const padTop = 20;
|
|
134
|
+
const padBottom = 46;
|
|
135
|
+
const plotW = svgWidth - padLeft - padRight;
|
|
136
|
+
const plotH = svgHeight - padTop - padBottom;
|
|
137
|
+
|
|
138
|
+
const renderCartesian = () => {
|
|
139
|
+
const ticks = [0, 0.25, 0.5, 0.75, 1];
|
|
140
|
+
if (visualization === 'bar') {
|
|
141
|
+
const gap = Math.min(16, Math.max(4, Math.floor(plotW / (series.length * 4))));
|
|
142
|
+
const barW = Math.max(8, (plotW - gap * (series.length + 1)) / series.length);
|
|
143
|
+
return (
|
|
144
|
+
<svg
|
|
145
|
+
role="img"
|
|
146
|
+
aria-labelledby={svgTitleId}
|
|
147
|
+
viewBox={`0 0 ${svgWidth} ${svgHeight}`}
|
|
148
|
+
style={{ width: '100%', height: 260, display: 'block' }}
|
|
149
|
+
>
|
|
150
|
+
<title id={svgTitleId}>{`${title} - ${metricLabel}`}</title>
|
|
151
|
+
{ticks.map((ratio) => {
|
|
152
|
+
const y = padTop + plotH - ratio * plotH;
|
|
153
|
+
return (
|
|
154
|
+
<g key={`grid-${ratio}`}>
|
|
155
|
+
<line
|
|
156
|
+
x1={padLeft}
|
|
157
|
+
y1={y}
|
|
158
|
+
x2={svgWidth - padRight}
|
|
159
|
+
y2={y}
|
|
160
|
+
stroke={token.colorSplit}
|
|
161
|
+
strokeDasharray="3 3"
|
|
162
|
+
/>
|
|
163
|
+
<text x={padLeft - 8} y={y + 4} textAnchor="end" fontSize={11} fill={token.colorTextSecondary}>
|
|
164
|
+
{formatCompactNumber(ratio * maxVal)}
|
|
165
|
+
</text>
|
|
166
|
+
</g>
|
|
167
|
+
);
|
|
168
|
+
})}
|
|
169
|
+
{series.map((item, idx) => {
|
|
170
|
+
const h = Math.max(2, (Math.max(0, item.value) / maxVal) * plotH);
|
|
171
|
+
const x = padLeft + gap + idx * (barW + gap);
|
|
172
|
+
const y = padTop + plotH - h;
|
|
173
|
+
const showLabel = series.length <= 12 || idx % Math.ceil(series.length / 8) === 0;
|
|
174
|
+
return (
|
|
175
|
+
<g key={`${item.key}-${idx}`}>
|
|
176
|
+
<Tooltip title={`${item.label}: ${item.value.toLocaleString()} (${t('Hits')}: ${item.count})`}>
|
|
177
|
+
<rect
|
|
178
|
+
x={x}
|
|
179
|
+
y={y}
|
|
180
|
+
width={barW}
|
|
181
|
+
height={h}
|
|
182
|
+
rx={3}
|
|
183
|
+
fill={PALETTE[idx % PALETTE.length]}
|
|
184
|
+
style={{ cursor: onSelectBucket ? 'pointer' : 'default' }}
|
|
185
|
+
onClick={() => onSelectBucket?.(item.key)}
|
|
186
|
+
/>
|
|
187
|
+
</Tooltip>
|
|
188
|
+
{showLabel && (
|
|
189
|
+
<text
|
|
190
|
+
x={x + barW / 2}
|
|
191
|
+
y={padTop + plotH + 18}
|
|
192
|
+
textAnchor="middle"
|
|
193
|
+
fontSize={11}
|
|
194
|
+
fill={token.colorTextSecondary}
|
|
195
|
+
>
|
|
196
|
+
{truncateLabel(item.label, 12)}
|
|
197
|
+
</text>
|
|
198
|
+
)}
|
|
199
|
+
</g>
|
|
200
|
+
);
|
|
201
|
+
})}
|
|
202
|
+
</svg>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const stepX = series.length > 1 ? plotW / (series.length - 1) : plotW / 2;
|
|
207
|
+
const points = series.map((item, idx) => {
|
|
208
|
+
const x = series.length > 1 ? padLeft + idx * stepX : padLeft + plotW / 2;
|
|
209
|
+
const y = padTop + plotH - (Math.max(0, item.value) / maxVal) * plotH;
|
|
210
|
+
return { x, y, item, idx };
|
|
211
|
+
});
|
|
212
|
+
const linePath = points.map((pt, i) => `${i === 0 ? 'M' : 'L'} ${pt.x.toFixed(1)} ${pt.y.toFixed(1)}`).join(' ');
|
|
213
|
+
const areaPath =
|
|
214
|
+
points.length > 0
|
|
215
|
+
? `${linePath} L ${points[points.length - 1].x.toFixed(1)} ${(padTop + plotH).toFixed(
|
|
216
|
+
1,
|
|
217
|
+
)} L ${points[0].x.toFixed(1)} ${(padTop + plotH).toFixed(1)} Z`
|
|
218
|
+
: '';
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<svg
|
|
222
|
+
role="img"
|
|
223
|
+
aria-labelledby={svgTitleId}
|
|
224
|
+
viewBox={`0 0 ${svgWidth} ${svgHeight}`}
|
|
225
|
+
style={{ width: '100%', height: 260, display: 'block' }}
|
|
226
|
+
>
|
|
227
|
+
<title id={svgTitleId}>{`${title} - ${metricLabel}`}</title>
|
|
228
|
+
{ticks.map((ratio) => {
|
|
229
|
+
const y = padTop + plotH - ratio * plotH;
|
|
230
|
+
return (
|
|
231
|
+
<g key={`grid-${ratio}`}>
|
|
232
|
+
<line
|
|
233
|
+
x1={padLeft}
|
|
234
|
+
y1={y}
|
|
235
|
+
x2={svgWidth - padRight}
|
|
236
|
+
y2={y}
|
|
237
|
+
stroke={token.colorSplit}
|
|
238
|
+
strokeDasharray="3 3"
|
|
239
|
+
/>
|
|
240
|
+
<text x={padLeft - 8} y={y + 4} textAnchor="end" fontSize={11} fill={token.colorTextSecondary}>
|
|
241
|
+
{formatCompactNumber(ratio * maxVal)}
|
|
242
|
+
</text>
|
|
243
|
+
</g>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
{visualization === 'area' && areaPath && <path d={areaPath} fill={token.colorPrimary} fillOpacity={0.18} />}
|
|
247
|
+
{linePath && <path d={linePath} fill="none" stroke={token.colorPrimary} strokeWidth={2.5} />}
|
|
248
|
+
{points.map(({ x, y, item, idx }) => {
|
|
249
|
+
const showLabel = series.length <= 10 || idx % Math.ceil(series.length / 7) === 0;
|
|
250
|
+
return (
|
|
251
|
+
<g key={`${item.key}-${idx}`}>
|
|
252
|
+
<Tooltip title={`${item.label}: ${item.value.toLocaleString()}`}>
|
|
253
|
+
<circle
|
|
254
|
+
cx={x}
|
|
255
|
+
cy={y}
|
|
256
|
+
r={4}
|
|
257
|
+
fill={token.colorBgContainer}
|
|
258
|
+
stroke={token.colorPrimary}
|
|
259
|
+
strokeWidth={2}
|
|
260
|
+
style={{ cursor: onSelectBucket ? 'pointer' : 'default' }}
|
|
261
|
+
onClick={() => onSelectBucket?.(item.key)}
|
|
262
|
+
/>
|
|
263
|
+
</Tooltip>
|
|
264
|
+
{showLabel && (
|
|
265
|
+
<text x={x} y={padTop + plotH + 18} textAnchor="middle" fontSize={11} fill={token.colorTextSecondary}>
|
|
266
|
+
{truncateLabel(item.label, 12)}
|
|
267
|
+
</text>
|
|
268
|
+
)}
|
|
269
|
+
</g>
|
|
270
|
+
);
|
|
271
|
+
})}
|
|
272
|
+
</svg>
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const renderPie = () => {
|
|
277
|
+
const totalValue = Math.max(
|
|
278
|
+
1,
|
|
279
|
+
series.reduce((acc, item) => acc + Math.max(0, item.value), 0),
|
|
280
|
+
);
|
|
281
|
+
const cx = 130;
|
|
282
|
+
const cy = 120;
|
|
283
|
+
const radius = 92;
|
|
284
|
+
let cumulativeAngle = -Math.PI / 2;
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 24 }}>
|
|
288
|
+
<svg
|
|
289
|
+
role="img"
|
|
290
|
+
aria-labelledby={svgTitleId}
|
|
291
|
+
viewBox="0 0 260 240"
|
|
292
|
+
style={{ width: 240, height: 220, flexShrink: 0 }}
|
|
293
|
+
>
|
|
294
|
+
<title id={svgTitleId}>{`${title} - ${metricLabel}`}</title>
|
|
295
|
+
{series.map((item, idx) => {
|
|
296
|
+
const val = Math.max(0, item.value);
|
|
297
|
+
const angle = (val / totalValue) * Math.PI * 2;
|
|
298
|
+
const startAngle = cumulativeAngle;
|
|
299
|
+
const endAngle = cumulativeAngle + angle;
|
|
300
|
+
cumulativeAngle = endAngle;
|
|
301
|
+
|
|
302
|
+
if (series.length === 1 || angle >= Math.PI * 2 - 0.001) {
|
|
303
|
+
return (
|
|
304
|
+
<Tooltip key={item.key} title={`${item.label}: ${item.value.toLocaleString()} (100%)`}>
|
|
305
|
+
<circle cx={cx} cy={cy} r={radius} fill={PALETTE[0]} />
|
|
306
|
+
</Tooltip>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const x1 = cx + radius * Math.cos(startAngle);
|
|
311
|
+
const y1 = cy + radius * Math.sin(startAngle);
|
|
312
|
+
const x2 = cx + radius * Math.cos(endAngle);
|
|
313
|
+
const y2 = cy + radius * Math.sin(endAngle);
|
|
314
|
+
const largeArc = angle > Math.PI ? 1 : 0;
|
|
315
|
+
const pathData = `M ${cx} ${cy} L ${x1.toFixed(2)} ${y1.toFixed(
|
|
316
|
+
2,
|
|
317
|
+
)} A ${radius} ${radius} 0 ${largeArc} 1 ${x2.toFixed(2)} ${y2.toFixed(2)} Z`;
|
|
318
|
+
const pct = ((val / totalValue) * 100).toFixed(1);
|
|
319
|
+
|
|
320
|
+
return (
|
|
321
|
+
<Tooltip key={`${item.key}-${idx}`} title={`${item.label}: ${item.value.toLocaleString()} (${pct}%)`}>
|
|
322
|
+
<path
|
|
323
|
+
d={pathData}
|
|
324
|
+
fill={PALETTE[idx % PALETTE.length]}
|
|
325
|
+
stroke={token.colorBgContainer}
|
|
326
|
+
strokeWidth={1.5}
|
|
327
|
+
style={{ cursor: onSelectBucket ? 'pointer' : 'default' }}
|
|
328
|
+
onClick={() => onSelectBucket?.(item.key)}
|
|
329
|
+
/>
|
|
330
|
+
</Tooltip>
|
|
331
|
+
);
|
|
332
|
+
})}
|
|
333
|
+
</svg>
|
|
334
|
+
<div style={{ flex: 1, minWidth: 200 }}>
|
|
335
|
+
<Space direction="vertical" size={6} style={{ width: '100%' }}>
|
|
336
|
+
{series.map((item, idx) => {
|
|
337
|
+
const pct = ((Math.max(0, item.value) / totalValue) * 100).toFixed(1);
|
|
338
|
+
return (
|
|
339
|
+
<div
|
|
340
|
+
key={`legend-${item.key}-${idx}`}
|
|
341
|
+
style={{ display: 'flex', justifyContent: 'space-between', gap: 12, fontSize: 13 }}
|
|
342
|
+
>
|
|
343
|
+
<Space size={8}>
|
|
344
|
+
<span
|
|
345
|
+
aria-hidden="true"
|
|
346
|
+
style={{
|
|
347
|
+
display: 'inline-block',
|
|
348
|
+
width: 10,
|
|
349
|
+
height: 10,
|
|
350
|
+
borderRadius: 2,
|
|
351
|
+
backgroundColor: PALETTE[idx % PALETTE.length],
|
|
352
|
+
}}
|
|
353
|
+
/>
|
|
354
|
+
<Text ellipsis style={{ maxWidth: 220 }}>
|
|
355
|
+
{item.label}
|
|
356
|
+
</Text>
|
|
357
|
+
</Space>
|
|
358
|
+
<Text strong>
|
|
359
|
+
{item.value.toLocaleString()} ({pct}%)
|
|
360
|
+
</Text>
|
|
361
|
+
</div>
|
|
362
|
+
);
|
|
363
|
+
})}
|
|
364
|
+
</Space>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
return (
|
|
371
|
+
<figure style={{ margin: 0 }}>
|
|
372
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
|
373
|
+
<figcaption style={{ fontSize: 12, color: token.colorTextSecondary }}>
|
|
374
|
+
{metricLabel} · {t('Hits')}: {totalHits.toLocaleString()}
|
|
375
|
+
</figcaption>
|
|
376
|
+
<Button size="small" type="link" onClick={() => setShowTableAlt((prev) => !prev)}>
|
|
377
|
+
{showTableAlt ? t('Show chart') : t('Show data table')}
|
|
378
|
+
</Button>
|
|
379
|
+
</div>
|
|
380
|
+
{showTableAlt ? (
|
|
381
|
+
<Table
|
|
382
|
+
size="small"
|
|
383
|
+
rowKey="key"
|
|
384
|
+
pagination={false}
|
|
385
|
+
dataSource={series}
|
|
386
|
+
columns={[
|
|
387
|
+
{ title: t('Bucket Field'), dataIndex: 'label', key: 'label' },
|
|
388
|
+
{ title: metricLabel || t('Value'), dataIndex: 'value', key: 'value' },
|
|
389
|
+
{ title: t('Hits'), dataIndex: 'count', key: 'count' },
|
|
390
|
+
]}
|
|
391
|
+
/>
|
|
392
|
+
) : visualization === 'pie' ? (
|
|
393
|
+
renderPie()
|
|
394
|
+
) : (
|
|
395
|
+
renderCartesian()
|
|
396
|
+
)}
|
|
397
|
+
</figure>
|
|
398
|
+
);
|
|
399
|
+
};
|