-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions now invokes State. Also State.highlightPath()
- eg. Navigation.updatePath -> State.navigateTo() - State.highlightPath() allows different components to react to highlights (mouseenter, mouseleave)
- Loading branch information
Showing
9 changed files
with
197 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function elm(tag, attrs, children, props) { | ||
const el = document.createElement(tag) | ||
for (const k in attrs) { | ||
el.setAttribute(k, attrs[k]) | ||
} | ||
|
||
if (children) { | ||
children = Array.isArray(children) ? children : [children] | ||
for (let child of children) { | ||
if (typeof child === 'string') { | ||
child = document.createTextNode(child) | ||
} | ||
el.appendChild(child) | ||
} | ||
} | ||
|
||
if (props) { | ||
for (const k in props) { | ||
el[k] = props[k] | ||
} | ||
} | ||
return el | ||
} | ||
|
||
class ListView extends Chart { | ||
navigateTo(path, current) { | ||
const navs = [ | ||
elm('h5', { class: 'nav-group-title' }, `${path.join('/')} ${format(current.value)}`, { | ||
onclick: () => State.navigateTo(path.slice(0, -1)) | ||
}) | ||
] | ||
|
||
let str = '----------\n' | ||
const nodes = current._children || current.children || [] | ||
|
||
const INITIAL_LOAD = 10 | ||
|
||
nodes | ||
.sort((a, b) => { | ||
if (a.value < b.value) return 1 | ||
if (a.value > b.value) return -1 | ||
return 0 | ||
}) | ||
.slice(0, INITIAL_LOAD) | ||
.forEach(child => { | ||
str += child.name + '\t' + format(child.value) + '\n' | ||
|
||
navs.push( | ||
elm( | ||
'span', | ||
{ | ||
class: 'nav-group-item', | ||
href: '#' | ||
}, | ||
[ | ||
elm('span', { class: 'icon icon-record', style: `color: ${fill(child)};` }), | ||
child.name, | ||
elm('span', { class: '', style: 'float:right;' }, format(child.value)) | ||
], | ||
{ | ||
onclick: () => child.children && State.navigateTo([...path, child.name]), | ||
onmouseenter: () => State.highlightPath([...path, child.name]), | ||
onmouseleave: () => State.highlightPath() | ||
} | ||
) | ||
) | ||
}) | ||
|
||
const remaining = nodes.length - INITIAL_LOAD | ||
if (remaining > 0) { | ||
navs.push( | ||
elm('span', { class: 'nav-group-item', href: '#' }, [ | ||
elm('span', { class: 'icon icon-record' }), | ||
`and ${remaining} other items....` | ||
]) | ||
) | ||
} | ||
|
||
log(str) | ||
;[...sidebar.childNodes].forEach(v => v.remove()) | ||
const nav = elm('nav', { class: 'nav-group' }, navs) | ||
sidebar.appendChild(nav) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.