|
1 | 1 | class Iso |
| 2 | + COLORS = [ |
| 3 | + new obelisk.CubeColor().getByHorizontalColor(0xeeeeee), |
| 4 | + new obelisk.CubeColor().getByHorizontalColor(0xd6e685), |
| 5 | + new obelisk.CubeColor().getByHorizontalColor(0x8cc665), |
| 6 | + new obelisk.CubeColor().getByHorizontalColor(0x44a340), |
| 7 | + new obelisk.CubeColor().getByHorizontalColor(0x1e6823) |
| 8 | + ] |
| 9 | + |
2 | 10 | constructor: (target) -> |
3 | 11 | if target |
4 | 12 | observer = new MutationObserver (mutations) => |
@@ -29,10 +37,10 @@ class Iso |
29 | 37 | days = $('.js-calendar-graph-svg rect') |
30 | 38 | bestDay = null |
31 | 39 | maxCount = null |
32 | | - (d3.selectAll days).attr 'data-contrib-count', (d, i) -> |
33 | | - if d[1] > maxCount |
34 | | - [bestDay, maxCount] = d |
35 | | - d[1] |
| 40 | + (d3.selectAll days).each -> |
| 41 | + if $(this).data('count') > maxCount |
| 42 | + bestDay = ($ this).data('date') |
| 43 | + maxCount = ($ this).data('count') |
36 | 44 | observer.disconnect() |
37 | 45 | target.setAttribute 'data-max-contributions', maxCount |
38 | 46 | target.setAttribute 'data-best-day', bestDay |
@@ -71,15 +79,15 @@ class Iso |
71 | 79 | (($ this).find 'rect').each (r) -> |
72 | 80 | r = ($ this).get 0 |
73 | 81 | y = parseInt (($ this).attr 'y') / GH_OFFSET |
74 | | - style = ($ this).attr 'style' |
75 | | - contribCount = parseInt ($ this).data 'contrib-count' |
| 82 | + fill = ($ this).attr 'fill' |
| 83 | + contribCount = parseInt ($ this).data 'count' |
76 | 84 | cubeHeight = 3 |
77 | 85 |
|
78 | 86 | if maxContributions > 0 |
79 | 87 | cubeHeight += parseInt MAX_HEIGHT / maxContributions * contribCount |
80 | 88 |
|
81 | 89 | dimension = new obelisk.CubeDimension SIZE, SIZE, cubeHeight |
82 | | - color = self.getSquareColor style |
| 90 | + color = self.getSquareColor fill |
83 | 91 | cube = new obelisk.Cube dimension, color, false |
84 | 92 | p3d = new obelisk.Point3D SIZE * x, SIZE * y, 0 |
85 | 93 | pixelView.renderObject cube, p3d |
@@ -154,10 +162,12 @@ class Iso |
154 | 162 |
|
155 | 163 | # Best day |
156 | 164 | countBest = ($ '.js-calendar-graph').data 'max-contributions' |
157 | | - dateParts = (($ '.js-calendar-graph').data 'best-day').split ' ' |
| 165 | + dateParts = (($ '.js-calendar-graph').data 'best-day').split '-' |
158 | 166 | dateBest = 'Not so busy after all.' |
159 | | - if dateParts[1]? |
160 | | - dateBest = "#{dateParts[1]} #{dateParts[2]} #{dateParts[3]}" |
| 167 | + if dateParts[0]? |
| 168 | + options = {month: "long", day: "numeric"} |
| 169 | + date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2], 0, 0, 0) |
| 170 | + dateBest = date.toLocaleDateString('en-US', options) |
161 | 171 |
|
162 | 172 | html = """ |
163 | 173 | <div class="ic-stats-block ic-stats-top"> |
@@ -226,19 +236,13 @@ class Iso |
226 | 236 | """ |
227 | 237 | ($ html).appendTo $ '.ic-contributions-wrapper' |
228 | 238 |
|
229 | | - getSquareColor: (style) -> |
230 | | - color0 = new obelisk.CubeColor().getByHorizontalColor 0xeeeeee |
231 | | - color1 = new obelisk.CubeColor().getByHorizontalColor 0xd6e685 |
232 | | - color2 = new obelisk.CubeColor().getByHorizontalColor 0x8cc665 |
233 | | - color3 = new obelisk.CubeColor().getByHorizontalColor 0x44a340 |
234 | | - color4 = new obelisk.CubeColor().getByHorizontalColor 0x1e6823 |
235 | | - |
236 | | - color = switch style |
237 | | - when 'fill: rgb(238, 238, 238);', 'fill: #eeeeee;' then color0 |
238 | | - when 'fill: rgb(214, 230, 133);', 'fill: #d6e685;' then color1 |
239 | | - when 'fill: rgb(140, 198, 101);', 'fill: #8cc665;' then color2 |
240 | | - when 'fill: rgb(68, 163, 64);', 'fill: #44a340;' then color3 |
241 | | - when 'fill: rgb(30, 104, 35);', 'fill: #1e6823;' then color4 |
| 239 | + getSquareColor: (fill) -> |
| 240 | + color = switch fill |
| 241 | + when 'rgb(238, 238, 238)', '#eeeeee' then COLORS[0] |
| 242 | + when 'rgb(214, 230, 133)', '#d6e685' then COLORS[1] |
| 243 | + when 'rgb(140, 198, 101)', '#8cc665' then COLORS[2] |
| 244 | + when 'rgb(68, 163, 64)', '#44a340' then COLORS[3] |
| 245 | + when 'rgb(30, 104, 35)', '#1e6823' then COLORS[4] |
242 | 246 |
|
243 | 247 | # Inject code |
244 | 248 | Iso.inject() |
|
0 commit comments