Skip to content

Commit 6c07154

Browse files
authored
Merge branch 'main' into add_chart_tests
2 parents e96d46b + e07770e commit 6c07154

File tree

13 files changed

+56
-48
lines changed

13 files changed

+56
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- When X axis dimension labels are close to each other, they are rotated to avoid overlapping.
2929
- The event handler registration order changed. Now the handlers are called in the opposite order of the registration.
3030
- Added the padded rectangle, the bounding rectangle and the align parameter to the draw text event object.
31+
- Tooltip works on marker labels too.
3132

3233
## [0.9.3] - 2023-12-20
3334

src/apps/weblib/interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void Interface::addRecord(ObjectRegistry::Handle chart,
322322
const char *Interface::dataMetaInfo(ObjectRegistry::Handle chart)
323323
{
324324
thread_local std::string res;
325-
res = Conv::toJSON(getChart(chart)->getTable().getInfos());
325+
res = getChart(chart)->getTable().getInfos();
326326
return res.c_str();
327327
}
328328

src/apps/weblib/ts-api/plugins/tooltip.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Snapshot } from '../module/cchart.js'
2-
import { Element, Marker, PointerEvent } from '../events.js'
2+
import { Element, Marker, MarkerLabel, PointerEvent } from '../events.js'
33
import { Plugin, type PluginHooks, type PrepareAnimationContext } from '../plugins.js'
44

