Skip to content

Commit

Permalink
feat:add metric 3D bars (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: laixingyou <[email protected]>
  • Loading branch information
coder-sett authored Dec 5, 2023
1 parent a95c27b commit 9f6049a
Show file tree
Hide file tree
Showing 37 changed files with 1,757 additions and 285 deletions.
2 changes: 1 addition & 1 deletion apps/web/i18n
Submodule i18n updated 2 files
+23 −2 en/analyze.json
+23 −2 zh/analyze.json
3 changes: 2 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@types/file-saver": "^2.0.5",
"@types/qrcode": "^1.5.0",
"ahooks": "^3.7.0",
"axios": "^1.1.3",
"antd": "^5.9.2",
"axios": "^1.1.3",
"big.js": "^6.2.1",
"class-variance-authority": "^0.6.0",
"classnames": "^2.3.1",
Expand All @@ -39,6 +39,7 @@
"debug": "^4.3.4",
"dom-to-svg": "^0.12.2",
"echarts": "^5.4.1",
"echarts-gl": "^2.0.9",
"file-saver": "^2.0.5",
"framer-motion": "^7.2.1",
"graphql": "^16.6.0",
Expand Down
15 changes: 15 additions & 0 deletions apps/web/public/images/chart-legend/cube-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions apps/web/public/images/chart-legend/cube-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions apps/web/public/images/chart-legend/cube-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions apps/web/src/common/components/EChartGl/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, { useRef, useEffect, useCallback } from 'react';
import { useDeepCompareEffect } from 'ahooks';
import { init, getInstanceByDom } from 'echarts';
import type { CSSProperties } from 'react';
import type { EChartsOption, ECharts, SetOptionOpts } from 'echarts';
import { useResizeDetector } from 'react-resize-detector';
import useInViewportDebounce from '@common/hooks/useInViewportDebounce';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { Bar3DChart } from 'echarts-gl/charts';
import { Grid3DComponent } from 'echarts-gl/components';

echarts.use([Grid3DComponent, Bar3DChart, CanvasRenderer]);
export interface ReactEChartsProps {
option: EChartsOption;
style?: CSSProperties;
settings?: SetOptionOpts;
loading?: boolean;
theme?: 'light' | 'dark';
containerRef?: React.RefObject<HTMLElement>;
_tracing?: string;
}

const EChartX: React.FC<ReactEChartsProps> = ({
option,
style,
settings = { notMerge: true },
loading,
theme,
containerRef,
}) => {
const inView = useInViewportDebounce(containerRef);
const chartRef = useRef<HTMLDivElement>(null);

useEffect(() => {
// init
let chart: ECharts | undefined;
if (chartRef.current !== null) {
chart = init(chartRef.current, theme);
}
return () => {
chart?.dispose();
};
}, [theme]);

useDeepCompareEffect(() => {
// Update chart
if (inView && chartRef.current !== null) {
const chart = getInstanceByDom(chartRef.current)!;
chart.setOption(option, settings);
}
}, [option, settings, inView]);

useEffect(() => {
// Update chart
if (chartRef.current !== null) {
const chart = getInstanceByDom(chartRef.current)!;
if (inView) {
loading === true ? chart?.showLoading() : chart?.hideLoading();
} else {
}
}
}, [loading, inView]);

// ----------------container resize------------------------------
const onResize = useCallback((width?: number, height?: number) => {
if (chartRef.current !== null) {
const chart = getInstanceByDom(chartRef.current)!;
chart?.resize({
width: 'auto',
height: Number(height) > 650 ? 650 : 280,
});
}
}, []);

useResizeDetector({
targetRef: containerRef,
onResize,
skipOnMount: true,
});

return (
<div ref={chartRef} style={{ width: '100%', height: '100%', ...style }} />
);
};

export default React.memo(EChartX);
155 changes: 80 additions & 75 deletions apps/web/src/common/options/gradientRamp.ts
Original file line number Diff line number Diff line change
@@ -1,128 +1,133 @@
export const gradientRamp = [
[
'#4a90e2',
'#1d2c4e',
'#29467f',
'#2d51a0',
'#5470c6',
'#3063c5',
'#3978d7',
'#70b1ea',
'#9ecdf2',
'#c6e0f7',
'#4a90e2',
'#3063c5',
'#3978d7',
'#70b1ea',
'#9ecdf2',
'#c6e0f7',
'#dfedfa',
'#f1f7fd',
],
[
'#9858f4',
'#320962',
'#4e1e85',
'#5e23a6',
'#6d25cb',
'#8136e7',
'#9858f4',
'#a872f9',
'#d1b5fd',
'#e5d6fe',
'#f1e8ff',
'#f9f5ff',
// '#dfedfa',
// '#f1f7fd',
],
[
'#91cc75',
'#50961a',
'#6bbc26',
'#89d744',
'#a7e56d',
'#ccf1a5',
'#6bbc26',
'#142909',
'#2f4e19',
'#335c1a ',
'#3f7219',
'#50961a',
'#6bbc26',
'#89d744',
'#a7e56d',
'#ccf1a5',
'#e5f8cf',
'#f3fce9',
],
[
// '#e9b308',
// '#a06207',
'#fac858',
'#cb8a03',
'#e9b308',
'#f9cc15',
'#fce146',
'#fff08a',
'#cb8a03',
'#e9b308',
'#f9cc15',
'#fce146',
'#fff08a',
'#fef9c4',
],
[
'#ee6666',
'#b91b1c',
'#dc2626',
'#f87271',
'#fca5a5',
'#fecaca',
'#ee4444',
'#b91b1c',
'#dc2626',
'#f87271',
'#fca5a5',
'#fecaca',
],
[
'#f97316',
'#431407',
'#7c2d12',
'#9a3412',
'#c2410c',
'#ea580c',
'#fb923c',
'#fdba74',
'#fed7aa',
'#f97316',
'#c2410c',
'#ea580c',
'#fb923c',
'#fdba74',
'#fed7aa',
'#ffedd5',
'#fff7ed',
],
[
'#14b8a6',
'#042f2e',
'#134e4a',
'#115e59',
'#0f766e',
'#0d9488',
'#2dd4bf',
'#5eead4',
'#99f6e4',
'#14b8a6',
'#0f766e',
'#0d9488',
'#2dd4bf',
'#5eead4',
'#99f6e4',
'#ccfbf1',
'#f0fdfa',
],
[
'#9858f4',
'#6d25cb',
'#8136e7',
'#a872f9',
'#d1b5fd',
'#e5d6fe',
'#9858f4',
'#6d25cb',
'#8136e7',
'#a872f9',
'#d1b5fd',
'#e5d6fe',
],
[
'#ec4899',
'#500725',
'#831843',
'#9c164d',
'#be185e',
'#db2879',
'#f472b5',
'#f8a8d3',
'#fccfea',
'#ec4899',
'#be185e',
'#db2879',
'#f472b5',
'#f8a8d3',
'#fccfea',
'#fbe7f3',
'#fcf2f8',
],
[
'#e9b308',
'#432007',
'#714013',
'#844d0e',
'#a06207',
'#cb8a03',
'#e9b308',
'#f9cc15',
'#fce146',
'#fff08a',
'#fef9c4',
'#fefce8',
],
[
'#ee4444',
'#450a0a',
'#7f1d1c',
'#9b1b1b',
'#b91b1c',
'#dc2626',
'#ee4444',
'#f87271',
'#fca5a5',
'#fecaca',
'#fde2e2',
'#fef2f2',
],

[
'#8c90a1',
'#2f3135',
'#52555d',
'#626571',
'#787a8c',
'#a1a5b3',
'#8c8fa2',
'#b6b8c5',
'#d2d6db',
'#dfe3e6',
'#edeff3',
'#f5f7f9',
'#8c90a1',
'#787a8c',
'#a1a5b3',
'#b6b8c5',
'#d2d6db',
'#dfe3e6',
],
];
5 changes: 5 additions & 0 deletions apps/web/src/common/utils/format.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,8 @@ export const convertMonthsToDays = (value: number | string) => {
}
return value;
};

export const toUnderline = (str: string) => {
//驼峰命名法转换为下划线命名
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
};
Loading

2 comments on commit 9f6049a

@vercel
Copy link

@vercel vercel bot commented on 9f6049a Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 9f6049a Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.