ソースを参照

Add NYT Light theme.

parisminton 8 年 前
コミット
98be2ad05d
共有2 個のファイルを変更した43 個の追加0 個の削除を含む
  1. 34 0
      renderer/patterns.js
  2. 9 0
      settings/themes.json

+ 34 - 0
renderer/patterns.js ファイルの表示

@@ -5,6 +5,7 @@ module.exports = {
5 5
   pixel: filledPath(d3.curveStep),
6 6
   roundBars: bars(true),
7 7
   bars: bars(),
8
+  halfbars: halfbars(),
8 9
   bricks: bricks(),
9 10
   equalizer: bricks(true),
10 11
   line: strokedPath(),
@@ -71,6 +72,39 @@ function filledPath(interpolator) {
71 72
 
72 73
 }
73 74
 
75
+function halfbars () {
76
+  return function(context, data, options) {
77
+
78
+    context.fillStyle = options.waveColor;
79
+
80
+    var waveHeight = options.waveBottom - options.waveTop;
81
+
82
+    var baseline = options.waveTop + waveHeight / 2;
83
+
84
+    var barX = d3.scaleBand()
85
+      .paddingInner(0.5)
86
+      .paddingOuter(0.01)
87
+      .domain(d3.range(data.length))
88
+      .rangeRound([options.waveLeft, options.waveRight]);
89
+
90
+    var height = d3.scaleLinear()
91
+      .domain([0, 1])
92
+      .range([0, waveHeight / 2]);
93
+
94
+    var barWidth = barX.bandwidth();
95
+
96
+    data.forEach(function(val, i){
97
+
98
+      var h = height(val[0]) * 2,
99
+          x = barX(i),
100
+          y = waveHeight - h;
101
+
102
+      context.fillRect(x, y, barWidth, h);
103
+
104
+    });
105
+  }
106
+} // end halfbars function
107
+
74 108
 function bars(round) {
75 109
 
76 110
   return function(context, data, options) {

+ 9 - 0
settings/themes.json ファイルの表示

@@ -15,6 +15,15 @@
15 15
     "captionLeft": 200,
16 16
     "captionRight": 1080
17 17
   },
18
+  "NYT Light": {
19
+    "pattern": "halfbars",
20
+    "waveTop": 500,
21
+    "waveBottom": 720,
22
+    "waveColor": "#d9d9d9",
23
+    "foregroundColor": "#000",
24
+    "captionTop": 100,
25
+    "captionLeft": 0
26
+  },
18 27
   "Basic": {
19 28
     "backgroundColor": "#eee",
20 29
     "foregroundColor": "#de1e3d"