git ssb

2+

mixmix / ticktack



Commit 906d2b16d835447b38891af55f5b7b58dcbed9c9

working filtering BY BLOG for stats graphs

mix irving committed on 4/26/2018, 12:37:46 AM
Parent: 0c87e21e892bcd81a17492864bae0c5e13a767fb

Files changed

app/page/statsShow.jschanged
app/page/statsShow.mcsschanged
styles/mixins.jschanged
app/page/statsShow.jsView
@@ -4,8 +4,9 @@
44 const marksum = require('markdown-summary')
55 const Chart = require('chart.js')
66 const groupBy = require('lodash/groupBy')
77 const flatMap = require('lodash/flatMap')
8+const get = require('lodash/get')
89
910 exports.gives = nest('app.page.statsShow')
1011
1112 exports.needs = nest({
@@ -18,8 +19,13 @@
1819 const LIKES = 'likes'
1920 const SHARES = 'shares'
2021 const DAY = 24 * 60 * 60 * 1000
2122
23+const getRoot = {
24+ [COMMENTS]: (msg) => get(msg, 'value.content.root'),
25+ [LIKES]: (msg) => get(msg, 'value.content.vote.link')
26+}
27+
2228 exports.create = (api) => {
2329 return nest('app.page.statsShow', statsShow)
2430
2531 function statsShow (location) {
@@ -56,11 +62,14 @@
5662 })
5763 })
5864
5965 function totalOnscreenData (focus) {
60- return computed([foci[focus], context.range], (msgs, range) => {
66+ return computed([foci[focus], context], (msgs, context) => {
67+ const { range, blog } = context
6168 return msgs
6269 .filter(msg => {
70+ if (blog && getRoot[focus](msg) !== blog) return false
71+
6372 const ts = msg.value.timestamp
6473 return ts > range.lower && ts <= range.upper
6574 })
6675 .length
@@ -112,21 +121,28 @@
112121 ])
113122 ])
114123
115124 function BlogRow (blog) {
116- return h('tr.blog', { id: blog.key }, [
125+ const className = computed(context.blog, b => {
126+ if (!b) return ''
127+ if (b !== blog.key) return '-background'
128+ })
129+
130+ return h('tr.blog', { id: blog.key, className }, [
117131 h('td.details', [
118- h('div.title', {}, getTitle({ blog, mdRenderer: api.message.html.markdown })),
119- h('a',
120- {
121- href: '#',
122- 'ev-click': ev => {
123- ev.stopPropagation() // stop the click catcher!
124- api.history.sync.push(blog)
125- }
126- },
127- 'View blog'
128- )
132+ h('div.title', {
133+ 'ev-click': () => {
134+ if (context.blog() === blog.key) context.blog.set('')
135+ else context.blog.set(blog.key)
136+ }
137+ }, getTitle({ blog, mdRenderer: api.message.html.markdown })),
138+ h('a', {
139+ href: '#',
140+ 'ev-click': ev => {
141+ ev.stopPropagation() // stop the click catcher!
142+ api.history.sync.push(blog)
143+ }
144+ }, 'View blog')
129145 ]),
130146 h('td.comments', computed(store.comments.get(blog.key), msgs => msgs ? msgs.length : 0)),
131147 h('td.likes', computed(store.likes.get(blog.key), msgs => msgs ? msgs.length : 0)),
132148 h('td.shares', computed(store.shares.get(blog.key), msgs => msgs ? msgs.length : 0))
@@ -189,11 +205,17 @@
189205
190206 function initialiseChart ({ canvas, context, foci }) {
191207 var chart = new Chart(canvas.getContext('2d'), chartConfig({ context }))
192208
193- const chartData = computed([context.focus, foci], (focus, foci) => {
194- zeroGraphOnFocusChange(focus)
195- const msgs = foci[focus]
209+ const chartData = computed([context, foci], (context, foci) => {
210+ fixAnimationWhenNeeded(context)
211+
212+ const msgs = foci[context.focus]
213+ .filter(msg => {
214+ if (!context.blog) return true
215+
216+ return context.blog === getRoot[context.focus](msg)
217+ })
196218 const grouped = groupBy(msgs, m => toDay(m.value.timestamp))
197219
198220 return Object.keys(grouped)
199221 .map(day => {
@@ -240,15 +262,17 @@
240262
241263 // ///// HELPERS /////
242264
243265 // HACK - if the focus has changed, then zero the data
244- // this prevents the graph from showing some confusing animations when transforming between foci
245- var lastFocus = context.focus()
246- function zeroGraphOnFocusChange (focus) {
247- if (focus !== lastFocus) {
266+ // this prevents the graph from showing some confusing animations when transforming between foci / selecting blog
267+ var prevFocus = context.focus()
268+ var prevBlog = context.blog()
269+ function fixAnimationWhenNeeded (context) {
270+ if (context.focus !== prevFocus || context.blog !== prevBlog) {
248271 chart.data.datasets[0].data = []
249272 chart.update()
250- lastFocus = focus
273+ prevFocus = context.focus
274+ prevBlog = context.blog
251275 }
252276 }
253277 function toDay (ts) { return Math.floor(ts / DAY) }
254278 }
app/page/statsShow.mcssView
@@ -89,8 +89,9 @@
8989 width: 70%
9090 padding: 0 2rem 0 0
9191 }
9292 th.comments, th.likes, th.shares {
93+ $colorFontSubtle
9394 width: 10%
9495 }
9596 }
9697 }
@@ -104,14 +105,15 @@
104105
105106 div.title {
106107 font-size: 1.3rem
107108 font-weight: 600
108- margin-bottom: .5rem
109+ cursor: pointer
109110 }
110111
111112 a {
112- color: hsl(0, 0%, 15%)
113- font-size: .8rem
113+ $colorFontSubtle
114+ letter-spacing: .8px
115+ font-size: .7rem
114116 text-decoration: none
115117
116118 :hover {
117119 text-decoration: underline
@@ -124,8 +126,12 @@
124126 font-size: 1.3rem
125127 font-weight: 600
126128 text-align: center
127129 }
130+
131+ -background {
132+ filter: opacity(40%)
133+ }
128134 }
129135 }
130136 }
131137 }
styles/mixins.jsView
@@ -63,9 +63,9 @@
6363 color: #2f63ad
6464 }
6565
6666 $colorFontSubtle {
67- color: #999
67+ color: hsla(0, 0%, 52%, 1)
6868 }
6969
7070 $backgroundPrimary {
7171 background-color: #f5f6f7

Built with git-ssb-web