vg_helper 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/vg_helper/version.rb +1 -1
- data/lib/vg_helper.rb +154 -66
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4dbf940d1eca83928ba5bbb9881af79c29744be7b4287ff2cc23dc6d055a5a87
|
|
4
|
+
data.tar.gz: b4c473be9618bbba21f1e3bf3d297295d5206317925b95fbb6b88471f011d819
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e82f4ac7b4123e4324114cc7ec897b15e6737d9e2c7c4018b4909e86a61e9bc4576d38222259028c0dab108e95e212c6535e7c1233316170f6e71754b4fb1b76
|
|
7
|
+
data.tar.gz: a63d810f05411f24ffc0eef693c7c06a3de2a50562c7fcb638e86d283295b487dbeae24b267d678044e5fa04a8ef725296e3fafdd43921ae7b92b51e7be47714
|
data/lib/vg_helper/version.rb
CHANGED
data/lib/vg_helper.rb
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
require "vega"
|
|
2
2
|
require "rover"
|
|
3
|
+
require "json"
|
|
3
4
|
|
|
4
5
|
# パラメータを任意に足せる/変更できるようにするには?
|
|
5
|
-
# 第2軸の設定は?
|
|
6
|
-
# 垂直線も入れたい
|
|
7
|
-
# 日付軸の水平線 点線未対応
|
|
8
6
|
|
|
9
7
|
# Use Rover::DataFrame, Not Daru
|
|
10
8
|
# Usage: VGHelper::draw_xdate(df, "datetime", "value", ["category1", "category2"])
|
|
11
9
|
|
|
10
|
+
# TODO:
|
|
11
|
+
# With a secondary y-axis, the horizontal-line layer creates another
|
|
12
|
+
# y-axis overlapping the main y-axis because y scales are independent.
|
|
13
|
+
# Currently both axes intentionally use the same style.
|
|
14
|
+
# Refactor main + horizontal layers into a nested layer in a future release.
|
|
15
|
+
|
|
12
16
|
module VGHelper
|
|
13
17
|
|
|
14
18
|
# functionalize
|
|
@@ -51,6 +55,60 @@ module VGHelper
|
|
|
51
55
|
Time.local(t.year, t.month, t.day).to_i * 1000
|
|
52
56
|
end
|
|
53
57
|
|
|
58
|
+
def mark_preset(kind)
|
|
59
|
+
case kind
|
|
60
|
+
when :line
|
|
61
|
+
{
|
|
62
|
+
type: "line",
|
|
63
|
+
tooltip: true,
|
|
64
|
+
clip: true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
when :line_dot
|
|
68
|
+
{
|
|
69
|
+
type: "line",
|
|
70
|
+
point: {
|
|
71
|
+
filled: true,
|
|
72
|
+
size: 40
|
|
73
|
+
},
|
|
74
|
+
tooltip: true,
|
|
75
|
+
clip: true
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
when :small_dot
|
|
79
|
+
{
|
|
80
|
+
type: "point",
|
|
81
|
+
filled: true,
|
|
82
|
+
size: 25,
|
|
83
|
+
opacity: 0.75,
|
|
84
|
+
tooltip: true,
|
|
85
|
+
clip: true
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
when :large_dot
|
|
89
|
+
{
|
|
90
|
+
type: "point",
|
|
91
|
+
filled: true,
|
|
92
|
+
size: 100,
|
|
93
|
+
opacity: 0.75,
|
|
94
|
+
tooltip: true,
|
|
95
|
+
clip: true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
when :bar
|
|
99
|
+
{
|
|
100
|
+
type: "bar",
|
|
101
|
+
opacity: 0.75,
|
|
102
|
+
tooltip: true,
|
|
103
|
+
clip: true
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
else
|
|
107
|
+
raise ArgumentError,
|
|
108
|
+
"unknown mark preset: #{kind.inspect}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
54
112
|
def draw_xdate(df, x_col, y_col, category_col,
|
|
55
113
|
df2: nil, x2_col: nil, y2_col: nil, y2_category_col: nil,
|
|
56
114
|
horizontallines: [], horizontalcolors: nil,
|
|
@@ -78,11 +136,11 @@ module VGHelper
|
|
|
78
136
|
values1 = df.dup
|
|
79
137
|
|
|
80
138
|
if category_col.is_a?(Array)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
139
|
+
values1["multicategory"] =
|
|
140
|
+
values1[category_col].to_a.map { _1.values.join("_") }
|
|
141
|
+
category_col = "multicategory"
|
|
84
142
|
else
|
|
85
|
-
|
|
143
|
+
category_col = category_col.to_s
|
|
86
144
|
end
|
|
87
145
|
############################
|
|
88
146
|
# Default Settings
|
|
@@ -90,12 +148,27 @@ module VGHelper
|
|
|
90
148
|
|
|
91
149
|
categories ||= values1[category_col].to_a.uniq
|
|
92
150
|
|
|
93
|
-
markkind ||= {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
151
|
+
#markkind ||= {
|
|
152
|
+
# type: "line",
|
|
153
|
+
# point: { filled: true, size: 40 },
|
|
154
|
+
# tooltip: true,
|
|
155
|
+
# clip: true
|
|
156
|
+
#}
|
|
157
|
+
|
|
158
|
+
markkind =
|
|
159
|
+
case markkind
|
|
160
|
+
when nil
|
|
161
|
+
mark_preset(:line_dot)
|
|
162
|
+
when Symbol
|
|
163
|
+
mark_preset(markkind)
|
|
164
|
+
when Hash
|
|
165
|
+
markkind
|
|
166
|
+
else
|
|
167
|
+
raise ArgumentError,
|
|
168
|
+
"markkind must be a Symbol or Hash"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
|
|
99
172
|
title ||= y_col
|
|
100
173
|
|
|
101
174
|
colorset ||= (["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
|
|
@@ -235,6 +308,12 @@ module VGHelper
|
|
|
235
308
|
# x_encoding[:timeUnit] = "utcyearmonthdate"
|
|
236
309
|
#end
|
|
237
310
|
|
|
311
|
+
main_y_axis = {
|
|
312
|
+
orient: reverse_orient ? :right : :left,
|
|
313
|
+
titleFontSize: 16,
|
|
314
|
+
labelFontSize: 14
|
|
315
|
+
}
|
|
316
|
+
|
|
238
317
|
# 水平線データの構築
|
|
239
318
|
horiz_layer = []
|
|
240
319
|
if horizontallines && !horizontallines.empty?
|
|
@@ -264,7 +343,8 @@ module VGHelper
|
|
|
264
343
|
y: {
|
|
265
344
|
field: y_col,
|
|
266
345
|
type: "quantitative",
|
|
267
|
-
scale: { domain: [{expr: "min_y"}, {expr: "max_y"}] }
|
|
346
|
+
scale: { domain: [{expr: "min_y"}, {expr: "max_y"}] },
|
|
347
|
+
axis: main_y_axis
|
|
268
348
|
#axis: nil
|
|
269
349
|
},
|
|
270
350
|
color: {
|
|
@@ -275,7 +355,8 @@ module VGHelper
|
|
|
275
355
|
range: horizontalcolors
|
|
276
356
|
}
|
|
277
357
|
}
|
|
278
|
-
}
|
|
358
|
+
},
|
|
359
|
+
|
|
279
360
|
}]
|
|
280
361
|
end
|
|
281
362
|
|
|
@@ -314,14 +395,6 @@ module VGHelper
|
|
|
314
395
|
# filtering parameter settings
|
|
315
396
|
############################
|
|
316
397
|
|
|
317
|
-
# categ_params = categories.map do |c|
|
|
318
|
-
# {
|
|
319
|
-
# name: "show_#{c}",
|
|
320
|
-
# value: true,
|
|
321
|
-
# bind: { input: "checkbox", name: c }
|
|
322
|
-
# }
|
|
323
|
-
# end
|
|
324
|
-
|
|
325
398
|
params = []
|
|
326
399
|
|
|
327
400
|
if xslide
|
|
@@ -393,9 +466,9 @@ module VGHelper
|
|
|
393
466
|
]
|
|
394
467
|
end
|
|
395
468
|
|
|
396
|
-
categ_params = categories.map do |c|
|
|
469
|
+
categ_params = categories.map.with_index do |c, i|
|
|
397
470
|
ctp = {
|
|
398
|
-
name: "show_#{
|
|
471
|
+
name: "show_#{i}",
|
|
399
472
|
value: true
|
|
400
473
|
}
|
|
401
474
|
|
|
@@ -411,7 +484,9 @@ module VGHelper
|
|
|
411
484
|
|
|
412
485
|
params += categ_params
|
|
413
486
|
|
|
414
|
-
categ_transforms = categories.map {|c|
|
|
487
|
+
categ_transforms = categories.map.with_index {|c, i|
|
|
488
|
+
"(show_#{i} && datum[#{category_col.to_s.to_json}] == #{c.to_s.to_json})" }
|
|
489
|
+
.join(" || ")
|
|
415
490
|
|
|
416
491
|
# 第二縦軸
|
|
417
492
|
bar_layer = []
|
|
@@ -478,11 +553,12 @@ module VGHelper
|
|
|
478
553
|
field: y_col,
|
|
479
554
|
type: "quantitative",
|
|
480
555
|
title: y_col,
|
|
481
|
-
axis:
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
556
|
+
axis: main_y_axis,
|
|
557
|
+
# axis: {
|
|
558
|
+
# orient: reverse_orient ? :right : :left,
|
|
559
|
+
# titleFontSize: 16,
|
|
560
|
+
# labelFontSize: 14
|
|
561
|
+
#},
|
|
486
562
|
scale: { domain: [{expr: "min_y"}, {expr: "max_y"}] }
|
|
487
563
|
},
|
|
488
564
|
color: {
|
|
@@ -726,15 +802,28 @@ module VGHelper
|
|
|
726
802
|
# Mark settings
|
|
727
803
|
############################
|
|
728
804
|
|
|
729
|
-
markkind = {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}.merge(markkind || {})
|
|
805
|
+
# markkind = {
|
|
806
|
+
# type: "line",
|
|
807
|
+
# tooltip: true,
|
|
808
|
+
# point: {
|
|
809
|
+
# filled: false,
|
|
810
|
+
# size: 20
|
|
811
|
+
# },
|
|
812
|
+
# clip: true
|
|
813
|
+
# }.merge(markkind || {})
|
|
814
|
+
|
|
815
|
+
markkind =
|
|
816
|
+
case markkind
|
|
817
|
+
when nil
|
|
818
|
+
mark_preset(:line_dot)
|
|
819
|
+
when Symbol
|
|
820
|
+
mark_preset(markkind)
|
|
821
|
+
when Hash
|
|
822
|
+
markkind
|
|
823
|
+
else
|
|
824
|
+
raise ArgumentError,
|
|
825
|
+
"markkind must be a Symbol or Hash"
|
|
826
|
+
end
|
|
738
827
|
|
|
739
828
|
############################
|
|
740
829
|
# Main dataframe
|
|
@@ -1041,9 +1130,9 @@ module VGHelper
|
|
|
1041
1130
|
|
|
1042
1131
|
if category_check
|
|
1043
1132
|
category_params =
|
|
1044
|
-
categories.map do |c|
|
|
1133
|
+
categories.map.with_index do |c, i|
|
|
1045
1134
|
{
|
|
1046
|
-
name: "show_#{
|
|
1135
|
+
name: "show_#{i}",
|
|
1047
1136
|
value: true,
|
|
1048
1137
|
bind: {
|
|
1049
1138
|
input: "checkbox",
|
|
@@ -1055,8 +1144,8 @@ module VGHelper
|
|
|
1055
1144
|
params += category_params
|
|
1056
1145
|
|
|
1057
1146
|
categ_filter_str =
|
|
1058
|
-
categories.map do |c|
|
|
1059
|
-
"(show_#{
|
|
1147
|
+
categories.map.with_index do |c, i|
|
|
1148
|
+
"(show_#{i} && datum[#{category_col_str.to_s.to_json}] == #{c.to_s.to_json})"
|
|
1060
1149
|
end.join(" || ")
|
|
1061
1150
|
|
|
1062
1151
|
category_transforms = [
|
|
@@ -1067,6 +1156,16 @@ module VGHelper
|
|
|
1067
1156
|
]
|
|
1068
1157
|
end
|
|
1069
1158
|
|
|
1159
|
+
############################
|
|
1160
|
+
# Y Axises
|
|
1161
|
+
############################
|
|
1162
|
+
|
|
1163
|
+
main_y_axis = {
|
|
1164
|
+
orient: reverse_orient ? :right : :left,
|
|
1165
|
+
titleFontSize: 16,
|
|
1166
|
+
labelFontSize: 14
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1070
1169
|
############################
|
|
1071
1170
|
# Common X encoding
|
|
1072
1171
|
############################
|
|
@@ -1183,7 +1282,8 @@ module VGHelper
|
|
|
1183
1282
|
y: {
|
|
1184
1283
|
field: y_col_str,
|
|
1185
1284
|
type: "quantitative",
|
|
1186
|
-
scale: { domain: ydomain }
|
|
1285
|
+
scale: { domain: ydomain },
|
|
1286
|
+
axis: main_y_axis
|
|
1187
1287
|
#axis: nil
|
|
1188
1288
|
},
|
|
1189
1289
|
color: {
|
|
@@ -1295,27 +1395,15 @@ module VGHelper
|
|
|
1295
1395
|
field:
|
|
1296
1396
|
y_col_str,
|
|
1297
1397
|
|
|
1298
|
-
type:
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
titleFontSize:
|
|
1309
|
-
16,
|
|
1310
|
-
|
|
1311
|
-
labelFontSize:
|
|
1312
|
-
14
|
|
1313
|
-
},
|
|
1314
|
-
|
|
1315
|
-
scale: {
|
|
1316
|
-
domain:
|
|
1317
|
-
ydomain
|
|
1318
|
-
}
|
|
1398
|
+
type: "quantitative",
|
|
1399
|
+
# axis: {
|
|
1400
|
+
# orient: reverse_orient ? :right : :left,
|
|
1401
|
+
# title: y_col_str,
|
|
1402
|
+
# titleFontSize: 16,
|
|
1403
|
+
# labelFontSize: 14,
|
|
1404
|
+
# },
|
|
1405
|
+
axis: main_y_axis,
|
|
1406
|
+
scale: { domain: ydomain }
|
|
1319
1407
|
},
|
|
1320
1408
|
|
|
1321
1409
|
color: {
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vg_helper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- showata
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-09-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rover-df
|