Skip to content

Commit ea30d7a

Browse files
committed
New layout and improved cal graph
1 parent 44b9b0f commit ea30d7a

File tree

10 files changed

+2478
-4209
lines changed

10 files changed

+2478
-4209
lines changed

TODO.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
## Items
1313

14+
* [ ] ❗️ Don't use grey for ordinal colors (because charts use it to show deselected rows)
15+
* [ ] ⚠️ Row chart selected rows not changing opacity.
1416
* [ ] ⚠️ Firefox not loading
15-
* [ ] ~~❗️ Move all calculations into inner dictionary~~
17+
* [x] ~~❗️ Move all calculations into inner dictionary~~
1618
* [x] ~~⚠️ Seconds saved as seconds / 1000~~
1719
* [x] ~~⚠️ License text not scrolling~~
1820
* [ ] ⚠️ No tool tip on anatomy diagrams with no data
@@ -25,17 +27,18 @@
2527
* [ ] ❗️ Exit demo option when clicking "DEMO" indicator
2628
* Reload the page w/o `?demo` param
2729
* [ ] ❕ Query string chart state
30+
* Query string fucks up app cache, use fragment identifier instead
2831
* [ ] ❕ Add more bodyweight and only ring exercises to exercise lookup
29-
* [ ] ‼️ Debug mode indicator
30-
* [ ] Url param `debug` to enable
32+
* [x] ~~‼️ Debug mode indicator~~
33+
* [x] ~~Url param `debug` to enable~~
3134
* [ ] Make debug actions visible only on debug mode
3235
* [ ] ❔ User-defined exercises
3336
* This brings up a lot of issues with consistency when sharing data
3437
* [ ] ❕ Ability to delete entries
3538
* [ ] ❕ Ability to insert past entries
3639
* [ ] Raw data browser
3740
* [ ] ❕ Credits modal in about screen
38-
* [ ] Credit libs, contributors & artists
41+
* [x] ~~Credit libs, contributors & artists~~
3942
* [ ] ❕ Muscle browser
4043
* [ ] ❕ Anatomy diagram
4144
* [ ] ❕ Display muscle groups and components
@@ -57,8 +60,8 @@
5760
* [ ] ⚠️ Fix rounded corners on card header items
5861
* [ ] ⚠️ Fix white square corners on last rows in card
5962
* [ ] ❗️ Cleaner shapes that align with paths in anatomy svgs
60-
* [ ] ❗️ Revert to thin lines for paths
61-
* [ ] ❗️ Empty charts have very thick axis lines
63+
* [x] ~~❗️ Revert to thin lines for paths~~
64+
* [x] ~~❗️ Empty charts have very thick axis lines~~
6265
* On some browsers? On mobile? On certain sizes?
6366
* [ ] ❗️ Better start/stop icons on stopwatch (use noun project).
6467
* [ ] 💡❔ Bigger brush handles on mobile?
@@ -69,7 +72,7 @@
6972
* [ ] Store data as kg? convert to desired (default local) unit
7073
* [ ] New Set Modal
7174
* [ ] ❔ Notes field
72-
* [ ] ❗️ Better name: "Add Set"
75+
* [x] ~~❗️ Better name: "Add Set"~~
7376
* [ ] ❗️ Show e1rm, 1rm, max weight prs
7477
* [ ] ❗️ Reps, sets, weight graph
7578
* [ ] ❗️ PR alert box on pr
@@ -92,10 +95,10 @@
9295
* [ ] ❕ Total volume per workout (all exercises)
9396
* [ ] ‼️ Demo Mode
9497
* [ ] ❗️ Static "today" date from url param
95-
* [ ] ❗️ "DEMO" banner
98+
* [x] ~~❗️ "DEMO" banner~~
9699
* [ ] ❔ Reset everything
97100
* [ ] ❗️ Exit demo mode button
98-
* [ ] ‼️ Don't touch DB when in demo mode
101+
* [x] ~~‼️ Don't touch DB when in demo mode~~
99102
* [ ] ❕ Stats
100103
* Modal? Another item on dashboard?
101104
* [ ] ❕ Total workouts count
@@ -106,14 +109,14 @@
106109
* [ ] ❕ Exponential data axis (clearer differences)
107110
* [ ] ❕ Number of days since last workout/last rest day
108111
* ❕ Use red alert if it's been a while
109-
* [ ] ❗️ Workout list (third column)
112+
* [x] ~~❗️ Workout list (third column)~~
110113
* [ ] ❔ Expand to show entries
111114
* ❔ Hide on mobile
112115
* [x] ~~❗️ Move muscle filter to drop-down on anatomy box~~
113116
* [ ] ❗️ Make muscle filter actually work
114117
* [x] ~~❗️ Change metric selection to row of buttons~~
115-
* [ ] ❗️ Allow selecting multiple metrics (use max of each)
116-
* [ ] ‼️ Clamp column size to md or lg on xl (to make room for 3rd col)
118+
* [x] ~~❗️ Allow selecting multiple metrics (use max of each)~~
119+
* [x] ~~‼️ Clamp column size to md or lg on xl (to make room for 3rd col)~~
117120
* [ ] ❗️ "Expand/Collapse" button on muscle & exercise bar charts to show more than just 10 items
118121
* [ ] ❗️ Active vs Rest time pie chart
119122
* [ ] ❗️ Push vs pull pie chart

