JSDM

HTML

6
 
1
<head>
2
  <meta charset="utf-8">
3
  <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
4
5
</head>
6
<script src="https://cdn.rawgit.com/bm-w/d3/master/d3.js"></script>

CSS

xxxxxxxxxx
29
 
1
html{
2
  height: 100%;
3
}
4
body {
5
  min-height: 100%;
6
  background: #000000;
7
  padding:0;
8
  margin:0;
9
10
}
11
.icon{
12
  font-family:fontawesome;
13
  font-weight:bold;
14
  font-size:30px;
15
16
}
17
.goal,.completed{
18
  font-family: 'Myriad Set Pro', 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;
19
  fill:white;
20
  text-anchor:middle;
21
}
22
.goal{
23
  font-size: 30px;
24
25
26
}
27
.completed{
28
  font-size: 95px;
29
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

190
 
1
  //based on http://bl.ocks.org/mbostock/1096355
2
  //apple design:http://images.apple.com/watch/features/images/fitness_large.jpg
3
  "use strict";
4
5
  (function(){
6
    var gap = 2;
7
8
    var ranDataset = function () {
9
      var ran = Math.random();
10
11
      return    [
12
        {index: 0, name: 'move', icon: "\uF105", percentage: ran * 60 + 30},
13
        {index: 1, name: 'exercise', icon: "\uF101", percentage: ran * 60 + 30},
14
        {index: 2, name: 'stand', icon: "\uF106", percentage: ran * 60 + 30}
15
      ];
16
17
    };
18
19
    var ranDataset2 = function () {
20
      var ran = Math.random();
21
22
      return    [
23
        {index: 0, name: 'move', icon: "\uF105", percentage: ran * 60 + 30}
24
      ];
25
26
    };
27
    var colors = ["#e90b3a", "#a0ff03", "#1ad5de"];
28
    var width = 500,
29
        height = 500,
30
        τ = 2 * Math.PI;
31
32
    function build(dataset,singleArcView){
33
34
      var arc = d3.svg.arc()
35
          .startAngle(0)
36
          .endAngle(function (d) {
37
            return d.percentage / 100 * τ;
38
          })
39
          .innerRadius(function (d) {
40
            return 140 - d.index * (40 + gap)
41
          })
42
          .outerRadius(function (d) {
43
            return 180 - d.index * (40 + gap)
44
          })
45
          .cornerRadius(20);//modified d3 api only
46
47
      var background = d3.svg.arc()
48
          .startAngle(0)
49
          .endAngle(τ)
50
          .innerRadius(function (d, i) {
51
            return 140 - d.index * (40 + gap)
52
          })
53
          .outerRadius(function (d, i) {
54
            return 180 - d.index * (40 + gap)
55
          });
56
57
      var svg = d3.select("body").append("svg")
58
          .attr("width", width)
59
          .attr("height", height)
60
          .append("g")
61
          .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
62
63
      //add linear gradient, notice apple uses gradient alone the arc..
64
      //meh, close enough...
65
66
67
      var gradient = svg.append("svg:defs")
68
          .append("svg:linearGradient")
69
          .attr("id", "gradient")
70
          .attr("x1", "0%")
71
          .attr("y1", "100%")
72
          .attr("x2", "50%")
73
          .attr("y2", "0%")
74
          .attr("spreadMethod", "pad");
75
76
      gradient.append("svg:stop")
77
          .attr("offset", "0%")
78
          .attr("stop-color", "#fe08b5")
79
          .attr("stop-opacity", 1);
80
81
      gradient.append("svg:stop")
82
          .attr("offset", "100%")
83
          .attr("stop-color", "#ff1410")
84
          .attr("stop-opacity", 1);
85
86
87
      //add some shadows
88
      var defs = svg.append("defs");
89
90
      var filter = defs.append("filter")
91
          .attr("id", "dropshadow")
92
93
      filter.append("feGaussianBlur")
94
          .attr("in", "SourceAlpha")
95
          .attr("stdDeviation", 4)
96
          .attr("result", "blur");
97
      filter.append("feOffset")
98
          .attr("in", "blur")
99
          .attr("dx", 1)
100
          .attr("dy", 1)
101
          .attr("result", "offsetBlur");
102
103
      var feMerge = filter.append("feMerge");
104
105
      feMerge.append("feMergeNode")
106
          .attr("in", "offsetBlur");
107
      feMerge.append("feMergeNode")
108
          .attr("in", "SourceGraphic");
109
110
      var field = svg.selectAll("g")
111
          .data(dataset)
112
          .enter().append("g");
113
114
      field.append("path").attr("class", "progress").attr("filter", "url(#dropshadow)");
115
116
      field.append("path").attr("class", "bg")
117
          .style("fill", function (d) {
118
            return colors[d.index];
119
          })
120
          .style("opacity", 0.2)
121
          .attr("d", background);
122
123
      field.append("text").attr('class','icon');
124
125
126
      if(singleArcView){
127
128
        field.append("text").attr('class','goal').text("OF 600 CALS").attr("transform","translate(0,50)");
129
        field.append("text").attr('class','completed').attr("transform","translate(0,0)");
130
131
      }
132
133
      d3.transition().duration(1750).each(update);
134
135
      function update() {
136
        field = field
137
            .each(function (d) {
138
              this._value = d.percentage;
139
            })
140
            .data(dataset)
141
            .each(function (d) {
142
              d.previousValue = this._value;
143
            });
144
145
        field.select("path.progress").transition().duration(1750).delay(function (d, i) {
146
          return i * 200
147
        })
148
            .ease("elastic")
149
            .attrTween("d", arcTween)
150
            .style("fill", function (d) {
151
              if(d.index===0){
152
                return "url(#gradient)"
153
              }
154
              return colors[d.index];
155
            });
156
157
        field.select("text.icon").text(function (d) {
158
          return d.icon;
159
        }).attr("transform", function (d) {
160
              return "translate(10," + -(150 - d.index * (40 + gap)) + ")"
161
162
            });
163
164
        field.select("text.completed").text(function (d) {
165
          return Math.round(d.percentage /100 * 600);
166
        });
167
168
        setTimeout(update, 2000);
169
170
      }
171
172
      function arcTween(d) {
173
        var i = d3.interpolateNumber(d.previousValue, d.percentage);
174
        return function (t) {
175
          d.percentage = i(t);
176
          return arc(d);
177
        };
178
      }
179
180
181
    }
182
183
184
    build(ranDataset);
185
    build(ranDataset2,true);
186
187
188
  })()
189
190
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................