blib/lib/Database/BI/Tutorial.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 100% 8 / 8 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 8 / 8 totaltotal 98.7% 78 / 79 CC 11 SCAR 11.3
CC
11
Cov
98%
chapter_for_action
5.0
parts
4.0
covered_routes
4.0
CRAP 3.1
« blib/lib/Database/BI/I18N.pm ↑ Summary blib/lib/Database/BI/Sessions.pm »
1 package Database::BI::Tutorial;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 our $VERSION = '0.024.0';
7  
8 # ---------------------------------------------------------------------------
9 # The tutorial that the application shows at GET /tutorial.
10 #
11 # This is deliberately data, not a long HTML file. A chapter is one feature,
12 # and adding a feature means adding one hash to @CHAPTERS. The template
13 # (templates/web/en/tutorial.html.tt) knows how to show every field, so a new
14 # chapter needs no template change.
15 #
16 # To add a chapter:
17 # 1. Copy the shape of a chapter below.
18 # 2. Give it a unique id, a part, a title, a one-sentence lead and short
19 # numbered steps.
20 # 3. List the GET page routes that it covers in routes => [ ... ].
21 # t/tutorial.t fails when a GET page in lib/Database/BI.pm has no
22 # chapter, so this list is a reminder that cannot be forgotten.
23 # 4. Use short sentences and common words. The test also fails a lead,
24 # step or tip that is longer than 25 words.
25 #
26 # A route that is not a page for readers (JSON for a panel, for example) goes
27 # in %EXEMPT_ROUTES with a reason, instead of getting a chapter.
28 # ---------------------------------------------------------------------------
29  
30 12 my @INTRO = (
31 'Database::BI shows data files as tables and charts in your web browser.',
32 'It reads your files. It does not change them. Export writes a new file; it does not change the source.',
33 'You do not need to know Perl or any other programming language to use this tutorial.',
34 'This page uses the same words that you see on the screen.',
35 'The data folder contains example files. You can use them to try the steps.',
36 'A few chapters have a Walk through box: follow it on screen to learn a hard idea.',
37 );
38  
39 12 my @CHAPTERS = (
40  
41 # ---------------------------------------------------------------
42 # First steps
43 # ---------------------------------------------------------------
44 {
45 id => 'open-file',
46 part => 'First steps',
47 title => 'Open your first data file',
48 lead => 'The home page shows the data files that the program can read.',
49 steps => [
50 'Start the program. If you did not start it, ask the person who did. The usual address is http://localhost:3000.',
51 'Open that address in your web browser.',
52 'Find a file card. The card shows the name of a data file.',
53 'Click the card. The file opens as a table.',
54 'You can also drop a file onto the page. The program opens it at once.',
55 ],
56 tip => 'The program reads CSV, TSV, PSV, XLSX, XML, JSON, SQLite and Berkeley DB files. Start with a CSV file if you can.',
57 try => { href => '/', label => 'Open the home page' },
58 routes => [ '/' ],
59 },
60 {
61 id => 'find-your-way',
62 part => 'First steps',
63 title => 'Find your way around',
64 lead => 'Every page shows where you are and how you got there.',
65 steps => [
66 'The links at the top of every page are Home, Canvases, Catalog, Open file..., Preferences and Tutorial.',
67 'The Help link beside Tutorial opens the chapter for the page that you are on. F1 does the same.',
68 'Below the title, the breadcrumb lists each page between Home and this one. Click a step to go back to it.',
69 'Each step is named after what it shows, for example Bar chart: amount by region.',
70 'A chart, pivot, statistics or insights page shows a Drawn from: strip under the breadcrumb.',
71 'The strip lists the filters, the time range and the other changes that the page uses.',
72 'Click Change... in the strip to go back to the page that they came from and change them.',
73 'If an address is wrong, you see Page not found. Click Go to Home or Open a file.',
74 ],
75 tip => 'A chart opened from a chart keeps the whole trail, so you can always find the table that you started from.',
76 routes => [],
77 },
78 {
79 id => 'other-files',
80 part => 'First steps',
81 title => 'Open a file from another place',
82 lead => 'You are not limited to the files in the data folder.',
83 steps => [
84 'Open the home page and click Browse your files. Click folders to move down. Click Up to move back.',
85 'Click a data file in the list to open it.',
86 'To use a full path, type it in the box that shows /path/to/file.csv and click Open.',
87 'To open a file from your computer, drop it on the page. The program keeps a copy in a temporary folder.',
88 'A database file can hold more than one table. The program shows the table list first. Click one table.',
89 'To see a file as soon as the program starts, name it when you start the program: script/database-bi data/store.db.',
90 'The home address then shows that file. Click Home in the breadcrumb to see the usual list.',
91 'You can name only one file this way. To bring files together, open one and use Merge or Combine.',
92 'A JSON Lines file, ending .jsonl or .ndjson, has one JSON object on each line. Each line is one row.',
93 'Set json_flatten in the settings to show a nested object as columns such as address.city.',
94 'To open several files as one table, tick them in the list. Use Select all for a whole folder, or hold Shift to tick a range.',
95 'Click Combine selected. The rows of each file are stacked in one table.',
96 'The last column, source_file, names the file each row came from.',
97 ],
98 tip => 'A folder of reports in the same format, such as a DMARC archive, needs only Select all and Combine selected.',
99 routes => [ '/browse', '/open', '/tables' ],
100 },
101 {
102 id => 'remote-file',
103 part => 'First steps',
104 title => 'Open a file on another computer',
105 lead => 'You can open a data file on a remote server without copying it first.',
106 steps => [
107 'In the path box, type /../hostname/folder/file.csv where hostname is the server name.',
108 'To connect as a specific user, type /../user@hostname/folder/file.csv instead.',
109 'Click Open. The program downloads the file over SSH and shows it as a table.',
110 'The remote path also works in the Merge data panel and the column selector.',
111 'Files with unusual extensions such as .log are read and detected automatically.',
112 ],
113 tip => 'The remote host must run an SSH server. The program connects with SFTP and does not ask for a password here.',
114 routes => [ '/open' ],
115 },
116 {
117 id => 'web-table',
118 part => 'First steps',
119 title => 'Import a table from a web page',
120 lead => 'Some web pages contain data tables. You can open one without saving it.',
121 steps => [
122 'On the home page, find Import from a web page.',
123 'Paste the address of the page into the box.',
124 'If the page has more than one table, type its number. The first table is 0.',
125 'Click Import. The table opens in the program.',
126 ],
127 tip => 'The import reads the page each time. If the page changes, open it again.',
128 routes => [ '/import' ],
129 },
130  
131 # ---------------------------------------------------------------
132 # Work with a table
133 # ---------------------------------------------------------------
134 {
135 id => 'read-table',
136 part => 'Work with a table',
137 title => 'Read and move around a table',
138 lead => 'A table has rows and columns. A row is one record. A column is one kind of value.',
139 steps => [
140 'Click a column heading to sort by that column. Click it again to reverse the order.',
141 'When the table has more than one page, sorting goes back to page 1. The whole table is sorted, not only the page you see.',
142 'Drag a column heading to move that column to a new place.',
143 'A long table shows 200 rows at a time. Use Prev and Next below the table to see more rows.',
144 'Beside them, the page says where you are, for example Page 2 of 7.',
145 'Choose 25, 50, 100, 200 or All in Rows per page to change how many rows each page shows.',
146 'The first row you were looking at stays on screen. All puts every row on one page, which can be slow for a big file.',
147 'The number you choose stays when you merge or combine more data.',
148 'To change the number for every table, use the Preferences page.',
149 'Click Totals to add a row of sums at the bottom.',
150 'Click the box at the start of a row to select it. Click Delete selected to remove it from the view.',
151 ],
152 tip => 'The program remembers your sort order and column order in this browser. Delete selected only changes the view, not the file.',
153 routes => [ '/view/:table' ],
154 },
155 {
156 id => 'filter',
157 part => 'Work with a table',
158 title => 'Keep only the rows you need',
159 lead => 'A filter hides rows that do not match a rule.',
160 steps => [
161 'Find the filter row below the toolbar.',
162 'Choose a column. The comparison options change to match the column type.',
163 'For a date column a date picker appears. For a number column a number box appears. For text, type a value.',
164 'To keep rows between two dates, choose Date range and pick a start and an end date.',
165 'For a number column, such as a year, choose between and type the lowest and highest value.',
166 'The two values can be in either order.',
167 'To keep just a recent window instead, pick a Time range such as the last 30 days.',
168 'Time range is shown only when the table has a date or time column.',
169 'Choose the column that window applies to, then click Apply range.',
170 'Today and the other windows follow the time zone the maintainer set, if there is one.',
171 'Press Enter or click Apply filter.',
172 'Each active filter is shown as a small label in the toolbar. Click the x on a label to remove it.',
173 'For more rules, click Merge / Filter... and use the Filter results section.',
174 'To compare two columns, use Delta... instead. It is explained in its own chapter.',
175 'A link whose filter names a column the table does not have shows an error that lists the columns.',
176 ],
177 tip => 'A filter does not change your file. It only changes what you see and what you export. A time range is worked out from today every time.',
178 routes => [ '/view/:table' ],
179 },
180 {
181 id => 'dedup',
182 part => 'Work with a table',
183 title => 'Hide duplicate rows',
184 lead => 'A duplicate row is exactly the same as another row in every column.',
185 steps => [
186 'Click Hide duplicates in the toolbar.',
187 'The table now shows one copy of each row.',
188 'Click Show duplicates to see every row again.',
189 ],
190 tip => 'Export uses the same rows that you see. Check this button before you export. Charts, the pivot table and the statistics also use one copy of each row.',
191 routes => [],
192 },
193 {
194 id => 'join',
195 part => 'Work with a table',
196 title => 'Add columns from another file',
197 lead => 'A merge joins two tables by a value that both tables share. A customer number is one example.',
198 steps => [
199 'Open the main table.',
200 'Click Merge / Filter...',
201 'Choose the second table. You can also type its path.',
202 'Choose the column in the main table and the matching column in the second table.',
203 'Choose which rows to keep. The option Keep all rows from the left table is a safe first choice.',
204 'Click Apply.',
205 ],
206 tip => 'A merge can make the table much wider. Start with a second table that has only a few columns.',
207 walkthrough => {
208 title => 'Walk through: add customer names to sales',
209 intro => 'This example merges the sales and customer tables inside the store database.',
210 steps => [
211 { do => 'On the home page, click store.', see => 'The schema page lists customer, product and sales.' },
212 { do => 'Click sales. The table opens with four rows.', see => 'The rows show four sales, each with a customer_id from 1 to 3.' },
213 { do => 'Click Merge / Filter...', see => 'The panel asks for a table, two columns and a row rule.' },
214 { do => 'Under Table from the data directory, choose store / customer.', see => 'The matching column list fills with id, name and email.' },
215 { do => 'Choose customer_id for the left key and id for the right key.', see => 'The panel describes a match from customer_id to id.' },
216 { do => 'Choose Keep all rows from the left table and click Apply.', see => 'The result has four rows and new name and email columns.' },
217 ],
218 result => 'Alice Smith appears twice; Bob Jones and Carol White appear once, so every sale now names its customer.',
219 },
220 routes => [ '/join' ],
221 },
222 {
223 id => 'combine',
224 part => 'Work with a table',
225 title => 'Put one file under another',
226 lead => 'Combine stacks the rows of a second file under the rows of the first file.',
227 steps => [
228 'Open the first table.',
229 'Click Combine data...',
230 'Choose the second table or type its path.',
231 'Click Combine.',
232 'To combine many files at once, tick them in Browse your files and click Combine selected.',
233 'A source_file column then names the file each row came from.',
234 'You can merge a table and then combine another, in either order. The table keeps both, and so do its charts.',
235 ],
236 tip => 'The files do not need the same columns. A missing value is left blank.',
237 routes => [ '/combine' ],
238 },
239 {
240 id => 'delta',
241 part => 'Work with a table',
242 title => 'Keep only the rows where two columns differ',
243 lead => 'Delta removes every row where two columns are identical.',
244 steps => [
245 'Open the table.',
246 'Click Delta..., to the right of Combine data.',
247 'Choose the first column and the second column.',
248 'Click Apply. Only the rows where the two columns hold different values are left.',
249 'To see all the rows again, remove the filter chip above the table.',
250 ],
251 tip => 'Identical means the same text. Ann and ann differ, and so do 10 and 10.0. Two empty cells are identical, so that row is removed.',
252 routes => [ '/open' ],
253 },
254 {
255 id => 'calc',
256 part => 'Work with a table',
257 title => 'Make a new column with a calculation',
258 lead => 'A calculated column is a new column made from a formula.',
259 steps => [
260 'Open the table and click Calc fields...',
261 'Type a name for the new column, for example margin.',
262 'Type the formula, for example revenue - cost. Use the column names that you see in the table.',
263 'Click Save & apply. The new column appears in the table.',
264 ],
265 tip => 'The program remembers the field for this data file. It is applied the next time you open the file.',
266 walkthrough => {
267 title => 'Walk through: add a tax column',
268 intro => 'This example adds a column to the sales table.',
269 steps => [
270 { do => 'Open the sales table and click Calc fields...', see => 'The panel asks for a column name and an expression.' },
271 { do => 'Type tax_amount in the Column name box.', see => 'The name is ready for the new column.' },
272 { do => 'Type amount * 1.2 in the Expression box.', see => 'The formula uses the amount column that is already in the table.' },
273 { do => 'Click Save & apply.', see => 'A tax_amount column appears at the right of the table.' },
274 { do => 'Use tax_amount in a chart or pivot table.', see => 'The chart sums the calculated values like any other number column.' },
275 ],
276 result => 'The calculation is saved for this data file, so tax_amount is there the next time you open sales.',
277 },
278 routes => [],
279 },
280 {
281 id => 'cross-row',
282 part => 'Work with a table',
283 title => 'Add a running total or a moving average',
284 lead => 'A cross-row column is worked out from the rows around each row, not from the row alone.',
285 steps => [
286 'Open the table and click Cross-row...',
287 'Choose the number column to read, for example amount.',
288 'Choose what to work out, for example Running total.',
289 'Choose the column that says which order to read the rows in, for example the date.',
290 'Type a name for the new column and click Add column.',
291 ],
292 tip => 'The new column is in the table and in every chart list. The Cross-row chip removes it. A calculated column can read it by name. Restart for each groups the rows before counting. On a canvas, a card can hold cross-row columns of its own. Choose Has a column of its own in Add current view, then Add this column once for each. Each one is listed there and can be taken out before the card is added.',
293 walkthrough => {
294 title => 'Walk through: a running total per region',
295 intro => 'This example adds a running total to the sales table.',
296 steps => [
297 { do => 'Open the sales table and click Cross-row...', see => 'The panel asks for a number column, a function and a name.' },
298 { do => 'Choose amount as the number column.', see => 'The new column will add up the amounts.' },
299 { do => 'Choose Running total, and id as the column to read rows in order of.', see => 'A running total needs an order, so the order box is required.' },
300 { do => 'Type running_amount as the name and click Add column.', see => 'The table gains a running_amount column and a Cross-row chip.' },
301 { do => 'Choose region under Restart for each and add a second column.', see => 'Each region now starts again from its own first row.' },
302 { do => 'Click Bar chart... and pick running_amount as the value.', see => 'A chart reads the new column like any other number column.' },
303 ],
304 result => 'A running total is a column of the view, so the table, the charts and the export all show the same numbers.',
305 },
306 routes => [],
307 },
308 {
309 id => 'groups',
310 part => 'Work with a table',
311 title => 'Group values into your own labels',
312 lead => 'A group gives several values one shared name.',
313 steps => [
314 'Click Group values...',
315 'Choose the source column.',
316 'Click Add group. Type a label, for example Northern.',
317 'Type the values for this group, one on each line. Click Save group.',
318 'The table gains a column named after the source column, for example region_group. Use it in a chart or pivot table.',
319 ],
320 tip => 'A value that is not in a group becomes (other).',
321 routes => [],
322 },
323 {
324 id => 'dates',
325 part => 'Work with a table',
326 title => 'Tell the program how your dates look',
327 lead => 'Dates can be written in many ways. The program needs to know which way your file uses.',
328 steps => [
329 'Click Date format...',
330 'Choose the date column.',
331 'Choose the format that matches your data, for example D/M/YYYY.',
332 'If the column also holds a time, set Clock time. Then hour() and time buckets work.',
333 'Click Save & apply.',
334 ],
335 tip => 'After you set the format, This year, This quarter and This month work in the date panel.',
336 routes => [],
337 },
338 {
339 id => 'lookups',
340 part => 'Work with a table',
341 title => 'Add columns from another file',
342 lead => 'A lookup adds columns from a second file, matched on one value, such as a region to its manager.',
343 steps => [
344 'Put the second file in the data folder.',
345 'Open the table and click Lookups...',
346 'Type a name, then choose the Lookup file.',
347 'Choose its Key in that file, and the Match column here that holds the same values.',
348 'Pick the Columns to add, or pick none to add them all. Type a Default for values the file does not have.',
349 'Click Save & apply.',
350 ],
351 tip => 'Click Skip in this view to see one view without a lookup. It stays saved for the others.',
352 routes => [],
353 },
354 {
355 id => 'extract',
356 part => 'Work with a table',
357 title => 'Split a column into new columns',
358 lead => 'An extraction pulls parts out of a text column with a pattern, such as the domain of an email address.',
359 steps => [
360 'Open the table and click Extract fields...',
361 'Type a name and choose the column.',
362 'Type a pattern. Each named part, written (?<name>...), becomes a column.',
363 'For example, @(?<domain>[\\w.-]+) makes a domain column from an email address.',
364 'Click Save & apply.',
365 ],
366 tip => 'A row that the pattern does not match shows (unparseable), so you can count those rows.',
367 routes => [],
368 },
369 {
370 id => 'folder',
371 part => 'Work with a table',
372 title => 'Browse records in folders',
373 lead => 'Folder view groups rows by the first letters of a code column.',
374 steps => [
375 'Click Folder view...',
376 'Choose the code column. Order numbers such as A10 and B3 are a good example.',
377 'Click Open.',
378 'Click a folder to see the rows in it.',
379 ],
380 tip => 'Folder view is a fast way to find a record when you know the start of its code.',
381 routes => [ '/folder' ],
382 },
383  
384 # ---------------------------------------------------------------
385 # Charts and summaries
386 # ---------------------------------------------------------------
387 {
388 id => 'first-chart',
389 part => 'Charts and summaries',
390 title => 'Make your first chart',
391 lead => 'A chart shows a pattern that is hard to see in a long table.',
392 steps => [
393 'Open a table.',
394 'Click a chart button in the toolbar. Bar chart... is a good first choice.',
395 'Choose a category column and a number column.',
396 'Click Plot.',
397 'Use Export SVG, Export PNG or Export PDF to save the chart. Use Copy link to share the page.',
398 'Chrome and Edge ask where to save. Choose the folder and type the file name you want, then click Save.',
399 ],
400 tip => 'If the chart is empty, check that you chose a number column for the value.',
401 routes => [],
402 },
403 {
404 id => 'chart-types',
405 part => 'Charts and summaries',
406 title => 'Choose the right chart',
407 lead => 'Each chart answers a different question. This table can help you choose.',
408 steps => [],
409 table => {
410 caption => 'Chart types and what they are good for',
411 head => [ 'Chart', 'Good for', 'What to choose' ],
412 rows => [
413 [ 'Line chart', 'A value over time', 'A date or number for X, and a number for Y' ],
414 [ 'Pie chart', 'Parts of one whole', 'A category and a number, with few categories' ],
415 [ 'Heatmap', 'Two groups compared by colour', 'Two category columns, and a count or sum' ],
416 [ 'Bar chart', 'Sizes of different groups', 'A category and a number' ],
417 [ 'Stacked bar chart', 'Groups and their parts', 'A category, a segment, and a number' ],
418 [ 'Scatter plot', 'A link between two numbers', 'Two number columns' ],
419 [ 'Combo chart', 'A bar value and a line value together', 'X, a bar number, and a line number' ],
420 [ 'Treemap', 'Big and small groups in boxes', 'A category and an optional number' ],
421 [ 'Histogram', 'How numbers are spread out', 'A number column and a bin count' ],
422 [ 'Map', 'Where the rows are in the world', 'Latitude and longitude, or a place column' ],
423 [ 'Word cloud', 'Which words a text column repeats', 'A text column' ],
424 ],
425 },
426 tip => 'A bar chart is a good first choice for most data.',
427 routes => [],
428 },
429 {
430 id => 'time-bucket',
431 part => 'Charts and summaries',
432 title => 'Group by hour, day or month',
433 lead => 'A time bucket turns a column of dates into one group per hour, day, month or year.',
434 steps => [
435 'Open a table and click a chart button, for example Bar chart...',
436 'Choose the date or timestamp column for the category or X axis.',
437 'Set Time bucket to the period you want, such as 1 hour or 1 month.',
438 'Click Plot.',
439 'A time that ends in Z or an offset, such as +01:00, lands in the day and hour of the time zone that was set.',
440 ],
441 tip => 'The bucket is a new column, so the chart still has the original timestamp beside it. Use the pivot table to bucket a row group the same way.',
442 routes => [],
443 },
444 {
445 id => 'line-chart',
446 part => 'Charts and summaries',
447 title => 'Line chart',
448 chart => 1,
449 lead => 'A line chart shows how a number changes along a series, often over time.',
450 steps => [
451 'Open the table and click Line graph...',
452 'Choose the X axis. A date column or a number column works well.',
453 'Choose the Y axis. This must be a number column.',
454 'Optional: choose Lines by to draw one line for each value of a column, such as one per region.',
455 'For a total per period, set Time bucket and then set Aggregate to Sum.',
456 'Click Plot.',
457 'Tick Min, Avg or Max above the chart to draw a line at that value.',
458 'Tick Trend to draw the straight line closest to the points. It shows whether the numbers go up or down overall.',
459 'Next to Trend, per point is how much the line rises from one point to the next. R squared near 1 means the points lie close to the line.',
460 'Drag across part of the chart to zoom in. The lines are worked out again for the points you can see.',
461 ],
462 tip => 'Use Copy link to share the chart. Use Export SVG, Export PNG or Export PDF to save the picture.',
463 routes => [ '/graph', '/line' ],
464 },
465 {
466 id => 'pie-chart',
467 part => 'Charts and summaries',
468 title => 'Pie chart',
469 chart => 1,
470 lead => 'A pie chart shows the parts of one whole.',
471 steps => [
472 'Open the table and click Pie chart...',
473 'Choose the column for Slice by. This gives the slices.',
474 'Choose Value. Count (rows) counts each row; a number column sums its values.',
475 'Set Top N slices if you want only the largest slices. The rest become Other.',
476 'Click Plot.',
477 ],
478 tip => 'Click a slice to open the matching rows in the table.',
479 walkthrough => {
480 title => 'Walk through: population share by region',
481 intro => 'This example uses the virginia_counties table in the data folder.',
482 steps => [
483 { do => 'Open the virginia_counties table and click Pie chart...', see => 'The pie panel opens.' },
484 { do => 'Choose region for Slice by.', see => 'Seven regions will become slices.' },
485 { do => 'Choose population for Value.', see => 'Each slice will show the total population for that region.' },
486 { do => 'Click Plot.', see => 'A pie chart appears. Northern Virginia is the largest slice.' },
487 ],
488 result => 'Northern Virginia holds the most people. Its slice is larger than all Southside and Southwest counties combined.',
489 },
490 try => { href => '/pie?l=table:virginia_counties&cat=region&val=population', label => 'Try population by region' },
491 routes => [ '/pie' ],
492 },
493 {
494 id => 'heatmap-chart',
495 part => 'Charts and summaries',
496 title => 'Heatmap',
497 chart => 1,
498 lead => 'A heatmap compares two groups with colour.',
499 steps => [
500 'Open the table and click Heatmap...',
501 'Choose X axis (columns).',
502 'Choose Y axis (rows).',
503 'Leave Value on Count (rows), or choose a number column to sum.',
504 'Click Plot.',
505 ],
506 tip => 'A darker colour means a larger count or sum.',
507 routes => [ '/heatmap' ],
508 },
509 {
510 id => 'bar-chart',
511 part => 'Charts and summaries',
512 title => 'Bar chart',
513 chart => 1,
514 lead => 'A bar chart compares the sizes of different groups.',
515 steps => [
516 'Open the table and click Bar chart...',
517 'Choose Category (bars).',
518 'Leave Value on Count (rows), or choose a number column to sum.',
519 'Use Sort bars and Orientation if you want a different order or direction.',
520 'Click Plot.',
521 ],
522 tip => 'A bar chart is a good first choice for most data.',
523 walkthrough => {
524 title => 'Walk through: top Virginia counties by population',
525 intro => 'This example uses the virginia_counties table in the data folder.',
526 steps => [
527 { do => 'Open the virginia_counties table and click Bar chart...', see => 'The bar panel opens.' },
528 { do => 'Choose county for Category.', see => 'There are 95 counties. Set a limit in the next step.' },
529 { do => 'Choose population for Value. Set Top N to 10 and Sort to By value.', see => 'The form is ready.' },
530 { do => 'Click Plot.', see => 'Ten bars appear. Fairfax County stands far above the rest.' },
531 ],
532 result => 'The ten most populous counties appear, sorted largest first. Fairfax County has more people than the bottom 30 counties together.',
533 },
534 try => { href => '/bar?l=table:virginia_counties&cat=county&val=population&sort=value&topn=10', label => 'Try top 10 counties by population' },
535 routes => [ '/bar' ],
536 },
537 {
538 id => 'stacked-chart',
539 part => 'Charts and summaries',
540 title => 'Stacked bar chart',
541 chart => 1,
542 lead => 'A stacked bar chart shows groups and their parts.',
543 steps => [
544 'Open the table and click Stacked bar...',
545 'Choose Category (X axis).',
546 'Choose Segment (series). This gives the parts of each bar.',
547 'Leave Value on Count (rows), or choose a number column to sum.',
548 'Click Plot.',
549 ],
550 tip => 'Click a part of the legend to hide or show that segment.',
551 routes => [ '/stacked' ],
552 },
553 {
554 id => 'scatter-chart',
555 part => 'Charts and summaries',
556 title => 'Scatter plot',
557 chart => 1,
558 lead => 'A scatter plot shows a link between two numbers.',
559 steps => [
560 'Open the table and click Scatter...',
561 'Choose X axis (horizontal, numeric).',
562 'Choose Y axis (vertical, numeric).',
563 'Optional: choose Colour by to colour the points by a group. Use Bubble size to size them by a number.',
564 'Click Plot.',
565 ],
566 tip => 'If a column is not numeric, it does not appear in the axis lists. A scatter card on a canvas keeps its colours and bubbles. In Add current view, choose Scatter chart to set Colour by and Bubble size there too.',
567 walkthrough => {
568 title => 'Walk through: county location and size',
569 intro => 'This example uses the virginia_counties table in the data folder.',
570 steps => [
571 { do => 'Open the virginia_counties table and click Scatter...', see => 'The scatter panel opens.' },
572 { do => 'Choose lon for X axis and lat for Y axis.', see => 'Each dot will sit at its map position.' },
573 { do => 'Choose region for Colour by.', see => 'Each region gets its own colour.' },
574 { do => 'Choose population for Bubble size. Click Plot.', see => 'Northern Virginia circles are much bigger than the rest.' },
575 ],
576 result => 'The chart mirrors Virginia shape. Large bubbles in the northeast show the high-population Northern Virginia counties.',
577 },
578 try => { href => '/scatter?l=table:virginia_counties&x=lon&y=lat&series=region&size=population', label => 'Try Virginia counties scatter plot' },
579 routes => [ '/scatter' ],
580 },
581 {
582 id => 'combo-chart',
583 part => 'Charts and summaries',
584 title => 'Combo chart',
585 chart => 1,
586 lead => 'A combo chart puts a bar value and a line value on the same X axis.',
587 steps => [
588 'Open the table and click Combo chart...',
589 'Choose X axis.',
590 'Choose Bar column (numeric).',
591 'Choose Line column (numeric).',
592 'Optional: choose a scheme in Colours. The bars take its first colour and the line its second.',
593 'Click Plot.',
594 ],
595 tip => 'Use a combo chart when two numbers are measured in different units. A combo card on a canvas keeps its colours.',
596 routes => [ '/combo' ],
597 },
598 {
599 id => 'treemap-chart',
600 part => 'Charts and summaries',
601 title => 'Treemap',
602 chart => 1,
603 lead => 'A treemap shows big and small groups as boxes.',
604 steps => [
605 'Open the table and click Treemap...',
606 'Choose Category column.',
607 'Leave Value (tile size) on Count (rows), or choose a number column to sum.',
608 'Set Top N tiles if you want only the largest groups.',
609 'Optional: choose Colour by to shade each tile by another number, such as a margin.',
610 'Colour from says how that number is worked out for each tile. Average is the default.',
611 'Colour scale picks the colours, from light for low values to dark for high ones.',
612 'Click Plot.',
613 ],
614 tip => 'A treemap is useful when one level has many groups. Size and colour can show two numbers at once: size for sales, colour for margin. A treemap card on a canvas keeps its colours.',
615 routes => [ '/treemap' ],
616 },
617 {
618 id => 'histogram-chart',
619 part => 'Charts and summaries',
620 title => 'Histogram',
621 chart => 1,
622 lead => 'A histogram shows how numbers are spread out.',
623 steps => [
624 'Open the table and click Histogram...',
625 'Choose Numeric column.',
626 'Set Number of bins. More bins show more detail.',
627 'Optional: choose Bar colour to fill the bars with the first colour of a scheme.',
628 'Click Plot.',
629 ],
630 tip => 'A histogram works best with a number column that has many different values.',
631 routes => [ '/histogram' ],
632 },
633 {
634 id => 'map-chart',
635 part => 'Charts and summaries',
636 title => 'Map',
637 chart => 1,
638 lead => 'A map shows where the rows are in the world.',
639 steps => [
640 'Open the table and click Map...',
641 'Keep Coordinate columns, then choose the latitude and longitude columns.',
642 'If your table has places instead, choose Place-name column and pick that column.',
643 'If the place is split over two columns, such as an address and its country, choose the second one under Followed by. The map then looks up "Brezje 8, Cerknica, Slovenia".',
644 'If the places need more to be found, type it in Add to each place. With Virginia, USA, the county Accomack is looked up as "Accomack, Virginia, USA".',
645 'Tick Remember columns. Next time, the panel chooses the same columns for this table, and fills in Add to each place. Click Forget remembered columns to stop this.',
646 'Tick Heatmap layer to colour the busy areas. Choose a Heat weight column to make some rows count for more.',
647 'Type an Initial zoom from 0 to 19 to start closer in. Leave it empty to fit every marker.',
648 'Choose Counties for Show boundaries to outline the county each marker is in. A checkbox on the map hides the outlines again.',
649 'The list also has countries, states or provinces, cities, towns and neighbourhoods. Choose States, provinces or regions for a map of Canada or India.',
650 'OpenStreetMap has many small places only as a point. A marker there has no outline, and the list under the map names it.',
651 'With the boundaries on, choose a column for Colour shade. Each outline is filled in a shade of one colour, darker for a larger total.',
652 'With coloured markers too, each outline is shaded in its own markers\' colour. Type a Shade colour to use one colour for them all.',
653 'Under the map, a list names each outline that holds more than one marker. Click its number of rows to see them in the table.',
654 'Two places in one outline can mean a name was looked up wrongly. Add to each place, or coordinate columns, make a lookup surer.',
655 'To colour the markers, choose Colour by column, then click Add rule. The first rule that matches gives the colour.',
656 'Type a Default colour for the markers that match no rule.',
657 'Click Open map.',
658 'If some rows could not be plotted, the map says how many, and why.',
659 'Click Show the rows that were not plotted in the table to see them all.',
660 'Or click List the places that were not plotted to see each place.',
661 'Click the number of rows beside a place to see those rows in the table.',
662 ],
663 tip => 'Rows at one place become one marker. Click a marker to see every row it stands for. What the rows share is shown once, and the rest is a short table. A place with many rows shows the first ten, with a link to them all. The scale bar and the key change as you zoom. The key lists only the colours you can see. To size each marker by a number, add &size= and a column name to the map address. To give each category its own colour and a legend, add &series= and a column name instead. A place the local data does not know is looked up on OpenStreetMap. The map opens at once with the places already known. A bar shows each new place as it is looked up. Click Cancel to stop and see the map with the places found so far. Every place found is kept, so the next map of it opens at once. County outlines come from OpenStreetMap too. It is sent each marker\'s position, rounded to about 100 metres. In India the outlines are districts, and in Spain provinces. Add &heat=1&weight= and a column name to colour each outline by its total, from green for the least to red for the most. A key in the corner of the map shows the totals each colour covers.',
664 walkthrough => {
665 title => 'Walk through: Virginia counties on a map',
666 intro => 'This example uses the virginia_counties table in the data folder.',
667 steps => [
668 { do => 'Open the virginia_counties table and click Map...', see => 'The map panel opens.' },
669 { do => 'Keep Coordinate columns. Choose lat for Latitude and lon for Longitude.', see => 'The form shows lat and lon selected.' },
670 { do => 'Click Open map.', see => 'A map appears with 95 markers, one for each Virginia county.' },
671 { do => 'Click any marker.', see => 'A popup shows the county name, population and region.' },
672 ],
673 result => 'All 95 Virginia counties appear as markers. Markers near one another cluster at low zoom.',
674 },
675 try => { href => '/map?l=table:virginia_counties&lat=lat&lon=lon', label => 'Try the Virginia counties map' },
676 routes => [ '/map' ],
677 },
678 {
679 id => 'wordcloud-chart',
680 part => 'Charts and summaries',
681 title => 'Word cloud',
682 chart => 1,
683 lead => 'A word cloud shows which words a text column repeats most.',
684 steps => [
685 'Open the table and click Word cloud...',
686 'Choose Text column. This column holds words, such as a product name or a note.',
687 'Set Words to show to the number of different words you want.',
688 'Set Shortest word to hide very short words such as "at".',
689 'Click Draw cloud.',
690 'To keep the cloud on a saved canvas, open the canvas and click Add current view, then choose Word cloud.',
691 'On a canvas, click a word to filter every other card to the rows that contain it.',
692 ],
693 tip => 'The biggest word appears in the most rows. Click a word to open the rows that contain it, or to cross-filter the canvas around it.',
694 try => { href => '/wordcloud?l=table:sales&col=product', label => 'Try a word cloud of the sales table' },
695 routes => [ '/wordcloud' ],
696 },
697 {
698 id => 'pivot',
699 part => 'Charts and summaries',
700 title => 'Summarise with a pivot table',
701 lead => 'A pivot table puts one group down the side and another group across the top. Each cell is a summary.',
702 steps => [
703 'Click Pivot table...',
704 'Add a row group. For example, choose region.',
705 'Add a measure. For example, choose Sum of amount.',
706 'The measure can also be Median, Std dev, First, Last, Range or a percentile.',
707 'Set Time bucket to group a row group by hour, day, month or year.',
708 'Click Build pivot.',
709 'Click Show subtotals and grand total if you want totals.',
710 'A pivot with many rows is shown a page at a time. Rows per page below it changes how many, as on a table.',
711 ],
712 tip => 'Start with one row group and one measure. Add more only when you need them.',
713 walkthrough => {
714 title => 'Walk through: sales by region and product',
715 intro => 'This example uses the sales table in the data folder.',
716 steps => [
717 { do => 'Open the sales table and click Pivot table...', see => 'The panel opens with one empty row group and one measure.' },
718 { do => 'In the first row group, choose region.', see => 'region becomes the group down the side.' },
719 { do => 'Click Add column and choose product.', see => 'Each product will become a column across the top.' },
720 { do => 'In the measure row, choose amount and keep Sum.', see => 'The measure is called amount_sum unless you type another alias.' },
721 { do => 'Tick Show subtotals and grand total, then click Build pivot.', see => 'The pivot shows a total for each region and one grand total.' },
722 ],
723 result => 'Regions run down the side, products run across the top, and each cell holds the sum of amount.',
724 },
725 routes => [ '/pivot' ],
726 },
727 {
728 id => 'stats',
729 part => 'Charts and summaries',
730 title => 'See statistics for each column',
731 lead => 'Statistics give you a quick summary of every column.',
732 steps => [
733 'Open a table and click Column stats.',
734 'Read one row for each column.',
735 'Rows is the number of rows. Non-null is the number of cells with a value. Null is the number of blank cells.',
736 'Distinct is the number of different values.',
737 'For a number column you also see Min, Max, Range, Mean, Median, Std dev and a percentile.',
738 'Mean is the average. Median is the middle value. Range is the largest value minus the smallest.',
739 'Std dev shows how widely the values spread.',
740 'First and Last are the values the column holds in the first and the last row that has one.',
741 'Change Percentile column to choose which percentile the extra column shows.',
742 ],
743 tip => 'Statistics use the rows that are visible after joins and filters.',
744 walkthrough => {
745 title => 'Walk through: column statistics for Virginia counties',
746 intro => 'This example uses the virginia_counties table in the data folder.',
747 steps => [
748 { do => 'Open the virginia_counties table and click Column stats.', see => 'The stats page shows one row per column.' },
749 { do => 'Find the population row.', see => 'Min is 2214 and Max is 1150309.' },
750 { do => 'Look at the Distinct count for region.', see => 'There are 7 distinct regions.' },
751 { do => 'Look at Mean and Median for population.', see => 'Mean is much higher than Median. A few large counties pull the average up.' },
752 { do => 'Look at Range for population.', see => 'Min is 2214, so Range is 1148095.' },
753 ],
754 result => 'Population is highly uneven. The maximum county is over 500 times larger than the minimum.',
755 },
756 try => { href => '/stats?l=table:virginia_counties', label => 'Try statistics on Virginia counties' },
757 routes => [ '/stats' ],
758 },
759 {
760 id => 'insights',
761 part => 'Charts and summaries',
762 title => 'Find outliers and trends automatically',
763 lead => 'Insights scans your data and flags unusual values, changes over time, and repeating patterns.',
764 steps => [
765 'Open a table and click Insights.',
766 'Each card shows one finding: an outlier, a period change, a top mover, or a seasonal pattern.',
767 'An outlier is a value far outside the normal range for its group.',
768 'A period change compares the most recent month to the one before it.',
769 'A top mover is the category that changed the most between two periods.',
770 'Seasonality means the same pattern repeats from one period to the next.',
771 'Click View in chart on any card to open the chart that shows it.',
772 'Click Summarize to read the findings as a few plain sentences.',
773 'If the program has an AI key, tick Use AI for better prose first. Only the findings are sent, never your rows.',
774 ],
775 tip => 'Insights need a date column and a number column to detect period changes and top movers.',
776 routes => [ '/insights' ],
777 },
778 {
779 id => 'ask',
780 part => 'Charts and summaries',
781 title => 'Ask for a chart in plain English',
782 lead => 'Ask turns a question such as "sales by region as a pie chart" into a chart.',
783 steps => [
784 'Open a table and click Ask...',
785 'Type what you want to see, for example: show me sales by region as a pie chart.',
786 'Click Ask. The panel names the chart that it suggests.',
787 'Click Run it to open that chart.',
788 'Click Save to canvas to keep it as a card on a new canvas.',
789 ],
790 tip => 'Ask appears only when the person who runs the program has set an AI key. Only the column names and their types are sent, never your rows. A question can be up to 500 characters.',
791 },
792  
793 # ---------------------------------------------------------------
794 # Save and share
795 # ---------------------------------------------------------------
796 {
797 id => 'export',
798 part => 'Save and share',
799 title => 'Save the data as a new file',
800 lead => 'Export writes the rows that you see to a new file.',
801 steps => [
802 'Click Export...',
803 'Choose the folder and type a file name.',
804 'The ending of the name chooses the format: .csv, .sql or .json.',
805 'Click Save. The program writes a new file. Your source file is not changed.',
806 ],
807 tip => 'Export includes your joins, filters and duplicate setting. It saves only the columns you can see, in the order you see them. A column that you deleted is not saved.',
808 routes => [ '/export' ],
809 },
810 {
811 id => 'print',
812 part => 'Save and share',
813 title => 'Print the table',
814 lead => 'Print puts the header row and every row of the table on paper, not only the page on the screen.',
815 steps => [
816 'Arrange the table the way you want it. Move or delete columns, and click a header to sort.',
817 'Click Print, to the right of Refresh.',
818 'Your browser opens its print window. Choose a printer, or save the page as a PDF.',
819 'A table of more than 10,000 rows asks first, because it can be hundreds of pages.',
820 ],
821 tip => 'Print uses the same rows as Export, so your joins and filters are included. A row that you deleted from the screen is still printed.',
822 routes => [ '/export' ],
823 },
824 {
825 id => 'catalog',
826 part => 'Save and share',
827 title => 'See all your data files at a glance',
828 lead => 'The dataset catalog lists every file in the data folder and shows which canvases use it.',
829 steps => [
830 'Open the home page and click Dataset catalog.',
831 'Each row shows the file name, type, size, and when it was last changed.',
832 'The Used by column lists the canvases that include this file.',
833 'Click a file name to open it as a table.',
834 'Use the catalog to check which canvases will be affected if a file changes.',
835 ],
836 tip => 'A file that appears in Used by is linked to a canvas. Moving or renaming it will break that canvas.',
837 try => { href => '/catalog', label => 'Open the dataset catalog' },
838 routes => [ '/catalog' ],
839 },
840 {
841 id => 'canvas',
842 part => 'Save and share',
843 title => 'Save a canvas with several charts',
844 lead => 'A canvas is a saved page that can hold tables and charts side by side.',
845 steps => [
846 'Open a table and set up the view that you want.',
847 'Click New canvas...',
848 'Type a name and click Save.',
849 'Click Open canvas. The current table or chart is the first card.',
850 'Click Add visual... to add another view from a data file.',
851 'In that panel, choose the Aggregate a chart works out: Sum, Average, Median, Std dev, or a percentile.',
852 'Drag a card by its header to move it. Use the Size menu to change its width and height.',
853 'Click Add text to put a title or an explanation on the canvas. The next chapter shows how.',
854 'To show only a recent window on every card, choose a Time range and its column above the cards. Then click Apply range.',
855 'Click Edit cross-row in a card header to see that card\'s cross-row columns, and to change or remove one.',
856 ],
857 tip => 'Click Canvases at the top of any page to see all your saved canvases. The home page lists them too. A banner appears if a data file has changed since the canvas was saved.',
858 walkthrough => {
859 title => 'Walk through: arrange and filter a canvas',
860 intro => 'This example starts from a canvas with at least two visuals. Open one from the home page.',
861 steps => [
862 { do => 'Click a bar or a slice in one chart.', see => 'The other cards show only rows for that value, and a chip names the filter.' },
863 { do => 'Click Clear on the filter chip.', see => 'Every card returns to the full data set.' },
864 { do => 'Open the Size menu in a card header and choose Half width.', see => 'The card takes half a row, and the cards beside it move to fit.' },
865 { do => 'Click Edit cross-row in a card header and click one of its columns.', see => 'The chip puts its column, function and name back in the fields, ready to change.' },
866 { do => 'Click Bookmarks, type a name and click Save.', see => 'A link to this exact view appears under the button.' },
867 { do => 'Click Print.', see => 'The browser print window opens with the canvas ready for paper or PDF.' },
868 { do => 'To save just one chart, use the SVG, PNG or PDF button in its card header.', see => 'Chrome and Edge ask where to save it, with a file name based on the card. Other browsers save it in the downloads folder.' },
869 ],
870 result => 'You filtered and arranged one dashboard, and saved a named view without changing any data file.',
871 },
872 routes => [ '/a/:id', '/canvases' ],
873 },
874 {
875 id => 'canvas-text',
876 part => 'Save and share',
877 title => 'Add a title or an explanation to a canvas',
878 lead => 'A text card puts your own words on a canvas, in the font, size and colours that you choose.',
879 steps => [
880 'Open a saved canvas.',
881 'Click Add text in the toolbar.',
882 'Type your words in the Text box. Press Enter to start a new line.',
883 'Choose how the text looks. The preview under the box changes as you choose.',
884 'Click Add to canvas. The card appears at the end of the canvas, across its full width.',
885 'Drag the card by its header to where you want it. The cards in the way move down.',
886 'Use the Size menu in the header to make the card narrower, or to make it taller.',
887 'To change the words or the look, double-click the text. You can also click Edit text in the header.',
888 'Change what you want and click Save text. The card shows each change as you make it, and Cancel puts it back.',
889 'To remove the card, double-click the text, click Remove card and confirm.',
890 ],
891 tip => 'Text is shown exactly as you type it, so HTML tags and Markdown appear as ordinary characters. A filter never changes a text card, because a text card reads no data.',
892 table => {
893 caption => 'What you can choose for a text card',
894 head => [ 'Setting', 'What it does' ],
895 rows => [
896 [ 'Font', 'Same as the page, Arial, Georgia, Times New Roman, Verdana, Trebuchet MS or Courier New.' ],
897 [ 'Size (points)', 'Any whole number from 8 to 96. A new card starts at 14.' ],
898 [ 'Alignment', 'Left, Centre or Right.' ],
899 [ 'Text colour', 'Pick a colour, or tick Follow the theme to match the light or dark page.' ],
900 [ 'Background', 'Pick a colour to fill the card, or tick None to leave it clear.' ],
901 [ 'Bold and Italic', 'Tick either one, or both.' ],
902 [ 'Hide the frame until pointed at', 'The card shows only its words until you point at it. This is ticked for a new card.' ],
903 ],
904 },
905 walkthrough => {
906 title => 'Walk through: put a heading on a canvas',
907 intro => 'This example starts from a canvas with at least one chart. Open one from the home page.',
908 steps => [
909 { do => 'Click Add text and type Quarterly sales in the Text box.', see => 'The words appear in the preview under the box.' },
910 { do => 'Choose Georgia, type 24 for the size, choose Centre and tick Bold.', see => 'The preview shows large, bold, centred text.' },
911 { do => 'Click Add to canvas.', see => 'The heading appears below the other cards, with no frame around it.' },
912 { do => 'Point at the heading.', see => 'A frame appears, with a header above the words.' },
913 { do => 'Drag the header to the top of the canvas.', see => 'The heading moves to the top row, and the charts move down below it.' },
914 { do => 'Reload the page.', see => 'The heading is still at the top, in a row only as tall as its text.' },
915 ],
916 result => 'You gave the canvas a heading that is saved with it and does not depend on any data file.',
917 },
918 routes => [],
919 },
920 {
921 id => 'share',
922 part => 'Save and share',
923 title => 'Share a link to a view',
924 lead => 'A link can open the same table, filters and chart for another person.',
925 steps => [
926 'Open a chart, or a table that has at least one filter.',
927 'Click Copy link. The program puts the address on your clipboard.',
928 'Paste the address into an email or a chat message.',
929 ],
930 tip => 'On a table, Copy link appears when a filter is active. On a chart, it is always there. The other person needs access to the file.',
931 routes => [],
932 },
933 {
934 id => 'share-canvas',
935 part => 'Save and share',
936 title => 'Share a canvas with a signed link',
937 lead => 'A canvas share link lets anyone with the link view the canvas for 30 days.',
938 steps => [
939 'Open a saved canvas.',
940 'Click Share... in the canvas toolbar.',
941 'Click Make a link, then Copy link. The link is now on your clipboard.',
942 'Send the link by email or in a message.',
943 'To show the canvas inside another page of this site, click Copy embed code instead. The panel names any other sites where it works.',
944 'The link stops working after 30 days. Click Make a new link to create another.',
945 'If the panel says a restart ends the link, the server forgets its links when it stops.',
946 ],
947 tip => 'The link gives read-only access. To keep a copy of the canvas, click Download as JSON. Import canvas on the Canvases page reads it back.',
948 routes => [],
949 },
950  
951 # ---------------------------------------------------------------
952 # Help
953 # ---------------------------------------------------------------
954 {
955 id => 'keyboard',
956 part => 'Help',
957 title => 'Use the program with the keyboard',
958 lead => 'Every control can be used without a mouse.',
959 steps => [
960 'Press Tab to move to the next control. Press Shift+Tab to move back.',
961 'Press Enter or Space to press a button or open a link.',
962 'On a column heading, press Enter to sort. Press Shift+Left or Shift+Right to move the column.',
963 'On a chart, press Tab until the resize grip has focus. Use the arrow keys to resize. Hold Shift for bigger steps.',
964 'On a canvas, focus a card header and use the arrow keys to move the card. Hold Shift to move it to the edge.',
965 ],
966 tip => 'The page says each change out loud for screen readers.',
967 routes => [],
968 },
969 {
970 id => 'preferences',
971 part => 'Help',
972 title => 'Set your preferences',
973 lead => 'The Preferences page chooses how the program looks to you: the theme, and how many rows a table shows on a page.',
974 steps => [
975 'Click Preferences at the top of any page.',
976 'Under Theme, choose Same as this device, Light or Dark.',
977 'Same as this device is the choice until you change it. The program follows the light or dark setting on your computer or phone, even while a page is open.',
978 'The page changes as soon as you choose. There is no Save button.',
979 'Every other page follows, including pages that are open in other tabs.',
980 'Tables and charts change with the page. A map keeps its usual colours.',
981 'Under Tables, choose how many rows a table or pivot shows on each page: 25, 50, 100, 200 or All.',
982 'The number takes effect from the next table you open. All can be slow for a big file.',
983 'The Rows per page list under a long table changes that table only.',
984 ],
985 tip => 'The choice is saved in this browser, so another browser or computer keeps its own. Saved charts and printed pages always use the light colours.',
986 try => { href => '/preferences', label => 'Open your preferences' },
987 routes => [ '/preferences' ],
988 },
989 {
990 id => 'log-in',
991 part => 'Help',
992 title => 'Log in',
993 lead => 'A program shared by several people can ask for a password before it shows anything.',
994 steps => [
995 'If a Log in page appears, type the password and click Log in.',
996 'Whoever runs the program chose the password. Ask them for it.',
997 'After you log in, the page you asked for opens.',
998 'Click Log out at the top of any page when you have finished.',
999 'If you do nothing for a working day, you are logged out by yourself.',
1000 'After ten wrong passwords, the page asks you to wait a few minutes.',
1001 ],
1002 tip => 'Share and embed links still work without the password, until they expire. Anyone holding one sees that canvas.',
1003 try => { href => '/login', label => 'Open the Log in page' },
1004 routes => [ '/login' ],
1005 },
1006  
1007 # ---------------------------------------------------------------
1008 # For maintainers
1009 # ---------------------------------------------------------------
1010 {
1011 id => 'alerts',
1012 part => 'For maintainers',
1013 title => 'Alert when a number crosses a limit',
1014 lead => 'The bi-alert script checks a canvas measure and signals when it crosses a threshold.',
1015 steps => [
1016 'The script is installed as bi-alert. In a copy of the source it is script/bi-alert.',
1017 'Run bi-alert --help to see all options.',
1018 'Pass --analysis with the canvas id and --threshold with the measure, comparison and value.',
1019 'For example: bi-alert --analysis abc123 --threshold count:gt:0 exits with code 1 when count is above 0.',
1020 'Pass --analysis or --threshold more than once to check several in the same run.',
1021 'Prefix a threshold with an analysis id, such as abc123:count:gt:10, to check a second canvas.',
1022 'Pass --dry-run to run the check and print the result without sending anything. A dry run does not count towards --suppress.',
1023 'A threshold that stays crossed is only worth hearing about once, so pass --suppress 1h to be told at most hourly.',
1024 'The script remembers the last alert in a small state file, and forgets it when the crossing ends.',
1025 'Pass --recovery to be told when the crossing ends as well as when it starts.',
1026 'The script can only see a crossing end when it remembers one starting, so --recovery keeps its state file.',
1027 'Pass --notify-cmd with a command such as mail to have the script deliver the alert and the recovery itself.',
1028 'Wire the script into a cron job or a monitoring system to get automatic alerts.',
1029 ],
1030 tip => 'Exit code 0 means no alert: the threshold was not crossed, or it was crossed and already reported in this period. Exit code 1 means it was crossed and reported now. Exit code 3 means a crossing that was reported has ended, which is what --recovery asks for. Exit code 2 means an error. When one run reports a crossing and a recovery together, exit code 1 wins.',
1031 routes => [],
1032 },
1033 {
1034 id => 'geocode',
1035 part => 'For maintainers',
1036 title => 'Look up place names before anyone opens the map',
1037 lead => 'The bi-geocode script finds the coordinates of every place in a column and keeps them for the map.',
1038 steps => [
1039 'The script is installed as bi-geocode. In a copy of the source it is script/bi-geocode.',
1040 'Pass --spec with the table, and --col with the column that holds the place names.',
1041 'Give --col twice for a place split over two columns, such as --col Address --col Country.',
1042 'For example: bi-geocode --spec table:virginia_counties --col county --region US.',
1043 'Pass --text to add the same words to the end of each place, as Add to each place does on the map.',
1044 'For example, --text \'Virginia, USA\' looks up Accomack as Accomack, Virginia, USA.',
1045 'Pass --region with a country code, such as GB or US, when the names could be in several countries.',
1046 'Pass --dry-run to look the places up without keeping the result.',
1047 'Places the local data does not know are looked up on OpenStreetMap, one each second. Pass --offline to stop that.',
1048 'Run it again at any time. Places that it already knows are not looked up twice.',
1049 ],
1050 tip => 'The map with a Place-name column then opens at once, because no place has to be looked up. The script needs Geo::Coder::List 0.39 and Geo::Coder::Free 0.48 or later. OpenStreetMap also needs Geo::Coder::OSM 0.03 or later. Exit code 0 means success.',
1051 routes => [],
1052 },
1053 {
1054 id => 'settings',
1055 part => 'For maintainers',
1056 title => 'Change the program settings',
1057 lead => 'A file called database_bi.conf in the application folder changes how the program runs.',
1058 steps => [
1059 'Create database_bi.conf next to the script folder. It holds one Perl hash, such as { data_dir => \'/srv/data\' }.',
1060 'data_dir is the folder that the home page lists. It can be a full path or a path inside the application folder.',
1061 'uploads_dir is where dropped files are kept. Set it when the application folder cannot be written.',
1062 'model_dir holds the saved canvases and settings. It must not be inside data_dir.',
1063 'Set page_cache_dir to keep a copy of the Catalog and Tutorial pages on disc. page_cache_duration says for how long.',
1064 'cache_dir is where the places found for maps, the extracts and the page cache are kept. CACHEDIR or CACHE_DIR in the environment wins over it.',
1065 'Set time_zone to UTC, local or an offset such as +05:30. A time that ends in Z or +01:00 is then read on that clock. Names such as Europe/London are not read.',
1066 'Set json_flatten to 1 to split nested JSON objects into columns, named by their path, such as address.city. Both settings apply to the whole server, not to one file.',
1067 'Set ai_api_key to show the Ask button and the AI choice on the insights page.',
1068 'Restart the program after you change the file.',
1069 ],
1070 tip => 'Every setting is optional. Without the file, the program lists the data folder and keeps its own files in .bi and .uploads.',
1071 routes => [],
1072 },
1073 {
1074 id => 'developers',
1075 part => 'For maintainers',
1076 title => 'Where this page lives',
1077 lead => 'This tutorial is part of the application. It is not in the Perl documentation.',
1078 steps => [
1079 'The text of this page is a list of chapters in lib/Database/BI/Tutorial.pm.',
1080 'The page itself is templates/web/en/tutorial.html.tt. The route is GET /tutorial.',
1081 'To add a chapter, add one entry to the list. Give it a title, a short lead, the steps, and the routes that it covers.',
1082 'Each page finds its Help link through the action map in the same module. Add a new page action there.',
1083 'Run prove -l t/tutorial.t. The test fails if a GET page has no chapter and no reason to be exempt.',
1084 'Read README.md for how to start the program and run the full test suite.',
1085 ],
1086 tip => 'Keep the words simple. The test also checks that no step is a very long sentence.',
1087 routes => [],
1088 },
1089 );
1090  
1091 12 my @FAQ = (
1092 {
1093 question => 'The file is not in the list. What can I do?',
1094 answer => 'Put the file in the data folder, or open it from Browse your files. The program only lists files that it can read.',
1095 },
1096 {
1097 question => 'A JSON file shows address as text, not columns.',
1098 answer => 'A nested object is shown as JSON text unless the maintainer sets json_flatten to 1. Then each value is its own column, such as address.city. A list is always shown as text.',
1099 },
1100 {
1101 question => 'Can I open a file with one JSON object on each line?',
1102 answer => 'Yes. A file ending .jsonl or .ndjson is a JSON Lines file, and each line is a row. A large one is read a line at a time, so it does not fill the memory.',
1103 },
1104 {
1105 question => 'A time near midnight falls on the wrong day.',
1106 answer => 'A time that ends in Z or an offset, such as +01:00, names one moment. If the maintainer set time_zone, it is moved to that clock before filters, ranges and buckets read it. Without it, the time is read as written. A time with no zone is always read as written, and the table shows every cell as it was written.',
1107 },
1108 {
1109 question => 'The home address shows one file, not the list.',
1110 answer => 'The program was started with the name of that file. Click Home in the breadcrumb to see the list. To stop this, start the program without a file name.',
1111 },
1112 {
1113 question => 'The program says that only one database can be opened.',
1114 answer => 'You named more than one file when you started the program. Name one, then use Merge or Combine on its page to add the others. To open a whole folder as one table, tick its files in Browse your files and click Combine selected.',
1115 },
1116 {
1117 question => 'Can I open all the files in a folder as one table?',
1118 answer => 'Yes, if they are in the same format. Open the folder in Browse your files, click Select all, then click Combine selected. A source_file column names the file each row came from.',
1119 },
1120 {
1121 question => 'The table says its extract is stale.',
1122 answer => 'The file has changed since its fast copy was made, so the file itself was read. Run bi-extract --all to make the copy again.',
1123 },
1124 {
1125 question => 'An extracted column says (unparseable).',
1126 answer => 'The pattern did not match the value in that row. Those rows are kept and grouped together, so you can see how many there are.',
1127 },
1128 {
1129 question => 'Delta shows no rows.',
1130 answer => 'The two columns hold the same value in every row, so Delta removed them all. Remove the filter label above the table to see the rows again.',
1131 },
1132 {
1133 question => 'Export left out a column, or put the columns in a new order.',
1134 answer => 'Export saves the columns that the table shows now, in the order that it shows them. A column that you deleted is not saved. Reload the page to get it back.',
1135 },
1136 {
1137 question => 'New columns appeared that are not in my file.',
1138 answer => 'A lookup or an extraction adds them. Open the Lookups or Extract fields panel to see them. Delete one there, or skip a lookup in this view.',
1139 },
1140 {
1141 question => 'The table says its saved columns could not be added.',
1142 answer => 'The file has changed, and a saved column can no longer be worked out. The note names it. Click the panel the note names, then correct or delete it.',
1143 },
1144 {
1145 question => 'A chart or map is blank after D3 or Leaflet was moved to another server.',
1146 answer => 'The pages only load scripts from the servers in the configuration. Set d3_url or the leaflet keys to the new address, and the page allows it.',
1147 },
1148 {
1149 question => 'Can I show a canvas on another web site?',
1150 answer => 'Only on the sites that whoever runs the program has listed. The Share panel names them. On any other site the canvas is refused, so send the share link instead.',
1151 },
1152 {
1153 question => 'Can someone on another computer open it?',
1154 answer => 'Only with a password. At first the program answers only the computer it runs on. Whoever runs it can set a password, then open it to others.',
1155 },
1156 {
1157 question => 'The page says the server does not answer to that name.',
1158 answer => 'Open it as localhost or by its number address instead. To use a name, whoever runs the program adds it to allowed_hosts in the configuration file.',
1159 },
1160 {
1161 question => 'A folder or file says it is not available here.',
1162 answer => 'Whoever runs the program has chosen which folders it may use, and that one is outside them. Choose a file or folder inside, or ask them to add it.',
1163 },
1164 {
1165 question => 'Import from a web page refuses the address.',
1166 answer => 'The page is on this computer or a private network, and the program only reads pages on the public internet. Whoever runs it can name intranet sites it may read.',
1167 },
1168 {
1169 question => 'Export says exports are saved only in the export folders.',
1170 answer => 'Whoever runs the program has chosen the folders exports go to. The Export panel opens on one of them, so save there.',
1171 },
1172 {
1173 question => 'Export will not save into a folder whose name starts with a dot.',
1174 answer => 'Those folders hold settings for other programs, so saving there is refused. Choose another folder.',
1175 },
1176 {
1177 question => 'Export says the name is already there and is not a plain file.',
1178 answer => 'A folder or a link has that name, and Export only replaces an ordinary file. Type another file name.',
1179 },
1180 {
1181 question => 'Ask says the AI has been asked too often this hour.',
1182 answer => 'Whoever runs the program limits how often it asks the AI each hour. Try again later. Insights still work, without the AI wording.',
1183 },
1184 {
1185 question => 'A chart says it cannot be drawn.',
1186 answer => 'The page says why, for example a column that the view does not have. Click Back, then choose other columns.',
1187 },
1188 {
1189 question => 'The program will not open my file.',
1190 answer => 'Check the end of the file name. The program reads CSV, TSV, PSV, XLSX, XML, JSON, SQLite and Berkeley DB files.',
1191 },
1192 {
1193 question => 'My JSON file shows a list of tables, not rows.',
1194 answer => 'The file holds more than one list of rows, such as findings and hosts. Each list is a table. Click the one you want.',
1195 },
1196 {
1197 question => 'The program says my JSON file holds no table.',
1198 answer => 'It needs a list of objects, or an object that holds one. A value inside a row that holds more data is shown as JSON text.',
1199 },
1200 {
1201 question => 'The page is dark, but my saved chart is white.',
1202 answer => 'This is on purpose. Saved charts and printed pages always use the light colours, so that they look the same to whoever receives them.',
1203 },
1204 {
1205 question => 'My text on a canvas is hard to read in the dark theme.',
1206 answer => 'A colour that you pick stays the same in both themes. Tick Follow the theme, or give the card a background colour too.',
1207 },
1208 {
1209 question => 'I cannot find the controls on my text card.',
1210 answer => 'The card hides its frame and header until you point at it. Point at the text, or double-click it to open its settings.',
1211 },
1212 {
1213 question => 'My text card is too tall or too short.',
1214 answer => 'A card one row high is as tall as its text when its row holds only text. Next to a chart, it is as tall as the chart. Choose 2 rows high in the Size menu for a taller card.',
1215 },
1216 {
1217 question => 'Undo did not bring back my text card.',
1218 answer => 'Undo and Redo step through filters and other page state. They do not undo a change to a card, so a removed text card has to be added again.',
1219 },
1220 {
1221 question => 'Can I open a MariaDB or MySQL database?',
1222 answer => 'Yes, once the server has been added to mariadb_servers in the configuration file. The home page then has a card for it, which lists its tables. Choose a table to open it. You can also type mariadb:shop/orders in the path box, or in Merge and Combine. Only a page of the table is read at a time, until you filter it.',
1223 link => { text => 'the configuration file', href => 'https://github.com/nigelhorne/Database-BI#configuration' },
1224 },
1225 {
1226 question => 'A number filter leaves out my blank cells.',
1227 answer => 'This is on purpose. Less than and greater than compare numbers, so a blank or a word in the cell does not match. Use the empty filter to find blank cells.',
1228 },
1229 {
1230 question => 'The program does not remember my theme.',
1231 answer => 'The choice is saved in this browser. A private window forgets it when you close the window. If the browser will not save it, the Preferences page says so.',
1232 },
1233 {
1234 question => 'My chart is empty.',
1235 answer => 'Check that you chose a number column for the value. Check also that your filters still show some rows.',
1236 },
1237 {
1238 question => 'A merge added blank cells.',
1239 answer => 'The two tables had no matching value in the key columns. Check the spelling and the type of the values.',
1240 },
1241 {
1242 question => 'My changes disappeared.',
1243 answer => 'A filter or a join lives in the page address. Save the view as a canvas, or copy the link before you close the page.',
1244 },
1245 {
1246 question => 'A table in my SQLite file says Cannot be opened.',
1247 answer => 'The name of that table has characters other than letters, digits and underscores, such as a colon or a space. The other tables in the file still open. To open this one, rename it in a copy of the file. The message shows the command to use.',
1248 },
1249 {
1250 question => 'The page says Page not found.',
1251 answer => 'The address names a table, a canvas or a page that is not there. Use the breadcrumb or Go to Home to find it again.',
1252 },
1253 {
1254 question => 'Some words are not spelled the way I expected.',
1255 answer => 'The pages follow the language your browser asks for. English (United States) gets American spelling, such as color. Any other English gets British spelling, such as colour.',
1256 },
1257 );
1258  
1259 12 my @GLOSSARY = (
1260 { term => 'Berkeley DB', meaning => 'A database file that ends in .db.' },
1261 { term => 'Breadcrumb', meaning => 'The row of links that shows each page between Home and this one.' },
1262 { term => 'Browser', meaning => 'The program that shows web pages, for example Firefox or Chrome.' },
1263 { term => 'Canvas', meaning => 'A saved page with several tables and charts.' },
1264 { term => 'Cell', meaning => 'One value in a table, at one row and one column.' },
1265 { term => 'Chart', meaning => 'A picture of numbers, for example a bar chart.' },
1266 { term => 'Column', meaning => 'One kind of value in a table, for example the price column.' },
1267 { term => 'Combine', meaning => 'Put the rows of one file under the rows of another file.' },
1268 { term => 'Cross-row column', meaning => 'A column worked out from several rows, for example a running total.' },
1269 { term => 'CSV', meaning => 'A text file with values separated by commas.' },
1270 { term => 'Data file', meaning => 'A file with rows and columns that the program can read.' },
1271 { term => 'Delta', meaning => 'Keep only the rows where two columns hold different values.' },
1272 { term => 'Duplicate', meaning => 'A row that is exactly the same as another row.' },
1273 { term => 'Export', meaning => 'Write the rows that you see to a new file.' },
1274 { term => 'Expression', meaning => 'A small formula, for example revenue - cost.' },
1275 { term => 'Filter', meaning => 'A rule that hides rows which do not match.' },
1276 { term => 'Geocode', meaning => 'Change a place name into a latitude and a longitude.' },
1277 { term => 'Join', meaning => 'Add columns from a second table by matching a shared value.' },
1278 { term => 'JSON Lines', meaning => 'A text file with one JSON object on each line.' },
1279 { term => 'Pivot table', meaning => 'A grid that summarises rows and columns.' },
1280 { term => 'PSV', meaning => 'A text file with values separated by pipe characters.' },
1281 { term => 'Row', meaning => 'One record in a table.' },
1282 { term => 'Server', meaning => 'The program on a computer that sends pages to your browser.' },
1283 { term => 'SQLite', meaning => 'A database file that can hold more than one table.' },
1284 { term => 'Time bucket', meaning => 'One group for each hour, day, month or other period.' },
1285 { term => 'Time zone', meaning => 'The clock that times are read on, set by the maintainer.' },
1286 { term => 'Time range', meaning => 'A recent window, such as the last 30 days, worked out from today.' },
1287 { term => 'TSV', meaning => 'A text file with values separated by tab characters.' },
1288 { term => 'URL', meaning => 'The address of a web page, shown in the address bar.' },
1289 { term => 'XLSX', meaning => 'An Excel spreadsheet file.' },
1290 { term => 'XML', meaning => 'A text file with data inside tags.' },
1291 );
1292  
1293 # Routes that are GET pages but are not chapters. Every entry needs a reason:
1294 # it is a decision to leave a page out of the tutorial, not an accident.
1295 # Actions that render a page, mapped to the chapter that helps with that page.
1296 # The layout turns this into a "Help: ..." link beside the main Tutorial link,
1297 # so a reader on the pie chart screen lands on the pie chart chapter. A new
1298 # page action belongs here; t/tutorial.t checks that every covered GET route
1299 # has an entry.
1300 12 my %ACTION_CHAPTERS = (
1301 index => 'open-file',
1302 browse => 'other-files',
1303 open_file => 'read-table',
1304 import_url => 'web-table',
1305 view => 'read-table',
1306 join_tables => 'join',
1307 combine_tables => 'combine',
1308 export_data => 'export',
1309 tables_view => 'other-files',
1310 graph_view => 'line-chart',
1311 pie_view => 'pie-chart',
1312 heatmap_view => 'heatmap-chart',
1313 bar_view => 'bar-chart',
1314 folder_view => 'folder',
1315 pivot_view => 'pivot',
1316 stats_view => 'stats',
1317 insights_view => 'insights',
1318 scatter_view => 'scatter-chart',
1319 stacked_view => 'stacked-chart',
1320 combo_view => 'combo-chart',
1321 treemap_view => 'treemap-chart',
1322 histogram_view => 'histogram-chart',
1323 wordcloud_view => 'wordcloud-chart',
1324 map_view => 'map-chart',
1325 canvas_render => 'canvas',
1326 catalog_view => 'catalog',
1327 canvases_view => 'canvas',
1328 preferences => 'preferences',
1329 login_form => 'log-in',
1330 );
1331  
1332 12 my %EXEMPT_ROUTES = (
1333 '/a/:id/visual/:n/:fmt' => 'per-visual CSV/PNG download; not a navigable page',
1334 '/api/analyses' => 'JSON for the saved-canvas list',
1335 '/api/analyses/:id' => 'JSON for one saved canvas',
1336 '/api/analyses/:id/export' => 'JSON export of one saved canvas',
1337 '/api/columns' => 'JSON list of columns for the join and filter panels',
1338 '/api/dirs' => 'JSON folder list for the browse and export panels',
1339 '/api/range' => 'JSON min/max ISO dates for the filter date-picker constraints',
1340 '/api/stat' => 'JSON file details for the home-page tooltips',
1341 '/calc/list' => 'JSON list of calculated fields for the Calc panel',
1342 '/dates/list' => 'JSON list of date formats for the Date panel',
1343 '/geo/list' => 'JSON list of saved coordinate column preferences for the Map panel',
1344 '/embed/:id' => 'chrome-less embed view; requires a share token and is not a standalone page',
1345 '/groups/list' => 'JSON list of value groups for the Group panel',
1346 '/extract/list' => 'JSON list of the stored field extractions of a dataset',
1347 '/lookups/list' => 'JSON list of the stored lookups of a dataset',
1348 '/share/:id' => 'shared read-only canvas view; requires a signed token and cannot be navigated to directly',
1349 '/tutorial' => 'this page',
1350 );
1351  
1352 11 ▶sub intro { return \@INTRO }
Subroutine intro: called CC=1 SCAR=0.0
Pod documented
1353 8 ▶sub chapters { return \@CHAPTERS }
Subroutine chapters: called CC=1 SCAR=0.0
Pod documented
1354 10 ▶sub faq { return \@FAQ }
Subroutine faq: called CC=1 SCAR=0.0
Pod documented
1355 10 ▶sub glossary { return \@GLOSSARY }
Subroutine glossary: called CC=1 SCAR=0.0
Pod documented
1356  
1357 9 ▶sub parts {
Subroutine parts: called CC=4 SCAR=13.9
Pod documented
1358 9 my @parts;
1359  
1360 9 for my $chapter (@CHAPTERS) {
1361 450 my $name = $chapter->{part};
1362  
1363 450 ▶ if (!@parts || $parts[-1]{name} ne $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @parts or $parts[-1]{"name"} ne $name) 54 396 450
Condition100%3/3
not @parts or $parts[-1]{"name"} ne $name
l!l&&r!l&&!r
945396
MC/DC100%2/2
not @parts or $parts[-1]{"name"} ne $name
not @parts $parts[-1]{"name"} ne $name
Truth table100%3/3
not(A) or B
A= not @partsB= $parts[-1]{"name"} ne $name
ABresult
1X1
011
000
1364 54 push @parts, {
1365 name => $name,
1366 id => _slug($name),
1367 chapters => [],
1368 };
1369 }
1370  
1371 450 push @{ $parts[-1]{chapters} }, $chapter;
1372 }
1373  
1374 9 return \@parts;
1375 }
1376  
1377 3 ▶sub covered_routes {
Subroutine covered_routes: called CC=4 SCAR=13.9
Pod documented
1378 3 my %routes;
1379  
1380 3 for my $chapter (@CHAPTERS) {
1381 150 ▶ for my $route (@{ $chapter->{routes} // [] }) {
Condition100%2/2
$chapter->{"routes"} // []
l!l
1473
MC/DC100%1/1
$chapter->{"routes"} // []
$chapter->{"routes"}
Truth table100%2/2
A
A= $chapter->{"routes"}
Aresult
11
00
1382 102 $routes{$route} = $chapter->{id};
1383 }
1384 }
1385  
1386 3 return \%routes;
1387 }
1388  
1389 4 ▶sub exempt_routes {
Subroutine exempt_routes: called CC=1 SCAR=0.0
Pod documented
1390 4 return { %EXEMPT_ROUTES };
1391 }
1392  
1393 3308 ▶sub chapter_for_action {
Subroutine chapter_for_action: called CC=5 SCAR=16.1
Pod documented
1394 3308 my $action = $_[1];
1395 3308 ▶ return unless defined $action;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action 239 3069 3308
1396  
1397 3069 ▶ my $id = $ACTION_CHAPTERS{$action} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $ACTION_CHAPTERS{$action} or return 1996 1073 3069
1398  
1399 1996 for my $chapter (@CHAPTERS) {
1400 40993 ▶ return $chapter if $chapter->{id} eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if $chapter->{"id"} eq $id 1996 38997 40993
1401 }
1402  
1403 0 return;
1404 }
1405  
1406 62 ▶sub _slug {
Subroutine _slug: called CC=1 SCAR=0.0
1407 62 my ($text) = @_;
1408  
1409 62 my $slug = lc $text;
1410 62 $slug =~ s/[^a-z0-9]+/-/g;
1411 62 $slug =~ s/\A-+|-+\z//g;
1412  
1413 62 return $slug;
1414 }
1415  
1416 12 1;
1417  
1418 =head1 NAME
1419  
1420 Database::BI::Tutorial - the chapters of the in-application tutorial
1421  
1422 =head1 SYNOPSIS
1423  
1424 use Database::BI::Tutorial;
1425  
1426 for my $part (@{ Database::BI::Tutorial->parts }) {
1427 print $part->{name}, ": ", scalar @{ $part->{chapters} }, " chapters\n";
1428 }
1429  
1430 my $chapter = Database::BI::Tutorial->chapter_for_action('bar_view');
1431 print $chapter->{title}, "\n" if $chapter;
1432  
1433 =head1 DESCRIPTION
1434  
1435 The tutorial that the application shows at C<GET /tutorial> is built from the
1436 data in this module. A chapter is one feature: a title, a short lead, numbered
1437 steps, and the C<routes> that it covers. The template renders the chapters in
1438 order, so adding a feature means adding a hash here, not editing HTML.
1439  
1440 A chapter may also have a C<walkthrough>: a worked example with a C<title>, an
1441 C<intro>, a list of C<steps> that each say what to C<do> and what to C<see>,
1442 and a C<result>. The template shows it as one box, and the contents marks the
1443 chapter so a reader can find it.
1444  
1445 C<t/tutorial.t> checks that every GET page in L<Database::BI> is either covered
1446 by a chapter or listed in C<exempt_routes()> with a reason. Keep the sentences
1447 short: the same test fails a lead, step, tip or walk-through sentence longer
1448 than 25 words.
1449  
1450 C<chapter_for_action()> maps a controller action to the chapter that helps with
1451 that page. The application calls it from a C<before_render> hook and the shared
1452 layout shows the result as a C<Help: ...> link beside the main Tutorial link.
1453 A new page action belongs in C<%ACTION_CHAPTERS>; the test fails until it is
1454 there.
1455  
1456 =head1 FUNCTIONS
1457  
1458 Each is called as a class method or a plain function; none takes arguments
1459 except C<chapter_for_action>. The returned structures are the module's own
1460 data: read them, do not change them.
1461  
1462 =head2 intro
1463  
1464 =head3 API SPECIFICATION
1465  
1466 =head4 OUTPUT
1467  
1468 [ 'string', ... ] # the introduction's sentences
1469  
1470 =head2 chapters
1471  
1472 =head3 API SPECIFICATION
1473  
1474 =head4 OUTPUT
1475  
1476 [ {
1477 id => 'string', # anchor, unique
1478 part => 'string', # the part the chapter belongs to
1479 title => 'string',
1480 lead => 'string',
1481 steps => 'arrayref', # sentences
1482 tip => 'string', # optional
1483 try => 'hashref', # optional; { href, label }
1484 routes => 'arrayref', # the GET routes the chapter covers
1485 walkthrough => 'hashref', # optional; { title, intro, steps => [ { do, see } ], result }
1486 }, ... ]
1487  
1488 In the order the page shows them.
1489  
1490 =head2 faq
1491  
1492 =head3 API SPECIFICATION
1493  
1494 =head4 OUTPUT
1495  
1496 [ { question => 'string', answer => 'string', link => { text, href }? }, ... ]
1497  
1498 C<link> makes the words C<text>, which occur once in C<answer>, a link to C<href>.
1499  
1500 =head2 glossary
1501  
1502 =head3 API SPECIFICATION
1503  
1504 =head4 OUTPUT
1505  
1506 [ { term => 'string', meaning => 'string' }, ... ]
1507  
1508 =head2 parts
1509  
1510 =head3 API SPECIFICATION
1511  
1512 =head4 OUTPUT
1513  
1514 [ { name => 'string', id => 'string', chapters => 'arrayref' }, ... ]
1515  
1516 The chapters grouped by C<part>, in order. C<id> is the part name in lower
1517 case with each run of other characters replaced by C<->. A new list is built
1518 on each call.
1519  
1520 =head2 covered_routes
1521  
1522 =head3 API SPECIFICATION
1523  
1524 =head4 OUTPUT
1525  
1526 { '/route' => 'chapter-id', ... }
1527  
1528 A route named by two chapters maps to the later one.
1529  
1530 =head2 exempt_routes
1531  
1532 =head3 API SPECIFICATION
1533  
1534 =head4 OUTPUT
1535  
1536 { '/route' => 'reason', ... } # a copy: GET pages with no chapter, and why
1537  
1538 =head2 chapter_for_action
1539  
1540 =head3 API SPECIFICATION
1541  
1542 =head4 INPUT
1543  
1544 $action # a controller action name, e.g. 'bar_view'
1545  
1546 =head4 OUTPUT
1547  
1548 A chapter hashref (as C<chapters> returns), or an empty list
1549  
1550 An undefined or unknown action returns an empty list. It must be called as a
1551 class method: the action is the second argument.
1552  
1553 =head1 AUTHOR
1554  
1555 Nigel Horne C<< <njh@nigelhorne.com> >>
1556  
1557 =head1 LICENCE AND COPYRIGHT
1558  
1559 Copyright 2026 Nigel Horne.
1560  
1561 Usage is subject to the GPL2 licence terms.
1562  
1563 =cut
« blib/lib/Database/BI/I18N.pm ↑ Summary blib/lib/Database/BI/Sessions.pm »