Skip to content

Commit

Permalink
Ability to hide winrate graph
Browse files Browse the repository at this point in the history
Close #608
  • Loading branch information
yishn committed Mar 1, 2020
1 parent fc697dc commit 4b2ebbd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class App extends Component {
showMoveColorization: state.showMoveColorization,
showNextMoves: state.showNextMoves,
showSiblings: state.showSiblings,
showWinrateGraph: state.showWinrateGraph,
showGameGraph: state.showGameGraph,
showCommentBox: state.showCommentBox,
showLeftSidebar: state.showLeftSidebar,
Expand Down
17 changes: 11 additions & 6 deletions src/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export default class Sidebar extends Component {
)
}

componentDidUpdate(_, {winrateData}) {
componentDidUpdate(_, {winrateGraphHeight, showWinrateGraph}) {
if (
winrateData.some(x => x != null) !==
this.state.winrateData.some(x => x != null)
winrateGraphHeight !== this.state.winrateGraphHeight ||
showWinrateGraph !== this.state.showWinrateGraph
) {
this.gameGraph.remeasure()
}
Expand All @@ -103,6 +103,7 @@ export default class Sidebar extends Component {
gameTree,
gameCurrents,
treePosition,
showWinrateGraph,
showGameGraph,
showCommentBox,

Expand All @@ -117,7 +118,7 @@ export default class Sidebar extends Component {
1
)
let level = gameTree.getLevel(treePosition)
let showWinrateGraph = winrateData.some(x => x != null)
showWinrateGraph = showWinrateGraph && winrateData.some(x => x != null)

return h(
'section',
Expand Down Expand Up @@ -227,12 +228,16 @@ export default class Sidebar extends Component {
Sidebar.getDerivedStateFromProps = function({
gameTree,
gameCurrents,
gameIndex
gameIndex,
showWinrateGraph
}) {
// Get winrate data

let currentTrack = [...gameTree.listCurrentNodes(gameCurrents[gameIndex])]
let winrateData = currentTrack.map(x => x.data.SBKV && x.data.SBKV[0])

return {winrateData}
return {
winrateData,
showWinrateGraph: showWinrateGraph && winrateData.some(x => x != null)
}
}
1 change: 0 additions & 1 deletion src/components/sidebars/WinrateGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export default class WinrateGraph extends Component {

return h(
'section',

{
ref: el => (this.element = el),
id: 'winrategraph',
Expand Down
12 changes: 12 additions & 0 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports.get = function(props = {}) {
showMoveColorization,
showNextMoves,
showSiblings,
showWinrateGraph,
showGameGraph,
showCommentBox,
showLeftSidebar,
Expand Down Expand Up @@ -581,6 +582,17 @@ exports.get = function(props = {}) {
click: () => toggleSetting('view.show_siblings')
},
{type: 'separator'},
{
label: i18n.t('menu.view', 'Show &Winrate Graph'),
type: 'checkbox',
checked: !!showWinrateGraph,
click: () => {
toggleSetting('view.show_winrategraph')
sabaki.setState(({showWinrateGraph}) => ({
showWinrateGraph: !showWinrateGraph
}))
}
},
{
label: i18n.t('menu.view', 'Show Game &Tree'),
type: 'checkbox',
Expand Down
1 change: 1 addition & 0 deletions src/modules/sabaki.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Sabaki extends EventEmitter {
consoleLog: [],
showLeftSidebar: setting.get('view.show_leftsidebar'),
leftSidebarWidth: setting.get('view.leftsidebar_width'),
showWinrateGraph: setting.get('view.show_winrategraph'),
showGameGraph: setting.get('view.show_graph'),
showCommentBox: setting.get('view.show_comments'),
sidebarWidth: setting.get('view.sidebar_width'),
Expand Down
1 change: 1 addition & 0 deletions src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ let defaults = {
'view.show_move_numbers': false,
'view.show_next_moves': true,
'view.show_siblings': true,
'view.show_winrategraph': true,
'view.sidebar_width': 200,
'view.sidebar_minwidth': 100,
'view.winrategraph_height': 60,
Expand Down

0 comments on commit 4b2ebbd

Please sign in to comment.