Skip to content

Commit

Permalink
fix(runtime): fail to identify annotation as mark (close: #4106) (#4109)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored and hustcc committed Aug 23, 2022
1 parent 7857047 commit 5d44648
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
46 changes: 45 additions & 1 deletion __tests__/unit/runtime/annotationText.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('render', () => {
fillOpacity: 1,
size: 18,
symbol: (x, y, r) => {
const path = [];
const path: any[] = [];
for (let i = 0; i < 5; i++) {
path.push([
i === 0 ? 'M' : 'L',
Expand Down Expand Up @@ -337,6 +337,50 @@ describe('render', () => {
mount(createDiv(), chart);
});

it('render({...}) should render view with single annotation', () => {
const chart = render<G2Spec>({
type: 'layer',
children: [
{
type: 'interval',
coordinate: [{ type: 'theta', innerRadius: 0.5 }],
scale: { color: { guide: null } },
data: [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
],
encode: {
y: 'sold',
color: 'genre',
},
},
{
type: 'annotation.text',
data: [{ x: 0.5, y: 0.5, text: 'G2' }],
scale: {
x: { guide: null },
y: { guide: null },
},
encode: {
x: 'x',
y: 'y',
text: 'text',
color: 'black',
},
style: {
fontSize: 60,
textBaseline: 'middle',
fontWeight: 'bold',
},
},
],
});
mount(createDiv(), chart);
});

afterAll(() => {
// unmountAll();
});
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export async function plot<T extends G2ViewTree>(
// Some helper functions.
const marks = new Set(
Object.keys(library)
.filter((d) => d.startsWith('mark'))
.map((d) => d.split('.').pop()),
.map((d) => /mark\.(.*)/.exec(d)?.[1])
.filter(defined),
);
const typeOf = (node: G2ViewTree) => {
const { type } = node;
Expand Down

0 comments on commit 5d44648

Please sign in to comment.