/
graph.j
60 lines (46 loc) · 1.3 KB
/
graph.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@import <AppKit/CPWebView.j>
@implementation Graph : CPWebView
{
DOMWindow domWin;
@outlet id delegate @accessors(property=delegate);
@accessors CPArray plots;
}
- (id)initWithFrame:(CGRect)aFrame
{
plots = [];
if (self = [super initWithFrame:aFrame]) {
[self setFrameLoadDelegate:self];
[self setMainFrameURL:[[CPBundle mainBundle] pathForResource:@"graph.html"]];
}
return self;
}
- (void) setDelegate:(id) theDelegate {
delegate = theDelegate;
}
- (void)webView:(CPWebView)aWebView didFinishLoadForFrame:(id)aFrame {
domWin = [self DOMWindow];
if (delegate && [delegate respondsToSelector:@selector(graphViewDidFinishLoading:)]) {
[delegate graphViewDidFinishLoading:self];
}
}
- (void) addPlot:(CPDictionary) options {
plots.push(options);
}
- (void) removePlotWithLabel:(CPString) label {
for (var i; i < plots.length; i++) {
if (plot[i].label == label) {
plots.splice(i, 1);
}
}
}
- (void) removePlotWithIndex:(int)index {
plots.splice(index, 1);
}
// call this when you're ready to plot or re-plot everything
- (void) refreshGraph {
//domWin.jQuery.plot(domWin.jQuery('#graph'), plots);
domWin.jQuery.plot.setData(plots);
domWin.jQuery.setupGrid();
domWin.jQuery.plot.draw();
}
@end