oncoprintjs 5.0.3 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +14746 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.js +14760 -0
- package/dist/index.js.map +1 -0
- package/dist/js/CachedProperty.d.ts +10 -10
- package/dist/js/binarysearch.d.ts +1 -1
- package/dist/js/bucketsort.d.ts +16 -16
- package/dist/js/clustering.d.ts +14 -14
- package/dist/js/extractrgba.d.ts +4 -4
- package/dist/js/haselementsininterval.d.ts +1 -1
- package/dist/js/heatmapcolors.d.ts +5 -4
- package/dist/js/makesvgelement.d.ts +1 -1
- package/dist/js/modelutils.d.ts +7 -7
- package/dist/js/oncoprint.d.ts +168 -170
- package/dist/js/oncoprintheaderview.d.ts +23 -22
- package/dist/js/oncoprintlabelview.d.ts +79 -78
- package/dist/js/oncoprintlegendrenderer.d.ts +32 -31
- package/dist/js/oncoprintminimapview.d.ts +69 -68
- package/dist/js/oncoprintmodel.d.ts +403 -398
- package/dist/js/oncoprintruleset.d.ts +176 -177
- package/dist/js/oncoprintshape.d.ts +67 -67
- package/dist/js/oncoprintshapetosvg.d.ts +2 -2
- package/dist/js/oncoprintshapetovertexes.d.ts +5 -5
- package/dist/js/oncoprinttooltip.d.ts +23 -22
- package/dist/js/oncoprinttrackinfoview.d.ts +40 -39
- package/dist/js/oncoprinttrackoptionsview.d.ts +58 -57
- package/dist/js/oncoprintwebglcellview.d.ts +168 -167
- package/dist/js/oncoprintzoomslider.d.ts +28 -27
- package/dist/js/polyfill.d.ts +4 -4
- package/dist/js/precomputedcomparator.d.ts +13 -13
- package/dist/js/shaders.d.ts +2 -2
- package/dist/js/svgfactory.d.ts +24 -23
- package/dist/js/utils.d.ts +16 -16
- package/dist/js/workers/clustering-worker.d.ts +19 -20
- package/dist/test/gradientCategoricalRuleset.spec.d.ts +1 -1
- package/dist/test/monolith.spec.d.ts +1 -1
- package/jest.config.ts +2 -0
- package/package.json +20 -26
- package/rollup.config.ts +14 -0
- package/rules/geneticrules.ts +344 -305
- package/server.js +11 -0
- package/src/img/menudots.svg +9 -9
- package/src/img/zoomtofit.svg +12 -12
- package/src/index.tsx +13 -0
- package/src/js/CachedProperty.ts +6 -7
- package/src/js/binarysearch.ts +8 -3
- package/src/js/bucketsort.ts +89 -47
- package/src/js/clustering.ts +22 -10
- package/src/js/extractrgba.ts +16 -12
- package/src/js/haselementsininterval.ts +8 -4
- package/src/js/heatmapcolors.ts +515 -515
- package/src/js/main.js +1 -1
- package/src/js/makesvgelement.ts +2 -2
- package/src/js/modelutils.ts +11 -8
- package/src/js/oncoprint.ts +706 -385
- package/src/js/oncoprintheaderview.ts +165 -125
- package/src/js/oncoprintlabelview.ts +388 -170
- package/src/js/oncoprintlegendrenderer.ts +203 -72
- package/src/js/oncoprintminimapview.ts +965 -423
- package/src/js/oncoprintmodel.ts +905 -532
- package/src/js/oncoprintruleset.ts +694 -379
- package/src/js/oncoprintshape.ts +240 -97
- package/src/js/oncoprintshapetosvg.ts +77 -26
- package/src/js/oncoprintshapetovertexes.ts +153 -48
- package/src/js/oncoprinttooltip.ts +58 -27
- package/src/js/oncoprinttrackinfoview.ts +115 -59
- package/src/js/oncoprinttrackoptionsview.ts +354 -187
- package/src/js/oncoprintwebglcellview.ts +951 -415
- package/src/js/oncoprintzoomslider.ts +172 -107
- package/src/js/polyfill.ts +7 -3
- package/src/js/precomputedcomparator.ts +133 -50
- package/src/js/shaders.ts +2 -4
- package/src/js/svgfactory.ts +128 -73
- package/src/js/utils.ts +51 -31
- package/src/js/workers/clustering-worker.ts +50 -42
- package/src/test/gradientCategoricalRuleset.spec.ts +55 -38
- package/src/test/monolith.spec.ts +718 -285
- package/test/generate_data.py +108 -0
- package/test/glyphmap-data.js +1041 -0
- package/test/heatmap-data.js +1027 -0
- package/test/index.html +21 -0
- package/test/oncoprint-glyphmap.js +79 -0
- package/test/oncoprint-heatmap.js +123 -0
- package/tsconfig.json +4 -10
- package/tsconfig.test.json +11 -0
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/oncoprintjs.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -105
- package/dist/.gitkeep +0 -0
- package/dist/js/minimaputils.d.ts +0 -0
- package/dist/oncoprint.bundle.js +0 -44313
- package/jest.config.js +0 -12
- package/src/js/minimaputils.ts +0 -0
- package/typings/custom.d.ts +0 -7
- package/typings/missing.d.ts +0 -7
- package/webpack.config.js +0 -43
package/src/js/oncoprintshape.ts
CHANGED
|
@@ -1,141 +1,207 @@
|
|
|
1
|
-
import {Datum} from
|
|
2
|
-
import {RGBAColor} from
|
|
1
|
+
import { Datum } from './oncoprintmodel';
|
|
2
|
+
import { RGBAColor } from './oncoprintruleset';
|
|
3
3
|
|
|
4
|
-
type StringParameter =
|
|
5
|
-
type PercentNumberParameter =
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type StringParameter = 'type';
|
|
5
|
+
type PercentNumberParameter =
|
|
6
|
+
| 'width'
|
|
7
|
+
| 'height'
|
|
8
|
+
| 'x'
|
|
9
|
+
| 'y'
|
|
10
|
+
| 'x1'
|
|
11
|
+
| 'x2'
|
|
12
|
+
| 'x3'
|
|
13
|
+
| 'y1'
|
|
14
|
+
| 'y2'
|
|
15
|
+
| 'y3';
|
|
16
|
+
type PlainNumberParameter = 'z' | 'stroke-width' | 'stroke-opacity';
|
|
17
|
+
type RGBAParameter = 'stroke' | 'fill';
|
|
8
18
|
type NumberParameter = PercentNumberParameter | PlainNumberParameter;
|
|
9
19
|
type Parameter = StringParameter | NumberParameter | RGBAParameter;
|
|
10
20
|
|
|
11
|
-
const default_parameter_values:{[x in StringParameter]?:string
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const default_parameter_values: { [x in StringParameter]?: string } &
|
|
22
|
+
{ [x in NumberParameter]?: number } &
|
|
23
|
+
{ [x in RGBAParameter]?: RGBAColor } = {
|
|
24
|
+
width: 100,
|
|
25
|
+
height: 100,
|
|
26
|
+
x: 0,
|
|
27
|
+
y: 0,
|
|
28
|
+
z: 0,
|
|
29
|
+
x1: 0,
|
|
30
|
+
x2: 0,
|
|
31
|
+
x3: 0,
|
|
32
|
+
y1: 0,
|
|
33
|
+
y2: 0,
|
|
34
|
+
y3: 0,
|
|
35
|
+
stroke: [0, 0, 0, 0],
|
|
36
|
+
fill: [23, 23, 23, 1],
|
|
25
37
|
'stroke-width': 0,
|
|
26
|
-
'stroke-opacity': 0
|
|
38
|
+
'stroke-opacity': 0,
|
|
27
39
|
};
|
|
28
40
|
|
|
29
|
-
const percent_parameter_name_to_dimension_index:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const percent_parameter_name_to_dimension_index: {
|
|
42
|
+
[x in PercentNumberParameter]: number;
|
|
43
|
+
} = {
|
|
44
|
+
width: 0,
|
|
45
|
+
x: 0,
|
|
46
|
+
x1: 0,
|
|
47
|
+
x2: 0,
|
|
48
|
+
x3: 0,
|
|
49
|
+
height: 1,
|
|
50
|
+
y: 1,
|
|
51
|
+
y1: 1,
|
|
52
|
+
y2: 1,
|
|
53
|
+
y3: 1,
|
|
40
54
|
};
|
|
41
55
|
|
|
42
|
-
const hash_parameter_order:Parameter[] = [
|
|
43
|
-
|
|
56
|
+
const hash_parameter_order: Parameter[] = [
|
|
57
|
+
'width',
|
|
58
|
+
'height',
|
|
59
|
+
'x',
|
|
60
|
+
'y',
|
|
61
|
+
'z',
|
|
62
|
+
'x1',
|
|
63
|
+
'x2',
|
|
64
|
+
'x3',
|
|
65
|
+
'y1',
|
|
66
|
+
'y2',
|
|
67
|
+
'y3',
|
|
68
|
+
'stroke',
|
|
69
|
+
'fill',
|
|
70
|
+
'stroke-width',
|
|
71
|
+
'stroke-opacity',
|
|
72
|
+
'type',
|
|
44
73
|
];
|
|
45
74
|
|
|
46
|
-
type StringParamFunction = (d:Datum)=>string;
|
|
47
|
-
type NumberParamFunction = (d:Datum)=>number;
|
|
48
|
-
type RGBAParamFunction = (d:Datum)=>RGBAColor;
|
|
49
|
-
type ParamFunction =
|
|
75
|
+
type StringParamFunction = (d: Datum) => string;
|
|
76
|
+
type NumberParamFunction = (d: Datum) => number;
|
|
77
|
+
type RGBAParamFunction = (d: Datum) => RGBAColor;
|
|
78
|
+
type ParamFunction =
|
|
79
|
+
| StringParamFunction
|
|
80
|
+
| NumberParamFunction
|
|
81
|
+
| RGBAParamFunction;
|
|
50
82
|
|
|
51
|
-
export type ShapeParams =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{[x in
|
|
83
|
+
export type ShapeParams = {
|
|
84
|
+
[x in StringParameter]?: string | StringParamFunction;
|
|
85
|
+
} &
|
|
86
|
+
{ [x in NumberParameter]?: number | NumberParamFunction } &
|
|
87
|
+
{ [x in RGBAParameter]?: RGBAColor | RGBAParamFunction };
|
|
55
88
|
|
|
56
89
|
type ShapeParamsWithType = {
|
|
57
|
-
[x in StringParameter]?:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} &
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
[x in StringParameter]?:
|
|
91
|
+
| { type: 'function'; value: StringParamFunction }
|
|
92
|
+
| { type: 'value'; value: string };
|
|
93
|
+
} &
|
|
94
|
+
{
|
|
95
|
+
[x in NumberParameter]?:
|
|
96
|
+
| { type: 'function'; value: NumberParamFunction }
|
|
97
|
+
| { type: 'value'; value: number };
|
|
98
|
+
} &
|
|
99
|
+
{
|
|
100
|
+
[x in RGBAParameter]?:
|
|
101
|
+
| { type: 'function'; value: RGBAParamFunction }
|
|
102
|
+
| { type: 'value'; value: RGBAColor };
|
|
103
|
+
};
|
|
63
104
|
|
|
64
|
-
export type ComputedShapeParams = {[x in StringParameter]?:string
|
|
105
|
+
export type ComputedShapeParams = { [x in StringParameter]?: string } &
|
|
106
|
+
{ [x in NumberParameter]?: number } &
|
|
107
|
+
{ [x in RGBAParameter]?: RGBAColor };
|
|
65
108
|
|
|
66
|
-
function isPercentParam(
|
|
109
|
+
function isPercentParam(
|
|
110
|
+
param_name: string
|
|
111
|
+
): param_name is PercentNumberParameter {
|
|
67
112
|
return param_name in percent_parameter_name_to_dimension_index;
|
|
68
113
|
}
|
|
69
114
|
|
|
70
115
|
export class Shape {
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private onlyDependsOnWidthAndHeight:boolean;
|
|
116
|
+
private static cache: { [hash: string]: ComputedShapeParams } = {}; // shape cache to reuse objects and thus save memory
|
|
117
|
+
private params_with_type: ShapeParamsWithType = {};
|
|
118
|
+
private onlyDependsOnWidthAndHeight: boolean;
|
|
75
119
|
|
|
76
120
|
private instanceCache = {
|
|
77
|
-
lastComputedParams: null as ComputedShapeParams|null,
|
|
78
|
-
lastWidth
|
|
79
|
-
lastHeight
|
|
121
|
+
lastComputedParams: null as ComputedShapeParams | null,
|
|
122
|
+
lastWidth: -1,
|
|
123
|
+
lastHeight: -1,
|
|
80
124
|
};
|
|
81
125
|
|
|
82
|
-
constructor(private params:ShapeParams) {
|
|
126
|
+
constructor(private params: ShapeParams) {
|
|
83
127
|
this.completeWithDefaults();
|
|
84
128
|
this.markParameterTypes();
|
|
85
129
|
}
|
|
86
130
|
|
|
87
|
-
public static hashComputedShape(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
131
|
+
public static hashComputedShape(
|
|
132
|
+
computed_params: ComputedShapeParams,
|
|
133
|
+
z_index?: number | string
|
|
134
|
+
) {
|
|
135
|
+
return (
|
|
136
|
+
hash_parameter_order.reduce(function(
|
|
137
|
+
hash: string,
|
|
138
|
+
param_name: Parameter
|
|
139
|
+
) {
|
|
140
|
+
return hash + ',' + computed_params[param_name];
|
|
141
|
+
},
|
|
142
|
+
'') +
|
|
143
|
+
',' +
|
|
144
|
+
z_index
|
|
145
|
+
);
|
|
91
146
|
}
|
|
92
147
|
|
|
93
|
-
private static getCachedShape(computed_params:ComputedShapeParams) {
|
|
148
|
+
private static getCachedShape(computed_params: ComputedShapeParams) {
|
|
94
149
|
const hash = Shape.hashComputedShape(computed_params);
|
|
95
150
|
Shape.cache[hash] = Shape.cache[hash] || Object.freeze(computed_params);
|
|
96
151
|
return Shape.cache[hash];
|
|
97
152
|
}
|
|
98
153
|
|
|
99
|
-
public getRequiredParameters():Parameter[] {
|
|
100
|
-
throw
|
|
154
|
+
public getRequiredParameters(): Parameter[] {
|
|
155
|
+
throw 'Not defined for base class';
|
|
101
156
|
}
|
|
102
157
|
|
|
103
158
|
public completeWithDefaults() {
|
|
104
159
|
const required_parameters = this.getRequiredParameters();
|
|
105
|
-
for (let i=0; i<required_parameters.length; i++) {
|
|
160
|
+
for (let i = 0; i < required_parameters.length; i++) {
|
|
106
161
|
const param = required_parameters[i];
|
|
107
|
-
this.params[param] = (typeof this.params[param] === 'undefined'
|
|
162
|
+
this.params[param] = (typeof this.params[param] === 'undefined'
|
|
163
|
+
? default_parameter_values[param]
|
|
164
|
+
: this.params[param]) as any;
|
|
108
165
|
}
|
|
109
166
|
}
|
|
110
167
|
public markParameterTypes() {
|
|
111
168
|
const parameters = Object.keys(this.params) as Parameter[];
|
|
112
169
|
let onlyDependsOnWidthAndHeight = true;
|
|
113
|
-
for (let i=0; i<parameters.length; i++) {
|
|
170
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
114
171
|
const param_name = parameters[i];
|
|
115
172
|
const param_val = this.params[param_name];
|
|
116
173
|
if (typeof param_val === 'function') {
|
|
117
|
-
|
|
118
|
-
|
|
174
|
+
this.params_with_type[param_name] = {
|
|
175
|
+
type: 'function',
|
|
176
|
+
value: param_val as any,
|
|
177
|
+
};
|
|
119
178
|
onlyDependsOnWidthAndHeight = false;
|
|
120
179
|
} else {
|
|
121
|
-
|
|
122
|
-
|
|
180
|
+
this.params_with_type[param_name] = {
|
|
181
|
+
type: 'value',
|
|
182
|
+
value: param_val,
|
|
183
|
+
} as any;
|
|
123
184
|
}
|
|
124
185
|
}
|
|
125
186
|
this.onlyDependsOnWidthAndHeight = onlyDependsOnWidthAndHeight;
|
|
126
187
|
}
|
|
127
|
-
public getComputedParams(
|
|
128
|
-
|
|
188
|
+
public getComputedParams(
|
|
189
|
+
d: Datum,
|
|
190
|
+
base_width: number,
|
|
191
|
+
base_height: number
|
|
192
|
+
) {
|
|
193
|
+
if (
|
|
194
|
+
this.onlyDependsOnWidthAndHeight &&
|
|
129
195
|
this.instanceCache.lastWidth === base_width &&
|
|
130
|
-
this.instanceCache.lastHeight === base_height
|
|
131
|
-
|
|
196
|
+
this.instanceCache.lastHeight === base_height
|
|
197
|
+
) {
|
|
132
198
|
return this.instanceCache.lastComputedParams!;
|
|
133
199
|
}
|
|
134
200
|
|
|
135
|
-
const computed_params:Partial<ComputedShapeParams> = {};
|
|
201
|
+
const computed_params: Partial<ComputedShapeParams> = {};
|
|
136
202
|
const param_names = Object.keys(this.params_with_type) as Parameter[];
|
|
137
|
-
const dimensions:[number, number] = [base_width, base_height];
|
|
138
|
-
for (let i=0; i<param_names.length; i++) {
|
|
203
|
+
const dimensions: [number, number] = [base_width, base_height];
|
|
204
|
+
for (let i = 0; i < param_names.length; i++) {
|
|
139
205
|
const param_name = param_names[i];
|
|
140
206
|
const param_val_map = this.params_with_type[param_name];
|
|
141
207
|
let param_val = param_val_map.value;
|
|
@@ -147,7 +213,13 @@ export class Shape {
|
|
|
147
213
|
|
|
148
214
|
if (isPercentParam(param_name)) {
|
|
149
215
|
// if its a percentage param, compute value as percentage of width or height
|
|
150
|
-
param_val =
|
|
216
|
+
param_val =
|
|
217
|
+
((param_val as number) / 100) *
|
|
218
|
+
dimensions[
|
|
219
|
+
percent_parameter_name_to_dimension_index[
|
|
220
|
+
param_name
|
|
221
|
+
]
|
|
222
|
+
];
|
|
151
223
|
}
|
|
152
224
|
}
|
|
153
225
|
//@ts-ignore
|
|
@@ -158,46 +230,117 @@ export class Shape {
|
|
|
158
230
|
// only cache if its cacheable, otherwise it would be a waste of memory to save
|
|
159
231
|
this.instanceCache.lastHeight = base_height;
|
|
160
232
|
this.instanceCache.lastWidth = base_width;
|
|
161
|
-
this.instanceCache.lastComputedParams = Shape.getCachedShape(
|
|
233
|
+
this.instanceCache.lastComputedParams = Shape.getCachedShape(
|
|
234
|
+
computed_params
|
|
235
|
+
);
|
|
162
236
|
}
|
|
163
237
|
|
|
164
238
|
return Shape.getCachedShape(computed_params);
|
|
165
|
-
}
|
|
239
|
+
}
|
|
166
240
|
}
|
|
167
241
|
|
|
168
|
-
type SpecificComputedShapeParams<ShapeParamType> =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
{[x in ShapeParamType &
|
|
242
|
+
type SpecificComputedShapeParams<ShapeParamType> = {
|
|
243
|
+
[x in ShapeParamType & StringParameter]: string;
|
|
244
|
+
} &
|
|
245
|
+
{ [x in ShapeParamType & NumberParameter]: number } &
|
|
246
|
+
{ [x in ShapeParamType & RGBAParameter]: RGBAColor };
|
|
172
247
|
|
|
173
|
-
type RectangleParameter =
|
|
174
|
-
|
|
248
|
+
type RectangleParameter =
|
|
249
|
+
| 'width'
|
|
250
|
+
| 'height'
|
|
251
|
+
| 'x'
|
|
252
|
+
| 'y'
|
|
253
|
+
| 'z'
|
|
254
|
+
| 'stroke'
|
|
255
|
+
| 'stroke-width'
|
|
256
|
+
| 'fill';
|
|
257
|
+
export type ComputedRectangleParams = SpecificComputedShapeParams<
|
|
258
|
+
RectangleParameter
|
|
259
|
+
>;
|
|
175
260
|
export class Rectangle extends Shape {
|
|
176
261
|
public getRequiredParameters(): RectangleParameter[] {
|
|
177
|
-
return [
|
|
262
|
+
return [
|
|
263
|
+
'width',
|
|
264
|
+
'height',
|
|
265
|
+
'x',
|
|
266
|
+
'y',
|
|
267
|
+
'z',
|
|
268
|
+
'stroke',
|
|
269
|
+
'fill',
|
|
270
|
+
'stroke-width',
|
|
271
|
+
];
|
|
178
272
|
}
|
|
179
273
|
}
|
|
180
274
|
|
|
181
|
-
type TriangleParameter =
|
|
182
|
-
|
|
275
|
+
type TriangleParameter =
|
|
276
|
+
| 'x1'
|
|
277
|
+
| 'x2'
|
|
278
|
+
| 'x3'
|
|
279
|
+
| 'y1'
|
|
280
|
+
| 'y2'
|
|
281
|
+
| 'y3'
|
|
282
|
+
| 'z'
|
|
283
|
+
| 'stroke'
|
|
284
|
+
| 'stroke-width'
|
|
285
|
+
| 'fill';
|
|
286
|
+
export type ComputedTriangleParams = SpecificComputedShapeParams<
|
|
287
|
+
TriangleParameter
|
|
288
|
+
>;
|
|
183
289
|
export class Triangle extends Shape {
|
|
184
290
|
public getRequiredParameters(): TriangleParameter[] {
|
|
185
|
-
return [
|
|
291
|
+
return [
|
|
292
|
+
'x1',
|
|
293
|
+
'x2',
|
|
294
|
+
'x3',
|
|
295
|
+
'y1',
|
|
296
|
+
'y2',
|
|
297
|
+
'y3',
|
|
298
|
+
'z',
|
|
299
|
+
'stroke',
|
|
300
|
+
'fill',
|
|
301
|
+
'stroke-width',
|
|
302
|
+
];
|
|
186
303
|
}
|
|
187
304
|
}
|
|
188
305
|
|
|
189
|
-
export type EllipseParameter =
|
|
190
|
-
|
|
306
|
+
export type EllipseParameter =
|
|
307
|
+
| 'width'
|
|
308
|
+
| 'height'
|
|
309
|
+
| 'x'
|
|
310
|
+
| 'y'
|
|
311
|
+
| 'z'
|
|
312
|
+
| 'stroke'
|
|
313
|
+
| 'stroke-width'
|
|
314
|
+
| 'fill';
|
|
315
|
+
export type ComputedEllipseParams = SpecificComputedShapeParams<
|
|
316
|
+
EllipseParameter
|
|
317
|
+
>;
|
|
191
318
|
export class Ellipse extends Shape {
|
|
192
319
|
public getRequiredParameters(): EllipseParameter[] {
|
|
193
|
-
return [
|
|
320
|
+
return [
|
|
321
|
+
'width',
|
|
322
|
+
'height',
|
|
323
|
+
'x',
|
|
324
|
+
'y',
|
|
325
|
+
'z',
|
|
326
|
+
'stroke',
|
|
327
|
+
'fill',
|
|
328
|
+
'stroke-width',
|
|
329
|
+
];
|
|
194
330
|
}
|
|
195
331
|
}
|
|
196
332
|
|
|
197
|
-
export type LineParameter =
|
|
333
|
+
export type LineParameter =
|
|
334
|
+
| 'x1'
|
|
335
|
+
| 'y1'
|
|
336
|
+
| 'x2'
|
|
337
|
+
| 'y2'
|
|
338
|
+
| 'z'
|
|
339
|
+
| 'stroke'
|
|
340
|
+
| 'stroke-width';
|
|
198
341
|
export type ComputedLineParams = SpecificComputedShapeParams<LineParameter>;
|
|
199
342
|
export class Line extends Shape {
|
|
200
343
|
public getRequiredParameters(): LineParameter[] {
|
|
201
344
|
return ['x1', 'x2', 'y1', 'y2', 'z', 'stroke', 'stroke-width'];
|
|
202
345
|
}
|
|
203
|
-
}
|
|
346
|
+
}
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
import makeSVGElement from './makesvgelement';
|
|
2
2
|
import extractRGBA from './extractrgba';
|
|
3
3
|
import {
|
|
4
|
-
ComputedEllipseParams,
|
|
4
|
+
ComputedEllipseParams,
|
|
5
|
+
ComputedLineParams,
|
|
5
6
|
ComputedRectangleParams,
|
|
6
7
|
ComputedShapeParams,
|
|
7
|
-
ComputedTriangleParams
|
|
8
|
-
} from
|
|
9
|
-
import {rgbString} from
|
|
8
|
+
ComputedTriangleParams,
|
|
9
|
+
} from './oncoprintshape';
|
|
10
|
+
import { rgbString } from './utils';
|
|
10
11
|
|
|
11
|
-
function extractColor(str:string) {
|
|
12
|
-
if (str.indexOf(
|
|
12
|
+
function extractColor(str: string) {
|
|
13
|
+
if (str.indexOf('rgb(') > -1) {
|
|
13
14
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
rgb: str,
|
|
16
|
+
opacity: 1,
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
const rgba_arr = extractRGBA(str);
|
|
19
20
|
return {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
rgb:
|
|
22
|
+
'rgb(' +
|
|
23
|
+
rgba_arr[0] * 255 +
|
|
24
|
+
',' +
|
|
25
|
+
rgba_arr[1] * 255 +
|
|
26
|
+
',' +
|
|
27
|
+
rgba_arr[2] * 255 +
|
|
28
|
+
')',
|
|
29
|
+
opacity: rgba_arr[3],
|
|
22
30
|
};
|
|
23
31
|
}
|
|
24
32
|
|
|
25
|
-
function rectangleToSVG(
|
|
33
|
+
function rectangleToSVG(
|
|
34
|
+
params: ComputedRectangleParams,
|
|
35
|
+
offset_x: number,
|
|
36
|
+
offset_y: number
|
|
37
|
+
) {
|
|
26
38
|
return makeSVGElement('rect', {
|
|
27
39
|
width: params.width,
|
|
28
40
|
height: params.height,
|
|
@@ -32,24 +44,38 @@ function rectangleToSVG(params:ComputedRectangleParams, offset_x:number, offset_
|
|
|
32
44
|
'stroke-opacity': params.stroke[3],
|
|
33
45
|
'stroke-width': params['stroke-width'],
|
|
34
46
|
fill: rgbString(params.fill),
|
|
35
|
-
'fill-opacity': params.fill[3]
|
|
47
|
+
'fill-opacity': params.fill[3],
|
|
36
48
|
});
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
function triangleToSVG(
|
|
51
|
+
function triangleToSVG(
|
|
52
|
+
params: ComputedTriangleParams,
|
|
53
|
+
offset_x: number,
|
|
54
|
+
offset_y: number
|
|
55
|
+
) {
|
|
40
56
|
return makeSVGElement('polygon', {
|
|
41
|
-
points: [
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
points: [
|
|
58
|
+
[params.x1 + offset_x, params.y1 + offset_y],
|
|
59
|
+
[params.x2 + offset_x, params.y2 + offset_y],
|
|
60
|
+
[params.x3 + offset_x, params.y3 + offset_y],
|
|
61
|
+
]
|
|
62
|
+
.map(function(a) {
|
|
63
|
+
return a[0] + ',' + a[1];
|
|
64
|
+
})
|
|
65
|
+
.join(' '),
|
|
44
66
|
stroke: rgbString(params.stroke),
|
|
45
67
|
'stroke-opacity': params.stroke[3],
|
|
46
68
|
'stroke-width': params['stroke-width'],
|
|
47
69
|
fill: rgbString(params.fill),
|
|
48
|
-
'fill-opacity': params.fill[3]
|
|
70
|
+
'fill-opacity': params.fill[3],
|
|
49
71
|
});
|
|
50
72
|
}
|
|
51
73
|
|
|
52
|
-
function ellipseToSVG(
|
|
74
|
+
function ellipseToSVG(
|
|
75
|
+
params: ComputedEllipseParams,
|
|
76
|
+
offset_x: number,
|
|
77
|
+
offset_y: number
|
|
78
|
+
) {
|
|
53
79
|
return makeSVGElement('ellipse', {
|
|
54
80
|
rx: params.width / 2,
|
|
55
81
|
height: params.height / 2,
|
|
@@ -59,11 +85,15 @@ function ellipseToSVG(params:ComputedEllipseParams, offset_x:number, offset_y:nu
|
|
|
59
85
|
'stroke-opacity': params.stroke[3],
|
|
60
86
|
'stroke-width': params['stroke-width'],
|
|
61
87
|
fill: rgbString(params.fill),
|
|
62
|
-
'fill-opacity': params.fill[3]
|
|
88
|
+
'fill-opacity': params.fill[3],
|
|
63
89
|
});
|
|
64
90
|
}
|
|
65
91
|
|
|
66
|
-
function lineToSVG(
|
|
92
|
+
function lineToSVG(
|
|
93
|
+
params: ComputedLineParams,
|
|
94
|
+
offset_x: number,
|
|
95
|
+
offset_y: number
|
|
96
|
+
) {
|
|
67
97
|
return makeSVGElement('line', {
|
|
68
98
|
x1: params.x1 + offset_x,
|
|
69
99
|
y1: params.y1 + offset_y,
|
|
@@ -75,15 +105,36 @@ function lineToSVG(params:ComputedLineParams, offset_x:number, offset_y:number)
|
|
|
75
105
|
});
|
|
76
106
|
}
|
|
77
107
|
|
|
78
|
-
export default function shapeToSVG(
|
|
108
|
+
export default function shapeToSVG(
|
|
109
|
+
oncoprint_shape_computed_params: ComputedShapeParams,
|
|
110
|
+
offset_x: number,
|
|
111
|
+
offset_y: number
|
|
112
|
+
) {
|
|
79
113
|
var type = oncoprint_shape_computed_params.type;
|
|
80
114
|
if (type === 'rectangle') {
|
|
81
|
-
return rectangleToSVG(
|
|
115
|
+
return rectangleToSVG(
|
|
116
|
+
oncoprint_shape_computed_params as ComputedRectangleParams,
|
|
117
|
+
offset_x,
|
|
118
|
+
offset_y
|
|
119
|
+
);
|
|
82
120
|
} else if (type === 'triangle') {
|
|
83
|
-
return triangleToSVG(
|
|
121
|
+
return triangleToSVG(
|
|
122
|
+
oncoprint_shape_computed_params as ComputedTriangleParams,
|
|
123
|
+
offset_x,
|
|
124
|
+
offset_y
|
|
125
|
+
);
|
|
84
126
|
} else if (type === 'ellipse') {
|
|
85
|
-
return ellipseToSVG(
|
|
127
|
+
return ellipseToSVG(
|
|
128
|
+
oncoprint_shape_computed_params as ComputedEllipseParams,
|
|
129
|
+
offset_x,
|
|
130
|
+
offset_y
|
|
131
|
+
);
|
|
86
132
|
} else if (type === 'line') {
|
|
87
|
-
return lineToSVG(
|
|
133
|
+
return lineToSVG(
|
|
134
|
+
oncoprint_shape_computed_params as ComputedLineParams,
|
|
135
|
+
offset_x,
|
|
136
|
+
offset_y
|
|
137
|
+
);
|
|
88
138
|
}
|
|
89
|
-
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|