Skip to content

Commit

Permalink
Add stats_rewrite setting
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 15, 2024
1 parent 9a8ed83 commit 64b2667
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- A GitHub action to check the build
- Add support for "not in order" in extended and advanced search
- The `stats_rewrite` setting for altering the statistics table

### Changed

Expand Down
1 change: 1 addition & 0 deletions app/scripts/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ model.normalizeStatsData = function (data) {
}
}

/** The Proxy classes wrap API requests with pre-/postprocessing and progress reporting. */
class BaseProxy {
constructor() {
this.prev = ""
Expand Down
7 changes: 6 additions & 1 deletion app/scripts/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ const createStatisticsService = function () {
corpora: _.keys(data.corpora),
prevNonExpandedCQP,
}
def.resolve([e.data, columns, searchParams])
let result = [e.data, columns, searchParams]
// Invoke configurable stats rewriting
if (settings.stats_rewrite) {
result = settings.stats_rewrite(result)
}
def.resolve(result)
}

statsWorker.postMessage({
Expand Down
9 changes: 6 additions & 3 deletions doc/frontend_devel.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@ parameters for attributes.
- **sidebar_hide_label**: `boolean`. If `true`, do not show the localized attribute label and the colon following it in the
sidebar, only the attribute value. This can be used, for example, if the `pattern` for the attribute includes the label but
the label should be shown in the attribute lists of the extended search or statistics.
- **stats_cqp**: See [Custom statistics functions](#custom-statistics-functions).
- **stats_stringify**: See [Custom statistics functions](#custom-statistics-functions).
- **stats_cqp**: See [Rendering attribute values in the statistics view](#rendering-attribute-values-in-the-statistics-view).
- **stats_rewrite**: A function that takes the array `[data, columns, searchParams]`, modifies and returns it.
- **stats_stringify**: See [Rendering attribute values in the statistics view](#rendering-attribute-values-in-the-statistics-view).
- **translation**: An object containing translations of possible values of the attribute, in this format:
```
{
Expand Down Expand Up @@ -676,7 +677,7 @@ Data about the search, the current token and current attribute is stored in a nu
*Note: The component not an actual Angular.js [component](https://docs.angularjs.org/guide/component). It will be added to the interface by manually creating a new scope and using `$controller` to instantiate the controller and `$compile` to instantiate the template.*
#### Rendering attribute values in the statistics-view
#### Rendering attribute values in the statistics view
Define your own rules for rendering values and generating CQP-expressions for certain attributes.
Expand All @@ -703,6 +704,8 @@ export default {
Rendering values and generating CQP can also be controlled by editing `app/config/statistics_config.js`, but
of course it is best to avoid editing the actual code if it is possible.
If you need to merge rows or otherwise alter the table structure, implement and assign a function to the `stats_rewrite` setting.
#### Stringify functions
Add all custom pretty-printing to `custom/stringify.js`. Example file:
Expand Down

0 comments on commit 64b2667

Please sign in to comment.