存档

‘Ubuntu’ 分类的存档

跨越浏览器的d3.js图表显示

2012年1月22日 没有评论
No Gravatar

最近一段时间对正在采用的图表组件不满意了。看过d3.js之后,别的图表显示确实很难入眼。问题的难度是d3.js采用的SVG技术导致它只能在几种浏览器里使用,在我们客户大量使用的IE,特别是IE6的客户里很难显示正常。SVG之于IE的问题要想解决有几个思路:
一个可以想像的方式是采用svgweb,不过在调试的时候发现IE在加载d3.js经常出非常小且2的问题。比如一个函数里使用了两次while(++i < j)之后,d3.js就不能正常载入,提示的错误居然是“缺少’)'”。
二一个是在后端生成图片,这样就不存在SVG格式的问题了。这个世界近两年来流行的node.js可以在后台执行javascript,这让人有柳暗花明的感觉。
第三个方式是我们后端生成svg文件,前端使用svgweb加载。

沿着第一个思路太耗费时间,不符合想快速解决问题的思路。所以第二、三个方法做了重点测试。
首先可以参照的方法是d3.js里自带的node-canvas例子us-counties。如果将这个图片通过http输出到客户端第二个方法的技术问题就解决了。
然后是@mattbaker提交的gist 1511770,这个例子通过node.js完成了svg文件的生成。加上svgweb,在IE里显示svg图表的问题也就完全不存在了。
@mattbaker提供的gist 1509145提供了直接通过http输出png图片的例子。
我们聊加改造,其实是去除了一些功能就可以得到如下代码:

var http = require('http'),
    url = require('url'),
    jsdom = require('jsdom'),
    child_proc = require('child_process'),
    w = 400,
    h = 400,
    scripts = ["file://"+__dirname+"/../d3.min.js",
               "file://"+__dirname+"/../d3.layout.min.js",
               "file://"+__dirname+"/pie.js"],
    htmlStub = '<!DOCTYPE html><div id="pie" style="width:'+w+'px;height:'+h+'px;"></div>';

http.createServer(function (req, res) {
  var values = (url.parse(req.url, true).query['values'] || ".5,.5")
        .split(",")
        .map(function(v){return parseFloat(v)});
  // 去除生成图片的代码
  //convert.stdout.on('data', function (data) {
  //  res.write(data);
  //});
  //convert.on('exit', function(code) {
  //  res.end();
  //});

  jsdom.env({features:{QuerySelector:true}, html:htmlStub, scripts:scripts, done:function(errors, window) {
    var svgsrc = window.insertPie("#pie", w, h, values).innerHTML;
    //jsdom's domToHTML will lowercase element names
    svgsrc = svgsrc.replace(/radialgradient/g,'radialGradient');
    res.writeHead(200, {'Content-Type': 'image/svg+xml'});
    res.write(svgsrc);
    res.end();
  // 去除生成图片的代码
  //  convert.stdin.write(svgsrc);
  //  convert.stdin.end();
  }});
}).listen(8888, "0.0.0.0");

console.log('Pie SVG server running at http://127.0.0.1:8888/');
console.log('ex. http://127.0.0.1:8888/?values=.4,.3,.2,.1');

用node.js运行后,使用下面页面即可:

<!DOCTYPE html>
<html>
  <!-- Tests using the OBJECT syntax to embed an SVG file -->

  <head>

    <!-- Optional meta tag; if left off, we default to only using the Flash
         renderer for Internet Explorer and using native support on other
         browsers. You can force the Flash renderer for all browsers by
         setting the META tag below to true. -->
    <!-- meta name="svg.render.forceflash" content="true" / -->  <!-- disabled  -->

    <script src="../../src/svg.js" data-path="../../src/"></script>
  </head>

  <body>
    <h1>Tests using the OBJECT syntax to embed an SVG file</h1>

    <!--[if !IE]>-->
      <object data="http://localhost:8888/?values=.4,.3,.2,.1" type="image/svg+xml"
              width="1250" height="750" id="mySVGObject"> <!--<![endif]-->
    <!--[if lt IE 9]>
      <object src="http://localhost:8888/?values=.4,.3,.2,.1" classid="image/svg+xml"
              width="1250" height="750" id="mySVGObject"> <![endif]-->
    <!--[if gte IE 9]>
      <object data="http://localhost:8888/?values=.4,.3,.2,.1" type="image/svg+xml"
              width="1250" height="750" id="mySVGObject"> <![endif]-->
      </object>

    <h1>Test HTML H1</h1>
  </body>
