analytics/assets/js/dashboard/stats/bar.js
RobertJoonas 0541098330
Make the ListReport component more flexible (#3078)
* refactor ListReport

Pass a 'getFilterFor' function instead of a 'filter' object to ListReport

* Keep the statsBoxClass in one place only

* add classname prop to MoreLink

* define metric structs as ListReport inputs

* Fix a bug

If the query changes, we also want to reset the eventListener function.
Otherwise we keep calling an outdated function that fetches old data.

* fix CI
2023-07-06 17:29:08 +03:00

31 lines
684 B
JavaScript

import React from 'react';
function barWidth(count, all, plot) {
let maxVal = all[0][plot];
for (const val of all) {
if (val > maxVal) maxVal = val[plot]
}
return count / maxVal * 100
}
export default function Bar({count, all, bg, maxWidthDeduction, children, plot = "visitors"}) {
const width = barWidth(count, all, plot)
const style = maxWidthDeduction ? {maxWidth: `calc(100% - ${maxWidthDeduction})`} : {}
return (
<div
className="w-full h-full relative"
style={style}
>
<div
className={`absolute top-0 left-0 h-full ${bg || ''}`}
style={{width: `${width}%`}}
>
</div>
{children}
</div>
)
}