55
import Vizzu from '../vizzu.js'
@@ -71,8 +71,8 @@ export class Tooltip implements Plugin {
7171
_mouseon(param: PointerEvent): void {
7272
this._id++
7373
const id = this._id
74-
if (param.target && this._isMarker(param.target)) {
75-
const markerId = param.target.index
74+
const markerId = this._getMarkerId(param.target)
75+
if (markerId !== null) {
7676
setTimeout(() => {
7777
this._in(id, markerId)
7878
}, 0)
@@ -86,6 +86,8 @@ export class Tooltip implements Plugin {
8686
_getMarkerId(target: Element | null): number | null {
8787
if (target && this._isMarker(target)) {
8888
return target.index
89+
} else if (target && this._isMarkerLabel(target)) {
90+
return target.parent.index
8991
} else {
9092
return null
9193
}
@@ -95,6 +97,10 @@ export class Tooltip implements Plugin {
9597
return target.tagName === 'plot-marker'
9698
}
9799

100+
_isMarkerLabel(target: Element): target is MarkerLabel {
101+
return target.tagName === 'plot-marker-label'
102+
}
103+
98104
_in(id: number, markerId: number): void {
99105
if (this._id === id) {
100106
if (!this._animating) {

src/chart/generator/marker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,17 @@ Conv::JSONObj &&Marker::appendToJSON(Conv::JSONObj &&jsonObj) const
158158
std::ranges::views::transform(cellInfo.categories,
159159
[this](const auto &pair)
160160
{
161-
return std::make_pair(pair.first.toString(table),
161+
return std::make_pair(
162+
pair.first.toString(table.get()),
162163
table.get()
163164
.getInfo(pair.first.getColIndex().value())
164165
.categories()[pair.second]);
165166
}))("values",
166167
std::ranges::views::transform(cellInfo.values,
167168
[this](const auto &pair)
168169
{
169-
return std::make_pair(pair.first.toString(table),
170+
return std::make_pair(
171+
pair.first.toString(table.get()),
170172
pair.second);
171173
}))("index", idx);
172174
}

src/chart/options/optionssetter.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@
55

66
#include "options.h"
77

8-
namespace Vizzu
9-
{
10-
11-
namespace Data
12-
{
13-
class DataTable;
14-
}
15-
16-
namespace Gen
8+
namespace Vizzu::Gen
179
{
1810

1911
class OptionsSetter
@@ -59,7 +51,6 @@ class OptionsSetter
5951
const Data::DataTable *table{};
6052
};
6153

62-
}
6354
}
6455

6556
#endif

src/data/datacube/datacube.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ DataCube::DataCube(const DataTable &table,
2323
auto size =
2424
idx.getType().isReal()
2525
? table.getInfo(idx.getColIndex().value())
26-
.dimensionValueCnt()
26+
.categories()
27+
.size()
2728
: idx.getType() == SeriesType::Index
2829
? table.getRowCount()
2930
: throw std::logic_error("internal error: cannot "
@@ -63,7 +64,7 @@ DataCube::DataCube(const DataTable &table,
6364
}
6465
}
6566

66-
MultiIndex DataCube::getIndex(const TableRow<double> &row,
67+
MultiIndex DataCube::getIndex(const DataTable::Row &row,
6768
const std::vector<SeriesIndex> &indices,
6869
size_t rowIndex)
6970
{
@@ -238,9 +239,9 @@ MultiDim::SubSliceIndex DataCube::subSliceIndex(
238239
for (const auto &pair : stringMarkerId) {
239240
auto colIdx = table->getColumn(pair.first);
240241
auto seriesIdx = table->getIndex(colIdx);
241-
const auto &values =
242-
table->getInfo(colIdx).dimensionValueIndexes();
243-
auto valIdx = values.at(pair.second);
242+
auto valIdx =
243+
table->getInfo(colIdx).dimensionValueIndexes().at(
244+
pair.second);
244245
auto dimIdx = getDimBySeries(SeriesIndex(seriesIdx));
245246
index.push_back(
246247
MultiDim::SliceIndex{dimIdx, MultiDim::Index{valIdx}});

src/data/datacube/datacube.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
namespace Vizzu::Data
1616
{
1717

18-
class DataTable;
1918
template <typename T> class TableRow;
2019

2120
using SubCellIndex =
@@ -101,7 +100,7 @@ class DataCube
101100
std::map<SeriesIndex, SubCellIndex> subIndexBySeries;
102101
std::vector<SeriesIndex> seriesBySubIndex;
103102

104-
static MultiDim::MultiIndex getIndex(const TableRow<double> &row,
103+
static MultiDim::MultiIndex getIndex(const DataTable::Row &row,
105104
const std::vector<SeriesIndex> &indices,
106105
size_t rowIndex);
107106

src/data/datacube/datastat.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ DataStat::DataStat(const DataTable &table,
1111
for (const auto &idx : indices) {
1212
if (idx.getType().isReal()) {
1313
auto valueCnt = table.getInfo(idx.getColIndex().value())
14-
.dimensionValueCnt();
14+
.categories()
15+
.size();
1516
usedColumnIDs.insert(
1617
{static_cast<size_t>(idx.getColIndex().value()),
1718
usedValues.size()});
@@ -37,7 +38,7 @@ size_t DataStat::usedValueCntOf(const SeriesIndex &index) const
3738
return 0;
3839
}
3940

40-
void DataStat::trackIndex(const TableRow<double> &row,
41+
void DataStat::trackIndex(const DataTable::Row &row,
4142
const std::vector<SeriesIndex> &indices)
4243
{
4344
for (auto i = 0U; i < indices.size(); ++i) {

src/data/datacube/datastat.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
namespace Vizzu::Data
1010
{
1111

12-
class DataTable;
13-
1412
class DataStat
1513
{
1614
public:
@@ -21,7 +19,7 @@ class DataStat
2119
size_t usedValueCntOf(const SeriesIndex &index) const;
2220

2321
private:
24-
void trackIndex(const TableRow<double> &row,
22+
void trackIndex(const DataTable::Row &row,
2523
const std::vector<SeriesIndex> &indices);
2624

2725
void countValues();

src/data/table/columninfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ const ColumnInfo::Values &ColumnInfo::categories() const
7171
return values;
7272
}
7373

74-
size_t ColumnInfo::dimensionValueCnt() const { return values.size(); }
75-
7674
std::string ColumnInfo::getName() const { return name; }
7775

78-
std::string ColumnInfo::getUnit() const { return unit; }
76+
const std::string &ColumnInfo::getUnit() const { return unit; }
7977

8078
Math::Range<double> ColumnInfo::getRange() const { return range; }
8179

0 commit comments

Comments
 (0)