</html>

龙年将至,发文记之,期待腾飞。

分类: Coding, Linux, Ubuntu, 技巧 标签: ,

Ubuntu开机挂载ntfs硬盘内容

2011年11月27日 没有评论
No Gravatar

把照片整理到老硬盘上之后,以前一直是在nautilus里手工挂载,昨天晚上一时高兴将之umount了。就想如果开机自动挂载会更好些。

于是在/etc/fstab里加入了

/dev/sda1 /opt/photos ext4 defaults 0 2

但是启动的时候发现提示无法挂载。

思路真是乱了,原来的硬盘是NTFS分区!

/dev/sda1 /opt/photos ntfs-3g defaults,locale=en_US.UTF-8 0 2

终于可以mount上了。现在的配置文件基本上都使用UUID来进行设备的加载,查了一下,可以通过

ls /dev/disk/by-uuid/ -l

来获得磁盘的UUID信息。于是/dev/sda1就变成了类似UUID=1234567890ABCDEF的样子。

顺便解释一下几个参数。

/dev/sda1或者UUID=123456列指的是分区或者设备。

/opt/photos列指的是挂载点。就是启动后你可以通过/opt/photos访问上面的分区或设备。

ext4/ntfs/ntfs-3g指的是分区的类型。其中ntfs-3g现在跟ntfs已经没有区别了。按照这个问答的内容,我们ls /sbin/mount.ntfs -l 可以清晰的看到它指向的是mount.ntfs-3g。

defaults,locale=en_US.UTF-8一列指的是挂载选项。详细的内容可以参照这里

0这一列,就是第5列指的是dump选项。dump是一个备份工具。如果是0,就会忽略。

2这一列,就是第6列指的是fsck选项。无需检查的话就是0。不为了的话就是检查的顺序。1当然应该是/或者/boot,这里就随便指定了个2.

10。世界很2。

分类: Linux, Ubuntu, 技术 标签: , , , ,

Ubuntu 10.10安装vim

2011年11月26日 2 条评论
No Gravatar
再次重新整理一下vim的安装:
1. 系统和主要插件
sudo apt-get install vim vim-gui-common vim-gnome vim-addon-manager vim-scripts cscope vim-doc ttf-dejavu persgml libtemplate-perl cbrowser
2. 字体
/usr/share/fonts/truetype/
wget -c http://www.gringod.com/wp-upload/MONACO.TTF -O monaco.ttf
3. 喜欢的一个主题:cobalt
需要安装到:.vim/colors
wget -c http://www.vim.org/scripts/download_script.php?src_id=15086 -O cobalt.vim
4. 其它常用插件:
sudo vim-addons install ctags taglist winmanager bufexplorer colors\ sampler\ pack
5. 如果你开发RoR:
sudo gem install VimMate
注:如果提示你需要gtk2模块,需要:
sudo apt-get install ruby-gnome2
reference:

1. http://www.lowing.org/fonts/
2. Pydiction : Tab-complete your Python code
3. 磨快你的RoR开发军刀 (vim配置)
4.

分类: Linux, Ubuntu, 技术 标签: , , , ,

Ubuntu 11.10,还有很长的路要走

2011年10月21日 没有评论
No Gravatar

在吐槽之前,回忆一下这几天将Ubuntu升级到11.10的过程。
话说上周五之前,一切还都是那样美好。虽然nvidia并没有因为可以接3个显示器就支持它,虽然因为编译cheese导致我的amd显卡的台式机ubuntu-desktop出现问题后也出现了多屏的配置问题,但最后都解决了。
周五的时候因为已经提醒可以更新新版了就将笔记本(nvidia显卡)带回家。升级过程很顺利。不顺利的是amd显卡的那台。一番折腾之总算好了。不过是少了一个链接。
周一到单位之后一接上那台显示器之后发现无法启动双屏:
1. 如果设置TwinView则黑屏

