hit-detail.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { FC } from "react";
  2. import cn from "classnames";
  3. import { SegmentDetailModel } from "@/models/datasets";
  4. import { useTranslation } from "react-i18next";
  5. import Divider from "@/app/components/base/divider";
  6. import { SegmentIndexTag } from "../documents/detail/completed";
  7. import s from "../documents/detail/completed/style.module.css";
  8. import ReactECharts from "echarts-for-react";
  9. type IScatterChartProps = {
  10. data: Array<number[]>
  11. curr: Array<number[]>
  12. }
  13. const ScatterChart: FC<IScatterChartProps> = ({ data, curr }) => {
  14. const option = {
  15. xAxis: {},
  16. yAxis: {},
  17. tooltip: {
  18. trigger: 'item',
  19. axisPointer: {
  20. type: 'cross'
  21. }
  22. },
  23. series: [
  24. {
  25. type: 'effectScatter',
  26. symbolSize: 5,
  27. data: curr,
  28. },
  29. {
  30. type: 'scatter',
  31. symbolSize: 5,
  32. data,
  33. }
  34. ]
  35. };
  36. return (
  37. <ReactECharts option={option} style={{ height: 380, width: 430 }} />
  38. )
  39. }
  40. type IHitDetailProps = {
  41. segInfo?: Partial<SegmentDetailModel> & { id: string };
  42. vectorInfo?: { curr: Array<number[]>; points: Array<number[]> };
  43. };
  44. const HitDetail: FC<IHitDetailProps> = ({ segInfo, vectorInfo }) => {
  45. const { t } = useTranslation();
  46. return (
  47. <div className={"flex flex-row"}>
  48. <div className="flex-1 bg-gray-25 p-6">
  49. <div className="flex items-center">
  50. <SegmentIndexTag
  51. positionId={segInfo?.position || ""}
  52. className="w-fit mr-6"
  53. />
  54. <div className={cn(s.commonIcon, s.typeSquareIcon)} />
  55. <span className={cn("mr-6", s.numberInfo)}>
  56. {segInfo?.word_count} {t("datasetDocuments.segment.characters")}
  57. </span>
  58. <div className={cn(s.commonIcon, s.targetIcon)} />
  59. <span className={s.numberInfo}>
  60. {segInfo?.hit_count} {t("datasetDocuments.segment.hitCount")}
  61. </span>
  62. </div>
  63. <Divider />
  64. <div className={s.segModalContent}>{segInfo?.content}</div>
  65. <div className={s.keywordTitle}>
  66. {t("datasetDocuments.segment.keywords")}
  67. </div>
  68. <div className={s.keywordWrapper}>
  69. {!segInfo?.keywords?.length
  70. ? "-"
  71. : segInfo?.keywords?.map((word: any) => {
  72. return <div className={s.keyword}>{word}</div>;
  73. })}
  74. </div>
  75. </div>
  76. <div className="flex-1 bg-white p-6">
  77. <div className="flex items-center">
  78. <div className={cn(s.commonIcon, s.bezierCurveIcon)} />
  79. <span className={s.numberInfo}>
  80. {t("datasetDocuments.segment.vectorHash")}
  81. </span>
  82. </div>
  83. <div
  84. className={cn(s.numberInfo, "w-[400px] truncate text-gray-700 mt-1")}
  85. >
  86. {segInfo?.index_node_hash}
  87. </div>
  88. <ScatterChart data={vectorInfo?.points || []} curr={vectorInfo?.curr || []} />
  89. </div>
  90. </div>
  91. );
  92. };
  93. export default HitDetail;