Skip to content

Commit 33dc49b

Browse files
authored
Merge pull request #112 from simzer/main
Presets fixed
2 parents a7e29f2 + 8d92b1e commit 33dc49b

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- Allow more than 5 colors in TS color palette and gradient declaration.
88
The format won`t be checked in compile time, only in runtime.
99
- animation-begin event called after actual animation is set up.
10-
- animation control methods take effect immediately.
10+
- Animation control methods take effect immediately.
11+
- Wrong orientation after switching from circle geometry fixed.
1112

1213
### Added
1314

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Chart presets
2+
3+
In this tutorial, we have shown how you can create charts with Vizzu
4+
using a chart type-agnostic, uniform way, without being limited to a predefined
5+
set of available charts. But sometimes, we know exactly the chart type we
6+
would like to use, and it is easier to start with that, skipping all the
7+
necessary configurations to build it from scratch. For this reason, Vizzu
8+
provides preset configurations for many known chart types
9+
(for all available presets, see the [preset galery](#chart-presets)).
10+
11+
Presets are available through methods of the 'presets' static property of the Vizzu class.
12+
These methods are returning chart configuration objects which can be passed to
13+
the 'animate' method. Let's create a Stacked Bubble chart.
14+
15+
```javascript { "title": "Using a preset" }
16+
chart.animate(Vizzu.presets.stackedBubble({
17+
size: 'Popularity',
18+
color: 'Kinds',
19+
stackedBy: 'Genres'
20+
}));
21+
```
22+
23+
Presets will override all the channels, so previously set series will be
24+
removed from the chart. They will also explicitly set most of the chart
25+
configuration parameters since these will effectively result in the selected
26+
chart type. Exceptions are the 'legend', 'title', 'reverse', and 'sort' properties
27+
which can be set along with the preset. Let's sort the next preset chart by values.
28+
29+
```javascript { "title": "Setting sorting for a preset" }
30+
chart.animate(Vizzu.presets.radialStackedBar({
31+
angle: 'Popularity',
32+
radius: 'Genres',
33+
stackedBy: 'Kinds',
34+
sort: 'byValue'
35+
}));
36+
```
37+
38+
Presets will affect only the chart configuration. If you need to set the styles
39+
or the underlying data, you can use the more verbose syntax below, explicitly
40+
pass the preset to the 'config' property of the animate method's parameter.
41+
42+
```javascript { "title": "Setting style for a preset" }
43+
chart.animate({
44+
config: Vizzu.presets.radialBar({
45+
angle: 'Popularity',
46+
radius: 'Genres',
47+
}),
48+
style: {
49+
'plot.xAxis.interlacing.color': '#ffffff00'
50+
}
51+
});
52+
```
53+
54+
As you can see, the preset won't override the previously configured sorting,
55+
and it won't affect the rest of the chart config parameters mentioned above,
56+
which can be set along with the preset.

src/apps/weblib/js-api/presets.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export default class Presets {
358358
orientation: "horizontal",
359359
rotate: 0,
360360
split: false,
361+
geometry: "rectangle",
361362
channels: {
362363
x: null,
363364
y: null,
@@ -367,16 +368,15 @@ export default class Presets {
367368
noop: null,
368369
label: null,
369370
},
370-
legend: "auto",
371-
title: "",
372-
reverse: false,
373-
sort: "none",
374371
};
375372
}
376373

377374
_createPresetConfig(presetName) {
378375
let presetConfig = this._presetConfigs[presetName];
376+
let nullConfig = this._nullConfig();
377+
let channelBase = Object.assign(nullConfig.channels, presetConfig.channels);
379378
let base = Object.assign(this._nullConfig(), presetConfig);
379+
base.channels = channelBase;
380380
return base;
381381
}
382382

src/apps/weblib/js-api/vizzu.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ type Snapshot = number;
713713
- tooltip: tooltips on the chart appearing on markers on mouse over.
714714
Since the tooltip uses the animation interface, calling animate() while
715715
the tooltip is enabled can cause unwanted behaviour. */
716-
type Feature = 'tooltip';
716+
type Feature = 'tooltip'|'logging'|'rendering';
717717

718718
/** Class representing a single chart in Vizzu. */
719719
export default class Vizzu {

src/chart/options/advancedoptions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ OptionsSetter &OrientationSelector::setHorizontal(bool horizontal)
8686
return *this;
8787
}
8888

89+
OptionsSetter &OrientationSelector::setShape(const ShapeType::Type &type)
90+
{
91+
Base::setShape(type);
92+
fixHorizontal();
93+
return *this;
94+
}
95+
8996
void OrientationSelector::fixHorizontal()
9097
{
9198
auto horOver = horizontalOverride();

src/chart/options/advancedoptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class OrientationSelector : public OptionsSetter
1818
std::optional<size_t> pos = std::nullopt) override;
1919
OptionsSetter &deleteSeries(const ScaleId &scaleId, const Data::SeriesIndex &index) override;
2020
OptionsSetter &setHorizontal(bool horizontal) override;
21+
OptionsSetter &setShape(const ShapeType::Type &type) override;
22+
2123
private:
2224
std::optional<bool> horizontalOverride() const;
2325
void fixHorizontal();

0 commit comments

Comments
 (0)