mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* refactor: store is updated * temp * fix: eslint error is fixed * fix:eslint linting error is updated * chore: react-grid-layout is added * chore: linting changes are updated * chore: linting changes are updated * chore: @types/node is moved to devDependecies and @types/react-grid-layout is added * chore: tsconfig is updated * chore: updateUrl function is updated * feat: All Dashboard is updated * feat: All Dashboard page is updated * feat: New Dashboard is added * feat: App Layout is updated * feat: Add Tags is updated * chore: uuid package is added * chore: AppRoutes is updated * chore: UI components are updated * chore: baseUrl is added in the apiUrl and removed from other api request * chore: commonApi Response is updated * chore: ErrorResponse handler is updated * chore: useFetch hook is made * chore: axios instance is updated * chore:some of the changes are updated * chore: list of all dashboard types is updated * chore: logic is updated to the global state * chore: all dashboard data is fetched from the global state * chore: unnessary prop is removed * chore: changes are updated * chore: getAll and create is updated * chore: getDashboard is updated * chore: isEditMode is moved to the global state * chore: get,getAll is updated * chore: update title,tags,description is now fixed * chore: new widget is updated * chore: graph is updated * chore: input component accept input props * chore: name of the dashboard is updated * chore: Widgets page in WIP * chore: types for the error api is updated * chore: getQuery data is updated * chore: widget types is updated * default widget is updated * chore: getQuery is updated * chore: Add Query is updated * fix: creating new widget bug is resolved * chore: widget type is updated * chore: Query error is updated * chore: query error and success state is handled * chore: label of graph in WIP * chore: legend input placeholder is updated * chore: changes are updated * chore: no data component is updated and error component is rendered along with the data * chore: data fetching over the initial render is fixed over the initial mount * chore: convertDateToAndPm is updated * chore: x-axis label is now fixed * chore: label is updated * chore: labels name is updated * chore: labels name is updated * chore: labels color is updated * chore: values are parsed in float * chore: tags is updated * chore: datasets type is updated * chore: graph is updated * chore: more eslint rules are updated * chore: some of the linting changes and data is updated * chore: chart.js version is updated * chore: gitignore is updated * chore: graph component is updated * chore: apply functionality is updated * chore: dashboard is now saved * chore: getChartData is updated * feat: Dashboard graph is reflected * chore: some of the bugs is resolved * fix: aspect ratio is made false * chore: some small css are fixed * chore: widgetId and graphType is preAdded if present in the search params * chore: user is now able to change the time via global time and reflect new graph values * chore: query is updated * chore: onBlurHandler is updated * fix: usage explorer is now fixed * chore: bar element is updated * chore: chartjs adapter is added * chore: old instance for the charts are removed via re-chart * chore: re-chart is removed * chore: get chart data is updated * chore: added the counter in the useEffect * chore: history is added * chore: some of the features are updated * chore: history package is updated * chore: AppRoutes is updated * fix: some are components breaking while moving from BrowserRouter to Router * chore: Dashboard icon is updated * chore: Full screen component is updated * stepSize (optional) is added in the widgets type * fix: fetching query result is fixed * update: start and end time function is updated * fix: Alert color is updated * update: Query fetching is updated * fix: start and end time is fixed * fix: chartjs data is compatable for larger data set and no ajax call for empty query is fixed * fix: last 1 week selection is fixed * fix: legends is added * update: antd version is updated * feat: value graph is updated * feat: Title is added for the value graph * fix: Full Screen view is updated with refresh functionality and alignment is updated to flex-end * fix: Graph component is updated * fix: metric graph are fixed * feature: Delete widget functionality is updated * fix: empty value bug is resolved * fix: delete widget position is fixed * fix: resize functionality is fixed * fix: sumation of the query is fixed * update: default legend is removed * update: resize handlers is removed and service metric component is updated * fix: legends is updated * update: querySuccess reducer is updated * Modal component is updated * fix: ant-d tab css is updated of the tabs * update: stringToHTML is made * update: graph component is updated * fix: several component in the metric and traces are updated * wip: build error is fixed * fix: metric section is fixed * update: console.log are commented * fix: onClick graph re-render is stopped * fix: trace graph is updated * fix: updated the min,max time for the value type graph * getQueryMaxMin Time is updated * fix: trace chart is updated * fix: re-render is fixed * fix: localstorage persistance is there * update: if label is not present legend is not displayed * fix: graph is changed while updated the global time * fix: default title is updated while creation of the dashboard * update: external database call tabs are made of same size * fix: query graph max-min time is updated in the full screen mode * fix: Request per sec graph is fixed * fix: ErrorChart is fixed Co-authored-by: Palash gupta <palashgdev@gmail.com>
236 lines
5.0 KiB
TypeScript
236 lines
5.0 KiB
TypeScript
import {
|
|
BarController,
|
|
BarElement,
|
|
CategoryScale,
|
|
Chart,
|
|
ChartOptions,
|
|
ChartType,
|
|
Decimation,
|
|
Filler,
|
|
Legend,
|
|
// LegendItem,
|
|
LinearScale,
|
|
LineController,
|
|
LineElement,
|
|
PointElement,
|
|
ScaleOptions,
|
|
SubTitle,
|
|
TimeScale,
|
|
TimeSeriesScale,
|
|
Title,
|
|
Tooltip,
|
|
} from 'chart.js';
|
|
import chartjsAdapter from 'chartjs-adapter-date-fns';
|
|
// import { colors } from 'lib/getRandomColor';
|
|
// import stringToHTML from 'lib/stringToHTML';
|
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
import { useThemeSwitcher } from 'react-css-theme-switcher';
|
|
|
|
// import Legends from './Legend';
|
|
// import { LegendsContainer } from './styles';
|
|
|
|
const Graph = ({
|
|
data,
|
|
type,
|
|
title,
|
|
isStacked,
|
|
label,
|
|
xAxisType,
|
|
onClickHandler,
|
|
}: GraphProps): JSX.Element => {
|
|
const chartRef = useRef<HTMLCanvasElement>(null);
|
|
const { currentTheme } = useThemeSwitcher();
|
|
|
|
// const [tooltipVisible, setTooltipVisible] = useState<boolean>(false);
|
|
const lineChartRef = useRef<Chart>();
|
|
|
|
const getGridColor = useCallback(() => {
|
|
if (currentTheme === undefined) {
|
|
return 'rgba(231,233,237,0.1)';
|
|
}
|
|
|
|
if (currentTheme === 'dark') {
|
|
return 'rgba(231,233,237,0.1)';
|
|
}
|
|
|
|
return 'rgba(231,233,237,0.8)';
|
|
}, [currentTheme]);
|
|
|
|
const buildChart = useCallback(() => {
|
|
if (lineChartRef.current !== undefined) {
|
|
lineChartRef.current.destroy();
|
|
}
|
|
|
|
if (chartRef.current !== null) {
|
|
Chart.register(
|
|
LineElement,
|
|
PointElement,
|
|
LineController,
|
|
CategoryScale,
|
|
LinearScale,
|
|
TimeScale,
|
|
TimeSeriesScale,
|
|
Decimation,
|
|
Filler,
|
|
Legend,
|
|
Title,
|
|
Tooltip,
|
|
SubTitle,
|
|
BarController,
|
|
BarElement,
|
|
);
|
|
|
|
const options: ChartOptions = {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
interaction: {
|
|
mode: 'index',
|
|
intersect: false,
|
|
},
|
|
plugins: {
|
|
title: {
|
|
display: title === undefined ? false : true,
|
|
text: title,
|
|
},
|
|
legend: {
|
|
// just making sure that label is present
|
|
display: !(
|
|
data.datasets.find((e) => e.label !== undefined) === undefined
|
|
),
|
|
labels: {
|
|
usePointStyle: true,
|
|
pointStyle: 'circle',
|
|
},
|
|
position: 'bottom',
|
|
// labels: {
|
|
// generateLabels: (chart: Chart): LegendItem[] => {
|
|
// return (data.datasets || []).map((e, index) => {
|
|
// return {
|
|
// text: e.label || '',
|
|
// datasetIndex: index,
|
|
// };
|
|
// });
|
|
// },
|
|
// pointStyle: 'circle',
|
|
// usePointStyle: true,
|
|
// },
|
|
},
|
|
},
|
|
layout: {
|
|
padding: 0,
|
|
},
|
|
scales: {
|
|
x: {
|
|
animate: false,
|
|
grid: {
|
|
display: true,
|
|
color: getGridColor(),
|
|
},
|
|
labels: label,
|
|
adapters: {
|
|
date: chartjsAdapter,
|
|
},
|
|
type: xAxisType,
|
|
},
|
|
y: {
|
|
display: true,
|
|
grid: {
|
|
display: true,
|
|
color: getGridColor(),
|
|
},
|
|
},
|
|
stacked: {
|
|
display: isStacked === undefined ? false : 'auto',
|
|
},
|
|
},
|
|
elements: {
|
|
line: {
|
|
tension: 0,
|
|
cubicInterpolationMode: 'monotone',
|
|
},
|
|
},
|
|
onClick: onClickHandler,
|
|
};
|
|
|
|
lineChartRef.current = new Chart(chartRef.current, {
|
|
type: type,
|
|
data: data,
|
|
options,
|
|
// plugins: [
|
|
// {
|
|
// id: 'htmlLegendPlugin',
|
|
// afterUpdate: (chart: Chart): void => {
|
|
// if (
|
|
// chart &&
|
|
// chart.options &&
|
|
// chart.options.plugins &&
|
|
// chart.options.plugins.legend &&
|
|
// chart.options.plugins.legend.labels &&
|
|
// chart.options.plugins.legend.labels.generateLabels
|
|
// ) {
|
|
// const labels = chart.options.plugins?.legend?.labels?.generateLabels(
|
|
// chart,
|
|
// );
|
|
|
|
// const id = 'htmlLegend';
|
|
|
|
// const response = document.getElementById(id);
|
|
|
|
// if (labels && response && response?.childNodes.length === 0) {
|
|
// const labelComponent = labels.map((e, index) => {
|
|
// return {
|
|
// element: Legends({
|
|
// text: e.text,
|
|
// color: colors[index] || 'white',
|
|
// }),
|
|
// dataIndex: e.datasetIndex,
|
|
// };
|
|
// });
|
|
|
|
// labelComponent.map((e) => {
|
|
// const el = stringToHTML(e.element);
|
|
|
|
// if (el) {
|
|
// el.addEventListener('click', () => {
|
|
// chart.setDatasetVisibility(
|
|
// e.dataIndex,
|
|
// !chart.isDatasetVisible(e.dataIndex),
|
|
// );
|
|
// chart.update();
|
|
// });
|
|
// response.append(el);
|
|
// }
|
|
// });
|
|
// }
|
|
// }
|
|
// },
|
|
// },
|
|
// ],
|
|
});
|
|
}
|
|
}, [chartRef, data, type, title, isStacked, label, xAxisType, getGridColor]);
|
|
|
|
useEffect(() => {
|
|
buildChart();
|
|
}, [buildChart]);
|
|
|
|
return (
|
|
<>
|
|
<canvas ref={chartRef} />
|
|
{/* <LegendsContainer id="htmlLegend" /> */}
|
|
</>
|
|
);
|
|
};
|
|
|
|
interface GraphProps {
|
|
type: ChartType;
|
|
data: Chart['data'];
|
|
title?: string;
|
|
isStacked?: boolean;
|
|
label?: string[];
|
|
xAxisType?: ScaleOptions['type'];
|
|
onClickHandler?: ChartOptions['onClick'];
|
|
}
|
|
|
|
export default Graph;
|