-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change font size on responsive for sankey and sunburst chart (#977
) * feat: change font size on responsive * remove logs * Sunburst * WIP * Sankey label hide * Format correct object * add styled components * Replace document with container * Return overlapping elements * Drag * Fix lint * Fix test & make tooltip absoliute based on cursor position * Update storybook for charts * Resizable in separate page * Fix responsive class for sunburst * type
- Loading branch information
1 parent
e67064e
commit 2625698
Showing
9 changed files
with
332 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...porary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/tests/utils.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getOverlappingElements, isOverlapping } from '../utils'; | ||
|
||
const overlapRects = [ | ||
{ | ||
x: 10, | ||
y: 10, | ||
width: 10, | ||
height: 10, | ||
}, | ||
{ | ||
x: 12, | ||
y: 12, | ||
width: 12, | ||
height: 12, | ||
}, | ||
{ | ||
x: 32, | ||
y: 32, | ||
width: 32, | ||
height: 32, | ||
}, | ||
]; | ||
|
||
const notOverlapRects = [ | ||
{ | ||
x: 10, | ||
y: 10, | ||
width: 10, | ||
height: 10, | ||
}, | ||
{ | ||
x: 24, | ||
y: 15, | ||
width: 15, | ||
height: 15, | ||
}, | ||
{ | ||
x: 32, | ||
y: 32, | ||
width: 32, | ||
height: 32, | ||
}, | ||
]; | ||
|
||
const createSVGs = objects => | ||
objects.map(data => { | ||
const el = document.createElementNS('http://www.w3.org/2000/svg', 'text'); | ||
el.getBoundingClientRect = jest.fn(() => data); | ||
|
||
return el; | ||
}); | ||
|
||
// https://www.khanacademy.org/computer-programming/rectx-y-width-height-radius/839496660 | ||
describe('legacy-plugin-chart-sankey/utils', () => { | ||
it('isOverlapping to be truthy', () => { | ||
const [rect1, rect2] = overlapRects; | ||
expect(isOverlapping(rect1, rect2)).toBeTruthy(); | ||
}); | ||
|
||
it('isOverlapping to be falsy', () => { | ||
const [rect1, rect2] = notOverlapRects; | ||
expect(isOverlapping(rect1, rect2)).toBeFalsy(); | ||
}); | ||
|
||
it('getOverlappingElements to be truthy', () => { | ||
const elements = createSVGs(overlapRects); | ||
expect(getOverlappingElements(elements).length).toBe(2); | ||
}); | ||
|
||
it('getOverlappingElements to be falsy', () => { | ||
const elements = createSVGs(notOverlapRects); | ||
expect(getOverlappingElements(elements).length).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rontend/temporary_superset_ui/superset-ui/plugins/legacy-plugin-chart-sankey/src/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
type Rect = { | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
export function getLabelFontSize(width: number): number { | ||
if (width > 550) { | ||
return 0.8; | ||
} | ||
|
||
if (width > 400 && width <= 550) { | ||
return 0.55; | ||
} | ||
|
||
return 0.45; | ||
} | ||
|
||
export const isOverlapping = (rect1: Rect, rect2: Rect): boolean => { | ||
const { x: x1, y: y1, width: width1, height: height1 } = rect1; | ||
const { x: x2, y: y2, width: width2, height: height2 } = rect2; | ||
|
||
return !(x1 > x2 + width2 || x1 + width1 < x2 || y1 > y2 + height2 || y1 + height1 < y2); | ||
}; | ||
|
||
export const getRectangle = (element: SVGElement, offset = 0): Rect => { | ||
const { x, y, width, height } = element.getBoundingClientRect(); | ||
|
||
return { | ||
x, | ||
y: y + offset, | ||
width, | ||
height: height - offset * 2, | ||
}; | ||
}; | ||
|
||
export const getOverlappingElements = (elements: SVGElement[]): SVGElement[] => { | ||
const overlappingElements: SVGElement[] = []; | ||
|
||
elements.forEach((e1, index1) => { | ||
const rect1: Rect = getRectangle(e1, 1); | ||
|
||
elements.forEach((e2, index2) => { | ||
if (index2 <= index1) return; | ||
const rect2: Rect = getRectangle(e2, 1); | ||
|
||
if (isOverlapping(rect1, rect2)) { | ||
overlappingElements.push(elements[index2]); | ||
overlappingElements.push(elements[index1]); | ||
} | ||
}); | ||
}); | ||
|
||
return overlappingElements; | ||
}; |
Oops, something went wrong.