Skip to content
This repository was archived by the owner on Oct 12, 2018. It is now read-only.

Commit be7a6b4

Browse files
committed
Keep old graphs data while rebuilding sensors list
1 parent 24e792f commit be7a6b4

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

HWMonitor/GraphsView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
@interface GraphsView : NSView
3333
{
3434
NSMutableArray *_items;
35-
NSMutableDictionary *_graphs;
3635

3736
NSRect _graphBounds;
3837
double _minY;
@@ -49,6 +48,7 @@
4948
@property (nonatomic, assign) BOOL useSmoothing;
5049
@property (nonatomic, assign) float graphScale;
5150
@property (nonatomic, assign) HWSensorGroup sensorGroup;
51+
@property (readonly) NSMutableDictionary *graphs;
5252

5353
- (NSArray*)addItemsFromList:(NSArray*)itemsList forSensorGroup:(HWSensorGroup)sensorsGroup;
5454
- (void)calculateGraphBoundsFindExtremes:(BOOL)findExtremes;

HWMonitor/GraphsView.m

+17-11
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,24 @@
3030
#import "HWMonitorDefinitions.h"
3131
#import "Localizer.h"
3232

33+
static NSMutableDictionary *graphs_history = nil;
34+
3335
@implementation GraphsView
3436

3537
#define LeftViewMargin 1
3638
#define TopViewMargin 1
3739
#define RightViewMargin 1
3840
#define BottomViewMargin 1
3941

42+
-(NSMutableDictionary *)graphs
43+
{
44+
if (!graphs_history) {
45+
graphs_history = [[NSMutableDictionary alloc] init];
46+
}
47+
48+
return graphs_history;
49+
}
50+
4051
-(id)init
4152
{
4253
self = [super init];
@@ -92,17 +103,12 @@ - (NSArray*)addItemsFromList:(NSArray*)itemsList forSensorGroup:(HWSensorGroup)s
92103
else {
93104
[_items removeAllObjects];
94105
}
95-
96-
if (!_graphs) {
97-
_graphs = [[NSMutableDictionary alloc] init];
98-
}
99-
else {
100-
[_graphs removeAllObjects];
101-
}
102106

103107
for (HWMonitorItem *item in itemsList) {
104108
[_items addObject:item];
105-
[_graphs setObject:[[NSMutableArray alloc] init] forKey:[[item sensor] name]];
109+
if (![self.graphs objectForKey:item.sensor.name]) {
110+
[self.graphs setObject:[[NSMutableArray alloc] init] forKey:[[item sensor] name]];
111+
}
106112
}
107113

108114
[self calculateGraphBoundsFindExtremes:YES];
@@ -114,7 +120,7 @@ - (void)captureDataToHistoryNow;
114120
{
115121
for (HWMonitorItem *item in _items) {
116122
HWMonitorSensor *sensor = [item sensor];
117-
NSMutableArray *history = [_graphs objectForKey:[sensor name]];
123+
NSMutableArray *history = [self.graphs objectForKey:[sensor name]];
118124

119125
if ([sensor rawValue]) {
120126
[history addObject:[sensor rawValue]];
@@ -142,7 +148,7 @@ - (void)calculateGraphBoundsFindExtremes:(BOOL)findExtremes
142148
continue;
143149

144150
HWMonitorSensor *sensor = [item sensor];
145-
NSArray *points = [_graphs objectForKey:[sensor name]];
151+
NSArray *points = [self.graphs objectForKey:[sensor name]];
146152

147153
if (points) {
148154
for (NSNumber *point in points) {
@@ -235,7 +241,7 @@ - (void)drawRect:(NSRect)rect
235241
continue;
236242

237243
HWMonitorSensor *sensor = [item sensor];
238-
NSArray *values = [_graphs objectForKey:[sensor name]];
244+
NSArray *values = [self.graphs objectForKey:[sensor name]];
239245

240246
if (!values || [values count] < 2)
241247
continue;

0 commit comments

Comments
 (0)