Skip to content

Commit

Permalink
Get kinks out of BarChartCompact story.
Browse files Browse the repository at this point in the history
  • Loading branch information
patcon committed Sep 23, 2024
1 parent c43ed40 commit a1326c0
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions stories/client-participation/BarChartCompact.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { getMath } from '../../.storybook/utils'
import { svgDecorator } from '../../.storybook/decorators'
import * as globals from '../../polis/client-participation/vis2/components/globals'

const mathResults = getMath()
const mathResult = getMath()
const getGroupIds = (mathResult) => (mathResult['group-clusters'].map(g => g.id))
const getGroupLabels = (mathResult) => (
getGroupIds(mathResult).map((gid) => globals.groupLabels[gid])
)

const groupIndexFromName = (groupName) => globals.groupLabels.indexOf(groupName)

Expand All @@ -13,31 +17,36 @@ export default {
component: BarChartCompact,
decorators: [svgDecorator],
argTypes: {
// TODO: make statement display logic.
statement: {
options: ['1: Foo bar', '2: Foo baz'],
control: { type: 'select' },
},
group: {
options: ['A', 'B', 'C', 'D'],
control: { type: 'inline-radio' },
// Makes [0, 1, 2, 3]
options: getGroupIds(mathResult),
control: {
type: 'inline-radio',
// Makes {0: 'A', 1: 'B', 2: 'C', 3: 'D'}
labels: Object.assign({}, getGroupLabels(mathResult)),
},
},
},
render: ({ statement, group, ...args }) => {
const groupIndex = groupIndexFromName(group)

Object.assign(args.groupVotes, mathResults['group-votes'][groupIndex])
Object.assign(args.groupVotes, mathResult['group-votes'][group])
// TODO: make statement logic.
return <BarChartCompact {...args} />
},
}

const initialGroup = 'A'
const initialGroup = 0
const initialStatement = 4
export const Default = {
args: {
group: initialGroup,
statement: initialStatement,
selectedComment: { tid: initialStatement },
groupVotes: mathResults['group-votes'][groupIndexFromName(initialGroup)],
translate: 'translate(0,0)',
groupVotes: Object.assign({}, mathResult['group-votes'][initialGroup]),
translate: 'translate(1,1)',
}
}

0 comments on commit a1326c0

Please sign in to comment.