@datama/studio-skill-instructions 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,117 +0,0 @@
1
- # Studio instantiation
2
-
3
- How the Studio template boots Datama Studio, and every parameter it accepts. The template already calls `DatamaStudio.render`; you only provide `DATASET`, `CONFIGURATION`, `THEME` and `LICENSE`. Read this file to build the `source` bag correctly, and when a request needs a parameter the template does not set.
4
-
5
- ## `DatamaStudio.render(container, options)` — what the template calls
6
-
7
- ```js
8
- DatamaStudio.render("#datama-studio", {
9
- source: DATASET, // rows array, or the source bag below
10
- configuration: CONFIGURATION, // story configuration bag (studio-stories.md); {} = defaults
11
- theme: THEME, // look (theming.md); undefined = Datama default
12
- license: LICENSE, // license token string; "" = demo page
13
- sourceMeta: {embedded: true},
14
- callbacks: {exportAsHTML, onError},
15
- }).then((studio) => { /* DatamaStudio instance */ });
16
- ```
17
-
18
- | Option | Type | Default | Meaning |
19
- | --- | --- | --- | --- |
20
- | `container` (1st argument) | `Element` or string | — | The element, a `#id` / `.class` selector, or a bare element id |
21
- | `source` (alias `data`) | `Object[]` or source bag | `{data: []}` | The dataset, see below |
22
- | `configuration` | Object | `{}` | Stories, modules, pins, language ([studio-stories.md](studio-stories.md)). A Datama Light settings bag is also accepted and migrated |
23
- | `theme` | Object | Datama default | `{colors: {...}}` ([theming.md](theming.md)) |
24
- | `license` | string | `""` | `DL2.…` token (or a legacy Datama Light token). Empty = demo / unlicensed page |
25
- | `sourceMeta` | Object | `{embedded: true}` | Free metadata about the dataset origin shown in the header (`embedded`, `createdAt`, `editable`) |
26
- | `callbacks` | Object | `{windowOpen}` | Host listeners, see [Callbacks](#callbacks) |
27
- | `debug` | boolean | `false` | Verbose console logs and timers |
28
- | `context` | string | `"export"` | Host context label |
29
- | `host` | Object | `{configurable: true}` | `configurable: false` = read-only page: no settings editing, silent notifications |
30
-
31
- `render` resolves with the mounted `DatamaStudio` instance once the first story is rendered. The template stores it on `window.__DATAMA_STUDIO_INSTANCE__`.
32
-
33
- ## The `source` bag
34
-
35
- The simplest source is the rows array itself. Use the bag form to control how columns are classified:
36
-
37
- ```json
38
- {
39
- "data": [
40
- {"Date": "2025-01-06", "Country": "France", "Device": "Mobile", "Session": 1200, "Checkout": 84, "Revenue": 5120.5}
41
- ],
42
- "dimensions": ["Date", "Country", "Device"],
43
- "metrics": ["Session", "Checkout", "Revenue"]
44
- }
45
- ```
46
-
47
- | Key | Type | Meaning |
48
- | --- | --- | --- |
49
- | `data` | `Object[]` | One flat object per row. Same keys on every row. Values: string, number, or `null` |
50
- | `dimensions` | `string[]` | Columns used as dimensions (text, date, ids, years). Omitted: deduced (text and date columns) |
51
- | `metrics` | `string[]` | Numeric columns used as metrics, **in market-equation order** (first metric = top of the funnel). Omitted: every numeric column, in column order |
52
- | `meta` | Object | Column metadata hint. Leave it out: Studio deduces it from the rows |
53
- | `dateHierarchies` | boolean | `true` adds period columns `Date[Year]`, `Date[Quarter]`, `Date[Month]`, `Date[Week]`, `Date[Day]` for every date column. Default `false` |
54
-
55
- Rules for the rows:
56
-
57
- - **Dates**: one consistent format per column, ISO `YYYY-MM-DD` (or `YYYY-MM-DD HH:mm:ss`) preferred. Studio casts them internally; you keep writing the dataset values in configurations (comparisons, filters).
58
- - **Metrics**: plain numbers (no `"1 200 €"` strings, no thousands separators). Use `null` for a missing value, never `""`.
59
- - **Ratios and averages** (`conversion_rate`, `AOV`, `CTR`…) should not be metrics: give the raw counts and let the market equation compute ratios ([market-equation.md](market-equation.md)).
60
- - A numeric column that is really a label (year, store id, zip code) goes in `dimensions` explicitly, otherwise it is read as a metric.
61
- - Aggregate before inlining when the raw data is larger than ~20 000 rows: keep only the dimensions the request needs and sum the metrics.
62
- - `metrics` defines what the automatic market equation uses: listing only `["Session", "Checkout", "Revenue"]` gives the funnel Session → Checkout per Session → Revenue per Checkout without writing any step.
63
-
64
- ## License
65
-
66
- - No license (`null` in the template): the page runs as a demo. Datama decides which features a demo shows (for instance "Download as HTML" is disabled in demo mode).
67
- - Licensed page: the template's `__LICENSE__` receives the token string the user or the skill package provided. Never invent, edit or reuse a token from elsewhere.
68
-
69
- ## Callbacks
70
-
71
- `callbacks` keys are event channels registered on the instance. Every listener is optional.
72
-
73
- | Key | Arguments | When |
74
- | --- | --- | --- |
75
- | `exportAsHTML` | `(settings)` | Header "Download as HTML": receives the live configuration bag. The template builds and saves a standalone page |
76
- | `onError` | `(error)` | A refresh failed |
77
- | `onSuccess` | `()` | A refresh succeeded |
78
- | `onRenderSettled` | `(detail)` | Charts finished drawing (screenshots, bots) |
79
- | `onStoryActivate` | `(story, id)` | The active story changed |
80
- | `onSettingsApply` | `(configurationBag)` | The user saved settings in the page (persist the bag to reload it later) |
81
- | `windowOpen` | `(url, target)` | Opens a link (default: `window.open`) |
82
- | `getDataset` | `async () => sourceBag` | Only with `DatamaStudio.create({data: null})`: Studio awaits the dataset |
83
-
84
- ## Instance methods
85
-
86
- | Method | Use |
87
- | --- | --- |
88
- | `await studio.exportConfigurationForHost()` | Current configuration bag (same shape as `configuration`), with the user's live edits |
89
- | `await studio.applyLicense(token)` | Apply a license without losing the live settings |
90
- | `await studio.setStoryLanguage("fr-FR")` | Switch the language (`en-US`, `fr-FR`, `de-DE`, `es-ES`) |
91
- | `studio.startStoryPresentation()` / `exitStoryPresentation()` | Full-screen slide presentation of the active story |
92
- | `studio.refresh()` | Re-render after an external change |
93
-
94
- ## `DatamaStudio.create(params)` — lower-level entry
95
-
96
- `render(container, options)` is `create` with page defaults. Use `create` only when you need one of its extra parameters:
97
-
98
- | Param | Meaning |
99
- | --- | --- |
100
- | `container` | Element or element id |
101
- | `data` | Rows array or source bag; `null` to wait for `callbacks.getDataset` |
102
- | `dimensions` / `metrics` / `meta` / `dateHierarchies` | Same as the source bag keys, at the top level |
103
- | `configuration`, `license`, `theme`, `callbacks`, `debug`, `host`, `sourceMeta` | Same as `render` |
104
- | `lite` | `true` = reduced effects and animations (slow devices) |
105
-
106
- ## Minimal examples
107
-
108
- Compare with every default (first date column split into its older half vs its newer half, automatic market equation from `metrics`):
109
-
110
- ```js
111
- var DATASET = {"data": [/* rows */], "metrics": ["Session", "Checkout", "Revenue"]};
112
- var CONFIGURATION = {};
113
- var THEME = null;
114
- var LICENSE = null;
115
- ```
116
-
117
- `{}` creates one default story per bundled solution; the first one (Compare) is shown. To open on a given solution, with a title and a precise analysis, write a story ([studio-stories.md](studio-stories.md)).
@@ -1,241 +0,0 @@
1
- # Studio configuration: stories, modules and pins
2
-
3
- `CONFIGURATION` in the Studio template is the same bag Studio itself saves and reloads. Write it in that shape and the page opens exactly on the requested analysis.
4
-
5
- ## Shape
6
-
7
- ```json
8
- {
9
- "stories": {
10
- "story-revenue": {
11
- "title": "Why did revenue drop in March?",
12
- "emoji": "📉",
13
- "displayMode": "scroll",
14
- "pins": {
15
- "comparison": {"inputs": {"comparisons": [/* see Comparisons */], "relative": false, "order": "desc"}},
16
- "marketEquation": {"inputs": {"formula": "[1]*[2]*[3]", "totalStepName": "Revenue", "totalStepUnit": "€"}, "steps": [/* market-equation.md */]}
17
- },
18
- "modules": [
19
- {"module": "compare.waterfall", "inputs": {/* solution inputs */}, "configuration": {"plotter": {/* chart tuning */}}}
20
- ]
21
- }
22
- },
23
- "activeStory": "story-revenue",
24
- "inputs": {"language": "en-US"}
25
- }
26
- ```
27
-
28
- | Key | Type | Meaning |
29
- | --- | --- | --- |
30
- | `stories` | Object (id → story) or array of stories with an `id` | Every story of the page, shown as tabs |
31
- | `activeStory` | string | Id of the story shown first. Missing or unknown: the first story |
32
- | `inputs.language` | `"en-US"` · `"fr-FR"` · `"de-DE"` · `"es-ES"` | Language of the whole page (labels, generated titles and comments). Default `en-US`. Match the user's language |
33
- | `theme` | Object | Same as the template `THEME` ([theming.md](theming.md)); prefer the template variable |
34
-
35
- `{}` is valid: Studio creates one default story per bundled solution with default analyses. Write stories as soon as the request names a solution, a comparison, metrics or a chart.
36
-
37
- ## Story
38
-
39
- | Key | Type | Default | Meaning |
40
- | --- | --- | --- | --- |
41
- | `title` | string | solution name | Tab and slide title. Write the user's question or the insight they want |
42
- | `emoji` | string | 📊 | One emoji shown in the tab |
43
- | `displayMode` | `"scroll"` · `"slide"` | `"scroll"` | `scroll`: modules stacked in a scrolling page. `slide`: one module per slide, arrow navigation |
44
- | `appearance` | Object | flat | Story canvas tokens, see [Appearance](#appearance). Omit it for the default flat look |
45
- | `pins` | Object | `{}` | Analysis scopes shared by every module of the story, see [Pins](#pins) |
46
- | `modules` | Array | default module of the solution | Render modules, in display order. `activeModules` is accepted as an alias |
47
-
48
- A story id is any string (`story-` + a slug is the convention). Keep ids unique.
49
-
50
- ## Module slot
51
-
52
- A module is one analysis rendered with Plotter. Its key is `<solution id>.<module id>`; the bundled keys are listed in [generated/solutions.md](generated/solutions.md) (`compare.waterfall`, `explore.dimensions`, `detect.anomaly`, `pivot.tree`).
53
-
54
- ```json
55
- {"module": "explore.dimensions", "inputs": {"primary": "Country", "metric1": "Revenue"}, "configuration": {}}
56
- ```
57
-
58
- A bare string (`"compare.waterfall"`) is a module with default inputs.
59
-
60
- | Key | Type | Meaning |
61
- | --- | --- | --- |
62
- | `module` | string | Module key (required) |
63
- | `instance` | string | Stable slot id. Optional; needed only to tell two slots of the same module apart |
64
- | `inputs` | Object | Solution inputs of this slot: view, chart, analysis method, display options. Keys per solution in `solutions/*.md` and defaults in [generated/solutions.md](generated/solutions.md) |
65
- | `steps` | Array | Market-equation steps of this slot only (prefer the `marketEquation` pin) |
66
- | `configuration` | Object | Display state; `configuration.plotter` tunes the chart ([plotter/embedded.md](plotter/embedded.md)). `{}` keeps the solution look |
67
- | `whatIf` | Object | What-if scenarios of this slot (prefer the `whatIf` pin) |
68
- | `smart` | Object | Internal state written by Studio. Never author it |
69
-
70
- Several modules in one story read the same data and pins: for instance a Compare waterfall followed by an Explore chart of the same comparison.
71
-
72
- ## Pins
73
-
74
- A pin holds one analysis scope **once for the whole story**: every module reads it, and a key held by a pin is ignored on the module slots. This is where Studio saves comparisons, filters and the market equation, so write them there.
75
-
76
- | Share id | Holds | Use for |
77
- | --- | --- | --- |
78
- | `comparison` | `inputs: {comparisons, relative, order, anchor}` | Start vs End sides ([Comparisons](#comparisons)) |
79
- | `filters` | `inputs: {dataFilters}` | Rows kept for the analysis ([Filters](#filters)) |
80
- | `marketEquation` | `inputs: {formula, totalStepName, totalStepUnit, totalStepEmoji}` + `steps` | Metrics, steps and main KPI ([market-equation.md](market-equation.md)) |
81
- | `dimensions` | `inputs: {dimensionsHierarchy, clusteringThreshold, metricForClustering, hierarchicalMix, …}` | Drill-down hierarchy and segment grouping (Compare) |
82
- | `clustering` | `inputs: {clusteringThreshold, metricForClustering}` | Grouping of small segments into "Other" |
83
- | `date` | `inputs: {startOfWeek, dateDisplayFormat, dateDisplayCustomPattern, dateHierarchies}` | Date display and period columns |
84
- | `analysisMethod` | `inputs: {analysisMethod, waterfallMeasure, …, primary, secondary, metric1, metric2}` | Compare / Explore method shared by every module |
85
- | `detection` | `inputs: {detectionMethod, detectionThreshold, lastPointsCount, lastPointsOnlyEnabled, …}` | Detect settings shared by every module |
86
- | `whatIf` | `whatIf: {scenarios}` | What-if scenarios ([What if](#what-if)) |
87
- | `events` | `calendar` | Calendar events (set in the app; do not author) |
88
- | `theme` | `theme` | Story colors (set in the app; use `THEME` instead) |
89
-
90
- The exact key list of each pin is generated in [generated/solutions.md](generated/solutions.md#story-pins). A key that is not in its pin list is dropped on load.
91
-
92
- Default choice:
93
-
94
- - `comparison`, `filters` and `marketEquation`: always as pins.
95
- - Everything else (views, chart bindings, methods, display options): on the module `inputs`, unless the user wants it shared by several modules.
96
-
97
- ## Comparisons
98
-
99
- `pins.comparison.inputs`:
100
-
101
- ```json
102
- {
103
- "comparisons": [
104
- {
105
- "mode": "dimension",
106
- "start": {"column": "Date", "operator": "between", "value": ["2025-01-01", "2025-01-31"]},
107
- "end": {"column": "Date", "operator": "between", "value": ["2025-02-01", "2025-02-28"]}
108
- }
109
- ],
110
- "relative": false,
111
- "order": "desc"
112
- }
113
- ```
114
-
115
- | Key | Values | Meaning |
116
- | --- | --- | --- |
117
- | `comparisons` | Array | One entry per comparison. The first is the primary one; a second entry adds a secondary comparison |
118
- | `comparisons[].mode` | `"dimension"` · `"metric"` | Compare two groups of rows, or two metric columns |
119
- | `start` / `end` | clause `{column, operator, value}` | The two sides. `column` is the comparison dimension, the same on both sides |
120
- | `operator` | `"between"` · `"in"` | `between [low, high]` for a date or numeric range (inclusive); `in [v1, v2, …]` for a list of values |
121
- | `value` | Array | Exact dataset values (same spelling and date format as the rows) |
122
- | `relative` | boolean | `false`: values are dataset values (use this). `true`: values are indices in the sorted distinct values, `0` = most recent with `order: "desc"` (rolling periods, see below) |
123
- | `order` | `"desc"` · `"asc"` | Sort used by relative indices and by the comparison dimension. Keep `"desc"` |
124
- | `anchor` | `"data"` · `"today"` | Reference instant of relative indices. Default `"data"` |
125
-
126
- Rules:
127
-
128
- - Date comparison: `between` with the first and last date of each period. Two periods of the same length make the clearest analysis.
129
- - Categorical comparison: `in` with one value per side (`["Mobile"]` vs `["Desktop"]`), or several values merged on one side (`["Desktop", "Tablet"]`).
130
- - Both sides use the same `column`. Values must exist in that column.
131
- - Default when the user gives no comparison: the first date column, its older half of dates vs its newer half (Studio applies it automatically when no comparison pin exists; write it explicitly only when you want other periods).
132
- - Rolling periods ("last 7 days vs the 7 days before", whatever the data): `relative: true`, `order: "desc"`, `start: {"column": "Date", "operator": "between", "value": [13, 7]}`, `end: {"column": "Date", "operator": "between", "value": [6, 0]}`.
133
-
134
- Metric comparison (two metric columns of the same rows, for example budget vs actual):
135
-
136
- ```json
137
- {"mode": "metric", "pairs": [{"start": "Revenue_budget", "end": "Revenue_actual", "name": "Revenue"}], "startSegment": "Budget", "endSegment": "Actual"}
138
- ```
139
-
140
- Datama Light shorthand is still accepted and converted on load: `{"context": "Device", "start": ["Mobile"], "end": ["Desktop"], "relative": false}` (date sides as `[first, last]`). Prefer the canonical `comparisons` form above.
141
-
142
- ## Filters
143
-
144
- `pins.filters.inputs.dataFilters` keeps only the matching rows (AND of every clause):
145
-
146
- ```json
147
- {"dataFilters": [
148
- {"id": "filter-country", "column": "Country", "operator": "in", "value": ["France", "Germany"]},
149
- {"id": "filter-date", "column": "Date", "operator": "between", "value": ["2025-01-01", "2025-03-31"]}
150
- ]}
151
- ```
152
-
153
- | Operator | `value` | Keeps |
154
- | --- | --- | --- |
155
- | `in` | Array of values | Rows whose column is one of the values |
156
- | `not` | Array of values | Rows whose column is none of the values |
157
- | `like` | string | Rows whose column contains the text |
158
- | `gte` / `lte` | number or date | Rows above / below the bound (inclusive) |
159
- | `between` | `[low, high]` | Rows inside the range (inclusive) |
160
- | `after` / `before` | date | Rows after / before the date |
161
-
162
- `id` is any unique string. Filter only what the user asked for; a filter on the comparison dimension can empty one side.
163
-
164
- ## What if
165
-
166
- Scenario that changes a KPI on a segment and compares it with the baseline (Compare):
167
-
168
- ```json
169
- {"whatIf": {"scenarios": [{
170
- "name": "Optimize Mobile",
171
- "enabled": true,
172
- "comparison": true,
173
- "baseline": {"name": "", "dimension": "Device", "segments": ["Mobile"]},
174
- "kpis": [{"name": "Basket per Session", "scope": {}, "impact": {"type": "relative", "value": 10}, "pinned": true}]
175
- }]}}
176
- ```
177
-
178
- `kpis[].name` is a step name of the market equation; `impact.type` `"relative"` takes a percentage. Place it in `pins.whatIf`. Use it only when the user asks for a simulation.
179
-
180
- ## Appearance
181
-
182
- Story canvas tokens. Omit `appearance` for the default flat look (no padding, no card). The official Datama "slide" card look is:
183
-
184
- ```json
185
- {"paddingY": 20, "paddingX": 24, "modulePaddingY": 16, "modulePaddingX": 16, "background": "#EEF2F2", "border": true, "radius": 12, "borderWidth": 1, "borderColor": "#C8D6D6", "shadow": true, "shadowSize": 5, "shadowAlign": "center", "shadowColor": "#000000", "shadowOpacity": 25}
186
- ```
187
-
188
- Colors accept `#rgb`, `#rrggbb`, `rgb(...)`, `rgba(...)` or `transparent`; numbers are pixels (opacity in percent).
189
-
190
- ## Complete examples
191
-
192
- Compare, February vs January on Revenue:
193
-
194
- ```json
195
- {
196
- "stories": {
197
- "story-revenue-feb-vs-jan": {
198
- "title": "Revenue: February vs January",
199
- "emoji": "📉",
200
- "pins": {
201
- "comparison": {"inputs": {
202
- "comparisons": [{"mode": "dimension",
203
- "start": {"column": "Date", "operator": "between", "value": ["2025-01-01", "2025-01-31"]},
204
- "end": {"column": "Date", "operator": "between", "value": ["2025-02-01", "2025-02-28"]}}],
205
- "relative": false, "order": "desc"}},
206
- "marketEquation": {
207
- "inputs": {"formula": "[1]*[2]*[3]", "totalStepName": "Revenue", "totalStepUnit": "€"},
208
- "steps": [
209
- {"name": "Session", "numerator": "Session", "denominator": "", "exclude": []},
210
- {"name": "Checkout per Session", "numerator": "Checkout", "denominator": "Session", "exclude": [], "unit": "%"},
211
- {"name": "Revenue per Checkout", "numerator": "Revenue", "denominator": "Checkout", "exclude": [], "unit": "€"}
212
- ]}
213
- },
214
- "modules": [
215
- {"module": "compare.waterfall", "inputs": {"stylePreset": "standard"}}
216
- ]
217
- }
218
- },
219
- "activeStory": "story-revenue-feb-vs-jan",
220
- "inputs": {"language": "en-US"}
221
- }
222
- ```
223
-
224
- Two stories, one Explore breakdown and one Detect, in French:
225
-
226
- ```json
227
- {
228
- "stories": {
229
- "story-breakdown": {"title": "Sessions par pays et canal", "modules": [
230
- {"module": "explore.dimensions", "inputs": {"primary": "Country", "secondary": "Channel", "metric1": "Session", "chart.category": "bar", "chart.layout": "stacked", "trace": "bar", "view": "bar"}}
231
- ]},
232
- "story-anomalies": {"title": "Anomalies des commandes", "modules": ["detect.anomaly"]}
233
- },
234
- "activeStory": "story-breakdown",
235
- "inputs": {"language": "fr-FR"}
236
- }
237
- ```
238
-
239
- ## Datama Light configurations
240
-
241
- A Datama Light settings bag (`{inputs, steps, configuration}` without `stories`) is still accepted: Studio creates one story per bundled solution from it and opens the first (Compare). Use the story shape for anything new: it is the only way to choose the solution, the title and the modules.