Skip to content

Commit

Permalink
调整Demo的展示形式
Browse files Browse the repository at this point in the history
调整Demo的展示形式,保证Demo不会出现特别看不清的情况
  • Loading branch information
Pluto-Y committed Dec 5, 2015
1 parent dca4d0c commit 02c8407
Show file tree
Hide file tree
Showing 16 changed files with 868 additions and 733 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,5 @@
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iOS-Echarts_Demo/Controller/PieDemoController.m"
timestampString = "465592154.800775"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "157"
endingLineNumber = "157"
landmarkName = "-showDoughnut3Demo"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
2 changes: 1 addition & 1 deletion iOS-Echarts/Model/PYOption.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ - (instancetype)init
{
self = [super init];
if (self) {
_grid = [[PYGrid alloc] init];

}
return self;
}
Expand Down
5 changes: 4 additions & 1 deletion iOS-Echarts/PYEchartsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@protocol PYEchartsViewDelegate <NSObject>

@optional
-(void)echartClick:(NSDictionary *)dic pointInView:(CGPoint) point;
-(void)echartClick:(NSDictionary *)paramDic pointInView:(CGPoint) point;
-(void)echartDbClick:(NSDictionary *)paramDic;

@end

Expand All @@ -23,6 +24,7 @@
@property (assign, nonatomic) UIEdgeInsets padding;
@property (assign, nonatomic) CGSize divSize;
@property (assign, nonatomic) CGFloat maxWidth;
@property (assign, nonatomic) BOOL scalable;

@property (retain, nonatomic) id<PYEchartsViewDelegate> echartDelegate;

Expand All @@ -38,4 +40,5 @@
*/
-(void)setOption:(PYOption *)pyOption;


@end
27 changes: 18 additions & 9 deletions iOS-Echarts/PYEchartsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ -(void)initAll {

_divSize = CGSizeZero;
minWidth = self.frame.size.width - 10;
_scalable = NO;


_maxWidth = NSIntegerMax;
Expand Down Expand Up @@ -119,13 +120,13 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView {
[self resizeDiv];

NSString *jsonStr = [PYJsonUtil getJSONString:option];
// NSLog(@"%@",jsonStr);
NSLog(@"%@",jsonStr);
NSString *js = [NSString stringWithFormat:@"%@(%@)", @"loadEcharts", jsonStr];
[webView stringByEvaluatingJavaScriptFromString:js];
}

/**
* 根据
*
*/
-(void)resizeDiv {
float height = self.frame.size.height - 20;
Expand Down Expand Up @@ -156,6 +157,9 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
* 缩放手势
*/
-(void)pinchGestureHandle:(id)sender {
if (!_scalable) {
return;
}
UIPinchGestureRecognizer *recognizer = (UIPinchGestureRecognizer *)sender;
int touchCount = (int)[recognizer numberOfTouches];
//当手指离开屏幕时,将lastscale设置为1.0
Expand All @@ -164,9 +168,6 @@ -(void)pinchGestureHandle:(id)sender {
return;
}
CGFloat scale = 1.0 - (lastScale - [recognizer scale]);
// CGAffineTransform currentTransform = [recognizer view].transform;
// CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
// [[recognizer view]setTransform:newTransform];
if (_divSize.width >= _maxWidth && scale > 1) {
return;
}
Expand All @@ -192,6 +193,10 @@ -(void)pinchGestureHandle:(id)sender {
lastScale = [recognizer scale];
}

/**
* 用于处理Echart出现的各种事件
* 如点击、双击等
*/
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSLog(@"%@", url);
Expand All @@ -215,10 +220,8 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
}
}



// look at the actionType and do whatever you want here
if ([actionType isEqualToString:ACTION_TYPE_CLICK]) {
if ([actionType isEqualToString:ACTION_TYPE_CLICK]) {// Click Event
if (tapPoint.x != 0 || tapPoint.y != 0) {
if (paramsDic != nil) {
if (_echartDelegate != nil && [_echartDelegate respondsToSelector:@selector(echartClick:pointInView:)]) {
Expand All @@ -227,7 +230,13 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
}
tapPoint = CGPointZero;
}
} else if([actionType isEqualToString:ACTION_TYPE_DBCLICK] ) {
} else if([actionType isEqualToString:ACTION_TYPE_DBCLICK] ) {// Double Click Event
if (paramsDic != nil) {
if (_echartDelegate != nil && [_echartDelegate respondsToSelector:@selector(echartDbClick:)]) {
[_echartDelegate echartDbClick:paramsDic];
}
}
} else {

}

Expand Down
20 changes: 18 additions & 2 deletions iOS-Echarts/Resources/echarts.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<script src="js/echarts.js"></script>
<script type="text/javascript">
var option;
var myChart;
function echartViewAction(param) {
if (typeof param.seriesIndex != 'undefined') {
document.location.href = 'pyEchartAction://' + param.type + '#{"seriesIndex":"' + + param.seriesIndex + '","dataIndex":"' + param.dataIndex + '"}';
} else {
document.location.href = 'pyEchartAction://' + param.type;
}
//document.location.href = 'pyEchartAction://' + param.type + '#{' + param.seriesIndex + ':' + param.dataIndex + '}';
}
function preTask(obj) {
var result;
if(typeof(obj) == 'object') {
Expand Down Expand Up @@ -69,7 +78,7 @@
],
function (ec) {
// 基于准备好的dom,初始化echarts图表
var myChart = ec.init(document.getElementById('main'));
myChart = ec.init(document.getElementById('main'));
option = preTask(testdate);
//option = preTask(testdate);
// 为echarts对象加载数据
Expand All @@ -94,7 +103,9 @@
'echarts',
'echarts/chart/line', // 使用柱状图就加载line模块,按需加载
'echarts/chart/bar',
'echarts/chart/pie'
'echarts/chart/pie',
'echarts/chart/k',
'echarts/chart/scatter'
],
function (ec) {
var ecConfig = require('echarts/config');
Expand All @@ -104,6 +115,11 @@
// 为echarts对象加载数据
myChart.setOption(option);
myChart.on(ecConfig.EVENT.CLICK, echartViewAction);
myChart.on(ecConfig.EVENT.DBLCLICK, echartViewAction);
myChart.on(ecConfig.EVENT.DATA_ZOOM, echartViewAction);
myChart.on(ecConfig.EVENT.LEGEND_SELECTED, echartViewAction);
myChart.on(ecConfig.EVENT.MAGIC_TYPE_CHANGED, echartViewAction);
myChart.on(ecConfig.EVENT.DATA_VIEW_CHANGED, echartViewAction);
}
);
}
Expand Down
Loading

0 comments on commit 02c8407

Please sign in to comment.