コード例 #1
0
void
ViewHistory::Update(DataHistory* history, int32 width, int32 resolution,
	bigtime_t toTime, bigtime_t step, bigtime_t refresh)
{
	if (width > 16384) {
		// ignore this - it seems the view hasn't been layouted yet
		return;
	}

	// Check if we need to invalidate the existing values
	if ((int32)fValues.Size() != width
		|| fResolution != resolution
		|| fRefresh != refresh) {
		fValues.SetSize(width);
		fResolution = resolution;
		fRefresh = refresh;
		fLastTime = 0;
	}

	// Compute how many new values we need to retrieve
	if (fLastTime < history->Start())
		fLastTime = history->Start();
	if (fLastTime > history->End())
		return;

	int32 updateWidth = int32((toTime - fLastTime) / step);
	if (updateWidth < 1)
		return;

	if (updateWidth > (int32)fValues.Size()) {
		updateWidth = fValues.Size();
		fLastTime = toTime - updateWidth * step;
	}

	for (int32 i = 0; i < updateWidth; i++) {
		int64 value = history->ValueAt(fLastTime += step);

		if (step > refresh) {
			uint32 count = 1;
			for (bigtime_t offset = refresh; offset < step; offset += refresh) {
				// TODO: handle int64 overflow correctly!
				value += history->ValueAt(fLastTime + offset);
				count++;
			}
			value /= count;
		}

		fValues.AddItem(value);
	}
}