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.
Files changed (100) hide show
  1. package/README.md +34 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.es.js +14746 -0
  4. package/dist/index.es.js.map +1 -0
  5. package/dist/index.js +14760 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/js/CachedProperty.d.ts +10 -10
  8. package/dist/js/binarysearch.d.ts +1 -1
  9. package/dist/js/bucketsort.d.ts +16 -16
  10. package/dist/js/clustering.d.ts +14 -14
  11. package/dist/js/extractrgba.d.ts +4 -4
  12. package/dist/js/haselementsininterval.d.ts +1 -1
  13. package/dist/js/heatmapcolors.d.ts +5 -4
  14. package/dist/js/makesvgelement.d.ts +1 -1
  15. package/dist/js/modelutils.d.ts +7 -7
  16. package/dist/js/oncoprint.d.ts +168 -170
  17. package/dist/js/oncoprintheaderview.d.ts +23 -22
  18. package/dist/js/oncoprintlabelview.d.ts +79 -78
  19. package/dist/js/oncoprintlegendrenderer.d.ts +32 -31
  20. package/dist/js/oncoprintminimapview.d.ts +69 -68
  21. package/dist/js/oncoprintmodel.d.ts +403 -398
  22. package/dist/js/oncoprintruleset.d.ts +176 -177
  23. package/dist/js/oncoprintshape.d.ts +67 -67
  24. package/dist/js/oncoprintshapetosvg.d.ts +2 -2
  25. package/dist/js/oncoprintshapetovertexes.d.ts +5 -5
  26. package/dist/js/oncoprinttooltip.d.ts +23 -22
  27. package/dist/js/oncoprinttrackinfoview.d.ts +40 -39
  28. package/dist/js/oncoprinttrackoptionsview.d.ts +58 -57
  29. package/dist/js/oncoprintwebglcellview.d.ts +168 -167
  30. package/dist/js/oncoprintzoomslider.d.ts +28 -27
  31. package/dist/js/polyfill.d.ts +4 -4
  32. package/dist/js/precomputedcomparator.d.ts +13 -13
  33. package/dist/js/shaders.d.ts +2 -2
  34. package/dist/js/svgfactory.d.ts +24 -23
  35. package/dist/js/utils.d.ts +16 -16
  36. package/dist/js/workers/clustering-worker.d.ts +19 -20
  37. package/dist/test/gradientCategoricalRuleset.spec.d.ts +1 -1
  38. package/dist/test/monolith.spec.d.ts +1 -1
  39. package/jest.config.ts +2 -0
  40. package/package.json +20 -26
  41. package/rollup.config.ts +14 -0
  42. package/rules/geneticrules.ts +344 -305
  43. package/server.js +11 -0
  44. package/src/img/menudots.svg +9 -9
  45. package/src/img/zoomtofit.svg +12 -12
  46. package/src/index.tsx +13 -0
  47. package/src/js/CachedProperty.ts +6 -7
  48. package/src/js/binarysearch.ts +8 -3
  49. package/src/js/bucketsort.ts +89 -47
  50. package/src/js/clustering.ts +22 -10
  51. package/src/js/extractrgba.ts +16 -12
  52. package/src/js/haselementsininterval.ts +8 -4
  53. package/src/js/heatmapcolors.ts +515 -515
  54. package/src/js/main.js +1 -1
  55. package/src/js/makesvgelement.ts +2 -2
  56. package/src/js/modelutils.ts +11 -8
  57. package/src/js/oncoprint.ts +706 -385
  58. package/src/js/oncoprintheaderview.ts +165 -125
  59. package/src/js/oncoprintlabelview.ts +388 -170
  60. package/src/js/oncoprintlegendrenderer.ts +203 -72
  61. package/src/js/oncoprintminimapview.ts +965 -423
  62. package/src/js/oncoprintmodel.ts +905 -532
  63. package/src/js/oncoprintruleset.ts +694 -379
  64. package/src/js/oncoprintshape.ts +240 -97
  65. package/src/js/oncoprintshapetosvg.ts +77 -26
  66. package/src/js/oncoprintshapetovertexes.ts +153 -48
  67. package/src/js/oncoprinttooltip.ts +58 -27
  68. package/src/js/oncoprinttrackinfoview.ts +115 -59
  69. package/src/js/oncoprinttrackoptionsview.ts +354 -187
  70. package/src/js/oncoprintwebglcellview.ts +951 -415
  71. package/src/js/oncoprintzoomslider.ts +172 -107
  72. package/src/js/polyfill.ts +7 -3
  73. package/src/js/precomputedcomparator.ts +133 -50
  74. package/src/js/shaders.ts +2 -4
  75. package/src/js/svgfactory.ts +128 -73
  76. package/src/js/utils.ts +51 -31
  77. package/src/js/workers/clustering-worker.ts +50 -42
  78. package/src/test/gradientCategoricalRuleset.spec.ts +55 -38
  79. package/src/test/monolith.spec.ts +718 -285
  80. package/test/generate_data.py +108 -0
  81. package/test/glyphmap-data.js +1041 -0
  82. package/test/heatmap-data.js +1027 -0
  83. package/test/index.html +21 -0
  84. package/test/oncoprint-glyphmap.js +79 -0
  85. package/test/oncoprint-heatmap.js +123 -0
  86. package/tsconfig.json +4 -10
  87. package/tsconfig.test.json +11 -0
  88. package/.idea/misc.xml +0 -6
  89. package/.idea/modules.xml +0 -8
  90. package/.idea/oncoprintjs.iml +0 -12
  91. package/.idea/vcs.xml +0 -6
  92. package/.idea/workspace.xml +0 -105
  93. package/dist/.gitkeep +0 -0
  94. package/dist/js/minimaputils.d.ts +0 -0
  95. package/dist/oncoprint.bundle.js +0 -44313
  96. package/jest.config.js +0 -12
  97. package/src/js/minimaputils.ts +0 -0
  98. package/typings/custom.d.ts +0 -7
  99. package/typings/missing.d.ts +0 -7
  100. package/webpack.config.js +0 -43
