Skip to content

Commit dfb199f

Browse files
author
minjk-bl
committed
Add helpviewer and doclinks
1 parent e8dafda commit dfb199f

File tree

6 files changed

+123
-8
lines changed

6 files changed

+123
-8
lines changed

visualpython/css/component/popupComponent.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,21 @@
191191
float: left;
192192
margin-top: 9px;
193193
margin-left: 10px;
194+
line-height: 20px;
194195
}
195196
.vp-popup-button[data-type="data"] {
196197
float: left;
197198
margin-top: 9px;
198199
margin-left: 10px;
200+
line-height: 20px;
199201
}
200202
.vp-popup-button[data-type="help"] {
201203
float: left;
202204
margin-top: 9px;
203205
margin-left: 10px;
206+
background-color: #F9B52A;
207+
color: var(--vp-background-color);
208+
line-height: 20px;
204209
}
205210
.vp-popup-button[data-type="cancel"] {
206211
float: right;

visualpython/data/m_library/pandasLibrary.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define([
3232
"name": "Series",
3333
"library": "pandas",
3434
"description": "1 dimension array with same data types",
35+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.Series.html",
3536
"code": "${o0} = pd.Series(${i0}${index}${name})",
3637
"options": [
3738
{
@@ -64,6 +65,7 @@ define([
6465
"name": "DataFrame",
6566
"library": "pandas",
6667
"description": "2 dimension data table type pandas variable",
68+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html",
6769
"code": "${o0} = pd.DataFrame(${i0}${index}${columns})",
6870
"options": [
6971
{
@@ -98,6 +100,7 @@ define([
98100
"name": "Index",
99101
"library": "pandas",
100102
"description": "Create index object",
103+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.Index.html",
101104
"code": "${o0} = pd.Index(${data}${dtype}${copy}${name}${tupleize_cols})",
102105
"options": [
103106
{
@@ -162,6 +165,7 @@ define([
162165
"name": "Read CSV",
163166
"library": "pandas",
164167
"description": "",
168+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html",
165169
"code": "${o0} = pd.read_csv(${i0}${encoding}${header}${sep}${names}${usecols}${index_col}${na_values}${skiprows}${nrows}${chunksize}${etc})",
166170
"options": [
167171
{
@@ -250,6 +254,7 @@ define([
250254
"name": "To CSV",
251255
"library": "pandas",
252256
"description": "dataframe to csv",
257+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html",
253258
"code": "${i0}.to_csv(${i1}${encoding}${header}${index}${sep}${na_rep}${columns}${etc})",
254259
"options": [
255260
{
@@ -320,6 +325,7 @@ define([
320325
"name": "Merge",
321326
"library": "pandas",
322327
"description": "Merge 2 objects",
328+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.merge.html",
323329
"code": "${o0} = pd.merge(${i0}, ${i1}${left_on}${right_on}${how}${sort})",
324330
"options": [
325331
{
@@ -390,6 +396,7 @@ define([
390396
"name": "Join",
391397
"library": "pandas",
392398
"description": "Merge multiple objects",
399+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.join.html",
393400
"code": "${o0} = ${i0}.join(${i1}${on}${how}${sort}${lsuffix}${rsuffix})",
394401
"options": [
395402
{
@@ -469,6 +476,7 @@ define([
469476
"name": "Concat",
470477
"library": "pandas",
471478
"description": "Merge multiple objects",
479+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.concat.html",
472480
"code": "${o0} = pd.concat([${i0}]${index}${axis}${sort}${join})",
473481
"options": [
474482
{
@@ -540,6 +548,7 @@ define([
540548
"name": "Sort By Index",
541549
"library": "pandas",
542550
"description": "Sort by index",
551+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_index.html",
543552
"code": "${o0} = ${i0}.sort_index(${axis}${ascending}${inplace}${kind})",
544553
"options": [
545554
{
@@ -624,6 +633,7 @@ define([
624633
"name": "Group By",
625634
"library": "pandas",
626635
"description": "Group DataFrame/Series",
636+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html",
627637
"code": "${o0} = ${i0}.groupby(${level}${axis}${sort}${as_index})",
628638
"options": [
629639
{
@@ -692,6 +702,7 @@ define([
692702
"name": "Period",
693703
"library": "pandas",
694704
"description": "Create Period object",
705+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.Period.html",
695706
"code": "${o0} = pd.Period(${i0}${freq}${year}${month}${day})",
696707
"options": [
697708
{
@@ -759,6 +770,7 @@ define([
759770
"name": "Drop NA",
760771
"library": "pandas",
761772
"description": "",
773+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html",
762774
"code": "${o0} = ${i0}.dropna(${axis}${how}${thresh})",
763775
"options": [
764776
{
@@ -823,6 +835,7 @@ define([
823835
"name": "Fill NA",
824836
"library": "pandas",
825837
"description": "replace null using value",
838+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.fillna.html",
826839
"code": "${o0} = ${i0}.fillna(${value}${axis}${method}${inplace}${limit})",
827840
"options": [
828841
{
@@ -902,6 +915,7 @@ define([
902915
"name": "Get Duplicates",
903916
"library": "pandas",
904917
"description": "Get duplicates",
918+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.duplicated.html",
905919
"code": "${o0} = ${i0}.duplicated(${keep})",
906920
"options": [
907921
{
@@ -986,6 +1000,7 @@ define([
9861000
"name": "Scala Replace",
9871001
"library": "pandas",
9881002
"description": "Replace scala value",
1003+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html",
9891004
"code": "${o0} = ${i0}.replace(${to_replace}${value}${method})",
9901005
"options": [
9911006
{
@@ -1038,6 +1053,7 @@ define([
10381053
"name": "List-like Replace",
10391054
"library": "pandas",
10401055
"description": "Replace values using list",
1056+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html",
10411057
"code": "${o0} = ${i0}.replace(${to_replace}${value}${method})",
10421058
"options": [
10431059
{
@@ -1090,6 +1106,7 @@ define([
10901106
"name": "Dict-like Replace",
10911107
"library": "pandas",
10921108
"description": "Replace values using dictionary",
1109+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html",
10931110
"code": "${o0} = ${i0}.replace(${to_replace}${value}${method})",
10941111
"options": [
10951112
{
@@ -1142,6 +1159,7 @@ define([
11421159
"name": "Regular Expression Replace",
11431160
"library": "pandas",
11441161
"description": "",
1162+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html",
11451163
"code": "${o0} = ${i0}.replace(${to_replace}${value}${method}${regex})",
11461164
"options": [
11471165
{
@@ -1203,6 +1221,7 @@ define([
12031221
"name": "Sum",
12041222
"library": "pandas",
12051223
"description": "",
1224+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sum.html",
12061225
"code": "${o0} = ${i0}.sum(${axis}${skipna}${level})",
12071226
"options": [
12081227
{
@@ -1262,6 +1281,7 @@ define([
12621281
"name": "Mean",
12631282
"library": "pandas",
12641283
"description": "",
1284+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.mean.html",
12651285
"code": "${o0} = ${i0}.mean(${axis}${skipna}${level})",
12661286
"options": [
12671287
{
@@ -1321,6 +1341,7 @@ define([
13211341
"name": "Count",
13221342
"library": "pandas",
13231343
"description": "Count except NA values",
1344+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.count.html",
13241345
"code": "${o0} = ${i0}.count(${axis}${skipna}${level})",
13251346
"options": [
13261347
{
@@ -1380,6 +1401,7 @@ define([
13801401
"name": "Max",
13811402
"library": "pandas",
13821403
"description": "",
1404+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.max.html",
13831405
"code": "${o0} = ${i0}.max(${axis}${skipna}${level})",
13841406
"options": [
13851407
{
@@ -1439,6 +1461,7 @@ define([
14391461
"name": "Min",
14401462
"library": "pandas",
14411463
"description": "",
1464+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.min.html",
14421465
"code": "${o0} = ${i0}.min(${axis}${skipna}${level})",
14431466
"options": [
14441467
{
@@ -1498,6 +1521,7 @@ define([
14981521
"name": "Median",
14991522
"library": "pandas",
15001523
"description": "Median(50%)",
1524+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.median.html",
15011525
"code": "${o0} = ${i0}.median(${axis}${skipna}${level}${numeric_only})",
15021526
"options": [
15031527
{
@@ -1574,6 +1598,7 @@ define([
15741598
"name": "Std",
15751599
"library": "pandas",
15761600
"description": "",
1601+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.std.html",
15771602
"code": "${o0} = ${i0}.std(${axis}${skipna}${level}${numeric_only})",
15781603
"options": [
15791604
{
@@ -1650,6 +1675,7 @@ define([
16501675
"name": "Quantile",
16511676
"library": "pandas",
16521677
"description": "Calculate quantile between 0 and 1",
1678+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.quantile.html",
16531679
"code": "${o0} = ${i0}.quantile(${q}${axis}${numeric_only}${interpolation})",
16541680
"options": [
16551681
{
@@ -1735,6 +1761,7 @@ define([
17351761
"name": "Drop Row/Column",
17361762
"library": "pandas",
17371763
"description": "Drop row and column",
1764+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.drop.html",
17381765
"code": "${o0} = ${i0}.drop(${i1}${axis})",
17391766
"options": [
17401767
{
@@ -1791,6 +1818,7 @@ define([
17911818
"name": "date_range",
17921819
"library": "pandas",
17931820
"description": "Create DatetimeIndex type timestamp",
1821+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.date_range.html",
17941822
"code": "${o0} = pd.date_range(${start}${end}${periods}${freq})",
17951823
"options": [
17961824
{
@@ -1862,6 +1890,7 @@ define([
18621890
"name": "Sort By Values",
18631891
"library": "pandas",
18641892
"description": "",
1893+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_values.html",
18651894
"code": "${o0} = ${i0}.sort_values(${by}${axis}${ascending}${inplace}${kind})",
18661895
"options": [
18671896
{
@@ -1946,6 +1975,7 @@ define([
19461975
"name": "Is Null",
19471976
"library": "pandas",
19481977
"description": "Find null",
1978+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.isnull.html",
19491979
"code": "${o0} = pd.isnull(${i0})",
19501980
"options": [
19511981
{
@@ -1974,6 +2004,7 @@ define([
19742004
"name": "Not Null",
19752005
"library": "pandas",
19762006
"description": "Find not null",
2007+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.notnull.html",
19772008
"code": "${o0} = pd.notnull(${i0})",
19782009
"options": [
19792010
{
@@ -2002,6 +2033,7 @@ define([
20022033
"name": "Transpose",
20032034
"library": "pandas",
20042035
"description": "Transpose row and column",
2036+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.T.html",
20052037
"code": "${o0} = ${i0}.T",
20062038
"options": [
20072039
{
@@ -2031,6 +2063,7 @@ define([
20312063
"name": "Get columns",
20322064
"library": "pandas",
20332065
"description": "",
2066+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.columns.html",
20342067
"code": "${o0} = ${i0}.columns",
20352068
"options": [
20362069
{
@@ -2375,6 +2408,7 @@ define([
23752408
"name": "Unique",
23762409
"library": "pandas",
23772410
"description": "",
2411+
"docs": "https://pandas.pydata.org/docs/reference/api/pandas.Series.unique.html",
23782412
"code": "${o0} = ${i0}.unique()",
23792413
"options": [
23802414
{

visualpython/js/com/component/LibraryComponent.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define([
3030
/** Write codes executed before rendering */
3131
this.config.dataview = false;
3232
this.config.sizeLevel = 1;
33+
this.config.helpview = true;
3334

3435
this.packageId = this.id;
3536
// deep copy package info
@@ -46,7 +47,42 @@ define([
4647
return;
4748
}
4849
this.config.checkModules = ['pd'];
49-
this.config.docs = 'https://pandas.pydata.org/docs/reference/index.html';
50+
51+
// set docs link
52+
if (this.package.docs === undefined) {
53+
let docsLink = 'https://pandas.pydata.org/docs/reference/api/pandas.';
54+
let docsMatchObj = this.package.code.match(/\= (.+)\.(.+)\(/);
55+
if (docsMatchObj) {
56+
let targetType = docsMatchObj[1]; // ${i0} or pd
57+
let method = docsMatchObj[2];
58+
if (targetType === 'pd') {
59+
docsLink += method + '.html';
60+
} else {
61+
docsLink += 'DataFrame.' + method + '.html';
62+
}
63+
this.config.docs = docsLink;
64+
} else {
65+
this.config.docs = 'https://pandas.pydata.org/docs/reference/index.html';
66+
}
67+
} else {
68+
this.config.docs = this.package.docs;
69+
}
70+
71+
// set helpview content
72+
let helpMatchObj = this.package.code.match(/\= (.+)\.(.+)\(/);
73+
if (helpMatchObj) {
74+
let helpContent = '';
75+
let targetType = helpMatchObj[1]; // ${i0} or pd
76+
let method = helpMatchObj[2];
77+
if (targetType === 'pd') {
78+
helpContent += '_vp_pd.' + method;
79+
} else {
80+
helpContent += '_vp_pd.' + 'DataFrame.' + method;
81+
}
82+
this.config.helpInfo.content = helpContent;
83+
} else {
84+
this.config.helpview = false;
85+
}
5086

5187
vpLog.display(VP_LOG_TYPE.DEVELOP, 'loading state', this.state);
5288
}

visualpython/js/com/component/NumpyComponent.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ define([
5353
}
5454
this.config.checkModules = ['np'];
5555

56+
if (this.package.docs === undefined) {
57+
if (packageName == 'numpy') {
58+
this.config.docs = 'https://numpy.org/doc/';
59+
} else if (packageName == 'python') {
60+
this.config.docs = 'https://docs.python.org/3.11/library/index.html';
61+
}
62+
} else {
63+
this.config.docs = this.package.docs;
64+
}
65+
5666
vpLog.display(VP_LOG_TYPE.DEVELOP, 'loading state', this.state);
5767
}
5868

0 commit comments

Comments
 (0)