Skip to content

Commit a20cf66

Browse files
authored
Merge pull request #2 from ant-mini-program/feat-basic
feat: basic graphics
2 parents 28bb340 + ed488a7 commit a20cf66

File tree

149 files changed

+4025
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+4025
-7
lines changed

README.md

Lines changed: 470 additions & 0 deletions
Large diffs are not rendered by default.

app.acss

Whitespace-only changes.

app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
App({});

app.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"pages": [
3+
"examples/index/index",
4+
"examples/line/index",
5+
"examples/area/index",
6+
"examples/dodge-area/index",
7+
"examples/stack-area/index",
8+
"examples/column/index",
9+
"examples/dodge/index",
10+
"examples/stack-column/index",
11+
"examples/bar/index",
12+
"examples/dodge-bar/index",
13+
"examples/stack-bar/index",
14+
"examples/radar/index",
15+
"examples/radar-fund/index",
16+
"examples/pie/index",
17+
"examples/radial-bar/index",
18+
"examples/labelline-pie/index",
19+
"examples/ring/index",
20+
"examples/rose/index",
21+
"examples/scatter/index",
22+
"examples/bubble/index",
23+
"examples/k/index",
24+
"examples/timeshare/index"
25+
],
26+
"window": {
27+
"defaultTitle": "小程序图表组件库"
28+
}
29+
}

components/area/index.acss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.am-mc-area{
2+
width:100%;
3+
height:100%;
4+
}
5+
6+
canvas{
7+
width:100%;
8+
height:100%;
9+
}

components/area/index.axml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<view class="am-mc-area">
2+
<canvas
3+
id="am-mc-area-{{$id}}"
4+
height="{{height}}"
5+
width="{{width}}"
6+
onTouchStart="touchStart"
7+
onTouchMove="touchMove"
8+
onTouchEnd="touchEnd"
9+
/>
10+
</view>

components/area/index.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import F2 from '@antv/my-f2';
2+
import methods from '../mixins/methods';
3+
import util from '../util';
4+
5+
Component({
6+
mixins: [methods],
7+
props: {
8+
categories: [],
9+
series: [],
10+
xAxis: {
11+
tickCount: 3,
12+
},
13+
yAxis: {
14+
tickCount: 3,
15+
},
16+
tooltip: false,
17+
legend: false,
18+
},
19+
didMount() {
20+
my.call('getStartupParams', {}, (result) => {
21+
util.tracert('area', result.appId, result.url);
22+
});
23+
24+
const id = `am-mc-area-${this.$id}`;
25+
const ctx = my.createCanvasContext(id);
26+
const canvas = this.canvas = new F2.Renderer(ctx);
27+
28+
const pixelRatio = my.getSystemInfoSync().pixelRatio;
29+
ctx.scale(pixelRatio, pixelRatio);
30+
31+
my.createSelectorQuery()
32+
.select(`#${id}`)
33+
.boundingClientRect()
34+
.exec(res => {
35+
if(!res || !res.length) {
36+
return;
37+
}
38+
const {width, height} = res[0];
39+
this.setData({
40+
width: width * pixelRatio,
41+
height: height * pixelRatio,
42+
});
43+
const { padding, appendPadding } = this.props;
44+
45+
this.chart = new F2.Chart({
46+
el: canvas,
47+
width,
48+
height,
49+
padding,
50+
appendPadding,
51+
});
52+
});
53+
},
54+
didUpdate() {
55+
const { categories, series, xAxis, yAxis, tooltip, legend, adjust } = this.props;
56+
57+
const chart = this.chart;
58+
chart.clear();
59+
60+
let data = [];
61+
if(series.length === 1) {
62+
data = series[0].data.map((item, i) => {
63+
return {
64+
key: categories[i],
65+
value: item,
66+
}
67+
});
68+
}
69+
else if(series.length > 1) {
70+
series.forEach(kind => {
71+
data = data.concat(kind.data.map((item, i) => {
72+
return {
73+
key: categories[i],
74+
value: item,
75+
type: kind.type,
76+
};
77+
}));
78+
});
79+
}
80+
chart.source(data);
81+
82+
if(xAxis) {
83+
xAxis.label = util.label;
84+
chart.scale('key', util.scale(xAxis));
85+
chart.axis('key', util.axis(xAxis));
86+
}
87+
if(yAxis) {
88+
chart.scale('value', util.scale(yAxis));
89+
chart.axis('value', util.axis(yAxis));
90+
}
91+
chart.tooltip(tooltip);
92+
chart.legend(legend);
93+
94+
const style = {};
95+
series.forEach(kind => {
96+
style[kind.type] = kind.style;
97+
});
98+
const color = {};
99+
series.forEach(kind => {
100+
color[kind.type] = kind.color;
101+
});
102+
103+
if(series.length === 1) {
104+
chart.area().position('key*value').color('type', type => {
105+
return color[type];
106+
}).adjust(adjust);
107+
chart.line().position('key*value').color('type', type => {
108+
return color[type];
109+
}).shape('type', type => {
110+
return style[type] || 'line';
111+
}).adjust(adjust);
112+
if(series[0].point) {
113+
chart.point().position('key*value').style(series[0].point);
114+
}
115+
}
116+
else if(series.length > 1) {
117+
chart.area().position('key*value').color('type', type => {
118+
return color[type];
119+
}).adjust(adjust);
120+
chart.line().position('key*value').color('type', type => {
121+
return color[type];
122+
}).shape('type', type => {
123+
return style[type] || 'line';
124+
}).adjust(adjust);
125+
let pointType = [];
126+
let pointStyle;
127+
series.forEach(kind => {
128+
if(kind.point) {
129+
pointType.push(kind.type);
130+
pointStyle = kind.point;
131+
}
132+
});
133+
if(pointType.length) {
134+
chart.point().position('key*value').color('type').size('type', v => {
135+
if(pointType.indexOf(v) === -1) {
136+
return 0;
137+
}
138+
}).style(pointStyle);
139+
}
140+
}
141+
142+
chart.render();
143+
},
144+
});

components/area/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"component": true
3+
}

components/bubble/index.acss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.am-mc-bubble{
2+
width:100%;
3+
height:100%;
4+
}
5+
6+
canvas{
7+
width:100%;
8+
height:100%;
9+
}

components/bubble/index.axml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<view class="am-mc-bubble">
2+
<canvas
3+
id="am-mc-bubble-{{$id}}"
4+
height="{{height}}"
5+
width="{{width}}"
6+
onTouchStart="touchStart"
7+
onTouchMove="touchMove"
8+
onTouchEnd="touchEnd"
9+
/>
10+
</view>

0 commit comments

Comments
 (0)