@@ -1,141 +1,207 @@
1
- import {Datum} from "./oncoprintmodel";
2
- import {RGBAColor} from "./oncoprintruleset";
1
+ import { Datum } from './oncoprintmodel';
2
+ import { RGBAColor } from './oncoprintruleset';
3
3
 
4
- type StringParameter = "type";
5
- type PercentNumberParameter = "width" | "height" | "x" | "y" | "x1" | "x2" | "x3" | "y1" | "y2" | "y3";
6
- type PlainNumberParameter = "z" | "stroke-width" | "stroke-opacity";
7
- type RGBAParameter = "stroke" | "fill";
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} & {[x in NumberParameter]?:number} & {[x in RGBAParameter]?:RGBAColor} = {
12
- 'width': 100,
13
- 'height': 100,
14
- 'x': 0,
15
- 'y': 0,
16
- 'z': 0,
17
- 'x1': 0,
18
- 'x2': 0,
19
- 'x3': 0,
20
- 'y1': 0,
21
- 'y2': 0,
22
- 'y3': 0,
23
- 'stroke': [0,0,0,0],
24
- 'fill': [23,23,23,1],
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:{[x in PercentNumberParameter]:number} = {
30
- 'width': 0,
31
- 'x':0,
32
- 'x1':0,
33
- 'x2':0,
34
- 'x3':0,
35
- 'height':1,
36
- 'y':1,
37
- 'y1':1,
38
- 'y2':1,
39
- 'y3':1
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
- "width", "height", "x", "y", "z", "x1", "x2", "x3", "y1", "y2", "y3", "stroke", "fill", "stroke-width", "stroke-opacity", "type"
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 = StringParamFunction | NumberParamFunction | RGBAParamFunction;
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
- {[x in StringParameter]?:string|StringParamFunction} &
53
- {[x in NumberParameter]?:number|NumberParamFunction} &
54
- {[x in RGBAParameter]?:RGBAColor|RGBAParamFunction };
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]?:({ type:"function", value:StringParamFunction} | {type:"value", value:string})
58
- } & {
59
- [x in NumberParameter]?:({ type:"function", value:NumberParamFunction} | {type:"value", value:number})
60
- } & {
61
- [x in RGBAParameter]?:({ type:"function", value:RGBAParamFunction} | {type:"value", value:RGBAColor})
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} & {[x in NumberParameter]?:number} & {[x in RGBAParameter]?:RGBAColor};
105
+ export type ComputedShapeParams = { [x in StringParameter]?: string } &
106
+ { [x in NumberParameter]?: number } &
107
+ { [x in RGBAParameter]?: RGBAColor };
65
108
 
