Commit ef721b5d authored by 李纪文's avatar 李纪文

fix: 修改实时数据数据为0展示--问题

parent 7fa4df59
......@@ -180,7 +180,8 @@
"react-redux": "^8.0.5",
"react-resizable": "^3.0.4",
"react-window": "1.8.9",
"sha1": "^1.1.1"
"sha1": "^1.1.1",
"skmeans": "^0.11.3"
},
"size-limit": [
{
......
import React from 'react';
import React, { useState } from 'react';
import { LimitCurve } from '../index';
import { Button } from 'antd';
const Demos = () => {
const [open, setOpen] = useState(false);
return (
<>
<LimitCurve />
<Button
onClick={() => {
setOpen(true);
}}
>
打开限制曲线
</Button>
<LimitCurve open={open} />
</>
);
};
......
const getDataRanges = (extremes) => {
var ranges = [];
for (var dimension in extremes) {
ranges[dimension] = extremes[dimension].max - extremes[dimension].min;
}
return ranges;
}
const getDataExtremes = (data)=> {
var extremes = [];
for (var i in data) {
var point = data[i];
for (var dimension in point) {
if (!extremes[dimension]) {
extremes[dimension] = { min: 1000, max: 0 };
}
if (point[dimension] < extremes[dimension].min) {
extremes[dimension].min = point[dimension];
}
if (point[dimension] > extremes[dimension].max) {
extremes[dimension].max = point[dimension];
}
}
}
return extremes;
}
const initMeans = (k, dataExtremes, dataRange) => {
if (!k) {
k = 3;
}
const means = [];
while (k--) {
var mean = [];
for (var dimension in dataExtremes) {
mean[dimension] = dataExtremes[dimension].min + Math.random() * dataRange[dimension];
}
means.push(mean);
}
return means;
}
const makeAssignments = (means, data) => {
const assignments = {};
for (var i in data) {
var point = data[i];
var distances = [];
for (var j in means) {
var mean = means[j];
var sum = 0;
for (var dimension in point) {
var difference = point[dimension] - mean[dimension];
difference *= difference;
sum += difference;
}
distances[j] = Math.sqrt(sum);
}
assignments[i] = distances.indexOf(Math.min.apply(null, distances));
}
return assignments;
}
const setup = (data) => {
const dataExtremes = getDataExtremes(data);
const dataRange = getDataRanges(dataExtremes);
const means = initMeans(3, dataExtremes, dataRange);
return makeAssignments(means, data);
}
export default setup;
......@@ -212,7 +212,7 @@ const RealTimeInfo = (props) => {
item.type = curData1[0].name || '--';
}
if (curData2.length) {
item.value = curData2[0].pv || '--';
item.value = curData2[0].pv || curData2[0].pv === 0 ? curData2[0].pv : '--';
}
});
return newData;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment