From 04a7085b34d3624aab7091448935239ff75d4ca0 Mon Sep 17 00:00:00 2001 From: ingawei Date: Tue, 4 Oct 2022 01:07:34 -0700 Subject: [PATCH] ehh --- web/components/answers/answers-panel.tsx | 82 ++++++++++++++--------- web/components/charts/contract/choice.tsx | 21 ++++-- web/tailwind.config.js | 1 + 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index 83200b2a..d15b7e94 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -25,6 +25,8 @@ import { UserLink } from 'web/components/user-link' import { Button } from 'web/components/button' import { useAdmin } from 'web/hooks/use-admin' import { needsAdminToResolve } from 'web/pages/[username]/[contractSlug]' +import { CATEGORY_COLORS } from '../charts/contract/choice' +import { getChartAnswers } from '../charts/contract/choice' export function AnswersPanel(props: { contract: FreeResponseContract | MultipleChoiceContract @@ -38,6 +40,7 @@ export function AnswersPanel(props: { const answers = (useAnswers(contract.id) ?? contract.answers).filter( (a) => a.number != 0 || contract.outcomeType === 'MULTIPLE_CHOICE' ) + const hasZeroBetAnswers = answers.some((answer) => totalBets[answer.id] < 1) const [winningAnswers, losingAnswers] = partition( @@ -104,6 +107,11 @@ export function AnswersPanel(props: { ? 'checkbox' : undefined + const colorSortedAnswer = getChartAnswers( + contract, + CATEGORY_COLORS.length + ).map((value, index) => value.text) + return ( {(resolveOption || resolution) && @@ -128,7 +136,12 @@ export function AnswersPanel(props: { )} > {answerItems.map((item) => ( - + ))} {hasZeroBetAnswers && !showAllAnswers && ( - - + */} ) } diff --git a/web/components/charts/contract/choice.tsx b/web/components/charts/contract/choice.tsx index 99e02fa8..35806b70 100644 --- a/web/components/charts/contract/choice.tsx +++ b/web/components/charts/contract/choice.tsx @@ -22,7 +22,7 @@ import { Row } from 'web/components/layout/row' import { Avatar } from 'web/components/avatar' // thanks to https://observablehq.com/@jonhelfman/optimal-orders-for-choosing-categorical-colors -const CATEGORY_COLORS = [ +export const CATEGORY_COLORS = [ '#00b8dd', '#eecafe', '#874c62', @@ -142,6 +142,16 @@ const Legend = (props: { className?: string; items: LegendItem[] }) => { ) } +export function getChartAnswers( + contract: FreeResponseContract | MultipleChoiceContract, + length: number +) { + return useMemo( + () => getTrackedAnswers(contract, CATEGORY_COLORS.length), + [contract] + ) +} + export const ChoiceContractChart = (props: { contract: FreeResponseContract | MultipleChoiceContract bets: Bet[] @@ -151,10 +161,11 @@ export const ChoiceContractChart = (props: { }) => { const { contract, bets, width, height, onMouseOver } = props const [start, end] = getDateRange(contract) - const answers = useMemo( - () => getTrackedAnswers(contract, CATEGORY_COLORS.length), - [contract] - ) + // const answers = useMemo( + // () => getTrackedAnswers(contract, CATEGORY_COLORS.length), + // [contract] + // ) + const answers = getChartAnswers(contract, CATEGORY_COLORS.length) const betPoints = useMemo(() => getBetPoints(answers, bets), [answers, bets]) const data = useMemo( () => [ diff --git a/web/tailwind.config.js b/web/tailwind.config.js index ef7220ec..0390038f 100644 --- a/web/tailwind.config.js +++ b/web/tailwind.config.js @@ -18,6 +18,7 @@ module.exports = { colors: { 'red-25': '#FDF7F6', 'greyscale-1': '#FBFBFF', + 'greyscale-1.5': '#F4F4FB', 'greyscale-2': '#E7E7F4', 'greyscale-3': '#D8D8EB', 'greyscale-4': '#B1B1C7',