/// <summary> /// 绘制谱图 /// </summary> /// <param name="data">频率、值</param> public void DrawData(Dictionary <double, short> data, int pRemainder, DateTime?pTime = null) { if (_writeableBmp == null) { return; } if (!_receiveData) { return; } if (_writeableBmp.PixelHeight == 0 || _writeableBmp.PixelWidth == 0) { _writeableBmp = new WriteableBitmap((int)uxWaterfall.Width, (int)uxWaterfall.Height, 96, 96, PixelFormats.Pbgra32, null); _writeableBmp.FillRectangle(0, 0, (int)uxWaterfall.Width, (int)uxWaterfall.Height, Colors.Transparent); uxWaterfall.Source = _writeableBmp; } foreach (var fv in data) { if (_maxColumn == 0 || _maxColumn < _writeableBmp.PixelWidth) { _maxColumn = _writeableBmp.PixelWidth; } _cachedDatas[fv.Key] = fv.Value; } _writeableBmp.Clear(Colors.Transparent); var c = (_maxRow * (_timestampCount - 1) / _writeableBmp.PixelHeight) % _timestampCount; if (c != c1) { Timestamps.RemoveAt(0); Timestamps.Insert(_timestampCount - 1, pTime == null ? "--:--:--" : pTime.Value.ToLongTimeString()); c1 = c; } if (_isCompletion) { _maxRow += 1; } else { _maxRow = _cachedDatas.Count; } _writeableBmp.FillRectangle(0, 0, _writeableBmp.PixelWidth, _maxRow > _writeableBmp.PixelHeight ? _writeableBmp.PixelHeight : _maxRow, Color.FromArgb(210, 22, 22, 255)); _row = _maxRow; foreach (var tuple in _cachedDatas) { if (tuple.Key < XAxisMinimum || tuple.Key > XAxisMaximum) { continue; } var currFreq = Math.Floor(tuple.Key); var xAxisMaximumKhz = WMonitorUtile.ConvertFreqValue("mhz", "khz", XAxisMaximum); var xAxisMinimumKhz = WMonitorUtile.ConvertFreqValue("mhz", "khz", XAxisMinimum); var xKey = WMonitorUtile.ConvertFreqValue("mhz", "khz", tuple.Key); //if (currFreq.Equals(Math.Floor(XAxisMaximum)) || WMonitorUtile.ConvertFreqValue("mhz", "khz", tuple.Key).Equals(XAxisMaximumKhz - pRemainder))//起始减去终止频率除以步进有余数时,瀑布图显示一半的bug //if (currFreq.Equals(Math.Floor(XAxisMaximum)) || (xAxisMaximumKhz - xKey) < pRemainder) //{ _isCompletion = true; //} var col = (int)((tuple.Key - XAxisMinimum) * XUnitLength) + 1; if (col < EdgeMargin) { col = EdgeMargin; } if (col > _writeableBmp.PixelWidth) { col = _writeableBmp.PixelWidth - 1; } var y = tuple.Value; if (y <= YAxisMinimum || y < ThresholdValue) //门限 { continue; } if (_cachedColors.Keys.Contains(y)) { _writeableBmp.DrawLine(col, 0, col, _row, _cachedColors[y]); } else { _cachedColors[y] = GetColorAtPoint(uxYAxisRect, new Point(uxYAxisRect.ActualWidth, uxYAxisRect.ActualHeight - Math.Abs(y - YAxisMinimum) * _yUnitLength)); _writeableBmp.DrawLine(col, 0, col, _row, _cachedColors[y]); } if (!IsCompletion || _maxRow >= _cachedDatas.Count) { _row--; } } // _writeableBmp.Invalidate(); }