index.html

Lines changed: 229 additions & 191 deletions
Large diffs are not rendered by default.

lib/bootstrap-flex.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/bootstrap.min.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/bootstrap.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mb.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CACHE MANIFEST
22
# Muscle Book
3-
# Last Updated: Sun Oct 23 2016 16:33:39 GMT-0700 (PDT)
3+
# Last Updated: Wed Oct 26 2016 21:30:39 GMT-0700 (PDT)
44
index.html
55
Icon512.png
66
fonts/ionicons.eot
@@ -15,7 +15,7 @@ mb/mb.css
1515
mb/mb.js
1616
mb/muscles.js
1717
mb/posterior.svg
18-
lib/bootstrap.min.css
18+
lib/bootstrap-flex.min.css
1919
lib/bootstrap.min.js
2020
lib/colorbrewer.js
2121
lib/crossfilter.js

mb/calendar.js

Lines changed: 93 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ dc.calendarGraph = function(parent, chartGroup) {
22
// http://bl.ocks.org/peterbsmith2/a37f2b733a75a6f348c2
33

44
var _chart = dc.marginMixin(dc.colorMixin(dc.baseMixin({})));
5-
var _squareSize = 13;
6-
var _daysBack = 365;
5+
var _squareSize = undefined;
6+
var _gap = 2;
7+
var _daysBack = undefined;
78
let _tipSelector = ".tip";
89

910
// http://stackoverflow.com/questions/11382606
@@ -60,54 +61,63 @@ dc.calendarGraph = function(parent, chartGroup) {
6061
return _chart;
6162
};
6263

63-
_chart.width = function(width) {
64-
if (!arguments.length) {
65-
return undefined;
66-
}
67-
return _chart;
68-
};
64+
_chart.gap = function(_) {
65+
if (!arguments.length) return _gap;
66+
_gap = _;
67+
return _chart;
68+
};
6969

70-
_chart.height = function(height) {
71-
if (!arguments.length) {
72-
return undefined;
73-
}
74-
return _chart;
75-
};
70+
_chart.squareSize = function(_) {
71+
if (!arguments.length) return _squareSize;
72+
_squareSize = _;
73+
return _chart;
74+
};
75+
76+
// _chart.width = function(width) {
77+
// if (!arguments.length) {
78+
// return undefined;
79+
// }
80+
// return _chart;
81+
// };
82+
83+
// _chart.height = function(height) {
84+
// if (!arguments.length) {
85+
// return undefined;
86+
// }
87+
// return _chart;
88+
// };
7689

7790
_chart._doRedraw = function () {
7891
return _chart._doRender();
7992
};
8093

8194
_chart._doRender = function () {
82-
var numCols = Math.ceil(_daysBack / 7);
83-
var calendar = [];
95+
// var numCols = Math.ceil(daysBack / 7);
96+
const today = new Date();
97+
const squareSize = calculateSquareSize(today);
98+
const daysBack = calculateDaysBack(today, squareSize);
99+
const calendar = [];
84100
var yAxis = [];
85-
var today = new Date();
86-
var lastYear = addDays(today,-_daysBack);
101+
var lastYear = addDays(today, -daysBack);
87102
var col = 0;
88103
var month = lastYear.getMonth();
89104
var first = true;
90105
var yAxisFormatter = d3.time.format("%b");
91106

92-
var width = 11 + (numCols * _squareSize); // 1 square + 53 squares with 2px padding
93-
var height = 11 + 6 * _squareSize; //1 square + 6 squares with 2px padding
94-
var legendX = 20;
95-
var legendY = height + 10;
96-
var viewboxWidth = width + _chart.margins().left + _chart.margins().right;
97-
var viewboxHeight = height + _chart.margins().top + _chart.margins().bottom;
98-
var aspect = viewboxWidth / viewboxHeight;
107+
// var width = 11 + (numCols * squareSize); // 1 square + 53 squares with 2px padding
108+
// var height = 11 + 6 * squareSize; //1 square + 6 squares with 2px padding
109+
// var legendX = 20;
110+
// var legendY = height + 10;
111+
// var viewboxWidth = width + _chart.margins().left + _chart.margins().right;
112+
// var viewboxHeight = height + _chart.margins().top + _chart.margins().bottom;
113+
// var aspect = viewboxWidth / viewboxHeight;
99114

100115
_chart.resetSvg();
101-
102-
_chart.svg()
103-
.attr("viewBox", "0 0 " + viewboxWidth + " " + viewboxHeight)
104-
.attr("preserveAspectRatio", "xMidYMid meet")
105-
.attr("style", "margin: 0.5rem;");
106116

107117
let g = _chart.svg().append("g")
108118
.attr("transform", "translate(" + _chart.margins().left + "," + _chart.margins().top + ")" );
109119

110-
for (i=0; i <= _daysBack; i++) {
120+
for (i=0; i <= daysBack; i++) {
111121
dateString = lastYear.toJSONLocal();
112122
var date = makeUTCDate(dateString);
113123
var c = date.getDay();
@@ -136,31 +146,34 @@ dc.calendarGraph = function(parent, chartGroup) {
136146
.style("fill", "#767676")
137147
.attr("text-anchor", "middle")
138148
.attr("dx", "-15")
139-
.attr("dy", "22");
149+
.attr("dy", (squareSize * 2) - _gap)
150+
.classed("axis", true);
140151

141152
g.append("text")
142153
.text("W")
143154
.style("fill", "#767676")
144155
.attr("text-anchor", "middle")
145156
.attr("dx", "-15")
146-
.attr("dy", "48");
157+
.attr("dy", (squareSize * 4) - _gap)
158+
.classed("axis", true);
147159

148160
g.append("text")
149161
.text("F")
150162
.attr("text-anchor", "middle")
151163
.style("fill", "#767676")
152164
.attr("dx", "-15")
153-
.attr("dy", "74");
165+
.attr("dy", (squareSize * 6) - _gap)
166+
.classed("axis", true);
154167

155168
g.selectAll(".cal")
156169
.data(calendar)
157170
.enter()
158171
.append("rect")
159172
.attr("class", "cal")
160-
.attr("width", _squareSize - 2)
161-
.attr("height", _squareSize - 2)
162-
.attr("x", function(d, i) { return d.col * _squareSize; })
163-
.attr("y", function(d, i) { return d.date.getDay() * _squareSize; })
173+
.attr("width", squareSize - _gap)
174+
.attr("height", squareSize - _gap)
175+
.attr("x", function(d, i) { return d.col * squareSize; })
176+
.attr("y", function(d, i) { return d.date.getDay() * squareSize; })
164177
.attr("fill", "#eeeeee");
165178

166179
g.selectAll(".y")
@@ -169,33 +182,34 @@ dc.calendarGraph = function(parent, chartGroup) {
169182
.append("text")
170183
.text(d => d.month)
171184
.attr("dy", -10)
172-
.attr("dx", d => d.col * _squareSize)
173-
.attr("fill", "#767676");
185+
.attr("dx", d => d.col * squareSize)
186+
.attr("fill", "#767676")
187+
.classed("axis", true);
174188

175-
g.selectAll('.legend')
176-
.data(_chart.colors().range())
177-
.enter()
178-
.append('rect')
179-
.attr('class','legend')
180-
.attr('width', _squareSize - 2)
181-
.attr('height', _squareSize - 2)
182-
.attr('x', (d, i) => legendX + i * _squareSize + 5)
183-
.attr('y', legendY)
184-
.attr('fill', d => d);
185-
186-
g.append('text')
187-
.attr('class','legend')
188-
.attr('x', legendX - 35)
189-
.attr('y', legendY + 10)
190-
.text('Less')
191-
.attr('fill','#767676');
192-
193-
g.append('text')
194-
.attr('class','legend')
195-
.attr('x', legendX + _chart.colors().range().length * _squareSize + 10)
196-
.attr('y', legendY + 10)
197-
.text('More')
198-
.attr('fill','#767676');
189+
// g.selectAll('.legend')
190+
// .data(_chart.colors().range())
191+
// .enter()
192+
// .append('rect')
193+
// .attr('class','legend')
194+
// .attr('width', squareSize - _gap)
195+
// .attr('height', squareSize - _gap)
196+
// .attr('x', (d, i) => legendX + i * squareSize + 5)
197+
// .attr('y', legendY)
198+
// .attr('fill', d => d);
199+
200+
// g.append('text')
201+
// .attr('class','legend')
202+
// .attr('x', legendX - 35)
203+
// .attr('y', legendY + 10)
204+
// .text('Less')
205+
// .attr('fill','#767676');
206+
207+
// g.append('text')
208+
// .attr('class','legend')
209+
// .attr('x', legendX + _chart.colors().range().length * squareSize + 10)
210+
// .attr('y', legendY + 10)
211+
// .text('More')
212+
// .attr('fill','#767676');
199213

200214
var data = _chart.data();
201215
var events = {};
@@ -232,5 +246,20 @@ dc.calendarGraph = function(parent, chartGroup) {
232246
return _chart;
233247
};
234248

249+
function calculateSquareSize(today) {
250+
if (_squareSize == undefined) {
251+
return Math.floor(_chart.effectiveHeight() / 7);
252+
}
253+
return _squareSize
254+
}
255+
256+
function calculateDaysBack(today, squareSize) {
257+
if (_daysBack === undefined) {
258+
const cols = Math.floor(_chart.effectiveWidth() / (squareSize));
259+
return (cols * 7) - (7 - (today.getDay()));
260+
}
261+
return _daysBack;
262+
}
263+
235264
return _chart.anchor(parent, chartGroup);
236265
};

0 commit comments

Comments
 (0)