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

Commit

Permalink
Keep old graphs data while rebuilding sensors list
Browse files Browse the repository at this point in the history
  • Loading branch information
CozmoNate committed Oct 19, 2013
1 parent 24e792f commit be7a6b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion HWMonitor/GraphsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
@interface GraphsView : NSView
{
NSMutableArray *_items;
NSMutableDictionary *_graphs;

NSRect _graphBounds;
double _minY;
Expand All @@ -49,6 +48,7 @@
@property (nonatomic, assign) BOOL useSmoothing;
@property (nonatomic, assign) float graphScale;
@property (nonatomic, assign) HWSensorGroup sensorGroup;
@property (readonly) NSMutableDictionary *graphs;

- (NSArray*)addItemsFromList:(NSArray*)itemsList forSensorGroup:(HWSensorGroup)sensorsGroup;
- (void)calculateGraphBoundsFindExtremes:(BOOL)findExtremes;
Expand Down
28 changes: 17 additions & 11 deletions HWMonitor/GraphsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@
#import "HWMonitorDefinitions.h"
#import "Localizer.h"

static NSMutableDictionary *graphs_history = nil;

@implementation GraphsView

#define LeftViewMargin 1
#define TopViewMargin 1
#define RightViewMargin 1
#define BottomViewMargin 1

-(NSMutableDictionary *)graphs
{
if (!graphs_history) {
graphs_history = [[NSMutableDictionary alloc] init];
}

return graphs_history;
}

-(id)init
{
self = [super init];
Expand Down Expand Up @@ -92,17 +103,12 @@ - (NSArray*)addItemsFromList:(NSArray*)itemsList forSensorGroup:(HWSensorGroup)s
else {
[_items removeAllObjects];
}

if (!_graphs) {
_graphs = [[NSMutableDictionary alloc] init];
}
else {
[_graphs removeAllObjects];
}

for (HWMonitorItem *item in itemsList) {
[_items addObject:item];
[_graphs setObject:[[NSMutableArray alloc] init] forKey:[[item sensor] name]];
if (![self.graphs objectForKey:item.sensor.name]) {
[self.graphs setObject:[[NSMutableArray alloc] init] forKey:[[item sensor] name]];
}
}

[self calculateGraphBoundsFindExtremes:YES];
Expand All @@ -114,7 +120,7 @@ - (void)captureDataToHistoryNow;
{
for (HWMonitorItem *item in _items) {
HWMonitorSensor *sensor = [item sensor];
NSMutableArray *history = [_graphs objectForKey:[sensor name]];
NSMutableArray *history = [self.graphs objectForKey:[sensor name]];

if ([sensor rawValue]) {
[history addObject:[sensor rawValue]];
Expand Down Expand Up @@ -142,7 +148,7 @@ - (void)calculateGraphBoundsFindExtremes:(BOOL)findExtremes
continue;

HWMonitorSensor *sensor = [item sensor];
NSArray *points = [_graphs objectForKey:[sensor name]];
NSArray *points = [self.graphs objectForKey:[sensor name]];

if (points) {
for (NSNumber *point in points) {
Expand Down Expand Up @@ -235,7 +241,7 @@ - (void)drawRect:(NSRect)rect
continue;

HWMonitorSensor *sensor = [item sensor];
NSArray *values = [_graphs objectForKey:[sensor name]];
NSArray *values = [self.graphs objectForKey:[sensor name]];

if (!values || [values count] < 2)
continue;
Expand Down

0 comments on commit be7a6b4

Please sign in to comment.