Skip to content

Commit 3df9874

Browse files
authored
Revise documentation for chart and handler classes
Updated the documentation for creating new chart and handler classes, including method definitions and example code.
1 parent 93a6da9 commit 3df9874

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎index.md‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ Create a new JavaScript class in the widgets folder of the view page. This class
7171

7272
The new class can optionally extend the `D3Visualization` class, which already has methods for fetching the data, creating and clearing the chart svg and the tooltip event handlers. To support the controls and export functionality of the toolbar, a `ControlsHandler` and an `ExportHandler` should be created and updated.
7373

74-
The new class also needs to provide an `init` and a `render` method. The init method will be called once after creation of the widget and should contain the first data fetch and rendering as well as the configuration of the controls. The render method will be called every time the chart data changes, for example after a filter is applied. You can use the following code as a starting point:
74+
The new class also needs to provide an `init` and a `render` method. The init method will be called once after creation of the widget and should contain the first data fetch and rendering as well as the configuration of the controls. The render method will be called every time the chart data changes, for example after a filter is applied.
75+
76+
You can use the following code as a starting point:
7577

7678
```js
7779
export default class NewChart extends D3Visualization {
@@ -117,9 +119,11 @@ Create a new JavaScript class in the `handler/widgets` folder of the editor page
117119

118120
The new handler can optionally extend the `FormHandler` class, which already has some methods for creating formular fields like text inputs and selects and initialization of the buttons.
119121

120-
A static field with default values for the widget configuration is required.
122+
A static field with default values for the widget configuration must be set.
123+
124+
The handler must define three methods: `init`, `createForm`, and `saveForm`. The `init` method is called once when the handler is created and should contain the initialization logic, such as setting up buttons or event listeners. The `createForm` method is executed each time the settings modal is opened. It must return a DOM element that contains the form fields used to modify the configuration. The `saveForm` method is triggered whenever the user saves changes in the modal. It should apply those changes to both the internal state and the DOM.
121125

122-
The handler needs to provide an `init`, a `createForm` and a `saveForm` method. The init method will be called once after creation of the handler and should contain the initialization of the buttons. The other two methods get called when the options formular opens/closes. They are for creating and saving the the formular data. You can use the following code as a starting point:
126+
You can use the following code as a starting point:
123127

124128
```js
125129
export default class NewChartHandler extends FormHandler {
@@ -140,8 +144,10 @@ export default class NewChartHandler extends FormHandler {
140144
this.item = item;
141145
}
142146

143-
init(grid) {
144-
this.initButtons("Chart Options", () => grid.removeWidget(this.item.el));
147+
init() {
148+
this.initButtons("Chart Options", () => {
149+
state.grid.removeWidget(this.item.el);
150+
});
145151

146152
// Set title, render chart preview ...
147153
}
@@ -170,9 +176,19 @@ const widgets = {
170176

171177
### Adding a new generator to the editor
172178

179+
Create a new JavaScript class in the `handler/generators` folder of the editor page. This class will get the generator configuration.
180+
181+
The new handler can optionally extend the `FormHandler` class, which already has some methods for creating formular fields like text inputs and selects and initialization of the buttons.
182+
183+
Static fields for the generator token (will be displayed as an icon for the generator), a short description of the generator (will be displayed in a tooltip) and the default values for the generator configuration must be set.
184+
185+
The handler must define three methods: `init`, `createForm`, and `saveForm`. The `init` method is called once when the handler is created and should contain the initialization logic, such as setting up buttons or event listeners. The `createForm` method is executed each time the settings modal is opened. It must return a DOM element that contains the form fields used to modify the configuration. The `saveForm` method is triggered whenever the user saves changes in the modal. It should apply those changes to both the internal state and the DOM.
186+
187+
You can use the following code as a starting point:
188+
173189
```js
174190
export default class NewGeneratorHandler extends FormHandler {
175-
static token = "TX";
191+
static token = "NG";
176192
static description = "Description of the NewGenerator generator.";
177193
static defaults = {
178194
name: "NewGenerator",
@@ -188,10 +204,13 @@ export default class NewGeneratorHandler extends FormHandler {
188204
this.generator = generator;
189205
}
190206

191-
init(generators) {
207+
init() {
192208
this.initButtons("Generator Options", () => {
209+
// Remove generator from the dom
193210
this.element.remove();
194-
generators.filter((item) => item.id !== this.generator.id);
211+
212+
// Remove generator from the state list
213+
removeGenerator(this.generator);
195214
});
196215

197216
// Set title ...
@@ -218,6 +237,7 @@ const generators = {
218237
};
219238
```
220239

240+
221241
## Contributing
222242
Guidelines for contributing
223243

0 commit comments

Comments
 (0)