-
Notifications
You must be signed in to change notification settings - Fork 0
/
24_aggrid_with_sparklines.qmd
83 lines (64 loc) · 2.09 KB
/
24_aggrid_with_sparklines.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: "AG Grid with Sparklines"
format:
html:
theme: flatly
font: Georgia
self-contained: true
page-layout: custom
mode: visual
---
```{r include=F}
library(tidyverse)
df <- tibble(
field = rep(c("field1", "field1", "field2"), each = 5),
product = rep(c("product1", "product2", "product3"), each = 5),
date = rep(seq(as.Date("2022-01-01"), as.Date("2022-05-01"), by = "months"), times = 3) %>% as.character(),
value = c(20, 50, 70, 60, 55, 70, 60, 55, 50, 20, 20, 30, 50, 35, 5)
) %>%
rowwise() %>%
mutate(chart = list(value)) %>% ungroup() %>%
group_by(field, product) %>%
summarise(
chart = list(chart)
)
ojs_define(df = df)
```
```{ojs}
//| echo: false
AgGrid = require('https://cdn.jsdelivr.net/npm/ag-grid-enterprise@25.2.0/dist/ag-grid-enterprise.min.js')
import { jQuery as $ } from "@ddspog/useful-libs"
jquerysparklines = require("https://omnipotent.net/jquery.sparkline/2.1.2/jquery.sparkline.min.js")
setInterval(function(){
$('.inlinesparkline').sparkline("html", { type:'line', lineColor:'red', fillColor: '#F0F0F0', disableTooltips:false, width:100, height:25 });
$('.inlinesparkline').removeClass('inlinesparkline').addClass('myinlinesparkline');
}, 200);
makeSparklinesAg = (arr) => `<span class="inlinesparkline">${arr.join()}</span>`
html `<style> .jqstooltip {-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;} </style>`
html`<div id="myGrid" style="width: 50%;height:400px;" class="ag-theme-alpine"></div>`
gridOptions = {
const eGridDiv = document.getElementById('myGrid');
const columnDefs = [
{ field: 'field'}, // , rowGroup: true
{ field: 'product', maxWidth: 110 },
{
field: 'chart',
maxWidth: 110,
cellRenderer: params => makeSparklinesAg(params.value)
},
];
const gridOptions = {
columnDefs: columnDefs,
rowData: transpose(df),
rowSelection: 'single',
defaultColDef: {
flex: 1,
minWidth: 100,
resizable: true,
},
};
new AgGrid.Grid(eGridDiv, gridOptions);
gridOptions.api.sizeColumnsToFit();
return gridOptions;
}
```