66
- function isPercentParam(param_name:string):param_name is PercentNumberParameter {
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 static cache:{[hash:string]:ComputedShapeParams} = {}; // shape cache to reuse objects and thus save memory
73
- private params_with_type:ShapeParamsWithType = {};
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:-1,
79
- lastHeight:-1
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(computed_params:ComputedShapeParams, z_index?:number|string) {
88
- return hash_parameter_order.reduce(function (hash:string, param_name:Parameter) {
89
- return hash + "," + computed_params[param_name];
90
- }, "") + "," + z_index;
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 "Not defined for base class";
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' ? default_parameter_values[param] : this.params[param]) as any;
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
- //@ts-ignore
118
- this.params_with_type[param_name] = {'type':'function', 'value':param_val};
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
- //@ts-ignore
122
- this.params_with_type[param_name] = {'type':'value', 'value': param_val};
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(d:Datum, base_width:number, base_height:number) {
128
- if (this.onlyDependsOnWidthAndHeight &&
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 = (param_val as number)/100 * dimensions[percent_parameter_name_to_dimension_index[param_name]];
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(computed_params);
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
- {[x in ShapeParamType & StringParameter]:string} &
170
- {[x in ShapeParamType & NumberParameter]:number} &
171
- {[x in ShapeParamType & RGBAParameter]:RGBAColor};
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 = "width" | "height" | "x" | "y" | "z" | "stroke" | "stroke-width" | "fill";
174
- export type ComputedRectangleParams = SpecificComputedShapeParams<RectangleParameter>;
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 ['width', 'height', 'x', 'y', 'z', 'stroke', 'fill', 'stroke-width'];
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 = "x1" | "x2" | "x3" | "y1" | "y2" | "y3" | "z" | "stroke" | "stroke-width" | "fill";
182
- export type ComputedTriangleParams = SpecificComputedShapeParams<TriangleParameter>;
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 ['x1', 'x2', 'x3', 'y1', 'y2', 'y3', 'z', 'stroke', 'fill', 'stroke-width'];
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 = "width" | "height" | "x" | "y" | "z" | "stroke" | "stroke-width" | "fill";
190
- export type ComputedEllipseParams = SpecificComputedShapeParams<EllipseParameter>;
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 ['width', 'height', 'x', 'y', 'z', 'stroke', 'fill', 'stroke-width'];
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 = "x1" | "y1" | "x2" | "y2" | "z" | "stroke" | "stroke-width";
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, ComputedLineParams,
4
+ ComputedEllipseParams,
5
+ ComputedLineParams,
5
6
  ComputedRectangleParams,
6
7
  ComputedShapeParams,
7
- ComputedTriangleParams
8
- } from "./oncoprintshape";
9
- import {rgbString} from "./utils";
8
+ ComputedTriangleParams,
9
+ } from './oncoprintshape';
10
+ import { rgbString } from './utils';
10
11
 
11
- function extractColor(str:string) {
12
- if (str.indexOf("rgb(") > -1) {
12
+ function extractColor(str: string) {
13
+ if (str.indexOf('rgb(') > -1) {
13
14
  return {
14
- 'rgb': str,
15
- 'opacity': 1
15
+ rgb: str,
16
+ opacity: 1,
16
17
  };
17
18
  }
18
19
  const rgba_arr = extractRGBA(str);
19
20
  return {
20
- 'rgb': 'rgb('+rgba_arr[0]*255+','+rgba_arr[1]*255+','+rgba_arr[2]*255+')',
21
- 'opacity': rgba_arr[3]
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(params:ComputedRectangleParams, offset_x:number, offset_y:number) {
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(params:ComputedTriangleParams, offset_x:number, offset_y:number) {
51
+ function triangleToSVG(
52
+ params: ComputedTriangleParams,
53
+ offset_x: number,
54
+ offset_y: number
55
+ ) {
40
56
  return makeSVGElement('polygon', {
41
- points: [[params.x1 + offset_x, params.y1 + offset_y], [params.x2 + offset_x, params.y2 + offset_y], [params.x3 + offset_x, params.y3 + offset_y]].map(function (a) {
42
- return a[0] + ',' + a[1];
43
- }).join(' '),
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(params:ComputedEllipseParams, offset_x:number, offset_y:number) {
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(params:ComputedLineParams, offset_x:number, offset_y:number) {
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(oncoprint_shape_computed_params:ComputedShapeParams, offset_x:number, offset_y:number) {
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(oncoprint_shape_computed_params as ComputedRectangleParams, offset_x, offset_y);
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(oncoprint_shape_computed_params as ComputedTriangleParams, offset_x, offset_y);
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(oncoprint_shape_computed_params as ComputedEllipseParams, offset_x, offset_y);
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(oncoprint_shape_computed_params as ComputedLineParams, offset_x, offset_y);
133
+ return lineToSVG(
134
+ oncoprint_shape_computed_params as ComputedLineParams,
135
+ offset_x,
136
+ offset_y
137
+ );
88
138
  }
89
- }
139
+ return undefined;
140
+ }