Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC DataTable Bar align #2726

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@
style="width: {Math.min(
Math.abs((row[column.id] / total_width) * 100),
100
)}%; background-color: {column.negativeBarColor}; height: 100%; position: absolute; right: {(1 -
)}%; background-color: {column.negativeBarColor}; height: 100%; position: absolute;
{column.align === 'right' ? 'left' : 'right'}: {(1 -
Math.abs(column_min) / (Math.abs(column_min) + column_max)) *
100}%;"
></div>
Expand All @@ -225,11 +226,11 @@
style="width: {Math.min(
(row[column.id] / total_width) * 100,
100
)}%; background-color: {column.barColor}; height: 100%; position: absolute; left: {column_min <
0
)}%; background-color: {column.barColor}; height: 100%; position: absolute;
{column.align === 'right' ? 'right' : 'left'}: {column_min < 0
? (Math.abs(column_min) / (Math.abs(column_min) + column_max)) * 100 + '%'
: '0'};"
></div>
></div>
{/if}

<!-- Display label -->
Expand All @@ -244,15 +245,13 @@
width: {(Math.abs(column_max) /
((column_min < 0 ? Math.abs(column_min) : 0) + Math.abs(column_max))) *
100}%;
left: {column_min < 0 && column_max >= 0
{column.align === 'right' ? 'right' : 'left'}: {column_min < 0 && column_max >= 0
? (Math.abs(column_min) / (Math.abs(column_min) + column_max)) * 100 + '%'
: '0'};"
>
{formatValue(row[column.id], column_format, useCol.columnUnitSummary)}
</div>
</div>

<!-- <div style="background-color: red; max-width: '{row[column.id] / column_max * 100}%'">{row[column.id]}</div> -->
{:else if column.contentType === 'sparkline' && row[column.id] !== undefined}
{@const alignment = column.align ?? 'center'}
<div class="items-{alignment} justify-{alignment} flex">
Expand Down
22 changes: 21 additions & 1 deletion sites/docs/pages/components/data-table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ This example includes a `custom_format` column, which contains a different curre
### Deltas

```sql country_summary
select date '2020-04-30' as date, 87 as value_usd, 0.0234 as yoy, 'Austria' as country, 'B' as category, 100384 as country_id, 'AT' as country_code, 'https://flaglog.com/codes/standardized-rectangle-120px/AT.png' as flag, 'https://www.google.ca/search?q=austria' as country_url
select date '2020-04-30' as date, -10 as value_usd, 0.0234 as yoy, 'Austria' as country, 'B' as category, 100384 as country_id, 'AT' as country_code, 'https://flaglog.com/codes/standardized-rectangle-120px/AT.png' as flag, 'https://www.google.ca/search?q=austria' as country_url
union all
select date '2020-05-01' as date, 95 as value_usd, 0.0534 as yoy, 'Australia' as country, 'C' as category, 104942 as country_id, 'AU' as country_code, 'https://flaglog.com/codes/standardized-rectangle-120px/AU.png' as flag, 'https://www.google.ca/search?q=australia' as country_url
archiewood marked this conversation as resolved.
Show resolved Hide resolved
union all
Expand Down Expand Up @@ -275,6 +275,26 @@ order by total_sales desc
<Column id=value_usd title="Sales" contentType=bar barColor=#ffe08a backgroundColor=#ebebeb/>
</DataTable>

### Bar Chart Column - Right Aligned

```svelte
<DataTable data={country_summary}>
<Column id=country />
<Column id=category align=center/>
<Column id=value_usd title="Sales" contentType=bar align=right />
<Column id=value_usd title="Sales" contentType=bar barColor=#aecfaf align=right />
<Column id=value_usd title="Sales" contentType=bar barColor=#ffe08a backgroundColor=#ebebeb align=right/>
</DataTable>
```

<DataTable data={country_summary}>
<Column id=country />
<Column id=category align=center/>
<Column id=value_usd title="Sales" contentType=bar align=right/>
<Column id=value_usd title="Sales" contentType=bar barColor=#aecfaf align=right/>
<Column id=value_usd title="Sales" contentType=bar barColor=#ffe08a backgroundColor=#ebebeb align=right/>
</DataTable>


### Total Row

Expand Down
Loading