-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdata.qmd
More file actions
279 lines (252 loc) · 10.5 KB
/
data.qmd
File metadata and controls
279 lines (252 loc) · 10.5 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
---
title: "Data"
---
{{< include _load-data.qmd >}}
Below we show metadata for the entire IRW, an example dataset, and illustrations of how to access the data programmatically. You can also explore the data [here](https://redivis.com/datasets/as2e-cv7jb41fd/tables).
## Metadata
<iframe width="800" height="500" allowfullscreen src="https://redivis.com/embed/tables/bdomingu.irw_meta:bdxt:current.metadata:h5gs#cells" style="border:0;"></iframe>
```{ojs}
// Load the dictionary and bib data
dictionary = data_index
function createDatasetMap(df) {
let dataArray = Array.from({ length: df[Object.keys(df)[0]].length }, (_, i) => {
return Object.fromEntries(Object.entries(df).map(([key, values]) => [key, values[i]]));
});
// Sort the array alphabetically by dataset
dataArray.sort((a, b) => a.dataset.localeCompare(b.dataset));
// Create the map from sorted array
let datasetMap = new Map();
for (let row of dataArray) {
datasetMap.set(row.dataset, row);
}
return datasetMap;
}
// Create dataset map from data_index instead of metadata
dataset_map = createDatasetMap(data_index);
// Dataset selector with default value
viewof dataset = Inputs.select(
dataset_map,
{
label: 'Dataset',
// Set default value to first entry in the map
value: Array.from(dataset_map.values())[0]
}
);
// Function to find dataset info from dictionary (fixed field name)
function findDatasetInfo(dictionary, datasetName) {
// Convert dictionary column data into array of objects
const dictionaryArray = Array.from({ length: dictionary[Object.keys(dictionary)[0]].length }, (_, i) => {
return Object.fromEntries(Object.entries(dictionary).map(([key, values]) => [key, values[i]]));
});
// Now we can use find on the array
const dictRow = dictionaryArray.find(row => row.dataset === datasetName);
return {
reference: dictRow?.reference || "Reference not available",
BibTex: dictRow?.BibTex || "BibTeX not available",
doi: dictRow?.doi
};
}
// Function to find dataset name from the Map
function findDatasetNameFromMap(map, selectedDataset) {
for (let [key, value] of map.entries()) {
if (value === selectedDataset) {
return key;
}
}
return null;
}
// Look up the name of the dataset
dataset_name = findDatasetNameFromMap(dataset_map, dataset);
dataset_info = findDatasetInfo(dictionary, dataset_name);
// Create the display elements with reference and BibTeX
display = {
const sanitizedDatasetName = dataset_name.replace(/\./g, "_"); // Replace all dots with underscores
const url = `https://redivis.com/embed/tables/datapages.item_response_warehouse:as2e:current.${sanitizedDatasetName}`;
const container = html`<div>
<div style="margin-bottom: 20px;">
<button onclick="toggleInfo(this)" style="
padding: 8px 16px;
background-color: #4287f5;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 500;
display: flex;
align-items: center;
gap: 5px;
transition: background-color 0.2s;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
">
<span>Show Citation Info</span>
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" style="transform: rotate(0deg); transition: transform 0.3s;">
<path d="M2 4L6 8L10 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<div style="
display: none;
margin-top: 10px;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
border: 1px solid #e1e4e8;
transition: all 0.3s ease;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
">
<div style="display: flex; gap: 20px;">
<div style="flex: 1;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
<div style="font-weight: 600; color: #24292e;">Reference</div>
<button onclick="copyText(this, 'reference')" style="
padding: 4px 12px;
background-color: #f6f8fa;
border: 1px solid #e1e4e8;
border-radius: 6px;
cursor: pointer;
font-size: 0.8em;
color: #24292e;
display: flex;
align-items: center;
gap: 4px;
transition: all 0.2s;
">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M8 4v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7.242a2 2 0 0 0-.602-1.43L16.083 2.57A2 2 0 0 0 14.685 2H10a2 2 0 0 0-2 2z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 18v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Copy
</button>
</div>
<div style="
font-size: 0.95em;
line-height: 1.6;
color: #24292e;
font-style: italic;
background-color: #f8f9fa;
padding: 12px;
border-radius: 6px;
border: 1px solid #e1e4e8;
" class="reference-text">${dataset_info.reference}</div>
</div>
<div style="flex: 1;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
<div style="font-weight: 600; color: #24292e;">BibTeX</div>
<button onclick="copyText(this, 'bibtex')" style="
padding: 4px 12px;
background-color: #f6f8fa;
border: 1px solid #e1e4e8;
border-radius: 6px;
cursor: pointer;
font-size: 0.8em;
color: #24292e;
display: flex;
align-items: center;
gap: 4px;
transition: all 0.2s;
">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M8 4v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7.242a2 2 0 0 0-.602-1.43L16.083 2.57A2 2 0 0 0 14.685 2H10a2 2 0 0 0-2 2z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 18v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Copy
</button>
</div>
<pre style="
margin: 0;
padding: 12px;
background-color: #f8f9fa;
border-radius: 6px;
border: 1px solid #e1e4e8;
font-size: 0.9em;
line-height: 1.5;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
color: #24292e;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
" class="bibtex-text"></pre>
</div>
</div>
<!-- R Package Citation -->
<div style="margin-top: 20px;">
<button onclick="toggleRCitation(this)" style="
padding: 6px 12px;
background-color: #4287f5;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 0.9em;
transition: background-color 0.2s;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
">To cite using IRW's R package</button>
<div class="r-citation" style="
display: none;
margin-top: 10px;
padding: 12px;
background-color: #f8f9fa;
border-radius: 6px;
border: 1px solid #e1e4e8;
font-family: monospace;
">
<div style="
padding: 8px;
background-color: #f8f9fa;
border-left: 3px solid #4287f5;
margin-bottom: 10px;
">
> <code>irw_citation('${dataset_name}')</code>
</div>
</div>
</div>
</div>
</div>
<iframe id="myIframe" width="800" height="500" allowfullscreen style="border: 1px solid #e1e4e8; border-radius: 8px;" src="${url}"></iframe>
</div>`;
// Add toggle functions to window object
window.toggleInfo = function(button) {
const infoDiv = button.nextElementSibling;
const arrow = button.querySelector('svg');
const isVisible = infoDiv.style.display === 'block';
infoDiv.style.display = isVisible ? 'none' : 'block';
arrow.style.transform = isVisible ? 'rotate(0deg)' : 'rotate(180deg)';
button.querySelector('span').textContent = isVisible ? 'Show Citation Info' : 'Hide Citation Info';
};
window.toggleRCitation = function(button) {
const citationDiv = button.nextElementSibling;
citationDiv.style.display = citationDiv.style.display === 'none' ? 'block' : 'none';
};
// Add copy function to window object
window.copyText = function(button, type) {
const container = button.closest('div').parentElement;
const text = type === 'reference' ?
container.querySelector('.reference-text').textContent :
container.querySelector('.bibtex-text').textContent;
navigator.clipboard.writeText(text).then(() => {
const originalText = button.textContent;
button.textContent = 'Copied!';
button.style.backgroundColor = '#28a745';
button.style.borderColor = '#28a745';
button.style.color = 'white';
setTimeout(() => {
button.innerHTML = `
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M8 4v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7.242a2 2 0 0 0-.602-1.43L16.083 2.57A2 2 0 0 0 14.685 2H10a2 2 0 0 0-2 2z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 18v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Copy
`;
button.style.backgroundColor = '#f6f8fa';
button.style.borderColor = '#e1e4e8';
button.style.color = '#24292e';
}, 2000);
});
};
// Update BibTeX text
const bibtexElement = container.querySelector('.bibtex-text');
if (bibtexElement) {
bibtexElement.textContent = dataset_info.BibTex || "BibTeX not available";
}
return container;
}
```