forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(partition): monotonic font size scaling (opensearch-project#681)
Ensures that font size doesn't overemphasize certain slices just because the text is shorter or there's more horizontal space. It works by constraining the maximum font size for a slice/sector/rectangle to the smallest of the rendered font sizes of slices/sectors/rectangles within the same ring or treemap layer that belong to larger or equal values. Also, adapts the simple hill climbing optimizer to turn font sizing into an O(log(N)) process: bisecting constrained maximization. Improves on type information via removing `any`s and adding generics. fix opensearch-project#661 Co-authored-by: nickofthyme <[email protected]>
- Loading branch information
1 parent
20cc6ec
commit d46767c
Showing
37 changed files
with
576 additions
and
298 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
Binary file modified
BIN
-8.86 KB
(92%)
...-visual-tests-for-all-stories-legend-piechart-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+571 Bytes
(100%)
...ests-for-all-stories-sunburst-bold-link-value-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-90 Bytes
(100%)
...for-all-stories-sunburst-clockwise-no-special-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+219 Bytes
(100%)
...ll-stories-sunburst-counter-clockwise-special-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.16 KB
(98%)
...stories-sunburst-donut-chart-with-fill-labels-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4.93 KB
(93%)
...-tests-for-all-stories-sunburst-heterogeneous-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+454 Bytes
(100%)
...s-for-all-stories-sunburst-linked-labels-only-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+681 Bytes
(100%)
...ual-tests-for-all-stories-sunburst-most-basic-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-12 KB
(87%)
...ual-tests-for-all-stories-sunburst-percentage-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.61 KB
(96%)
...all-stories-sunburst-sunburst-with-two-layers-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+229 Bytes
(100%)
...ests-for-all-stories-sunburst-value-formatted-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+871 Bytes
(100%)
...alue-formatted-with-categorical-color-palette-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-763 Bytes
(97%)
...-all-stories-sunburst-with-direct-text-labels-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.58 KB
(98%)
...sts-for-all-stories-sunburst-with-fill-labels-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.24 KB
(84%)
...al-tests-for-all-stories-treemap-custom-style-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-13.2 KB
(85%)
...ual-tests-for-all-stories-treemap-groove-text-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-8.5 KB
(90%)
...-tests-for-all-stories-treemap-mid-two-layers-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-17.1 KB
(79%)
...ual-tests-for-all-stories-treemap-multi-color-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.78 KB
(98%)
...ual-tests-for-all-stories-treemap-one-layer-2-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.03 KB
(98%)
...isual-tests-for-all-stories-treemap-one-layer-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-15.5 KB
(81%)
...sual-tests-for-all-stories-treemap-percentage-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.37 KB
(100%)
...ual-tests-for-all-stories-treemap-three-layer-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-31.9 KB
(72%)
...or-all-stories-treemap-two-layers-stress-test-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4.43 KB
(95%)
...ual-tests-for-all-stories-treemap-zero-values-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
127 changes: 127 additions & 0 deletions
127
packages/osd-charts/src/chart_types/partition_chart/layout/utils/calcs.test.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,127 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. 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 { integerSnap, monotonicHillClimb } from './calcs'; | ||
|
||
describe('monotonicHillClimb', () => { | ||
const arbitraryNumber = 27; | ||
|
||
describe('continuous functions', () => { | ||
test('linear case', () => { | ||
expect(monotonicHillClimb((n: number) => n, 100, arbitraryNumber)).toBeCloseTo(arbitraryNumber, 6); | ||
}); | ||
|
||
test('flat case should yield `maxVar`', () => { | ||
expect(monotonicHillClimb(() => arbitraryNumber, 100, 50)).toBeCloseTo(100, 6); | ||
}); | ||
|
||
test('nonlinear case', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n), Math.PI / 2, Math.sqrt(2) / 2)).toBeCloseTo(Math.PI / 4, 6); | ||
}); | ||
|
||
test('non-compliant for even `minVar` should yield NaN', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n), Math.PI / 2, -1)).toBeNaN(); | ||
}); | ||
|
||
test('`loVar > hiVar` should yield NaN', () => { | ||
expect( | ||
monotonicHillClimb( | ||
(n: number) => Math.sin(n), | ||
1, | ||
arbitraryNumber, | ||
(n: number) => n, | ||
2, | ||
), | ||
).toBeNaN(); | ||
}); | ||
|
||
test('compliant for `maxVar` should yield `maxVar`', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n), Math.PI / 2, 1)).toBeCloseTo(Math.PI / 2, 6); | ||
}); | ||
|
||
test('`loVar === hiVar`, compliant', () => { | ||
expect( | ||
monotonicHillClimb( | ||
(n: number) => Math.sin(n), | ||
Math.PI / 2, | ||
1, | ||
(n: number) => n, | ||
Math.PI / 2, | ||
), | ||
).toBe(Math.PI / 2); | ||
}); | ||
|
||
test('`loVar === hiVar`, non-compliant', () => { | ||
expect( | ||
monotonicHillClimb( | ||
(n: number) => Math.sin(n), | ||
Math.PI / 2, | ||
Math.sqrt(2) / 2, | ||
(n: number) => n, | ||
Math.PI / 2, | ||
), | ||
).toBeNaN(); | ||
}); | ||
}); | ||
|
||
describe('integral domain functions', () => { | ||
test('linear case', () => { | ||
expect(monotonicHillClimb((n: number) => n, 100, arbitraryNumber, integerSnap)).toBe(arbitraryNumber); | ||
}); | ||
|
||
test('flat case should yield `maxVar`', () => { | ||
expect(monotonicHillClimb(() => arbitraryNumber, 100, 50)).toBe(100); | ||
}); | ||
|
||
test('nonlinear case', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, Math.sqrt(2) / 2, integerSnap)).toBe(7); | ||
}); | ||
|
||
test('non-compliant for even `minVar` should yield NaN', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n), Math.PI / 2, -1, integerSnap)).toBeNaN(); | ||
}); | ||
|
||
test('`loVar > hiVar` should yield NaN', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n), 1, arbitraryNumber, integerSnap, 2)).toBeNaN(); | ||
}); | ||
|
||
test('compliant for `maxVar` should yield `maxVar`', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, 1, integerSnap)).toBe(15); | ||
}); | ||
|
||
test('`loVar === hiVar`, compliant', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, 1, integerSnap, 15)).toBe(15); | ||
}); | ||
|
||
test('`loVar === hiVar`, non-compliant', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, Math.sqrt(2) / 2, integerSnap, 15)).toBeNaN(); | ||
}); | ||
|
||
test('`loVar + 1 === hiVar`, latter is compliant', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, 1, integerSnap, 14)).toBe(15); | ||
}); | ||
|
||
test('`loVar + 1 === hiVar`, only former is compliant', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, 0.99, integerSnap, 14)).toBe(14); | ||
}); | ||
|
||
test('`loVar + 1 === hiVar`, non-compliant', () => { | ||
expect(monotonicHillClimb((n: number) => Math.sin(n / 10), 15, Math.sqrt(2) / 2, integerSnap, 14)).toBeNaN(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.