2. 黑屏后如果将TwinView改成Disabled则出现对话框:Failed to set MetaMode (1) ‘DFP-0: nvidia-auto-select @ 1920×1080 +0+0′ (Mode 1920×1080, id: 140) on X screen 0.

3. 再进入nvidia-settings 则原来的第二个显示器信息消失

参考了以下文章:

安装:sudo apt-get install libgl1-mesa-dri-experimental

安装nvidia 285驱动,结果死活pre-install script就过不去。这个闭源的驱动真不爽。折腾几回还是回到10.10吧, 前一段时间体验Unity已经有点烦了。反正家里还有一台是11.10。:)

阅读全文…

分类: Linux, Ubuntu 标签: , , , , ,

琐事:升级Ubuntu到11.10

2011年10月16日 1 条评论
No Gravatar

前几天刚学习了一句英语:

三十年河东,三十年河西

The river runs to the east for 30 years, the river runs to the west for 30 years

前段时间夸奖了AMD的驱动符合标准。这次升级过程就以使用NVidia显示的笔电为先。升级非常顺利。结合上次从10.10升级到11.04的愉快经验,最近Ubuntu在upgrading这个环节做的是越来越好了。

不过确实是三十年河东、三十年河西,上次升级没出现问题的台式机(使用的是AMD4850)出问题了。

1. 安装完驱动fglrx之后:

The selected configuration for displays could not be applied
requested position/size for CRTC 147 is outside the allowed limit: position=(1920,312), size=(1366, 768 ), maximum=(1920, 1920)”

2. 改安装fglrx post-release updates之后,Unity消失,进入X显示的是桌面nautilus的菜单

用了最傻的办法重新安装,结果发现问题还是如故。

在terminal下执行amdcccle发现提示,缺失libGL.so.1。在/usr/lib/目录中并没有这个文件,也许它是原因了。locate libGL.so.1发现它在/usr/lib/x86_64-linux-gnu/mesa/中,加入下面的链接:

sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so.1

OK.

关于三十年河东,三十年河西,参考:

百度百科,关于“三十年河东,三十年河西”词条的解释。 注意有黄河改道和郭子仪后人的两种解释。

nvidia Ubuntu下无法检测第二个显示器的问题

2011年9月20日 没有评论
No Gravatar

nvidia multi-monitor configure under Ubuntu

原来第二个显示器可以检测出来,后来拿走后就只能检测出来640×480了,经过复杂的过程发现需要在device段加入:

Option         “UseDisplayDevice” “DFP”

QUMI投影也可用了。

:

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 270.41.06  (buildmeister@swio-display-x86-rhel47-08.nvidia.com)  Mon Apr 18 15:14:00 PDT 2011
Section “ServerLayout”
    Identifier     “Layout0″
    Screen      0  ”Screen0″ 0 0
    InputDevice    ”Keyboard0″ “CoreKeyboard”
    InputDevice    ”Mouse0″ “CorePointer”
EndSection
Section “Files”
EndSection
Section “InputDevice”
    # generated from default
    Identifier     “Mouse0″
    Driver         “mouse”
    Option         “Protocol” “auto”
    Option         “Device” “/dev/psaux”
    Option         “Emulate3Buttons” “no”
    Option         “ZAxisMapping” “4 5″
EndSection
Section “InputDevice”
    # generated from default
    Identifier     “Keyboard0″
    Driver         “kbd”
EndSection
Section “Monitor”
    Identifier     “Monitor0″
    VendorName     “Unknown”
    ModelName      ”Unknown”
    HorizSync       28.0 – 33.0
    VertRefresh     43.0 – 72.0
    Option         “DPMS”
EndSection
Section “Device”
    Identifier     “Device0″
    Driver         “nvidia”
    VendorName     “NVIDIA Corporation”
    Option         “UseDisplayDevice” “DFP” # <<<<< important
EndSection
Section “Screen”
    Identifier     “Screen0″
    Device         “Device0″
    Monitor        ”Monitor0″
    DefaultDepth    24
    #Option         “UseEdid” “FALSE”
    #Option         “UseEdidFreqs” “FALSE”
    #Option         “NoDFPNativeResolutionCheck”
    SubSection     “Display”
        Depth       24
    EndSubSection
EndSection

Switch to our mobile site