Skip to content

Commit 419991b

Browse files
authored
line chart: refactor to move interface for Scale to types file (#4289)
Moved the Scale interface definition to the type so dependents do not have to load the implementation and keep it private to the lib.
1 parent 08ad9ce commit 419991b

File tree

5 files changed

+53
-52
lines changed

5 files changed

+53
-52
lines changed

tensorboard/webapp/widgets/line_chart_v2/lib/coordinator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
import {createScale, Scale} from './scale';
17-
import {Rect, ScaleType} from './internal_types';
16+
import {Rect, Scale, ScaleType} from './internal_types';
17+
import {createScale} from './scale';
1818
import {convertRectToExtent} from './utils';
1919

2020
/**

tensorboard/webapp/widgets/line_chart_v2/lib/scale.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
import {scaleLinear, scaleLog} from '../../../third_party/d3';
16-
17-
import {ScaleType} from './scale_types';
18-
19-
/**
20-
* A `Scale` takes `domain` and sometimes `range` and provide coordinate system
21-
* transformation and convenience method around interval. Similar abstraction as d3.scale.
22-
*
23-
* Unlike d3.scale, it is pure and does not have performance impact.
24-
*
25-
* Important: both `domain` and `range` require to be finite numbers. The order of the
26-
* values do not matter (e.g., domain[1] < domain[0] is okay).
27-
*/
28-
export interface Scale {
29-
/**
30-
* Converts `x` in `domain` coordinates into `range` coordinates.
31-
*/
32-
forward(domain: [number, number], range: [number, number], x: number): number;
33-
34-
/**
35-
* Converts `x` in `range` coordinates into `domain` coordinates.
36-
*/
37-
reverse(domain: [number, number], range: [number, number], x: number): number;
38-
39-
/**
40-
* Attempts to transform domain into nice round numbers. Analogous to `d3.nice`.
41-
*
42-
* @param domain Two finite numbers to compuute round number from.
43-
*/
44-
niceDomain(domain: [number, number]): [number, number];
45-
46-
/**
47-
* Returns "human friendly" numbers between the `domain` that can be used for ticks and
48-
* grid.
49-
*
50-
* In case the spread of an interval is 0 or negligible, it can return an empty array
51-
* depending on an implementation.
52-
*
53-
* Examples:
54-
* ticks([0, 10], 5) -> [0, 2, 4, 6, 8, 10]
55-
* ticks([10, 0], 5) -> [10, 8, 6, 4, 2, 0]
56-
* ticks([10, 10], 5) -> []
57-
*
58-
* @param domain Interval in which tick should be created.
59-
* @param sizeGuidance approximate number of the ticks. Depending on the domain, it
60-
* may return less or more ticks.
61-
*/
62-
ticks(domain: [number, number], sizeGuidance: number): number[];
63-
}
16+
import {Scale, ScaleType} from './scale_types';
6417

6518
export function createScale(type: ScaleType): Scale {
6619
switch (type) {

tensorboard/webapp/widgets/line_chart_v2/lib/scale_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
import {Scale, createScale} from './scale';
17-
import {ScaleType} from './scale_types';
16+
import {createScale} from './scale';
17+
import {Scale, ScaleType} from './scale_types';
1818

1919
describe('line_chart_v2/lib/scale test', () => {
2020
describe('linear', () => {

tensorboard/webapp/widgets/line_chart_v2/lib/scale_types.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,49 @@ export enum ScaleType {
1717
LINEAR,
1818
LOG10,
1919
}
20+
21+
/**
22+
* A `Scale` takes `domain` and sometimes `range` and provide coordinate system
23+
* transformation and convenience method around interval. Similar abstraction as d3.scale.
24+
*
25+
* Unlike d3.scale, it is pure and does not have performance impact.
26+
*
27+
* Important: both `domain` and `range` require to be finite numbers. The order of the
28+
* values do not matter (e.g., domain[1] < domain[0] is okay).
29+
*/
30+
export interface Scale {
31+
/**
32+
* Converts `x` in `domain` coordinates into `range` coordinates.
33+
*/
34+
forward(domain: [number, number], range: [number, number], x: number): number;
35+
36+
/**
37+
* Converts `x` in `range` coordinates into `domain` coordinates.
38+
*/
39+
reverse(domain: [number, number], range: [number, number], x: number): number;
40+
41+
/**
42+
* Attempts to transform domain into nice round numbers. Analogous to `d3.nice`.
43+
*
44+
* @param domain Two finite numbers to compuute round number from.
45+
*/
46+
niceDomain(domain: [number, number]): [number, number];
47+
48+
/**
49+
* Returns "human friendly" numbers between the `domain` that can be used for ticks and
50+
* grid.
51+
*
52+
* In case the spread of an interval is 0 or negligible, it can return an empty array
53+
* depending on an implementation.
54+
*
55+
* Examples:
56+
* ticks([0, 10], 5) -> [0, 2, 4, 6, 8, 10]
57+
* ticks([10, 0], 5) -> [10, 8, 6, 4, 2, 0]
58+
* ticks([10, 10], 5) -> []
59+
*
60+
* @param domain Interval in which tick should be created.
61+
* @param sizeGuidance approximate number of the ticks. Depending on the domain, it
62+
* may return less or more ticks.
63+
*/
64+
ticks(domain: [number, number], sizeGuidance: number): number[];
65+
}

tensorboard/webapp/widgets/line_chart_v2/lib/worker/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("//tensorboard/defs:defs.bzl", "tf_js_binary", "tf_ts_library")
22

33
package(default_visibility = ["//tensorboard/webapp/widgets/line_chart_v2/lib:__subpackages__"])
44

5+
licenses(["notice"])
6+
57
tf_ts_library(
68
name = "message_types",
79
srcs = [

0 commit comments

Comments
 (0)